antonio 2004/06/27 19:40:10
Modified: . status.xml src/java/org/apache/cocoon/generation JXTemplateGenerator.java src/webapp/samples/flow/jxcalc/screens getNumberA.xml Log: Fix Bug #27133: JxTemplateGenerator eats backslash-characters Revision Changes Path 1.376 +4 -1 cocoon-2.1/status.xml Index: status.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/status.xml,v retrieving revision 1.375 retrieving revision 1.376 diff -u -r1.375 -r1.376 --- status.xml 27 Jun 2004 17:40:10 -0000 1.375 +++ status.xml 28 Jun 2004 02:40:10 -0000 1.376 @@ -204,6 +204,9 @@ <changes> <release version="@version@" date="@date@"> + <action dev="AG" type="fix" fixes-bug="27133"> + Fix JxTemplateGenerator eats backslash-characters + </action> <action dev="AG" type="fix" fixes-bug="25083"> Add new <jx:comment> tag. XML comments are no more parsed. Sample: 1.49 +52 -74 cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java Index: JXTemplateGenerator.java =================================================================== RCS file: /home/cvs/cocoon-2.1/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java,v retrieving revision 1.48 retrieving revision 1.49 diff -u -r1.48 -r1.49 --- JXTemplateGenerator.java 27 Jun 2004 17:40:10 -0000 1.48 +++ JXTemplateGenerator.java 28 Jun 2004 02:40:10 -0000 1.49 @@ -1039,39 +1039,30 @@ } else { buf.append(c); } - } else { - if (c == '\\') { - ch = in.read(); - if (ch == -1) { - buf.append('\\'); - } else { - buf.append((char)ch); - } - } else if (c == '$' || c == '#') { - ch = in.read(); - if (ch == '{') { - xpath = c == '#'; - inExpr = true; - if (buf.length() > 0) { - char[] charArray = - new char[buf.length()]; - - buf.getChars(0, buf.length(), - charArray, 0); - substitutions.add(charArray); - buf.setLength(0); - } - continue top; - } else { - buf.append(c); - if (ch != -1) { - c = (char)ch; - continue processChar; - } + } else if (c == '$' || c == '#') { + ch = in.read(); + if (ch == '{') { + xpath = c == '#'; + inExpr = true; + if (buf.length() > 0) { + char[] charArray = + new char[buf.length()]; + + buf.getChars(0, buf.length(), + charArray, 0); + substitutions.add(charArray); + buf.setLength(0); } + continue top; } else { buf.append(c); + if (ch != -1) { + c = (char)ch; + continue processChar; + } } + } else { + buf.append(c); } break; } @@ -1273,34 +1264,25 @@ } else { buf.append(c); } - } else { - if (c == '\\') { - ch = in.read(); - if (ch == -1) { - buf.append('\\'); - } else { - buf.append((char)ch); - } - } if (c == '$' || c == '#') { - ch = in.read(); - if (ch == '{') { - if (buf.length() > 0) { - substEvents.add(new Literal(buf.toString())); - buf.setLength(0); - } - inExpr = true; - xpath = c == '#'; - continue top; - } else { - buf.append(c); - if (ch != -1) { - c = (char)ch; - continue processChar; - } + } else if (c == '$' || c == '#') { + ch = in.read(); + if (ch == '{') { + if (buf.length() > 0) { + substEvents.add(new Literal(buf.toString())); + buf.setLength(0); } + inExpr = true; + xpath = c == '#'; + continue top; } else { buf.append(c); + if (ch != -1) { + c = (char)ch; + continue processChar; + } } + } else { + buf.append(c); } break; } @@ -3161,15 +3143,7 @@ ev.location, exc); } if (value == null) { - DOMBuilder builder = new DOMBuilder(); - builder.startDocument(); - builder.startElement(NS, "set", "set", EMPTY_ATTRS); - execute(builder, jexlContext, jxpathContext, macroCall, - startSet.next, startSet.endInstruction); - builder.endElement(NS, "set", "set"); - builder.endDocument(); - Node node = builder.getDocument().getDocumentElement(); - NodeList nodeList = node.getChildNodes(); + NodeList nodeList = toDOMNodeList("set", startSet, jexlContext, macroCall); // JXPath doesn't handle NodeList, so convert it to an array int len = nodeList.getLength(); Node[] nodeArr = new Node[len]; @@ -3384,17 +3358,8 @@ } else if (ev instanceof StartComment) { StartComment startJXComment = (StartComment)ev; // Parse the body of the comment - DOMBuilder builder = new DOMBuilder(); - builder.startDocument(); - builder.startElement(NS, "comment", "comment", EMPTY_ATTRS); - execute(builder, jexlContext, jxpathContext, macroCall, - startJXComment.next, startJXComment.endInstruction); - builder.endElement(NS, "comment", "comment"); - builder.endDocument(); - Node node = builder.getDocument().getDocumentElement(); - NodeList nodeList = node.getChildNodes(); - // JXPath doesn't handle NodeList, so convert - // it to an array + NodeList nodeList = toDOMNodeList("comment", startJXComment, jexlContext, macroCall); + // JXPath doesn't handle NodeList, so convert it to an array int len = nodeList.getLength(); final StringBuffer buf = new StringBuffer(); Properties omit = XMLUtils.createPropertiesForXML(true); @@ -3669,5 +3634,18 @@ if (startEvent == null) return null; return startEvent.templateProperties.get(propertyName); + } + + private NodeList toDOMNodeList(String elementName, StartInstruction si, + MyJexlContext jexlContext, StartElement macroCall) throws SAXException{ + DOMBuilder builder = new DOMBuilder(); + builder.startDocument(); + builder.startElement(NS, elementName, elementName, EMPTY_ATTRS); + execute(builder, jexlContext, jxpathContext, macroCall, + si.next, si.endInstruction); + builder.endElement(NS, elementName, elementName); + builder.endDocument(); + Node node = builder.getDocument().getDocumentElement(); + return node.getChildNodes(); } } 1.6 +5 -3 cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/getNumberA.xml Index: getNumberA.xml =================================================================== RCS file: /home/cvs/cocoon-2.1/src/webapp/samples/flow/jxcalc/screens/getNumberA.xml,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- getNumberA.xml 27 Jun 2004 17:40:10 -0000 1.5 +++ getNumberA.xml 28 Jun 2004 02:40:10 -0000 1.6 @@ -32,8 +32,10 @@ <content> <jx:comment> The "comment" tag allows to insert comments in the result file. - JXTemplate Expresions are parsed. Sample: - This is the continuation id: #{$cocoon/continuation/id} + JXTemplate Expresions are parsed. Samples: + + This is the continuation id: #{$cocoon/continuation/id} + A backslash dir reference: d:\cocoon\ </jx:comment> <form method="post" action="continue.#{$cocoon/continuation/id}"> <para>Enter value of <strong>a</strong>: <input type="text" name="a"/></para>