Author: nbelaevski
Date: 2008-12-07 09:04:12 -0500 (Sun, 07 Dec 2008)
New Revision: 11614
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
Log:
Null string passed to TemplateEncoderRendererBase encoded to JS null
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2008-12-07
02:08:14 UTC (rev 11613)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2008-12-07
14:04:12 UTC (rev 11614)
@@ -77,62 +77,66 @@
}
public void writeScriptBody(Writer writer, String string) throws IOException {
- Properties tidyProperties = new Properties();
- InputStream propertiesStream = null;
- try {
- propertiesStream = URLToStreamHelper.urlToStreamSafe(
- TidyXMLFilter.class.getResource("tidy.properties"));
- tidyProperties.load(propertiesStream);
- } finally {
- if (propertiesStream != null) {
- propertiesStream.close();
+ if (string != null) {
+ Properties tidyProperties = new Properties();
+ InputStream propertiesStream = null;
+ try {
+ propertiesStream = URLToStreamHelper.urlToStreamSafe(
+ TidyXMLFilter.class.getResource("tidy.properties"));
+ tidyProperties.load(propertiesStream);
+ } finally {
+ if (propertiesStream != null) {
+ propertiesStream.close();
+ }
}
- }
-
- TidyParser tidyParser = new TidyParser(tidyProperties);
- Document parsedHtml = tidyParser.parseHtmlByTidy(new StringReader(string), null);
-
- Element documentElement = null;
-
- if (parsedHtml != null) {
- documentElement = parsedHtml.getDocumentElement();
- }
-
- if (documentElement != null) {
- writer.write("[");
+
+ TidyParser tidyParser = new TidyParser(tidyProperties);
+ Document parsedHtml = tidyParser.parseHtmlByTidy(new StringReader(string), null);
+
+ Element documentElement = null;
- NodeList nodeList = documentElement.getChildNodes();
- Node bodyNode = nodeList.item(nodeList.getLength() - 1);
- NodeList bodyChildren = bodyNode.getChildNodes();
- int bodyChildrenLength = bodyChildren.getLength();
-
- try {
- Transformer transformer;
-
- TransformerFactory factory = getTransformerFactory();
+ if (parsedHtml != null) {
+ documentElement = parsedHtml.getDocumentElement();
+ }
+
+ if (documentElement != null) {
+ writer.write("[");
- synchronized (factory) {
- transformer = factory.newTransformer();
- }
-
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
-
- ContentHandler contentHandler = createContentHandler(writer);
- Result result = new SAXResult(contentHandler);
-
- for (int i = 0; i < bodyChildrenLength; i++) {
- if (i != 0) {
- writer.write(", ");
+ NodeList nodeList = documentElement.getChildNodes();
+ Node bodyNode = nodeList.item(nodeList.getLength() - 1);
+ NodeList bodyChildren = bodyNode.getChildNodes();
+ int bodyChildrenLength = bodyChildren.getLength();
+
+ try {
+ Transformer transformer;
+
+ TransformerFactory factory = getTransformerFactory();
+
+ synchronized (factory) {
+ transformer = factory.newTransformer();
}
- transformer.transform(new DOMSource(bodyChildren.item(i)), result);
+
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+
+ ContentHandler contentHandler = createContentHandler(writer);
+ Result result = new SAXResult(contentHandler);
+
+ for (int i = 0; i < bodyChildrenLength; i++) {
+ if (i != 0) {
+ writer.write(", ");
+ }
+ transformer.transform(new DOMSource(bodyChildren.item(i)), result);
+ }
+ } catch (TransformerException e) {
+ throw new IOException(e.getMessage());
}
- } catch (TransformerException e) {
- throw new IOException(e.getMessage());
+
+ writer.write("]");
+
+ } else {
+ writer.write(ScriptUtils.toScript(JSReference.NULL));
}
-
- writer.write("]");
-
} else {
writer.write(ScriptUtils.toScript(JSReference.NULL));
}