You are viewing a plain text version of this content. The canonical link for it is here.
Posted to xang-cvs@xml.apache.org by md...@apache.org on 2001/08/07 08:21:15 UTC
cvs commit: xml-xang/java/samples system.script.xml
mdierken 01/08/06 23:21:15
Modified: java/samples system.script.xml
Log:
Add transform() method and use javax.xml.transform to abstrat knowledge of Xalan.
Revision Changes Path
1.2 +25 -23 xml-xang/java/samples/system.script.xml
Index: system.script.xml
===================================================================
RCS file: /home/cvs/xml-xang/java/samples/system.script.xml,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- system.script.xml 2000/09/13 18:40:26 1.1
+++ system.script.xml 2001/08/07 06:21:15 1.2
@@ -9,7 +9,7 @@
{
var value;
value=null;
-
+
while ((element != null) && (element.getNodeType() == 1))
{
value = element.getAttribute(name);
@@ -26,6 +26,22 @@
return getInheritedAttribute(element,'layout');
}
+// This uses the latest Xalan code
+function transform(source,layout,output)
+{
+ tFactory = Packages.javax.xml.transform.TransformerFactory.newInstance();
+
+ xmlSource = new Packages.javax.xml.transform.dom.DOMSource(source);
+ url = new Packages.java.net.URL(layout);
+ stream = url.openStream();
+ xslSource = new Packages.javax.xml.transform.stream.StreamSource(stream);
+
+ // Generate the transformer.
+ transformer = tFactory.newTransformer(xslSource);
+ // Perform the transformation, sending the output to the response.
+ transformer.transform(xmlSource,new Packages.javax.xml.transform.stream.StreamResult(output));
+}
+
/**
* This determines which XSL stylesheet to use and applies the stylesheet to the targeted
* element.
@@ -44,16 +60,16 @@
context.getResponse().sendError(404,"Page not found.");
return;
}
-
+
// require a trailing slash.
var path;
path = context.getRequest().getPathInfo();
- if (path.charAt(path.length-1) != '/')
+ if (path != null && path.charAt(path.length-1) != '/')
{
app.redirectTo(context,path+"/");
return;
}
-
+
// get the url to the XSL to use for the transform.
base = getInheritedAttribute(xml,'resources.server');
@@ -66,29 +82,15 @@
if (base != null && (layout.indexOf(':') <= 1))
{
media_root = Packages.org.apache.xang.util.ServletUtil.getRealPath(context);
+
layout = media_root + "/" + base + layout;
- layout = "file:///"+Packages.org.apache.xang.util.ServletUtil.resolveURL(layout);
+ layout = "file://localhost/"+Packages.org.apache.xang.util.ServletUtil.resolveURL(layout);
}
if (layout != null)
{
context.getResponse().setContentType("text/html");
- // do XSL via Xalan
- {
- processor = Packages.org.apache.xalan.xslt.XSLTProcessorFactory.getProcessorUsingLiaisonName("org.apache.xalan.xpath.xdom.XercesLiaison");
-
- source = new Packages.org.apache.xalan.xslt.XSLTInputSource();
- source.setNode(xml);
-
- stylesheet = new Packages.org.apache.xalan.xslt.XSLTInputSource();
- stylesheet.setSystemId(layout);
-
- output = new Packages.org.apache.xalan.xslt.XSLTResultTarget();
- output.setCharacterStream(doc);
-
- processor.process(source,stylesheet,output);
- }
-
+ transform(xml,layout,doc);
doc.flush();
}
}
@@ -110,7 +112,7 @@
doc = context.getResponse().getWriter();
util = new Packages.org.apache.xang.util.TextUtil();
-
+
s = "<html><body><pre>";
s += util.encodeToHTML(app.loadScript(null));
@@ -118,5 +120,5 @@
doc.println(s);
doc.flush();
}
-]]>
+]]>
</script>
---------------------------------------------------------------------
To unsubscribe, e-mail: xang-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xang-cvs-help@xml.apache.org