You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@myfaces.apache.org by lu...@apache.org on 2010/01/19 01:52:27 UTC
svn commit: r900630 -
/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
Author: lu4242
Date: Tue Jan 19 00:52:26 2010
New Revision: 900630
URL: http://svn.apache.org/viewvc?rev=900630&view=rev
Log:
MYFACES-2493 ViewMetadata facelets compiler should not output DTD, <?xml or any UIInstruction outside f:metadata
Modified:
myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
Modified: myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java
URL: http://svn.apache.org/viewvc/myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java?rev=900630&r1=900629&r2=900630&view=diff
==============================================================================
--- myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java (original)
+++ myfaces/core/trunk/impl/src/main/java/org/apache/myfaces/view/facelets/compiler/SAXCompiler.java Tue Jan 19 00:52:26 2010
@@ -391,25 +391,7 @@
public void startDTD(String name, String publicId, String systemId) throws SAXException
{
- if (this.inDocument)
- {
- StringBuffer sb = new StringBuffer(64);
- sb.append("<!DOCTYPE ").append(name);
- if (publicId != null)
- {
- sb.append(" PUBLIC \"").append(publicId).append("\"");
- if (systemId != null)
- {
- sb.append(" \"").append(systemId).append("\"");
- }
- }
- else if (systemId != null)
- {
- sb.append(" SYSTEM \"").append(systemId).append("\"");
- }
- sb.append(" >\n");
- this.unit.writeInstruction(sb.toString());
- }
+ // metadata does not require output doctype
this.inDocument = false;
}
@@ -498,7 +480,7 @@
{
is = new BufferedInputStream(src.openStream(), 1024);
mngr = new CompilationManager(alias, this);
- encoding = writeXmlDecl(is, mngr);
+ encoding = getXmlDecl(is, mngr);
ViewMetadataHandler handler = new ViewMetadataHandler(mngr, alias);
SAXParser parser = this.createSAXParser(handler);
parser.parse(is, handler);
@@ -548,6 +530,34 @@
}
return encoding;
}
+
+ protected static final String getXmlDecl(InputStream is, CompilationManager mngr) throws IOException
+ {
+ is.mark(128);
+ String encoding = "UTF-8";
+ try
+ {
+ byte[] b = new byte[128];
+ if (is.read(b) > 0)
+ {
+ String r = new String(b);
+ Matcher m = XmlDeclaration.matcher(r);
+ if (m.find())
+ {
+ //mngr.writeInstruction(m.group(0) + "\n");
+ if (m.group(3) != null)
+ {
+ encoding = m.group(3);
+ }
+ }
+ }
+ }
+ finally
+ {
+ is.reset();
+ }
+ return encoding;
+ }
private final SAXParser createSAXParser(DefaultHandler handler) throws SAXException,
ParserConfigurationException