vmassol 2002/12/01 01:32:03
Modified: framework/src/java/share/org/apache/cactus/server/runner
XMLTransformer.java
Log:
Fixed checkstyle errors + refactorings
Revision Changes Path
1.2 +43 -23
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/XMLTransformer.java
Index: XMLTransformer.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/runner/XMLTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- XMLTransformer.java 28 Nov 2002 20:06:07 -0000 1.1
+++ XMLTransformer.java 1 Dec 2002 09:32:03 -0000 1.2
@@ -74,7 +74,8 @@
* some output format determined by a stylesheet.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Christopher Lenz</a>
- *
+ * @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
+ *
* @version $Id$
*/
public class XMLTransformer
@@ -125,7 +126,7 @@
/**
* The MIME type of the content we'll be sending to the client. This
- * defaults to "text/html", but depends on the provided XSLT stylesheet.
+ * defaults to "text/xml", but depends on the provided XSLT stylesheet.
*/
private String contentType = XML_MIME_TYPE;
@@ -136,6 +137,8 @@
*
* @param theStylesheet The input stream for the stylesheet to use for the
* transformations
+ * @exception TransformerConfigurationException if an error occurs when
+ * creating the XSL templates
*/
public XMLTransformer(InputStream theStylesheet)
throws TransformerConfigurationException
@@ -148,26 +151,15 @@
TransformerFactory transformerFactory =
TransformerFactory.newInstance();
Source source = new StreamSource(theStylesheet);
- templates =
- transformerFactory.newTemplates(source);
+ this.templates = transformerFactory.newTemplates(source);
+
// Find out which content type is produced by the
// stylesheet (valid values per XSLT 1.0 are 'xml', 'html'
// and 'text')
- String outputMethod =
- templates.getOutputProperties().getProperty(
- XSL_OUTPUT_PROPERTY_METHOD);
- if (HTML_OUTPUT_METHOD.equals(outputMethod))
- {
- contentType = HTML_MIME_TYPE;
- }
- else if (TEXT_OUTPUT_METHOD.equals(outputMethod))
- {
- contentType = TEXT_MIME_TYPE;
- }
- else if (XML_OUTPUT_METHOD.equals(outputMethod))
- {
- contentType = XML_MIME_TYPE;
- }
+ String outputMethod = this.templates.getOutputProperties().getProperty(
+ XSL_OUTPUT_PROPERTY_METHOD);
+
+ this.contentType = getContentType(outputMethod);
}
// Public Methods ----------------------------------------------------------
@@ -180,7 +172,7 @@
*/
public String getContentType()
{
- return contentType;
+ return this.contentType;
}
/**
@@ -189,13 +181,41 @@
* @param theXml The XML source to transform
* @param theWriter The writer to which the transformation result should be
* written.
+ * @exception TransformerException if an error occurs when applying the
+ * XSL template to the XML source
*/
public void transform(Reader theXml, Writer theWriter)
throws TransformerException
{
- Transformer transformer = templates.newTransformer();
- transformer.transform(new StreamSource(theXml),
+ Transformer transformer = this.templates.newTransformer();
+ transformer.transform(new StreamSource(theXml),
new StreamResult(theWriter));
+ }
+
+ // Private Methods --------------------------------------------------------
+
+ /**
+ * @param theOutputMethod the output method type (Ex: "xml", "html",
+ * "text", etc)
+ * @return the MIME type of the content we'll be sending to the client
+ */
+ private String getContentType(String theOutputMethod)
+ {
+ String contentType;
+
+ if (HTML_OUTPUT_METHOD.equals(theOutputMethod))
+ {
+ contentType = HTML_MIME_TYPE;
+ }
+ else if (TEXT_OUTPUT_METHOD.equals(theOutputMethod))
+ {
+ contentType = TEXT_MIME_TYPE;
+ }
+ else
+ {
+ contentType = XML_MIME_TYPE;
+ }
+ return contentType;
}
}
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>