Author: alexsmirnov
Date: 2007-07-10 14:21:27 -0400 (Tue, 10 Jul 2007)
New Revision: 306
Added:
trunk/framework/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekoParserTestCase.java
Modified:
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java
trunk/framework/src/main/java/org/ajax4jsf/xml/serializer/ToXHTMLStream.java
trunk/framework/src/main/resources/org/ajax4jsf/xml/serializer/output_xhtml.properties
Log:
Fix NekoFilter output according to the HTML DTD
Modified:
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java
===================================================================
---
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java 2007-07-09
18:34:57 UTC (rev 305)
+++
trunk/framework/src/main/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekkoParser.java 2007-07-10
18:21:27 UTC (rev 306)
@@ -68,582 +68,674 @@
/**
* @author shura
- *
+ *
*/
-public class NekkoParser implements HtmlParser {
+public class NekkoParser implements HtmlParser {
- private static final Log _log = LogFactory.getLog(NekkoParser.class);
-
- private HtmlSAXParser _parser;
-
-// private HtmlWriter _writer= new HtmlWriter();
-
- private ElementRemover remover = new ElementRemover();
-
- private XMLDocumentFilter[] _filters = { new ViewStateFilter()/*,remover */, new
HtmlCorrectionFilter(), new Purifier() /*, _writer*/ };
+ private static final Log _log = LogFactory.getLog(NekkoParser.class);
- private DOMFragmentParser viewStateParser ;//= new DOMFragmentParser();
+ private HtmlSAXParser _parser;
- private Document viewStateDocument ;//= new HTMLDocumentImpl();
+ // private HtmlWriter _writer= new HtmlWriter();
- private DocumentFragment fragment = null;
+ private ElementRemover remover = new ElementRemover();
- private Set _scripts;
-
- private Set _styles;
-
- private String _viewState;
-
- private String _encoding;
+ private XMLDocumentFilter[] _filters = {
+ new ViewStateFilter()/* ,remover */, new HtmlCorrectionFilter(),
+ new Purifier() /* , _writer */};
- private Serializer _serializer;
+ private DOMFragmentParser viewStateParser;// = new DOMFragmentParser();
- private String _publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
- private String _systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
- private String _namespace = "http://www.w3.org/1999/xhtml";
+ private Document viewStateDocument;// = new HTMLDocumentImpl();
- private String _outputEncoding;
- /**
- *
- */
- public NekkoParser() {
- _parser=new HtmlSAXParser(getHtmlConfig());
-// Properties properties =
OutputPropertiesFactory.getDefaultMethodProperties(Method.XHTML);
- Properties properties =
OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
-// properties.put("encoding",_encoding);
- _serializer = SerializerFactory.getSerializer(properties);
-// serializer.setOutputStream(output);
-// _parser.setContentHandler(serializer.asContentHandler());
- viewStateParser = new DOMFragmentParser();
- // Set parser features
- try {
- viewStateParser.setProperty(
- "http://cyberneko.org/html/properties/names/elems",
- "lower");
- viewStateParser.setProperty(
- "http://cyberneko.org/html/properties/names/attrs",
- "lower");
- } catch (SAXException e) {
- _log.error("Exception in DOM parser configuration", e);
- }
- try {
- // Create Document Builder Factory
- DocumentBuilderFactory docFactory = DocumentBuilderFactory
- .newInstance();
- // Create Document Builder
- DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
- viewStateDocument = docBuilder.newDocument();
- } catch (ParserConfigurationException e) {
- viewStateDocument = new HTMLDocumentImpl();
- _log.error("Error on create DOM Document by JAXP, use Xerxes implementation.
Check JAXP configuration ",e);
- }
-// viewStateDocument = new HTMLDocumentImpl();
- remover.removeElement("style");
+ private DocumentFragment fragment = null;
+
+ private Set _scripts;
+
+ private Set _styles;
+
+ private String _viewState;
+
+ private String _encoding;
+
+ private Serializer _serializer;
+
+ private String _publicId = "-//W3C//DTD XHTML 1.0 Transitional//EN";
+
+ private String _systemid =
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd";
+
+ private String _namespace = "http://www.w3.org/1999/xhtml";
+
+ private String _outputEncoding;
+
+ /**
+ *
+ */
+ public NekkoParser() {
+ _parser = new HtmlSAXParser(getHtmlConfig());
+ Properties properties = OutputPropertiesFactory
+ .getDefaultMethodProperties(Method.XHTML);
+ // Properties properties =
+ // OutputPropertiesFactory.getDefaultMethodProperties(Method.XML);
+ // properties.put("encoding",_encoding);
+ _serializer = SerializerFactory.getSerializer(properties);
+ // serializer.setOutputStream(output);
+ // _parser.setContentHandler(serializer.asContentHandler());
+ viewStateParser = new DOMFragmentParser();
+ // Set parser features
+ try {
+ viewStateParser
+ .setProperty(
+ "http://cyberneko.org/html/properties/names/elems",
+ "lower");
+ viewStateParser
+ .setProperty(
+ "http://cyberneko.org/html/properties/names/attrs",
+ "lower");
+ } catch (SAXException e) {
+ _log.error("Exception in DOM parser configuration", e);
}
-
- /**
- * Reset parser state
- */
- public void reset(){
- _scripts=null;
- _styles=null;
- _viewState=null;
- _parser.reset();
- _serializer.reset();
+ try {
+ // Create Document Builder Factory
+ DocumentBuilderFactory docFactory = DocumentBuilderFactory
+ .newInstance();
+ // Create Document Builder
+ DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
+ viewStateDocument = docBuilder.newDocument();
+ } catch (ParserConfigurationException e) {
+ viewStateDocument = new HTMLDocumentImpl();
+ _log
+ .error(
+ "Error on create DOM Document by JAXP, use Xerxes implementation. Check JAXP
configuration ",
+ e);
}
+ // viewStateDocument = new HTMLDocumentImpl();
+ remover.removeElement("style");
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.InputStream,
java.io.OutputStream)
- */
- public void parseHtml(InputStream input, java.io.Writer output)
- throws IOException {
- InputSource src = new InputSource(input);
- parseSAXSource(src,output);
- }
+ /**
+ * Reset parser state
+ */
+ public void reset() {
+ _scripts = null;
+ _styles = null;
+ _viewState = null;
+ _parser.reset();
+ _serializer.reset();
+ }
- private void parseSAXSource(InputSource src, java.io.Writer output) throws IOException
{
-// PrintWriter printWriter = null;
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.InputStream,
+ * java.io.OutputStream)
+ */
+ public void parseHtml(InputStream input, java.io.Writer output)
+ throws IOException {
+ InputSource src = new InputSource(input);
+ parseSAXSource(src, output);
+ }
+
+ private void parseSAXSource(InputSource src, java.io.Writer output)
+ throws IOException {
+ // PrintWriter printWriter = null;
+ fragment = null;
+ if (null != _viewState) {
+ fragment = viewStateDocument.createDocumentFragment();
+ try {
+ viewStateParser.parse(new InputSource(new StringReader(
+ _viewState)), fragment);
+ } catch (Exception e) {
fragment = null;
- if(null != _viewState){
- fragment = viewStateDocument.createDocumentFragment();
- try {
- viewStateParser.parse(new InputSource(new StringReader(
- _viewState)), fragment);
- } catch (Exception e) {
- fragment = null;
- }
- // TODO - parse view state to DOM Fragment.
- }
- try {
-
_parser.setProperty("http://cyberneko.org/html/properties/default-en...;,
- _encoding);
- Properties properties = _serializer.getOutputFormat();
- properties.put("encoding",_outputEncoding);
- _serializer.setOutputFormat(properties);
- _serializer.setWriter(output);
-// _serializer.setOutputStream(new OutputStream(){
-//
-// public void write(int b) throws IOException {
-// // TODO Auto-generated method stub
-//
-// }});
- _parser.setContentHandler(_serializer.asContentHandler());
-// printWriter = new PrintWriter(output);
-// _writer.setWriter(printWriter);
-// _writer.setEncoding(_encoding);
- _parser.parse(src);
- } catch (SAXException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- } finally {
-// _writer.setWriter(null);
-// if(null != printWriter){
-// printWriter.flush();
-// printWriter.close();
-// }
-
- }
-
+ }
+ // TODO - parse view state to DOM Fragment.
}
+ try {
+ if (null != _encoding) {
+ _parser
+ .setProperty(
+ "http://cyberneko.org/html/properties/default-encoding",
+ _encoding);
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.Reader,
java.io.OutputStream)
- */
- public void parseHtml(Reader input, java.io.Writer output) throws IOException {
- InputSource src = new InputSource(input);
- parseSAXSource(src,output);
- }
+ }
+ Properties properties = _serializer.getOutputFormat();
+ if (null != _outputEncoding) {
+ properties.put("encoding", _outputEncoding);
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setEncoding(java.lang.String)
- */
- public void setInputEncoding(String encoding) {
- _encoding = encoding;
- }
+ }
+ _serializer.setOutputFormat(properties);
+ _serializer.setWriter(output);
+ // _serializer.setOutputStream(new OutputStream(){
+ //
+ // public void write(int b) throws IOException {
+ // // TODO Auto-generated method stub
+ //
+ // }});
+ _parser.setContentHandler(_serializer.asContentHandler());
+ // printWriter = new PrintWriter(output);
+ // _writer.setWriter(printWriter);
+ // _writer.setEncoding(_encoding);
+ _parser.parse(src);
+ } catch (SAXException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ } finally {
+ // _writer.setWriter(null);
+ // if(null != printWriter){
+ // printWriter.flush();
+ // printWriter.close();
+ // }
- public void setOutputEncoding(String encoding) {
- _outputEncoding = encoding;
}
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setMoveElements(boolean)
- */
- public void setMoveElements(boolean move) {
- // TODO Auto-generated method stub
- }
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setScripts(java.util.Set)
- */
- public void setScripts(Set scripts) {
- _scripts = scripts;
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#parseHtml(java.io.Reader,
+ * java.io.OutputStream)
+ */
+ public void parseHtml(Reader input, java.io.Writer output)
+ throws IOException {
+ InputSource src = new InputSource(input);
+ parseSAXSource(src, output);
+ }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setEncoding(java.lang.String)
+ */
+ public void setInputEncoding(String encoding) {
+ _encoding = encoding;
+ }
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setStyles(java.util.Set)
- */
- public void setStyles(Set styles) {
- _styles = styles;
+ public void setOutputEncoding(String encoding) {
+ _outputEncoding = encoding;
+ }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setMoveElements(boolean)
+ */
+ public void setMoveElements(boolean move) {
+ // TODO Auto-generated method stub
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setDoctype(java.lang.String)
- */
- public void setDoctype(String doctype) {
- this._publicId = doctype;
+ }
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setScripts(java.util.Set)
+ */
+ public void setScripts(Set scripts) {
+ _scripts = scripts;
- /* (non-Javadoc)
- * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setViewState(java.lang.String)
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setStyles(java.util.Set)
+ */
+ public void setStyles(Set styles) {
+ _styles = styles;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setDoctype(java.lang.String)
+ */
+ public void setDoctype(String doctype) {
+ this._publicId = doctype;
+
+ }
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.ajax4jsf.framework.ajax.xmlfilter.HtmlParser#setViewState(java.lang.String)
+ */
+ public void setViewState(String viewState) {
+ _viewState = viewState;
+
+ }
+
+ private static class HtmlSAXParser extends AbstractSAXParser {
+ /**
+ * Default constructor.
+ *
+ * @throws ServletException
*/
- public void setViewState(String viewState) {
- _viewState = viewState;
+ public HtmlSAXParser(HTMLConfiguration config) {
+ super(config);
}
-
- private static class HtmlSAXParser extends AbstractSAXParser {
- /** Default constructor.
- * @throws ServletException */
- public HtmlSAXParser(HTMLConfiguration config) {
- super(config);
-
- }
- }
-
- private class ViewStateFilter extends DefaultFilter{
- private boolean haveHtml = false;
- private boolean haveHead = false;
- private boolean headParsed = false;
- private int stateMarkerLevel = -1;
+ }
+ private class ViewStateFilter extends DefaultFilter {
+ private boolean haveHtml = false;
+ private boolean haveHead = false;
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#reset(org.apache.xerces.xni.parser.XMLComponentManager)
- */
- public void reset(XMLComponentManager componentManager) throws
XMLConfigurationException {
- haveHead = false;
- haveHtml = false;
- headParsed = false;
- stateMarkerLevel = -1;
- super.reset(componentManager);
- }
+ private boolean headParsed = false;
+ private int stateMarkerLevel = -1;
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void startElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- if(stateMarkerLevel >=0){
- stateMarkerLevel++;
- if(null != fragment){
- return;
- }
- }
- if (!headParsed) {
- if("html".equalsIgnoreCase(element.rawname)){
- haveHtml = true;
- } else if("head".equalsIgnoreCase(element.rawname)){
- haveHead = true;
- super.startElement(element, attributes, augs);
- insertResources();
- return;
- } else {
- if(!haveHtml){
- insertStartElement("html");
- }
- insertStartElement("head");
- insertResources();
- insertEndElement("head");
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#reset(org.apache.xerces.xni.parser.XMLComponentManager)
+ */
+ public void reset(XMLComponentManager componentManager)
+ throws XMLConfigurationException {
+ haveHead = false;
+ haveHtml = false;
+ headParsed = false;
+ stateMarkerLevel = -1;
+ super.reset(componentManager);
+ }
- }
- if(isStateMarker(element, attributes)){
- stateMarkerLevel = 0;
- return;
- };
- super.startElement(element, attributes, augs);
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#startElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void startElement(QName element, XMLAttributes attributes,
+ Augmentations augs) throws XNIException {
+ if (stateMarkerLevel >= 0) {
+ stateMarkerLevel++;
+ if (null != fragment) {
+ return;
}
+ }
+ if (!headParsed) {
+ if ("html".equalsIgnoreCase(element.rawname)) {
+ haveHtml = true;
+ } else if ("head".equalsIgnoreCase(element.rawname)) {
+ haveHead = true;
+ super.startElement(element, attributes, augs);
+ insertResources();
+ return;
+ } else {
+ if (!haveHtml) {
+ insertStartElement("html");
+ }
+ insertStartElement("head");
+ insertResources();
+ insertEndElement("head");
+ }
+ }
+ if (isStateMarker(element, attributes)) {
+ stateMarkerLevel = 0;
+ return;
+ }
+ ;
+ super.startElement(element, attributes, augs);
+ }
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#characters(org.apache.xerces.xni.XMLString,
org.apache.xerces.xni.Augmentations)
- */
- public void characters(XMLString text, Augmentations augs) throws XNIException {
- if(stateMarkerLevel >=0){
- if(null != fragment){
- return;
- }
- }
- super.characters(text, augs);
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#characters(org.apache.xerces.xni.XMLString,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void characters(XMLString text, Augmentations augs)
+ throws XNIException {
+ if (stateMarkerLevel >= 0) {
+ if (null != fragment) {
+ return;
}
+ }
+ super.characters(text, augs);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void endElement(QName element, Augmentations augs)
+ throws XNIException {
+ if (stateMarkerLevel >= 0) {
+ stateMarkerLevel--;
+ if (null != fragment || stateMarkerLevel == -1) {
+ return;
+ }
+ }
+ super.endElement(element, augs);
+ }
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.Augmentations)
- */
- public void endElement(QName element, Augmentations augs) throws XNIException {
- if(stateMarkerLevel >=0){
- stateMarkerLevel--;
- if(null != fragment || stateMarkerLevel == -1){
- return;
- }
- }
- super.endElement(element, augs);
+ private void insertResources() {
+ headParsed = true;
+ if (null != _styles) {
+ for (Iterator iter = _styles.iterator(); iter.hasNext();) {
+ String style = (String) iter.next();
+ QName element = new QName(null, "link", "link", null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ attrs.addAttribute(new QName(null, "href", "href", null),
+ "CDATA", style);
+ attrs.addAttribute(new QName(null, "type", "type", null),
+ "CDATA", "text/css");
+ attrs.addAttribute(new QName(null, "rel", "rel", null),
+ "CDATA", "stylesheet");
+ Augmentations augs = new HTMLAugmentations();
+ super.emptyElement(element, attrs, augs);
}
+ }
+ if (null != _scripts) {
+ for (Iterator iter = _scripts.iterator(); iter.hasNext();) {
+ String script = (String) iter.next();
+ QName element = new QName(null, "script", "script", null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ attrs.addAttribute(new QName(null, "src", "src", null),
+ "CDATA", script);
+ attrs.addAttribute(new QName(null, "type", "type", null),
+ "CDATA", "text/javascript");
+ Augmentations augs = new HTMLAugmentations();
+ super.startElement(element, attrs, augs);
+ super.endElement(element, augs);
+ }
+ }
+ }
- private void insertResources() {
- headParsed = true;
- if(null != _styles){
- for (Iterator iter = _styles.iterator(); iter.hasNext();) {
- String style = (String) iter.next();
- QName element = new QName(null,"link","link",null);
- XMLAttributes attrs = new XMLAttributesImpl();
- attrs.addAttribute(new QName(null,"href","href",null),
"CDATA", style);
- attrs.addAttribute(new QName(null,"type","type",null),
"CDATA", "text/css");
- attrs.addAttribute(new QName(null,"rel","rel",null),
"CDATA", "stylesheet");
- Augmentations augs = new HTMLAugmentations();
- super.emptyElement(element,attrs,augs);
- }
- }
- if(null != _scripts){
- for (Iterator iter = _scripts.iterator(); iter.hasNext();) {
- String script = (String) iter.next();
- QName element = new QName(null,"script","script",null);
- XMLAttributes attrs = new XMLAttributesImpl();
- attrs.addAttribute(new QName(null,"src","src",null),
"CDATA", script);
- attrs.addAttribute(new QName(null,"type","type",null),
"CDATA", "text/javascript");
- Augmentations augs = new HTMLAugmentations();
- super.startElement(element,attrs,augs);
- super.endElement(element, augs);
- }
- }
-
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#emptyElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void emptyElement(QName name, XMLAttributes attributes,
+ Augmentations augmentation) throws XNIException {
+ if (stateMarkerLevel >= 0) {
+ if (null != fragment) {
+ return;
}
+ }
+ if (!headParsed) {
+ if ("head".equalsIgnoreCase(name.rawname)) {
+ haveHead = true;
+ super.startElement(name, attributes, augmentation);
+ insertResources();
+ insertEndElement(name.rawname);
+ return;
+ }
+ }
+ if (isStateMarker(name, attributes)) {
+ return;
+ }
+ ;
+ super.emptyElement(name, attributes, augmentation);
+ }
-
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void emptyElement(QName name, XMLAttributes attributes, Augmentations
augmentation) throws XNIException {
- if(stateMarkerLevel >=0){
- if(null != fragment){
- return;
- }
- }
- if (!headParsed) {
- if("head".equalsIgnoreCase(name.rawname)){
- haveHead = true;
- super.startElement(name, attributes, augmentation);
- insertResources();
- insertEndElement(name.rawname);
- return;
- }
- }
- if(isStateMarker(name, attributes)){
- return;
- };
- super.emptyElement(name, attributes, augmentation);
+ /**
+ * @param name
+ * @param attributes
+ */
+ private boolean isStateMarker(QName name, XMLAttributes attributes) {
+ if (name.rawname.equalsIgnoreCase("span")
+ && AjaxViewHandler.STATE_MARKER_KEY.equals(attributes
+ .getValue("id"))) {
+ // STATE marker element - out real content.
+ if (null != fragment) {
+ try {
+ _serializer.asDOMSerializer().serialize(fragment);
+ } catch (IOException e) {
+ // Break output.
+ }
}
+ return true;
+ }
+ return false;
+ }
+ void insertStartElement(String name) {
+ QName element = new QName(null, name, name, null);
+ XMLAttributes attrs = new XMLAttributesImpl();
+ Augmentations augs = new HTMLAugmentations();
+ super.startElement(element, attrs, augs);
+ }
- /**
- * @param name
- * @param attributes
- */
- private boolean isStateMarker(QName name, XMLAttributes attributes) {
- if(name.rawname.equalsIgnoreCase("span") &&
AjaxViewHandler.STATE_MARKER_KEY.equals(attributes.getValue("id"))){
- // STATE marker element - out real content.
- if(null != fragment){
- try {
- _serializer.asDOMSerializer().serialize(fragment);
- } catch (IOException e) {
- // Break output.
- }
- }
- return true;
- }
- return false;
- }
-
- void insertStartElement(String name) {
- QName element = new QName(null,name,name,null);
- XMLAttributes attrs = new XMLAttributesImpl();
- Augmentations augs = new HTMLAugmentations();
- super.startElement(element,attrs,augs);
- }
-
-
- void insertEndElement(String name) {
- QName element = new QName(null,name,name,null);
-// XMLAttributes attrs = new XMLAttributesImpl();
- Augmentations augs = new HTMLAugmentations();
- super.endElement(element,augs);
- }
+ void insertEndElement(String name) {
+ QName element = new QName(null, name, name, null);
+ // XMLAttributes attrs = new XMLAttributesImpl();
+ Augmentations augs = new HTMLAugmentations();
+ super.endElement(element, augs);
+ }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#endDocument(org.apache.xerces.xni.Augmentations)
+ */
+ public void endDocument(Augmentations augs) throws XNIException {
+ if (!haveHtml) {
+ insertEndElement("html");
+ }
+ super.endDocument(augs);
+ }
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endDocument(org.apache.xerces.xni.Augmentations)
- */
- public void endDocument(Augmentations augs) throws XNIException {
- if (!haveHtml) {
- insertEndElement("html");
- }
- super.endDocument(augs);
- }
-
-
+ }
+ private static class HtmlWriter extends Writer {
+
+ /**
+ *
+ */
+ public HtmlWriter() {
+ super();
+ fEncoding = "UTF-8";
}
- private static class HtmlWriter extends Writer {
+ public void setEncoding(String encoding) {
+ this.fEncoding = encoding;
+ }
- /**
- *
- */
- public HtmlWriter() {
- super();
- fEncoding = "UTF-8";
- }
-
- public void setEncoding(String encoding){
- this.fEncoding = encoding;
- }
-
- public void setWriter( PrintWriter writer){
- this.fPrinter = writer;
- }
+ public void setWriter(PrintWriter writer) {
+ this.fPrinter = writer;
+ }
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.Writer#emptyElement(org.apache.xerces.xni.QName,
org.apache.xerces.xni.XMLAttributes, org.apache.xerces.xni.Augmentations)
- */
- public void emptyElement(QName element, XMLAttributes attributes, Augmentations augs)
throws XNIException {
- // TODO Auto-generated method stub
- super.emptyElement(element, attributes, augs);
- printEndElement(element);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.cyberneko.html.filters.Writer#emptyElement(org.apache.xerces.xni.QName,
+ * org.apache.xerces.xni.XMLAttributes,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void emptyElement(QName element, XMLAttributes attributes,
+ Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.emptyElement(element, attributes, augs);
+ printEndElement(element);
+ }
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#endCDATA(org.apache.xerces.xni.Augmentations)
- */
- public void endCDATA(Augmentations augs) throws XNIException {
- // TODO Auto-generated method stub
- super.endCDATA(augs);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#endCDATA(org.apache.xerces.xni.Augmentations)
+ */
+ public void endCDATA(Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.endCDATA(augs);
+ }
- /* (non-Javadoc)
- * @see
org.cyberneko.html.filters.DefaultFilter#startCDATA(org.apache.xerces.xni.Augmentations)
- */
- public void startCDATA(Augmentations augs) throws XNIException {
- // TODO Auto-generated method stub
- super.startCDATA(augs);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see
org.cyberneko.html.filters.DefaultFilter#startCDATA(org.apache.xerces.xni.Augmentations)
+ */
+ public void startCDATA(Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.startCDATA(augs);
+ }
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.DefaultFilter#textDecl(java.lang.String,
java.lang.String, org.apache.xerces.xni.Augmentations)
- */
- public void textDecl(String version, String encoding, Augmentations augs) throws
XNIException {
- // TODO Auto-generated method stub
- super.textDecl(version, encoding, augs);
- }
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.cyberneko.html.filters.DefaultFilter#textDecl(java.lang.String,
+ * java.lang.String, org.apache.xerces.xni.Augmentations)
+ */
+ public void textDecl(String version, String encoding, Augmentations augs)
+ throws XNIException {
+ // TODO Auto-generated method stub
+ super.textDecl(version, encoding, augs);
+ }
- /* (non-Javadoc)
- * @see org.cyberneko.html.filters.DefaultFilter#xmlDecl(java.lang.String,
java.lang.String, java.lang.String, org.apache.xerces.xni.Augmentations)
- */
- public void xmlDecl(String version, String encoding, String standalone, Augmentations
augs) throws XNIException {
- // TODO Auto-generated method stub
- super.xmlDecl(version, encoding, standalone, augs);
- }
-
-
+ /*
+ * (non-Javadoc)
+ *
+ * @see org.cyberneko.html.filters.DefaultFilter#xmlDecl(java.lang.String,
+ * java.lang.String, java.lang.String,
+ * org.apache.xerces.xni.Augmentations)
+ */
+ public void xmlDecl(String version, String encoding, String standalone,
+ Augmentations augs) throws XNIException {
+ // TODO Auto-generated method stub
+ super.xmlDecl(version, encoding, standalone, augs);
}
- /**
- * Factory method for create and configure HTML parser configuration.
- * Create configuration for use in parsing, set nessesary features and properties
- * @return
- * @throws ServletException
- */
- protected HTMLConfiguration getHtmlConfig() {
- HTMLConfiguration _config = new HTMLConfiguration();
- try {
- if (this.getPublicid() != null || this.getSystemid() != null) {
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-doctype",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/override-doctype",
- true);
- }
- if (this.getPublicid() != null) {
- _config.setProperty(
- "http://cyberneko.org/html/properties/doctype/pubid",
- getPublicid());
-
- }
- if (this.getSystemid() != null) {
- _config.setProperty(
- "http://cyberneko.org/html/properties/doctype/sysid",
- getSystemid());
-
- }
- if (this.getNamespace() != null) {
- _config.setFeature(
- "http://xml.org/sax/features/namespaces",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/override-namespaces",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-namespaces",
- true);
- _config.setProperty(
- "http://cyberneko.org/html/properties/namespaces-uri",
- getNamespace());
-
- }
- // config
- // .setFeature(
- //
"http://cyberneko.org/html/features/balance-tags/ignore-outside-content",
- // true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/cdata-sections",
- true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/script/strip-comment-delims",
- true);
- _config
- .setFeature(
- "http://cyberneko.org/html/features/scanner/style/strip-comment-delims",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-doctype",
- true);
- _config.setFeature(
- "http://cyberneko.org/html/features/insert-namespaces",
- true);
- //
- // Set properties
http://cyberneko.org/html/features/insert-namespaces
- // _config
- // .setProperty(
- // "http://cyberneko.org/html/properties/default-encoding",
- // encoding);
- _config.setProperty(
- "http://cyberneko.org/html/properties/names/elems",
- "lower");
- _config.setProperty(
- "http://cyberneko.org/html/properties/names/attrs",
- "lower");
-
_config.setProperty("http://cyberneko.org/html/properties/filters",
_filters);
- } catch (XMLConfigurationException e) {
-// throw new ServletException("error set Neko feature ", e);
- }
- return _config;
- }
- private String getNamespace() {
- // TODO Auto-generated method stub
- return this._namespace;
- }
+ }
- private String getSystemid() {
- // TODO Auto-generated method stub
- return this._systemid;
- }
+ /**
+ * Factory method for create and configure HTML parser configuration. Create
+ * configuration for use in parsing, set nessesary features and properties
+ *
+ * @return
+ * @throws ServletException
+ */
+ protected HTMLConfiguration getHtmlConfig() {
+ HTMLConfiguration _config = new HTMLConfiguration();
+ try {
+ if (this.getPublicid() != null || this.getSystemid() != null) {
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-doctype",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/override-doctype",
+ true);
+ }
+ if (this.getPublicid() != null) {
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/doctype/pubid",
+ getPublicid());
- private String getPublicid() {
- // TODO Auto-generated method stub
- return this._publicId;
- }
+ }
+ if (this.getSystemid() != null) {
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/doctype/sysid",
+ getSystemid());
- /**
- * @param namespace The namespace to set.
- */
- public void setNamespace(String namespace) {
- _namespace = namespace;
- }
+ }
+ if (this.getNamespace() != null) {
+
_config.setFeature("http://xml.org/sax/features/namespaces",
+ true);
+ _config
+ .setFeature(
+ "http://cyberneko.org/html/features/override-namespaces",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-namespaces",
+ true);
+ _config.setProperty(
+ "http://cyberneko.org/html/properties/namespaces-uri",
+ getNamespace());
- /**
- * @param publicId The publicId to set.
- */
- public void setPublicId(String publicId) {
- _publicId = publicId;
- }
+ }
+ // config
+ // .setFeature(
+ //
"http://cyberneko.org/html/features/balance-tags/ignore-outside-content",
+ // true);
+ _config
+ .setFeature(
+ "http://cyberneko.org/html/features/scanner/cdata-sections",
+ true);
+ _config
+ .setFeature(
+
"http://cyberneko.org/html/features/scanner/script/strip-comment-delims",
+ true);
+ _config
+ .setFeature(
+
"http://cyberneko.org/html/features/scanner/style/strip-comment-delims",
+ true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-doctype", true);
+ _config.setFeature(
+ "http://cyberneko.org/html/features/insert-namespaces",
+ true);
+ //
+ // Set properties
+ //
http://cyberneko.org/html/features/insert-namespaces
+ // _config
+ // .setProperty(
+ // "http://cyberneko.org/html/properties/default-encoding",
+ // encoding);
+ _config
+ .setProperty(
+ "http://cyberneko.org/html/properties/names/elems",
+ "lower");
+ _config
+ .setProperty(
+ "http://cyberneko.org/html/properties/names/attrs",
+ "lower");
+
_config.setProperty("http://cyberneko.org/html/properties/filters",
+ _filters);
+ } catch (XMLConfigurationException e) {
+ // throw new ServletException("error set Neko feature ", e);
+ }
+ return _config;
+ }
- /**
- * @param systemid The systemid to set.
- */
- public void setSystemid(String systemid) {
- _systemid = systemid;
- }
+ private String getNamespace() {
+ // TODO Auto-generated method stub
+ return this._namespace;
+ }
- public boolean setMime(String mimeType) {
- return false;
- }
+ private String getSystemid() {
+ // TODO Auto-generated method stub
+ return this._systemid;
+ }
+ private String getPublicid() {
+ // TODO Auto-generated method stub
+ return this._publicId;
+ }
+
+ /**
+ * @param namespace
+ * The namespace to set.
+ */
+ public void setNamespace(String namespace) {
+ _namespace = namespace;
+ }
+
+ /**
+ * @param publicId
+ * The publicId to set.
+ */
+ public void setPublicId(String publicId) {
+ _publicId = publicId;
+ }
+
+ /**
+ * @param systemid
+ * The systemid to set.
+ */
+ public void setSystemid(String systemid) {
+ _systemid = systemid;
+ }
+
+ public boolean setMime(String mimeType) {
+ return false;
+ }
+
}
Modified: trunk/framework/src/main/java/org/ajax4jsf/xml/serializer/ToXHTMLStream.java
===================================================================
---
trunk/framework/src/main/java/org/ajax4jsf/xml/serializer/ToXHTMLStream.java 2007-07-09
18:34:57 UTC (rev 305)
+++
trunk/framework/src/main/java/org/ajax4jsf/xml/serializer/ToXHTMLStream.java 2007-07-10
18:21:27 UTC (rev 306)
@@ -77,7 +77,8 @@
*/
private static final CharInfo m_htmlcharInfo =
// new CharInfo(CharInfo.HTML_ENTITIES_RESOURCE);
- CharInfo.getCharInfo(CharInfo.HTML_ENTITIES_RESOURCE, Method.HTML);
+ // Asmirnov - disable HTML Entities.
+ CharInfo.getCharInfo(CharInfo.XML_ENTITIES_RESOURCE, Method.XHTML);
/** A digital search trie for fast, case insensitive lookup of ElemDesc objects. */
static final Trie m_elementFlags = new Trie();
@@ -538,6 +539,8 @@
*/
static private final ElemDesc m_dummy = new ElemDesc(0 | ElemDesc.BLOCK);
+ public static final String XHTML_NAMESPACE_URI =
"http://www.w3.org/1999/xhtml";
+
/** True if URLs should be specially escaped with the %xx form. */
private boolean m_specialEscapeURLs = true;
@@ -838,7 +841,7 @@
// if this element has a namespace then treat it like XML
- if (null != namespaceURI && namespaceURI.length() > 0)
+ if (null != namespaceURI && namespaceURI.length() > 0 &&
(!XHTML_NAMESPACE_URI.equals(namespaceURI)))
{
super.startElement(namespaceURI, localName, name, atts);
@@ -952,7 +955,7 @@
closeCDATA();
// if the element has a namespace, treat it like XML, not HTML
- if (null != namespaceURI && namespaceURI.length() > 0)
+ if (null != namespaceURI && namespaceURI.length() > 0 &&
(!XHTML_NAMESPACE_URI.equals(namespaceURI)))
{
super.endElement(namespaceURI, localName, name);
Modified:
trunk/framework/src/main/resources/org/ajax4jsf/xml/serializer/output_xhtml.properties
===================================================================
---
trunk/framework/src/main/resources/org/ajax4jsf/xml/serializer/output_xhtml.properties 2007-07-09
18:34:57 UTC (rev 305)
+++
trunk/framework/src/main/resources/org/ajax4jsf/xml/serializer/output_xhtml.properties 2007-07-10
18:21:27 UTC (rev 306)
@@ -22,7 +22,8 @@
# XSLT properties do not need namespace qualification.
method=xhtml
-indent=yes
+indent=no
+omit-xml-declaration=yes
media-type=application/xml+xhtml
version=1.0
@@ -37,6 +38,8 @@
# Note that the colon after the protocol needs to be escaped.
{http\u003a//xml.apache.org/xalan}indent-amount=0
{http\u003a//xml.apache.org/xalan}content-handler=org.ajax4jsf.xml.serializer.ToXHTMLStream
-{http\u003a//xml.apache.org/xalan}entities=org/ajax4jsf/xml/serializer/HTMLEntities
+# XMLHttpRequest can't resolve HTTP entities.
+# {http\u003a//xml.apache.org/xalan}entities=org/ajax4jsf/xml/serializer/HTMLEntities
+{http\u003a//xml.apache.org/xalan}entities=org/ajax4jsf/xml/serializer/XMLEntities
{http\u003a//xml.apache.org/xalan}use-url-escaping=yes
{http\u003a//xml.apache.org/xalan}omit-meta-tag=yes
Added:
trunk/framework/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekoParserTestCase.java
===================================================================
---
trunk/framework/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekoParserTestCase.java
(rev 0)
+++
trunk/framework/src/test/java/org/ajax4jsf/framework/ajax/xmlfilter/nekko/NekoParserTestCase.java 2007-07-10
18:21:27 UTC (rev 306)
@@ -0,0 +1,55 @@
+/**
+ *
+ */
+package org.ajax4jsf.framework.ajax.xmlfilter.nekko;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.io.StringWriter;
+
+import junit.framework.TestCase;
+
+/**
+ * @author asmirnov
+ *
+ */
+public class NekoParserTestCase extends TestCase {
+
+ private NekkoParser parser;
+
+ /**
+ * @param name
+ */
+ public NekoParserTestCase(String name) {
+ super(name);
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ parser = new NekkoParser();
+ }
+
+ /* (non-Javadoc)
+ * @see junit.framework.TestCase#tearDown()
+ */
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ parser = null;
+ }
+
+ /**
+ * Test method for {@link
org.ajax4jsf.framework.ajax.xmlfilter.nekko.NekkoParser#parseHtml(java.io.Reader,
java.io.Writer)}.
+ * @throws IOException
+ */
+ public void testParseHtmlReaderWriter() throws IOException {
+ String html =
"<html><head/><body><div/><span></span><br><iframe></iframe><iframe/><div></body>";
+ StringReader reader = new StringReader(html);
+ StringWriter out = new StringWriter();
+ parser.parseHtml(reader, out);
+ System.out.println(out.toString());
+ }
+
+}