Methods Summary |
---|
public void | destroy()Cleanup; called when applet is terminated and unloaded.
if (null != m_trustedWorker)
{
m_trustedWorker.stop();
// m_trustedWorker.destroy();
m_trustedWorker = null;
}
m_styleURLOfCached = null;
m_documentURLOfCached = null;
|
public java.lang.String | escapeString(java.lang.String s)Given a String containing markup, escape the markup so it
can be displayed in the browser.
StringBuffer sb = new StringBuffer();
int length = s.length();
for (int i = 0; i < length; i++)
{
char ch = s.charAt(i);
if ('<" == ch)
{
sb.append("<");
}
else if ('>" == ch)
{
sb.append(">");
}
else if ('&" == ch)
{
sb.append("&");
}
else if (0xd800 <= ch && ch < 0xdc00)
{
// UTF-16 surrogate
int next;
if (i + 1 >= length)
{
throw new RuntimeException(
XSLMessages.createMessage(
XSLTErrorResources.ER_INVALID_UTF16_SURROGATE,
new Object[]{ Integer.toHexString(ch) })); //"Invalid UTF-16 surrogate detected: "
//+Integer.toHexString(ch)+ " ?");
}
else
{
next = s.charAt(++i);
if (!(0xdc00 <= next && next < 0xe000))
throw new RuntimeException(
XSLMessages.createMessage(
XSLTErrorResources.ER_INVALID_UTF16_SURROGATE,
new Object[]{
Integer.toHexString(ch) + " "
+ Integer.toHexString(next) })); //"Invalid UTF-16 surrogate detected: "
//+Integer.toHexString(ch)+" "+Integer.toHexString(next));
next = ((ch - 0xd800) << 10) + next - 0xdc00 + 0x00010000;
}
sb.append("");
sb.append(Integer.toHexString(next));
sb.append(";");
}
else
{
sb.append(ch);
}
}
return sb.toString();
|
public void | freeCache()The processor keeps a cache of the source and
style trees, so call this method if they have changed
or you want to do garbage collection.
m_styleURLOfCached = null;
m_documentURLOfCached = null;
|
public java.lang.String | getAppletInfo()Get basic information about the applet
return "Name: XSLTProcessorApplet\r\n" + "Author: Scott Boag";
|
public java.lang.String | getHtmlText()Assuming the stylesheet URL and the input XML URL have been set,
perform the transformation and return the result as a String.
m_trustedAgent.m_getData = true;
m_callThread = Thread.currentThread();
try
{
synchronized (m_callThread)
{
m_callThread.wait();
}
}
catch (InterruptedException ie)
{
System.out.println(ie.getMessage());
}
return m_htmlText;
|
public java.lang.String[][] | getParameterInfo()Get descriptions of the applet parameters.
String[][] info =
{
{ PARAM_styleURL, "String", "URL to an XSL stylesheet" },
{ PARAM_documentURL, "String", "URL to an XML document" },
};
return info;
|
public java.lang.String | getResultTreeAsText()Get the HTML result Tree as a text string suitable
for display in a browser. Note that this is for display of the
XML itself, not for rendering of HTML by the browser.
return escapeString(getHtmlText());
|
private java.lang.String | getSource()Use a Transformer to copy the source document
to a StreamResult.
StringWriter osw = new StringWriter();
PrintWriter pw = new PrintWriter(osw, false);
String text = "";
try
{
URL docURL = new URL(m_documentBase, m_treeURL);
synchronized (m_tfactory)
{
Transformer transformer = m_tfactory.newTransformer();
StreamSource source = new StreamSource(docURL.toString());
StreamResult result = new StreamResult(pw);
transformer.transform(source, result);
text = osw.toString();
}
}
catch (MalformedURLException e)
{
e.printStackTrace();
System.exit(-1);
}
catch (Exception any_error)
{
any_error.printStackTrace();
}
return text;
|
public java.lang.String | getSourceTreeAsText()Get the XML source Tree as a text string suitable
for display in a browser. Note that this is for display of the
XML itself, not for rendering of HTML by the browser.
return getTreeAsText(m_documentURL);
|
public java.lang.String | getStyleTreeAsText()Get the XSL style Tree as a text string suitable
for display in a browser. Note that this is for display of the
XML itself, not for rendering of HTML by the browser.
return getTreeAsText(m_styleURL);
|
public java.lang.String | getTreeAsText(java.lang.String treeURL)Get an XML document (or stylesheet)
m_treeURL = treeURL;
m_trustedAgent.m_getData = true;
m_trustedAgent.m_getSource = true;
m_callThread = Thread.currentThread();
try
{
synchronized (m_callThread)
{
m_callThread.wait();
}
}
catch (InterruptedException ie)
{
System.out.println(ie.getMessage());
}
return m_sourceText;
|
public void | init()Standard applet initialization.
// PARAMETER SUPPORT
// The following code retrieves the value of each parameter
// specified with the <PARAM> tag and stores it in a member
// variable.
//----------------------------------------------------------------------
String param;
// styleURL: Parameter description
//----------------------------------------------------------------------
param = getParameter(PARAM_styleURL);
// stylesheet parameters
m_parameters = new Hashtable();
if (param != null)
setStyleURL(param);
// documentURL: Parameter description
//----------------------------------------------------------------------
param = getParameter(PARAM_documentURL);
if (param != null)
setDocumentURL(param);
m_codeBase = this.getCodeBase();
m_documentBase = this.getDocumentBase();
// If you use a ResourceWizard-generated "control creator" class to
// arrange controls in your applet, you may want to call its
// CreateControls() method from within this method. Remove the following
// call to resize() before adding the call to CreateControls();
// CreateControls() does its own resizing.
//----------------------------------------------------------------------
resize(320, 240);
|
public void | paint(java.awt.Graphics g)Do not call; this applet contains no UI or visual components.
|
private java.lang.String | processTransformation()Process the transformation.
String htmlData = null;
this.showStatus("Waiting for Transformer and Parser to finish loading and JITing...");
synchronized (m_tfactory)
{
URL documentURL = null;
URL styleURL = null;
StringWriter osw = new StringWriter();
PrintWriter pw = new PrintWriter(osw, false);
StreamResult result = new StreamResult(pw);
this.showStatus("Begin Transformation...");
try
{
documentURL = new URL(m_codeBase, m_documentURL);
StreamSource xmlSource = new StreamSource(documentURL.toString());
styleURL = new URL(m_codeBase, m_styleURL);
StreamSource xslSource = new StreamSource(styleURL.toString());
Transformer transformer = m_tfactory.newTransformer(xslSource);
m_keys = m_parameters.keys();
while (m_keys.hasMoreElements()){
Object key = m_keys.nextElement();
Object expression = m_parameters.get(key);
transformer.setParameter((String) key, expression);
}
transformer.transform(xmlSource, result);
}
catch (TransformerConfigurationException tfe)
{
tfe.printStackTrace();
System.exit(-1);
}
catch (MalformedURLException e)
{
e.printStackTrace();
System.exit(-1);
}
this.showStatus("Transformation Done!");
htmlData = osw.toString();
}
return htmlData;
|
public void | setDocumentURL(java.lang.String urlString)Set the URL to the XML document that will be transformed
with the XSL stylesheet. No processing is done yet.
m_documentURL = urlString;
|
public void | setStyleSheetAttribute(java.lang.String nameOfIDAttrOfElemToModify, java.lang.String elemId, java.lang.String attrName, java.lang.String value)Set an attribute in the stylesheet, which gives the ability
to have some dynamic selection control.
m_nameOfIDAttrOfElemToModify = nameOfIDAttrOfElemToModify;
m_elemIdToModify = elemId;
m_attrNameToSet = attrName;
m_attrValueToSet = value;
|
public void | setStyleURL(java.lang.String urlString)Set the URL to the XSL stylesheet that will be used
to transform the input XML. No processing is done yet.
m_styleURL = urlString;
|
public void | setStylesheetParam(java.lang.String key, java.lang.String expr)Submit a stylesheet parameter.
m_parameters.put(key, expr);
|
public void | start()Automatically called when the HTML client containing the applet loads.
This method starts execution of the applet thread.
m_trustedAgent = new TrustedAgent();
Thread currentThread = Thread.currentThread();
m_trustedWorker = new Thread(currentThread.getThreadGroup(),
m_trustedAgent);
m_trustedWorker.start();
try
{
m_tfactory = TransformerFactory.newInstance();
this.showStatus("Causing Transformer and Parser to Load and JIT...");
// Prime the pump so that subsequent transforms are faster.
StringReader xmlbuf = new StringReader("<?xml version='1.0'?><foo/>");
StringReader xslbuf = new StringReader(
"<?xml version='1.0'?><xsl:stylesheet xmlns:xsl='http://www.w3.org/1999/XSL/Transform' version='1.0'><xsl:template match='foo'><out/></xsl:template></xsl:stylesheet>");
PrintWriter pw = new PrintWriter(new StringWriter());
synchronized (m_tfactory)
{
Templates templates = m_tfactory.newTemplates(new StreamSource(xslbuf));
Transformer transformer = templates.newTransformer();
transformer.transform(new StreamSource(xmlbuf), new StreamResult(pw));
}
System.out.println("Primed the pump!");
this.showStatus("Ready to go!");
}
catch (Exception e)
{
this.showStatus("Could not prime the pump!");
System.out.println("Could not prime the pump!");
e.printStackTrace();
}
|
public void | stop()Automatically called when the HTML page containing the applet is no longer
on the screen. Stops execution of the applet thread.
if (null != m_trustedWorker)
{
m_trustedWorker.stop();
// m_trustedWorker.destroy();
m_trustedWorker = null;
}
m_styleURLOfCached = null;
m_documentURLOfCached = null;
|
public java.lang.String | transformToHtml(java.lang.String doc, java.lang.String style)Process a document and a stylesheet and return
the transformation result. If one of these is null, the
existing value (of a previous transformation) is not affected.
if (null != doc)
{
m_documentURL = doc;
}
if (null != style)
{
m_styleURL = style;
}
return getHtmlText();
|
public java.lang.String | transformToHtml(java.lang.String doc)Process a document and a stylesheet and return
the transformation result. Use the xsl:stylesheet PI to find the
document, if one exists.
if (null != doc)
{
m_documentURL = doc;
}
m_styleURL = null;
return getHtmlText();
|