Author: maksimkaszynski
Date: 2008-03-21 09:47:23 -0400 (Fri, 21 Mar 2008)
New Revision: 7047
Removed:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
Log:
Reverted changes from version reverted changes in BaseXMLFilter
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2008-03-21
13:35:56 UTC (rev 7046)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -79,19 +79,12 @@
public static final String APPLICATION_XHTML_XML = "application/xhtml+xml";
- private static BaseXMLFilter INSTANCE;
-
public BaseFilter filter;
public void setFilter(BaseFilter filter) {
this.filter = filter;
}
- static BaseXMLFilter getInstance(FacesContext context) {
- return INSTANCE;//(BaseXMLFilter)
context.getExternalContext().getApplicationMap().get(APPLICATION_SCOPE_KEY);
- }
-
-
public void init(FilterConfig config) throws ServletException {
if (log.isDebugEnabled()) {
log.debug("init XML filter service with class "
@@ -112,9 +105,6 @@
setNamespace((String) nz(config.getInitParameter(NAMESPACE_PARAMETER),
getNamespace()));
-
- INSTANCE = this;
-
}
/**
@@ -375,7 +365,7 @@
protected abstract void reuseParser(HtmlParser parser);
- public abstract HtmlParser getParser(String mimetype, boolean isAjax,
+ protected abstract HtmlParser getParser(String mimetype, boolean isAjax,
String viewId);
/**
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java 2008-03-21
13:35:56 UTC (rev 7046)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ConfigurableXMLFilter.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -103,7 +103,7 @@
* @see org.ajax4jsf.webapp.BaseXMLFilter#getParser(java.lang.String,
* boolean, java.lang.String)
*/
- public HtmlParser getParser(String mimetype, boolean isAjax,
+ protected HtmlParser getParser(String mimetype, boolean isAjax,
String viewId) {
HtmlParser parser = null;
Deleted: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java 2008-03-21
13:35:56 UTC (rev 7046)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -1,49 +0,0 @@
-/**
- *
- */
-package org.ajax4jsf.webapp;
-
-import java.io.IOException;
-import java.io.Reader;
-import java.io.Writer;
-
-import javax.faces.component.UIViewRoot;
-import javax.faces.context.FacesContext;
-
-/**
- * @author Maksim Kaszynski
- *
- */
-public class ParserFacade {
-
- private HtmlParser parser;
-
- private BaseXMLFilter filter;
-
- public static ParserFacade newInstance(FacesContext context) {
- return new ParserFacade(context);
- }
-
- public ParserFacade(FacesContext context) {
- super();
- this.filter = BaseXMLFilter.getInstance(context);
- this.parser = getParser(context, filter);
-
- }
-
- public void parseHtml(Reader input, Writer output) throws IOException {
- parser.parseHtml(input, output);
- reuseParser();
- }
-
- protected HtmlParser getParser(FacesContext context, BaseXMLFilter filter) {
- UIViewRoot viewRoot = context.getViewRoot();
- HtmlParser parser = filter.getParser(filter.getMimetype(), true,
viewRoot.getViewId());
- return parser;
- }
-
- protected void reuseParser() {
- filter.reuseParser(parser);
- }
-
-}
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java 2008-03-21
13:35:56 UTC (rev 7046)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/nekko/NekkoXMLFilter.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -36,7 +36,7 @@
public NekkoXMLFilter() {}
- public HtmlParser getParser(String mimetype, boolean isAjax, String viewId) {
+ protected HtmlParser getParser(String mimetype, boolean isAjax, String viewId) {
HtmlParser parser = null;
if( isAjax ){
parser = getXmlParser();
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java 2008-03-21
13:35:56 UTC (rev 7046)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/tidy/TidyXMLFilter.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -67,7 +67,7 @@
* @param string Encodings for parser
* @return
*/
- public HtmlParser getParser(String mime, boolean isAjax, String viewId) {
+ protected HtmlParser getParser(String mime, boolean isAjax, String viewId) {
// For non-ajax, parse only html types !
if (isAjax || mime.startsWith(TEXT_HTML) || mime.startsWith(APPLICATION_XHTML_XML)) {
if(isAjax || isForcexml()){
Modified:
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
===================================================================
---
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2008-03-21
13:35:56 UTC (rev 7046)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2008-03-21
13:47:23 UTC (rev 7047)
@@ -5,18 +5,17 @@
import java.io.BufferedReader;
import java.io.IOException;
+import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.io.StringReader;
import java.io.StringWriter;
import java.io.Writer;
+import java.util.Properties;
import javax.faces.component.UIComponent;
import javax.faces.context.FacesContext;
import javax.faces.context.ResponseWriter;
-import javax.xml.parsers.DocumentBuilder;
-import javax.xml.parsers.DocumentBuilderFactory;
-import javax.xml.parsers.ParserConfigurationException;
import javax.xml.transform.OutputKeys;
import javax.xml.transform.Result;
import javax.xml.transform.Transformer;
@@ -28,15 +27,15 @@
import org.ajax4jsf.javascript.JSReference;
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
-import org.ajax4jsf.webapp.ParserFacade;
+import org.ajax4jsf.resource.util.URLToStreamHelper;
+import org.ajax4jsf.webapp.tidy.TidyParser;
+import org.ajax4jsf.webapp.tidy.TidyXMLFilter;
import org.richfaces.component.TemplateComponent;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.xml.sax.ContentHandler;
-import org.xml.sax.InputSource;
-import org.xml.sax.SAXException;
/**
* @author Nick Belaevski - mailto:nbelaevski@exadel.com
@@ -60,88 +59,68 @@
return true;
}
- protected ParserFacade getParserFacade(FacesContext context) {
- return ParserFacade.newInstance(context);
- }
-
public void writeScriptBody(Writer writer, String string) throws IOException {
- ParserFacade parserFacade = getParserFacade(FacesContext.getCurrentInstance());
- StringReader stringReader = new StringReader(string);
- StringWriter stringWriter = new StringWriter();
- parserFacade.parseHtml(stringReader, stringWriter);
+ 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();
+ }
+ }
- boolean wroteAnything = false;
- String wellFormed = stringWriter.toString();
- if (wellFormed != null && wellFormed.length() > 0) {
- Document document = parse(wellFormed);
+ TidyParser tidyParser = new TidyParser(tidyProperties);
+ Document parsedHtml = tidyParser.parseHtmlByTidy(new StringReader(string), null);
- Element documentElement = null;
+ Element documentElement = null;
+
+ if (parsedHtml != null) {
+ documentElement = parsedHtml.getDocumentElement();
+ }
+
+ if (documentElement != null) {
+ writer.write("[");
- if (document != null) {
- documentElement = document.getDocumentElement();
- }
-
- if (documentElement != null) {
- writer.write("[");
-
- NodeList nodeList = documentElement.getChildNodes();
- Node bodyNode = nodeList.item(nodeList.getLength() - 1);
- NodeList bodyChildren = bodyNode.getChildNodes();
- int bodyChildrenLength = bodyChildren.getLength();
+ NodeList nodeList = documentElement.getChildNodes();
+ Node bodyNode = nodeList.item(nodeList.getLength() - 1);
+ NodeList bodyChildren = bodyNode.getChildNodes();
+ int bodyChildrenLength = bodyChildren.getLength();
- try {
- Transformer transformer;
+ try {
+ Transformer transformer;
- TransformerFactory factory = getTransformerFactory();
-
- synchronized (factory) {
- transformer = factory.newTransformer();
- }
+ TransformerFactory factory = getTransformerFactory();
+
+ synchronized (factory) {
+ transformer = factory.newTransformer();
+ }
- transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
- transformer.setOutputProperty(OutputKeys.METHOD, "xml");
+ transformer.setOutputProperty(OutputKeys.OMIT_XML_DECLARATION, "yes");
+ transformer.setOutputProperty(OutputKeys.METHOD, "xml");
- ContentHandler contentHandler = createContentHandler(writer);
- Result result = new SAXResult(contentHandler);
+ 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);
+ for (int i = 0; i < bodyChildrenLength; i++) {
+ if (i != 0) {
+ writer.write(", ");
}
-
-
- } catch (TransformerException e) {
- throw new IOException(e.getMessage());
+ transformer.transform(new DOMSource(bodyChildren.item(i)), result);
}
-
- writer.write("]");
-
- wroteAnything = true;
-
+ } catch (TransformerException e) {
+ throw new IOException(e.getMessage());
}
- }
+
+ writer.write("]");
-
- if (!wroteAnything) {
+ } else {
writer.write(ScriptUtils.toScript(JSReference.NULL));
}
}
- private Document parse(String xml) throws IOException {
- try {
- DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
- DocumentBuilder documentBuilder = builderFactory.newDocumentBuilder();
- Document document = documentBuilder.parse(new InputSource(new StringReader(xml)));
- return document;
- } catch (ParserConfigurationException e) {
- throw new IOException(e.getMessage());
- } catch (SAXException e) {
- throw new IOException(e.getMessage());
- }
- }
-
protected void writeScriptBody(FacesContext context, UIComponent component, boolean
children)
throws IOException {
ResponseWriter writer = context.getResponseWriter();