Author: maksimkaszynski
Date: 2008-03-20 13:00:41 -0400 (Thu, 20 Mar 2008)
New Revision: 7020
Added:
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java
Modified:
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java
Log:
used parser from config
Modified: trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java
===================================================================
---
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-20
16:44:40 UTC (rev 7019)
+++
trunk/framework/impl/src/main/java/org/ajax4jsf/renderkit/RendererUtils.java 2008-03-20
17:00:41 UTC (rev 7020)
@@ -262,6 +262,7 @@
public static final String valign_ATTRIBUTE = "valign";
public static final String a_ELEMENT = "a";
public static final String HTML_ELEMENT = "html";
+ public static final String HEAD_ELEMENT = "head";
public static final String BODY_ELEMENT = "body";
public static final String TR_ELEMENT = "tr";
public static final String CAPTION_ELEMENT = "caption";
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-20
16:44:40 UTC (rev 7019)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/BaseXMLFilter.java 2008-03-20
17:00:41 UTC (rev 7020)
@@ -32,7 +32,6 @@
import javax.faces.context.FacesContext;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
-import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.ServletOutputStream;
import javax.servlet.ServletRequest;
@@ -79,6 +78,8 @@
public static final String TEXT_HTML = "text/html";
public static final String APPLICATION_XHTML_XML = "application/xhtml+xml";
+
+ private static BaseXMLFilter INSTANCE;
public BaseFilter filter;
@@ -86,11 +87,10 @@
this.filter = filter;
}
+ static BaseXMLFilter getInstance(FacesContext context) {
+ return INSTANCE;//(BaseXMLFilter)
context.getExternalContext().getApplicationMap().get(APPLICATION_SCOPE_KEY);
+ }
- /*public static final BaseXMLFilter getInstance(FacesContext context) {
- return (BaseXMLFilter)
context.getExternalContext().getApplicationMap().get(APPLICATION_SCOPE_KEY);
- }*/
-
public void init(FilterConfig config) throws ServletException {
if (log.isDebugEnabled()) {
@@ -113,7 +113,7 @@
getNamespace()));
- config.getServletContext().setAttribute(APPLICATION_SCOPE_KEY, this);
+ INSTANCE = this;
}
@@ -189,10 +189,10 @@
response.addCookie(cookie);
}
// Copy response headers
- Map headers = servletResponseWrapper.getHeaders();
- for (Iterator iter = headers.entrySet().iterator(); iter
+ Map<String, Object> headers = servletResponseWrapper.getHeaders();
+ for (Iterator<Map.Entry<String, Object>> iter =
headers.entrySet().iterator(); iter
.hasNext();) {
- Map.Entry header = (Map.Entry) iter.next();
+ Map.Entry<String, Object> header = iter.next();
response.setHeader((String) header.getKey(),
(String) header.getValue());
}
Added: trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java
===================================================================
--- trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java
(rev 0)
+++ trunk/framework/impl/src/main/java/org/ajax4jsf/webapp/ParserFacade.java 2008-03-20
17:00:41 UTC (rev 7020)
@@ -0,0 +1,40 @@
+/**
+ *
+ */
+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 BaseXMLFilter filter;
+
+ private FacesContext context;
+
+ public static ParserFacade newInstance(FacesContext context) {
+ return new ParserFacade(context);
+ }
+
+ private ParserFacade(FacesContext context) {
+ super();
+ this.context = context;
+ this.filter = BaseXMLFilter.getInstance(context);
+ }
+
+ public void parseHtml(Reader input, Writer output) throws IOException {
+ UIViewRoot viewRoot = context.getViewRoot();
+ HtmlParser parser = filter.getParser(filter.getMimetype(), true,
viewRoot.getViewId());
+ parser.parseHtml(input, output);
+ filter.reuseParser(parser);
+ }
+
+}
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-20
16:44:40 UTC (rev 7019)
+++
trunk/framework/impl/src/main/java/org/richfaces/renderkit/TemplateEncoderRendererBase.java 2008-03-20
17:00:41 UTC (rev 7020)
@@ -16,6 +16,9 @@
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,6 +31,7 @@
import org.ajax4jsf.javascript.ScriptUtils;
import org.ajax4jsf.renderkit.HeaderResourcesRendererBase;
import org.ajax4jsf.resource.util.URLToStreamHelper;
+import org.ajax4jsf.webapp.ParserFacade;
import org.ajax4jsf.webapp.tidy.TidyParser;
import org.ajax4jsf.webapp.tidy.TidyXMLFilter;
import org.richfaces.component.TemplateComponent;
@@ -36,6 +40,8 @@
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,25 +66,18 @@
}
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();
- }
- }
+ ParserFacade parserFacade =
ParserFacade.newInstance(FacesContext.getCurrentInstance());
+ StringReader stringReader = new StringReader(string);
+ StringWriter stringWriter = new StringWriter();
+ parserFacade.parseHtml(stringReader, stringWriter);
- TidyParser tidyParser = new TidyParser(tidyProperties);
- Document parsedHtml = tidyParser.parseHtmlByTidy(new StringReader(string), null);
+
+ Document document = parse(stringWriter.toString());
Element documentElement = null;
- if (parsedHtml != null) {
- documentElement = parsedHtml.getDocumentElement();
+ if (document != null) {
+ documentElement = document.getDocumentElement();
}
if (documentElement != null) {
@@ -121,6 +120,19 @@
}
}
+ 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();
Show replies by date