Author: cziegeler Date: Fri Oct 15 03:52:09 2004 New Revision: 54845 Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/Namespaces.java cocoon/branches/BRANCH_2_1_X/status.xml Log: Sync serializers block
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBase.java Fri Oct 15 03:52:09 2004 @@ -30,7 +30,7 @@ * Jakarta Commons <a href="http://jakarta.apache.org/commons/jxpath/index.html"> * JXPath package</a>. * - * @version CVS $Id: JXPathBindingBase.java,v 1.6 2004/05/07 22:04:20 joerg Exp $ + * @version CVS $Id$ */ public abstract class JXPathBindingBase implements Binding, LogEnabled { @@ -118,10 +118,15 @@ childWidget = parent.lookupWidget(id); if (childWidget == null) { + String containerId = parent.getRequestParameterName(); + if(containerId == null || "".equals(containerId)) { + containerId = "top-level form-widget"; + } else { + containerId = "container \"" + containerId + "\""; + } throw new RuntimeException(getClass().getName() + ": Widget \"" + - id + "\" does not exist in container \"" + - parent.getRequestParameterName() + "\" (" + - parent.getLocation() + ")."); + id + "\" does not exist in the " + containerId + + " (" + parent.getLocation() + ")."); } return childWidget; Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/JXPathBindingBuilderBase.java Fri Oct 15 03:52:09 2004 @@ -32,7 +32,7 @@ * which means: "continue in same leniency-mode as parent" </li> * </ul> * - * @version CVS $Id: JXPathBindingBuilderBase.java,v 1.3 2004/04/01 12:59:57 mpo Exp $ + * @version CVS $Id$ */ public abstract class JXPathBindingBuilderBase implements LogEnabled { @@ -92,7 +92,7 @@ * @return an instance of CommonAttributes * @throws BindingException */ - static CommonAttributes getCommonAttributes(Element bindingElm) throws BindingException { + protected static CommonAttributes getCommonAttributes(Element bindingElm) throws BindingException { try { //TODO: should we eventually remove this? //throw an error if people are still using the old-style @read-only or @readonly @@ -122,7 +122,7 @@ * member fields indicating the activity of the sepearate load and save * actions of a given binding. */ - static class CommonAttributes{ + protected static class CommonAttributes{ /** * Flag which controls whether a binding is active during loading. */ Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/binding/TempRepeaterJXPathBinding.java Fri Oct 15 03:52:09 2004 @@ -22,6 +22,7 @@ import org.apache.cocoon.forms.formmodel.Widget; import org.apache.commons.jxpath.JXPathContext; import org.apache.commons.jxpath.Pointer; +import org.w3c.dom.Document; import org.w3c.dom.Node; import org.w3c.dom.NodeList; @@ -33,7 +34,7 @@ * For a smarter binding that avoids deletion and recreation, consider * [EMAIL PROTECTED] org.apache.cocoon.forms.binding.RepeaterJXPathBinding} * - * @version CVS $Id: TempRepeaterJXPathBinding.java,v 1.5 2004/05/07 13:42:09 mpo Exp $ + * @version CVS $Id$ */ public class TempRepeaterJXPathBinding extends JXPathBindingBase { @@ -134,9 +135,13 @@ if (virtualRows == true) { Node repeaterNode = (Node)repeaterPointer.getNode(); Node virtualNode = repeaterNode.getOwnerDocument().createElementNS(null, "virtual"); - Node clone = ((Node)rowPointer.getNode()).cloneNode(true); + Node node = (Node)rowPointer.getNode(); + Node clone = node.cloneNode(true); + Node fakeDocElement = node.getOwnerDocument().getDocumentElement().cloneNode(false); virtualNode.appendChild(clone); - rowContext = JXPathContext.newContext(repeaterContext, virtualNode); + fakeDocElement.appendChild(virtualNode); + rowContext = JXPathContext.newContext(repeaterContext, fakeDocElement); + rowContext = rowContext.getRelativeContext(rowContext.getPointer("virtual")); } // Finally, perform the load row binding. @@ -190,8 +195,12 @@ // narrow the context to this initially empty new virtual row. if (virtualRows == true) { rowNode = (Node)rowContext.getContextBean(); - virtualNode = rowNode.getOwnerDocument().createElementNS(null, "virtual"); - rowContext = JXPathContext.newContext(repeaterContext, virtualNode); + Document document = rowNode.getOwnerDocument(); + virtualNode = document.createElementNS(null, "virtual"); + Node fakeDocElement = document.getDocumentElement().cloneNode(false); + fakeDocElement.appendChild(virtualNode); + rowContext = JXPathContext.newContext(repeaterContext, fakeDocElement); + rowContext = rowContext.getRelativeContext(rowContext.getPointer("virtual")); } // Perform the insert row binding Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/EncodingSerializer.java Fri Oct 15 03:52:09 2004 @@ -19,6 +19,7 @@ import java.io.OutputStream; import java.io.OutputStreamWriter; import java.io.UnsupportedEncodingException; +import java.util.Arrays; import org.apache.avalon.excalibur.pool.Recyclable; import org.apache.avalon.framework.configuration.Configurable; @@ -29,6 +30,7 @@ import org.apache.cocoon.components.serializers.encoding.Encoder; import org.apache.cocoon.components.serializers.util.Namespaces; import org.apache.cocoon.serialization.Serializer; +import org.apache.commons.lang.SystemUtils; import org.xml.sax.Attributes; import org.xml.sax.Locator; import org.xml.sax.SAXException; @@ -37,14 +39,12 @@ * * * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February 2003 - * @version CVS $Id: EncodingSerializer.java,v 1.2 2004/04/30 22:52:43 joerg Exp $ + * @version CVS $Id$ */ -public abstract class EncodingSerializer -implements Serializer, Locator, Recyclable, Configurable { +public abstract class EncodingSerializer implements Serializer, Locator, Recyclable, Configurable { /** The line separator string */ - private static final char S_EOL[] = - System.getProperty("line.separator").toCharArray(); + private static final char S_EOL[] = SystemUtils.LINE_SEPARATOR.toCharArray(); /* ====================================================================== */ @@ -80,6 +80,12 @@ /** Flag indicating if the document is being processed. */ private boolean processing = false; + /** Current nesting level */ + private int level = 0; + + /** Whitespace buffer for indentation */ + private char[] indentBuffer = null; + /* ====================================================================== */ /** The <code>Charset</code> associated with the character encoding. */ @@ -88,6 +94,8 @@ /** The <code>Namespace</code> associated with this instance. */ protected Namespaces namespaces = new Namespaces(); + /** Per level indent spaces */ + protected int indentPerLevel = 0; /* ====================================================================== */ /** @@ -144,10 +152,23 @@ throw new ConfigurationException("Encoding not supported: " + encoding, exception); } + + indentPerLevel = conf.getChild("indent").getValueAsInteger(0); + if (indentPerLevel > 0) { + assureIndentBuffer(indentPerLevel * 6); + } } /* ====================================================================== */ + private char[] assureIndentBuffer( int size ) { + if (indentBuffer == null || indentBuffer.length < size) { + indentBuffer = new char[size]; + Arrays.fill(indentBuffer,' '); + } + return indentBuffer; + } + /** * Encode and write a <code>String</code> */ @@ -355,6 +376,19 @@ } } + /** + * Write out character to indent the output according + * to the level of nesting + * @param indent + * @throws SAXException + */ + protected void writeIndent(int indent) throws SAXException { + this.charactersImpl("\n".toCharArray(),0,1); + if (indent > 0) { + this.charactersImpl(assureIndentBuffer(indent),0,indent); + } + } + /* ====================================================================== */ /** @@ -363,6 +397,7 @@ public void startDocument() throws SAXException { this.processing = true; + this.level = 0; } /** @@ -396,6 +431,11 @@ public void startElement(String nsuri, String local, String qual, Attributes attributes) throws SAXException { + if (indentPerLevel > 0) { + this.writeIndent(indentPerLevel*level); + level++; + } + String name = this.namespaces.qualify(nsuri, local, qual); if (this.prolog) { @@ -419,11 +459,24 @@ this.startElementImpl(nsuri, local, name, ns, at); } + public void characters (char ch[], int start, int length) + throws SAXException { + if (indentPerLevel > 0) { + this.writeIndent(indentPerLevel*level + 1); + } + this.charactersImpl(ch, start, length); + } + /** * Receive notification of the end of an element. */ public void endElement(String nsuri, String local, String qual) throws SAXException { + if (indentPerLevel > 0) { + level--; + this.writeIndent(indentPerLevel*level); + } + String name = this.namespaces.qualify(nsuri, local, qual); this.endElementImpl(nsuri, local, name); } @@ -451,6 +504,16 @@ */ public abstract void startElementImpl(String uri, String local, String qual, String namespaces[][], String attributes[][]) + throws SAXException; + + /** + * Receive character notifications + * @param ch + * @param start + * @param length + * @throws SAXException + */ + public abstract void charactersImpl (char ch[], int start, int length) throws SAXException; /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/XMLSerializer.java Fri Oct 15 03:52:09 2004 @@ -20,20 +20,20 @@ import org.apache.cocoon.components.serializers.encoding.XMLEncoder; import org.apache.cocoon.components.serializers.util.DocType; import org.apache.cocoon.components.serializers.util.Namespaces; +import org.apache.commons.lang.SystemUtils; import org.xml.sax.SAXException; /** * * * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February 2003 - * @version CVS $Id: XMLSerializer.java,v 1.5 2004/04/30 22:57:22 joerg Exp $ + * @version CVS $Id$ */ public class XMLSerializer extends EncodingSerializer { private static final XMLEncoder XML_ENCODER = new XMLEncoder(); - private static final char S_EOL[] = - System.getProperty("line.separator").toCharArray(); + private static final char S_EOL[] = SystemUtils.LINE_SEPARATOR.toCharArray(); private static final char S_DOCUMENT_1[] = "<?xml version=\"1.0".toCharArray(); private static final char S_DOCUMENT_2[] = "\" encoding=\"".toCharArray(); @@ -341,7 +341,7 @@ /** * Receive notification of character data. */ - public void characters(char data[], int start, int length) + public void charactersImpl(char data[], int start, int length) throws SAXException { if (this.processing_prolog) return; this.closeElement(false); @@ -353,7 +353,7 @@ */ public void ignorableWhitespace(char data[], int start, int length) throws SAXException { - this.characters(data, start, length); + this.charactersImpl(data, start, length); } /** Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/Namespaces.java ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/Namespaces.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/serializers/java/org/apache/cocoon/components/serializers/util/Namespaces.java Fri Oct 15 03:52:09 2004 @@ -22,7 +22,7 @@ * stack for XML namespaces declarations. * * @author <a href="mailto:[EMAIL PROTECTED]">Pier Fumagalli</a>, February 2003 - * @version CVS $Id: Namespaces.java,v 1.1 2004/04/21 09:33:27 pier Exp $ + * @version CVS $Id$ */ public class Namespaces { /** The array of all URIs in this stack. */ @@ -83,14 +83,15 @@ */ public synchronized void pop(String prefix) throws SAXException { - for (int x = this.position(prefix, pre); x < (--this.depth); x++) { + for (int x = this.position(prefix, pre); x < this.depth; x++) { int k = (x + 1); this.pre[x] = this.pre[k]; this.uri[x] = this.uri[k]; } - this.pre[this.depth] = null; - this.uri[this.depth] = null; + //this.pre[this.depth] = null; + //this.uri[this.depth] = null; this.last--; + this.depth--; } /** @@ -180,4 +181,5 @@ } throw new SAXException("Unable to map \"" + check + "\""); } + } Modified: cocoon/branches/BRANCH_2_1_X/status.xml ============================================================================== --- cocoon/branches/BRANCH_2_1_X/status.xml (original) +++ cocoon/branches/BRANCH_2_1_X/status.xml Fri Oct 15 03:52:09 2004 @@ -502,8 +502,17 @@ modification date is in the future and occasional ECM-related exceptions when a sitemap is reloaded. </action> + <action dev="BD" type="add" due-to="Stavros Kounis" fixes-bug="28834"> + Tour block: added Java shapes sample. + </action> <action dev="AG" type="update"> Updated Groovy to 1.0-beta5, qdox to 1.4 and util.concurrent to 1.3.4. + </action> + <action dev="TC" type="fix"> + Serializers block: Fixed the namespace handling of the XMLSerializer. + </action> + <action dev="TC" type="add"> + Serializers block: Added support for indentation to the XMLSerializer. </action> <action dev="DC" type="update" fixes-bug="28809" due-to="Dave Brondsema"> Chaperon block: Improvements for Chaperon JSPWiki to xdocs conversion:
