You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by sy...@apache.org on 2005/08/10 17:38:32 UTC
svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./
src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/
src/test/org/apache/cocoon/xml/
Author: sylvain
Date: Wed Aug 10 08:38:10 2005
New Revision: 231266
URL: http://svn.apache.org/viewcvs?rev=231266&view=rev
Log:
Propagate namespace mappings in JXTemplate to JXPath expressions. Refactor and extend NamespacesTable
Added:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java (with props)
cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java (with props)
Removed:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespaceSupport.java
Modified:
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespacesTable.java
cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/RedundantNamespacesFilter.java
cocoon/branches/BRANCH_2_1_X/status.xml
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java?rev=231266&r1=231265&r2=231266&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/generation/JXTemplateGenerator.java Wed Aug 10 08:38:10 2005
@@ -54,9 +54,11 @@
import org.apache.cocoon.environment.Request;
import org.apache.cocoon.environment.SourceResolver;
import org.apache.cocoon.transformation.ServiceableTransformer;
+import org.apache.cocoon.util.jxpath.NamespacesTablePointer;
import org.apache.cocoon.util.location.LocatedRuntimeException;
import org.apache.cocoon.util.location.LocationAttributes;
import org.apache.cocoon.xml.IncludeXMLConsumer;
+import org.apache.cocoon.xml.NamespacesTable;
import org.apache.cocoon.xml.RedundantNamespacesFilter;
import org.apache.cocoon.xml.XMLConsumer;
import org.apache.cocoon.xml.XMLUtils;
@@ -135,6 +137,8 @@
private static final JXPathContextFactory jxpathContextFactory = JXPathContextFactory.newInstance();
private static final Attributes EMPTY_ATTRS = new AttributesImpl();
+
+ private final NamespacesTable namespaces = new NamespacesTable();
private static final Iterator EMPTY_ITER = new Iterator() {
public boolean hasNext() {
@@ -2332,6 +2336,7 @@
this.variables = null;
this.definitions = null;
this.cocoon = null;
+ this.namespaces.clear();
super.recycle();
}
@@ -2444,6 +2449,7 @@
fillContext(contextObject, map);
}
jxpathContext = jxpathContextFactory.newContext(null, contextObject);
+ jxpathContext.setNamespaceContextPointer(new NamespacesTablePointer(namespaces));
jxpathContext.setVariables(variables);
jxpathContext.setLenient(parameters.getParameterAsBoolean("lenient-xpath", false));
globalJexlContext = new MyJexlContext();
@@ -2624,9 +2630,9 @@
EndElement endElement = (EndElement)ev;
StartElement startElement = endElement.startElement;
consumer.endElement(startElement.namespaceURI, startElement.localName, startElement.raw);
+ namespaces.leaveScope(consumer);
} else if (ev instanceof EndPrefixMapping) {
EndPrefixMapping endPrefixMapping = (EndPrefixMapping)ev;
- consumer.endPrefixMapping(endPrefixMapping.prefix);
} else if (ev instanceof IgnorableWhitespace) {
TextEvent text = (TextEvent)ev;
characters(jexlContext, jxpathContext, text, new CharHandler() {
@@ -2740,6 +2746,7 @@
if (value instanceof Pointer) {
Pointer ptr = (Pointer)value;
localJXPathContext = jxpathContext.getRelativeContext(ptr);
+ localJXPathContext.setNamespaceContextPointer(new NamespacesTablePointer(namespaces));
try {
value = ptr.getNode();
} catch (Exception exc) {
@@ -2747,6 +2754,7 @@
}
} else {
localJXPathContext = jxpathContextFactory.newContext(jxpathContext, value);
+ localJXPathContext.setNamespaceContextPointer(new NamespacesTablePointer(namespaces));
}
localJXPathContext.setVariables(localJXPathVariables);
if (var != null) {
@@ -2902,6 +2910,7 @@
vars.declareVariable(key, val);
}
JXPathContext localJXPathContext = jxpathContextFactory.newContext(null, jxpathContext.getContextBean());
+ localJXPathContext.setNamespaceContextPointer(new NamespacesTablePointer(namespaces));
localJXPathContext.setVariables(vars);
call(ev.location, startElement, consumer, localJexlContext, localJXPathContext, def.body, def.endInstruction);
ev = startElement.endElement.next;
@@ -2937,6 +2946,7 @@
attrs.addAttribute(attrEvent.namespaceURI, attrEvent.localName, attrEvent.raw, attrEvent.type, buf.toString());
}
}
+ namespaces.enterScope(consumer);
consumer.startElement(startElement.namespaceURI, startElement.localName, startElement.raw, attrs);
} else if (ev instanceof StartFormatNumber) {
StartFormatNumber startFormatNumber = (StartFormatNumber)ev;
@@ -2962,7 +2972,7 @@
}
} else if (ev instanceof StartPrefixMapping) {
StartPrefixMapping startPrefixMapping = (StartPrefixMapping)ev;
- consumer.startPrefixMapping(startPrefixMapping.prefix, startPrefixMapping.uri);
+ namespaces.addDeclaration(startPrefixMapping.prefix, startPrefixMapping.uri);
} else if (ev instanceof StartComment) {
StartComment startJXComment = (StartComment)ev;
// Parse the body of the comment
@@ -3138,6 +3148,7 @@
try {
Object obj = getValue(startImport.select, jexlContext, jxpathContext);
selectJXPath = jxpathContextFactory.newContext(null, obj);
+ selectJXPath.setNamespaceContextPointer(new NamespacesTablePointer(namespaces));
selectJXPath.setVariables(variables);
selectJexl = new MyJexlContext(jexlContext);
fillContext(obj, selectJexl);
Added: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java?rev=231266&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java Wed Aug 10 08:38:10 2005
@@ -0,0 +1,88 @@
+/*
+ * Copyright 2005 The Apache Software Foundation.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.cocoon.util.jxpath;
+
+import org.apache.cocoon.xml.NamespacesTable;
+import org.apache.commons.jxpath.ri.QName;
+import org.apache.commons.jxpath.ri.model.NodeIterator;
+import org.apache.commons.jxpath.ri.model.NodePointer;
+
+/**
+ * A JXPath <code>Pointer</code> that tracks namespaces defined by a {@link NamespacesTable}.
+ * This class is to be used to inform JXPath of the namespaces declared in a host environment
+ * (e.g. JXTemplateGenerator) using
+ * <a href="http://jakarta.apache.org/commons/jxpath/apidocs/org/apache/commons/jxpath/JXPathContext.html#setNamespaceContextPointer(org.apache.commons.jxpath.Pointer)">JXPathContext.setNamespaceContextPointer()</a>.
+ *
+ * @since 2.1.8
+ * @version $Id$
+ */
+public class NamespacesTablePointer extends NodePointer {
+
+ private NamespacesTable namespaces;
+
+ public NamespacesTablePointer(NamespacesTable namespaces) {
+ super(null);
+ this.namespaces = namespaces;
+ }
+
+ public String getNamespaceURI(String prefix) {
+ return namespaces.getUri(prefix);
+ }
+
+ protected String getDefaultNamespaceURI() {
+ return namespaces.getUri("");
+ }
+
+ public NodeIterator namespaceIterator() {
+ return null;
+ }
+
+ //-------------------------------------------------------------------------
+ // Dummy implementation of abstract methods
+ //-------------------------------------------------------------------------
+
+ public boolean isLeaf() {
+ return true;
+ }
+
+ public boolean isCollection() {
+ return false;
+ }
+
+ public int getLength() {
+ return 0;
+ }
+
+ public QName getName() {
+ return null;
+ }
+
+ public Object getBaseValue() {
+ return null;
+ }
+
+ public Object getImmediateNode() {
+ return null;
+ }
+
+ public void setValue(Object value) {
+ // ignore
+ }
+
+ public int compareChildNodePointers(NodePointer arg0, NodePointer arg1) {
+ return -1;
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/util/jxpath/NamespacesTablePointer.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespacesTable.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespacesTable.java?rev=231266&r1=231265&r2=231266&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespacesTable.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/NamespacesTable.java Wed Aug 10 08:38:10 2005
@@ -15,30 +15,69 @@
*/
package org.apache.cocoon.xml;
+import org.xml.sax.ContentHandler;
import org.xml.sax.SAXException;
/**
- * This utility class is used to keep track namespaces declarations and resolve
- * namespaces names.
+ * Keeps track of namespaces declarations and resolve namespaces names.
+ * <p>
+ * This class also provides a very convenient and safe way of handling
+ * namespace declarations in SAX pipes. It also allows to filter duplicate namespace
+ * declarations that too often clutter up XML documents that went through
+ * several transformations, and avoid useless namespace declarations that aren't followed
+ * by element events.
+ * <p>
+ * Usage example in a SAX pipe:
+ * <pre>
+ * NamespacesTable namespaces = new NamespacesTable();
+ * ContentHandler nextHandler;
*
- * @author <a href="mailto:pier@apache.org">Pierpaolo Fumagalli</a>
- * (Apache Software Foundation)
- * @version CVS $Id: NamespacesTable.java,v 1.3 2004/03/05 13:03:01 bdelacretaz Exp $
+ * public void startPrefixMapping(String prefix, String uri) throws SAXException {
+ * namespaces.addDeclaration(prefix, uri);
+ * }
+ *
+ * public void startElement(...) throws SAXException {
+ * // automatically start mappings for this scope
+ * namespaces.enterScope(nextHandler);
+ * nextHandler.startElement(...);
+ * }
+ *
+ * public void endElement(...) throws SAXException {
+ * nextHandler.endElement(...);
+ * // automatically end mappings for this scope
+ * namespaces.leaveScope(nextHandler);
+ * }
+ *
+ * public void endPrefixMapping(String prefix) throws SAXException {
+ * // Ignore, it is handled by the call to leaveScope above.
+ * }
+ * </pre>
+ *
+ * @version $Id$
*/
public class NamespacesTable {
- /** The initial namespace declaration. */
- private Entry entry=null;
+ /** The last namespace declaration. */
+ private Entry lastEntry = null;
+
+ private boolean filterDuplicate = true;
/**
* Construct a new <code>NamespacesTable</code> instance.
*/
public NamespacesTable() {
- super();
- this.entry=Entry.create("","");
- // Set the previous declaration of this namespace as self, so it will
- // not be possible to remove it :)
- this.entry.previousDeclaration=this.entry;
+ clear();
+ }
+
+ /**
+ * Clear and reinitialize this namespace table before reuse.
+ *
+ * @since 2.1.8
+ */
+ public void clear() {
+ this.lastEntry=Entry.create("","");
this.addDeclaration("xml", "http://www.w3.org/XML/1998/namespace");
+ // Lock this scope
+ this.lastEntry.closedScopes = 1;
}
/**
@@ -47,28 +86,24 @@
* @return The newly added <code>Declaration</code>.
*/
public Declaration addDeclaration(String prefix, String uri) {
- Entry e=Entry.create(prefix,uri);
- Entry previous=null;
- Entry current=this.entry;
- while (current!=null) {
- if (current.prefixHash==e.prefixHash) {
- // Set the current entry to be the previous declaration for the
- // specified prefix and remove it from the chain.
- e.previousDeclaration=current;
- e.nextEntry=current.nextEntry;
- current.nextEntry=null;
- // Set the new entry in the chain
- if (previous==null) this.entry=e;
- else previous.nextEntry=e;
- return(e);
- } else {
- previous=current;
- current=current.nextEntry;
+ // Find a previous declaration of the same prefix
+ Entry dup = this.lastEntry;
+ while (dup != null && !dup.prefix.equals(prefix)) {
+ dup = dup.previous;
+ }
+
+ if (dup != null) {
+ if (filterDuplicate && dup.uri.equals(uri)) {
+ return dup;
}
+ dup.overriden = true;
}
- if (previous==null) this.entry=e;
- else previous.nextEntry=e;
- return(e);
+
+ Entry e = Entry.create(prefix, uri);
+ e.previous = this.lastEntry;
+ e.overrides = dup;
+ this.lastEntry = e;
+ return e;
}
/**
@@ -80,26 +115,149 @@
* @return The removed <code>Declaration</code> or <b>null</b>.
*/
public Declaration removeDeclaration(String prefix) {
- int hash=prefix.hashCode();
- Entry previous=null;
- Entry current=this.entry;
- while (current!=null) {
- if (current.prefixHash==hash) {
- if (current.previousDeclaration==null) {
- if (previous==null) this.entry=current.nextEntry;
- else previous.nextEntry=current.nextEntry;
- } else {
- current.previousDeclaration.nextEntry=current.nextEntry;
- if (previous==null) this.entry=current.previousDeclaration;
- else previous.nextEntry=current.previousDeclaration;
+
+ Entry current = this.lastEntry;
+ Entry afterCurrent = null;
+ while(current != null) {
+ if (current.closedScopes > 0) {
+ // Don't undeclare mappings not declared in this scope
+ return null;
+ }
+
+ if (current.prefix.equals(prefix)) {
+ // Got it
+ // Remove it from the chain
+ if (afterCurrent != null) {
+ afterCurrent.previous = current.previous;
}
- return(current);
- } else {
- previous=current;
- current=current.nextEntry;
+ // And report closed scopes on the previous entry
+ current.previous.closedScopes += current.closedScopes;
+ Entry overrides = current.overrides;
+ if (overrides != null) {
+ // No more overriden
+ overrides.overriden = false;
+ }
+
+ return current;
}
+
+ afterCurrent = current;
+ current = current.previous;
}
- return(null);
+
+ // Not found
+ return null;
+ }
+
+ /**
+ * Enter a new scope, with no declared mappings.
+ *
+ * @see #getCurrentScopeDeclarations()
+ * @since 2.1.8
+ */
+ public void enterScope() {
+ this.lastEntry.closedScopes++;
+ }
+
+ /**
+ * Start all declared mappings of the current scope and enter a new scope.
+ * Typically called in a SAX handler <em>before</em> sending a <code>startElement()</code>
+ * event.
+ *
+ * @param handler the handler that will receive startPrefixMapping events.
+ * @throws SAXException
+ * @since 2.1.8
+ */
+ public void enterScope(ContentHandler handler) throws SAXException {
+ Entry current = this.lastEntry;
+ while (current != null && current.closedScopes == 0) {
+ handler.startPrefixMapping(current.prefix, current.uri);
+ current = current.previous;
+ }
+ enterScope();
+ }
+
+ /**
+ * Leave a scope. If <code>autoRemove</code> is true, all declared mappings for the
+ * scope that is left are automatically removed, without having to explicitely call
+ * {@link #removeDeclaration(String)}.
+ *
+ * @param autoRemove if <code>true</code>, remove all mappings for the current scope.
+ * @since 2.1.8
+ */
+ public void leaveScope(boolean autoUndeclare) {
+ Entry current = this.lastEntry;
+ if (current.closedScopes <= 0) {
+ throw new IllegalStateException("Misbalanced enter and leaving of scope.");
+ }
+ current.closedScopes--;
+ if (autoUndeclare) {
+ while (current != null && current.closedScopes == 0) {
+ Entry overrides = current.overrides;
+ if (overrides != null) {
+ // No more overriden
+ overrides.overriden = false;
+ }
+ current = current.previous;
+ }
+ }
+ this.lastEntry = current;
+ }
+
+ /**
+ * Leave a scope and end all declared mappings of the new scope.
+ * Typically called in a SAX handler <em>after</em> sending a <code>endElement()</code>
+ * event.
+ *
+ * @param handler the handler that will receive endPrefixMapping events.
+ * @throws SAXException
+ * @since 2.1.8
+ */
+ public void leaveScope(ContentHandler handler) throws SAXException {
+ Entry current = this.lastEntry;
+ if (current.closedScopes <= 0) {
+ throw new IllegalStateException("Misbalanced enter and leaving of scope.");
+ }
+ while (current != null && current.closedScopes == 0) {
+ handler.endPrefixMapping(current.prefix);
+ Entry overrides = current.overrides;
+ if (overrides != null) {
+ // No more overriden
+ overrides.overriden = false;
+ }
+ current = current.previous;
+ }
+
+ current.closedScopes--;
+ this.lastEntry = current;
+ }
+
+ private static final Declaration[] NO_DECLS = new Declaration[0];
+
+ /**
+ * Get the declarations that were declared within the current scope.
+ *
+ * @return the declarations (never null)
+ * @since 2.1.8
+ */
+ public Declaration[] getCurrentScopeDeclarations() {
+ int count = 0;
+ Entry current = this.lastEntry;
+ while (current != null && current.closedScopes == 0) {
+ count++;
+ current = current.previous;
+ }
+
+ if (count == 0) return NO_DECLS;
+
+ Declaration[] decls = new Declaration[count];
+ count = 0;
+ current = this.lastEntry;
+ while (current != null && current.closedScopes == 0) {
+ decls[count++] = current;
+ current = current.previous;
+ }
+ return decls;
}
/**
@@ -107,13 +265,16 @@
* prefix was not mapped.
*/
public String getUri(String prefix) {
- int hash=prefix.hashCode();
- Entry current=this.entry;
- while (current!=null) {
- if(current.prefixHash==hash) return(current.uri);
- else current=current.nextEntry;
+ Entry current = this.lastEntry;
+ while (current != null) {
+ if (current.prefix.equals(prefix)) {
+ return current.uri;
+ }
+ current = current.previous;
}
- return(null);
+
+ // Not found
+ return null;
}
/**
@@ -125,21 +286,25 @@
* @return A <b>non-null</b> <code>String</code> array.
*/
public String[] getPrefixes(String uri) {
- int hash=uri.hashCode();
- Entry current=this.entry;
+
+ Entry current=this.lastEntry;
int count=0;
while (current!=null) {
- if(current.uriHash==hash) count++;
- current=current.nextEntry;
+ if(!current.overriden && current.uri.equals(uri))
+ count++;
+ current=current.previous;
}
if (count==0) return(new String[0]);
+
String prefixes[]=new String[count];
count=0;
+ current = this.lastEntry;
while (current!=null) {
- if(current.uriHash==hash) prefixes[count++]=current.prefix;
- current=current.nextEntry;
+ if(!current.overriden && current.uri.equals(uri))
+ prefixes[count++] = current.prefix;
+ current = current.previous;
}
- return(prefixes);
+ return prefixes;
}
@@ -148,13 +313,13 @@
* <b>null</b>.
*/
public String getPrefix(String uri) {
- int hash=uri.hashCode();
- Entry current=this.entry;
- while (current!=null) {
- if(current.uriHash==hash) return(current.prefix);
- current=current.nextEntry;
+ Entry current = this.lastEntry;
+ while (current != null) {
+ if(!current.overriden && current.uri.equals(uri))
+ return current.prefix;
+ current = current.previous;
}
- return(null);
+ return null;
}
/**
@@ -233,37 +398,32 @@
/** The internal entry structure for this table. */
private static class Entry implements Declaration {
- /** The URI hashcode. */
- protected int uriHash=0;
- /** The prefix hashcode. */
- protected int prefixHash=0;
/** The URI string. */
protected String uri="";
/** The prefix string. */
protected String prefix="";
- /** The previous declaration for the same prefix. */
- protected Entry previousDeclaration;
- /** The declaration following this one in the table. */
- protected Entry nextEntry;
+ /** The previous declaration. */
+ protected Entry previous;
+ protected Entry overrides;
+ protected int closedScopes = 0;
+ protected boolean overriden = false;
/** Create a new namespace declaration. */
protected static Entry create(String prefix, String uri) {
// Create a new entry
- Entry e=new Entry();
- // Set the prefix string and hash code.
- if (prefix!=null) e.prefix=prefix;
- e.prefixHash=e.prefix.hashCode();
- // Set the uri string and hash code.
- if (uri!=null) e.uri=uri;
- e.uriHash=e.uri.hashCode();
+ Entry e = new Entry();
+ // Set the prefix string.
+ if (prefix != null) e.prefix=prefix;
+ // Set the uri string.
+ if (uri != null) e.uri=uri;
// Return the entry
- return(e);
+ return e;
}
/** Return the namespace URI. */
- public String getUri() { return(this.uri); }
+ public String getUri() { return this.uri; }
/** Return the namespace prefix. */
- public String getPrefix() { return(this.prefix); }
+ public String getPrefix() { return this.prefix; }
}
/** The default namespace-aware name declaration implementation */
@@ -278,13 +438,13 @@
protected String raw;
/** Return the namespace URI. */
- public String getUri() { return(this.uri); }
+ public String getUri() { return this.uri; }
/** Return the namespace prefix. */
- public String getPrefix() { return(this.prefix); }
+ public String getPrefix() { return this.prefix; }
/** Return the namespace local name. */
- public String getLocalName() { return(this.local); }
+ public String getLocalName() { return this.local; }
/** Return the namespace raw name. */
- public String getQName() { return(this.raw); }
+ public String getQName() { return this.raw; }
}
/**
Modified: cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/RedundantNamespacesFilter.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/RedundantNamespacesFilter.java?rev=231266&r1=231265&r2=231266&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/RedundantNamespacesFilter.java (original)
+++ cocoon/branches/BRANCH_2_1_X/src/java/org/apache/cocoon/xml/RedundantNamespacesFilter.java Wed Aug 10 08:38:10 2005
@@ -15,8 +15,6 @@
*/
package org.apache.cocoon.xml;
-import java.util.Enumeration;
-
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
@@ -28,13 +26,15 @@
* no element inbetween) that can be produced by some components (e.g. JXTG or
* BrowserUpdateTransformer). Such empty scopes confuse the Xalan serializer which
* then produces weird namespace declarations (<code>xmlns:%@$#^@#="%@$#^@#"</code>).
+ * <p>
+ * This is a the most simple use of {@link NamespaceHelper}.
*
* @version CVS $Id$
*/
public class RedundantNamespacesFilter extends AbstractXMLPipe {
/** Layered storage for all namespace declarations */
- private NamespaceSupport ns = new NamespaceSupport();
+ private NamespacesTable ns = new NamespacesTable();
/**
* No-arg constructor. Requires an explicit call to
@@ -55,31 +55,19 @@
}
public void startPrefixMapping(String prefix, String uri) throws SAXException {
- if (!uri.equals(ns.getURI(prefix))) {
- // New declaration: store it
- ns.declarePrefix(prefix, uri);
- }
+ // Just declare it: duplicate declarations are ignorede by NamespacesTable
+ ns.addDeclaration(prefix, uri);
}
public void startElement(String uri, String loc, String raw, Attributes a) throws SAXException {
// Declare namespaces for this scope, if any
- Enumeration prefixes = ns.getDeclaredPrefixes();
- while (prefixes.hasMoreElements()) {
- String prefix = (String) prefixes.nextElement();
- super.startPrefixMapping(prefix, ns.getURI(prefix));
- }
- ns.pushContext();
+ ns.enterScope(this.contentHandler);
super.startElement(uri, loc, raw, a);
}
public void endElement(String uri, String loc, String raw) throws SAXException {
super.endElement(uri, loc, raw);
- ns.popContext();
- // Undeclare namespaces for this scope, if any
- Enumeration prefixes = ns.getDeclaredPrefixes();
- while (prefixes.hasMoreElements()) {
- super.endPrefixMapping((String) prefixes.nextElement());
- }
+ ns.leaveScope(this.contentHandler);
}
public void endPrefixMapping(String prefix) throws SAXException {
Added: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java?rev=231266&view=auto
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java (added)
+++ cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java Wed Aug 10 08:38:10 2005
@@ -0,0 +1,117 @@
+package org.apache.cocoon.xml;
+
+import org.xml.sax.helpers.DefaultHandler;
+
+import junit.framework.TestCase;
+
+public class NamespacesTableTestCase extends TestCase {
+ public NamespacesTableTestCase(String name) {
+ super(name);
+ }
+
+ public void testSimple() {
+ NamespacesTable ns = new NamespacesTable();
+
+ ns.addDeclaration("ns1", "http://ns1");
+ ns.addDeclaration("ns2", "http://ns2");
+
+ ns.enterScope();
+
+ assertEquals("http://ns1", ns.getUri("ns1"));
+ assertEquals("ns1", ns.getPrefix("http://ns1"));
+
+ assertEquals("http://ns2", ns.getUri("ns2"));
+ assertEquals("ns2", ns.getPrefix("http://ns2"));
+
+ assertNull(ns.getPrefix(ns.getPrefix("http://ns3")));
+ assertNull(ns.getUri("ns3"));
+
+ ns.leaveScope(false);
+ assertNotNull(ns.removeDeclaration("ns1"));
+ assertNotNull(ns.removeDeclaration("ns2"));
+ assertNull(ns.removeDeclaration("ns3"));
+ }
+
+ public void testWrongUndeclare() {
+ NamespacesTable ns = new NamespacesTable();
+
+ ns.enterScope();
+ ns.addDeclaration("ns1", "http://ns1");
+ ns.addDeclaration("ns2", "http://ns2");
+
+ ns.enterScope(); // increments closedScopes on ns2
+
+ ns.addDeclaration("ns3", "http://ns3");
+
+ try {
+ ns.leaveScope(false);
+ } catch(IllegalStateException e) {
+ return;
+ }
+
+ fail();
+ }
+
+ public void testOverride() {
+ NamespacesTable ns = new NamespacesTable();
+
+ ns.addDeclaration("ns1", "http://ns1");
+ ns.enterScope();
+ ns.addDeclaration("ns1", "http://otherns1");
+ ns.enterScope();
+ ns.addDeclaration("ns1", "http://yetanotherns1");
+ ns.enterScope();
+
+ assertEquals("http://yetanotherns1", ns.getUri("ns1"));
+ assertEquals(0, ns.getPrefixes("http://ns1").length);
+
+ ns.leaveScope(true);
+ ns.leaveScope(true);
+
+ assertEquals("http://ns1", ns.getUri("ns1"));
+ assertEquals(1, ns.getPrefixes("http://ns1").length);
+
+ ns.leaveScope(true);
+ assertNull(ns.getUri("ns1"));
+ }
+
+ public void testMultiDeclaration() {
+ NamespacesTable ns = new NamespacesTable();
+ ns.addDeclaration("ns1", "http://ns1");
+ ns.enterScope();
+ // two in the same scope
+ ns.addDeclaration("ns2", "http://ns1");
+ ns.addDeclaration("ns3", "http://ns1");
+ ns.enterScope();
+
+ String[] prefixes = ns.getPrefixes("http://ns1");
+ assertEquals(3, prefixes.length);
+ assertEquals("ns3", prefixes[0]);
+ assertEquals("ns2", prefixes[1]);
+ assertEquals("ns1", prefixes[2]);
+ }
+
+ public void testStreamDeclarations() throws Exception {
+ NamespacesTable ns = new NamespacesTable();
+ ns.addDeclaration("ns1", "http://ns1");
+ ns.enterScope();
+ ns.addDeclaration("ns2", "http://ns2");
+ ns.enterScope(new DefaultHandler() {
+ public void startPrefixMapping(String prefix, String uri) throws org.xml.sax.SAXException {
+ assertEquals("ns2", prefix);
+ assertEquals("http://ns2", uri);
+ };
+ });
+
+ // Enter and leave a nested scope
+ ns.addDeclaration("ns3", "http://ns3");
+ ns.enterScope();
+ ns.leaveScope(true);
+
+ ns.leaveScope(new DefaultHandler() {
+ public void endPrefixMapping(String prefix) throws org.xml.sax.SAXException {
+ assertEquals("ns2", prefix);
+ };
+ });
+ }
+}
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: cocoon/branches/BRANCH_2_1_X/src/test/org/apache/cocoon/xml/NamespacesTableTestCase.java
------------------------------------------------------------------------------
svn:keywords = Id
Modified: cocoon/branches/BRANCH_2_1_X/status.xml
URL: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/status.xml?rev=231266&r1=231265&r2=231266&view=diff
==============================================================================
--- cocoon/branches/BRANCH_2_1_X/status.xml (original)
+++ cocoon/branches/BRANCH_2_1_X/status.xml Wed Aug 10 08:38:10 2005
@@ -196,6 +196,9 @@
<changes>
<release version="@version@" date="@date@">
+ <action dev="SW" type="fix">
+ JXTemplate: ensure JXPath expressions can use namespace prefix mappings declared in the template document.
+ </action>
<action dev="CZ" type="update">
Updated Axis to 1.2 and wsdl4j to 1.5.1.
</action>
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/ src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Ugo Cei <ug...@apache.org>.
On Aug 14, 2005, at 2:43 PM, Sylvain Wallez wrote:
> This is clearly a bug, either in NamespacesTable or in JXTemplate.
> I'll take care of this ASAP.
>
Thanks a lot.
> Just a precision though: what's are the direct children of the
> <jx:forEach>? Text, elements, mixed content?
>
Elements (and whitespace):
<jx:forEach items="${channels}" var="channel"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0">
<tr>
<td><a href="${channel.link}" target="_blank">$
{channel.title}</a></td>
<td><a href="${channel.url}" target="_blank">$
{channel.url}</a></td>
<td>${channel.lastUpdate}</td>
<td>${channel.description}</td>
<td><a href="refreshChannel.do?id=$
{channel.id}">Refresh</a></td>
</tr>
</jx:forEach>
Ugo
--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/ src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Ugo Cei <u....@pronetics.it>.
Il giorno 15/ago/05, alle 20:21, Sylvain Wallez ha scritto:
> Fixed! Please cross-check!
Looks good!
Ugo
--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Sylvain Wallez wrote:
> Ugo Cei wrote:
>
>> This patch seems to have broken some of the JX templates I was
>> using. In particular, I had templates where the jx namespace prefix
>> was declared in a single jx:forEach element (most of the content is
>> static and I just need to interate a collection to display a table):
>>
>> <jx:forEach items="${channels}" var="channel" xmlns:jx="http://
>> apache.org/cocoon/templates/jx/1.0">
>> ...
>> </jx;forEach>
>>
>> Now these templates throw the following exception:
>>
>> java.lang.IllegalStateException: Misbalanced enter and leaving of scope.
>> at org.apache.cocoon.xml.NamespacesTable.leaveScope
>> (NamespacesTable.java:228)
>> at org.apache.cocoon.xml.RedundantNamespacesFilter.endElement
>> (RedundantNamespacesFilter.java:72)
>> at org.apache.cocoon.generation.JXTemplateGenerator.execute
>> (JXTemplateGenerator.java:2632)
>> at
>> org.apache.cocoon.generation.JXTemplateGenerator.performGeneration
>> (JXTemplateGenerator.java:2497)
>> at org.apache.cocoon.generation.JXTemplateGenerator.generate
>> (JXTemplateGenerator.java:2491)
>>
>> A simple workaround consists in putting the namespace declaration in
>> the root element of the template, but this is not nice to people who
>> have lots of templates to change. Is this a bug or a feature?
>
>
>
> This is clearly a bug, either in NamespacesTable or in JXTemplate.
> I'll take care of this ASAP.
Fixed! Please cross-check!
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Ugo Cei wrote:
> This patch seems to have broken some of the JX templates I was using.
> In particular, I had templates where the jx namespace prefix was
> declared in a single jx:forEach element (most of the content is
> static and I just need to interate a collection to display a table):
>
> <jx:forEach items="${channels}" var="channel" xmlns:jx="http://
> apache.org/cocoon/templates/jx/1.0">
> ...
> </jx;forEach>
>
> Now these templates throw the following exception:
>
> java.lang.IllegalStateException: Misbalanced enter and leaving of scope.
> at org.apache.cocoon.xml.NamespacesTable.leaveScope
> (NamespacesTable.java:228)
> at org.apache.cocoon.xml.RedundantNamespacesFilter.endElement
> (RedundantNamespacesFilter.java:72)
> at org.apache.cocoon.generation.JXTemplateGenerator.execute
> (JXTemplateGenerator.java:2632)
> at
> org.apache.cocoon.generation.JXTemplateGenerator.performGeneration
> (JXTemplateGenerator.java:2497)
> at org.apache.cocoon.generation.JXTemplateGenerator.generate
> (JXTemplateGenerator.java:2491)
>
> A simple workaround consists in putting the namespace declaration in
> the root element of the template, but this is not nice to people who
> have lots of templates to change. Is this a bug or a feature?
This is clearly a bug, either in NamespacesTable or in JXTemplate. I'll
take care of this ASAP.
Just a precision though: what's are the direct children of the
<jx:forEach>? Text, elements, mixed content?
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/ src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Ugo Cei <ug...@apache.org>.
This patch seems to have broken some of the JX templates I was using.
In particular, I had templates where the jx namespace prefix was
declared in a single jx:forEach element (most of the content is
static and I just need to interate a collection to display a table):
<jx:forEach items="${channels}" var="channel" xmlns:jx="http://
apache.org/cocoon/templates/jx/1.0">
...
</jx;forEach>
Now these templates throw the following exception:
java.lang.IllegalStateException: Misbalanced enter and leaving of scope.
at org.apache.cocoon.xml.NamespacesTable.leaveScope
(NamespacesTable.java:228)
at org.apache.cocoon.xml.RedundantNamespacesFilter.endElement
(RedundantNamespacesFilter.java:72)
at org.apache.cocoon.generation.JXTemplateGenerator.execute
(JXTemplateGenerator.java:2632)
at
org.apache.cocoon.generation.JXTemplateGenerator.performGeneration
(JXTemplateGenerator.java:2497)
at org.apache.cocoon.generation.JXTemplateGenerator.generate
(JXTemplateGenerator.java:2491)
A simple workaround consists in putting the namespace declaration in
the root element of the template, but this is not nice to people who
have lots of templates to change. Is this a bug or a feature?
Ugo
--
Ugo Cei
Tech Blog: http://agylen.com/
Open Source Zone: http://oszone.org/
Wine & Food Blog: http://www.divinocibo.it/
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/ src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Torsten Curdt <tc...@apache.org>.
> As a side note, the refactored NamespacesTable I committed
> yesterday is a killer tool to cleanly handle namespaces (see
> RedundantNamespacesFilter). I plan to use it in some transformers
> that "consume" namespaces such as i18n, xinclude, etc to ensure the
> consumed namespaces never passes through the transformer. That will
> make cleaner and smaller web pages!
Awesome stuff! ...this was always a PITA :)
cheers
--
Torsten
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Leszek Gawron <lg...@mobilebox.pl>.
Sylvain Wallez wrote:
> <jx:forEach> -
> resource://org/apache/cocoon/forms/generation/jx-macros.xml:103:10
> <ft:repeater> - context://foo/bar.xml:23:12
> <map:serialize> - context://foo/sitemap.xmap:45:6
> <map:transform> - context://foo/sitemap.xmap:44:6
> <map:generate> - context://foo/sitemap.xmap:43:6
> showForm() - resource://org/apache/cocoon/forms/flow/js/form.js:30:-1
> do_stuff() - context://foo/flow.js:10:-1
> <map:call> - context://foo/sitemap.xmap:20:6
> <map:mount> - context://sitemap.xmap:20:10
>
> Looks cool, eh?
Lovely!
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Vadim Gritsenko wrote:
> Sylvain Wallez wrote:
>
>> Vadim Gritsenko wrote:
>>
>>>>>> As a side note, the refactored NamespacesTable I committed
>>>>>> yesterday is a killer tool to cleanly handle namespaces (see
>>>>>> RedundantNamespacesFilter). I plan to use it in some transformers
>>>>>> that "consume" namespaces such as i18n, xinclude, etc to ensure
>>>>>> the consumed namespaces never passes through the transformer.
>>>>>
>>>
>>> If transformer consumes its namespace completely, it's way more
>>> efficient to simply filter out the namespace completely.
>>
>>
>> It's not always that easy, as you have to remove the
>> startPrefixMapping and the endPrefixMapping. The start is easy
>> because you've got the URI, but the end isn't so easy as you have to
>> know which prefix to filter out, and several prefixes can be used for
>> the same URI (or the same prefix can also hide a previous one).
>
>
> I know. Won't simplier use of NamespacesTable solve this [1]?
Yes, that's exactly that! However, some components have to deal with
more complex combinations of namespaces and require more than what's in
XIncludeTransformer. One such component is JXTG where we may have
start/endPrefixMapping with no elements inbetween (macro declarations)
and prefixes we want to exclude from the result, like XSL's
exlude-result-prefixes. In such cases, the enterScope/leaveScope feature
of NamespacesTable is useful.
Sylvain
> [1]
> http://svn.apache.org/repos/asf/cocoon/trunk/src/java/org/apache/cocoon/transformation/IncludeTransformer.java
>
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:
> Vadim Gritsenko wrote:
>
>>>>> As a side note, the refactored NamespacesTable I committed
>>>>> yesterday is a killer tool to cleanly handle namespaces (see
>>>>> RedundantNamespacesFilter). I plan to use it in some transformers
>>>>> that "consume" namespaces such as i18n, xinclude, etc to ensure the
>>>>> consumed namespaces never passes through the transformer.
>>
>> If transformer consumes its namespace completely, it's way more
>> efficient to simply filter out the namespace completely.
>
> It's not always that easy, as you have to remove the startPrefixMapping
> and the endPrefixMapping. The start is easy because you've got the URI,
> but the end isn't so easy as you have to know which prefix to filter
> out, and several prefixes can be used for the same URI (or the same
> prefix can also hide a previous one).
I know. Won't simplier use of NamespacesTable solve this [1]?
>>> I will also modify AbtractProcessingPipeline so that it dumps the
>>> full chain of locations of the pipeline when an error occurs.
>>>
>>> That will lead to stacktraces like:
>>>
>>> <jx:forEach> -
>>> resource://org/apache/cocoon/forms/generation/jx-macros.xml:103:10
>>> <ft:repeater> - context://foo/bar.xml:23:12
>>
>> (hm, why it's context:// here - won't it usually resolve to file://?)
>
> context:// is a convenience provided by the error2html stylesheet to
> have shorter paths. But logs contain the full path with file://
Nice!
>>> <map:serialize> - context://foo/sitemap.xmap:45:6
>>> <map:transform> - context://foo/sitemap.xmap:44:6
>>> <map:generate> - context://foo/sitemap.xmap:43:6
>>> showForm() - resource://org/apache/cocoon/forms/flow/js/form.js:30:-1
>>> do_stuff() - context://foo/flow.js:10:-1
>>> <map:call> - context://foo/sitemap.xmap:20:6
>>> <map:mount> - context://sitemap.xmap:20:10
>>>
>>> Looks cool, eh?
>>
>> It is probably good idea to add some more context info like:
>>
>> <map:transform type="bar"> - context://foo/sitemap.xmap:44:6
>> <map:generate type="foo"> - context://foo/sitemap.xmap:43:6
>>
>> Or may that is too much... Dunno.
>
> Thought about this also. Actually, we can put there any information that
> is statically known. So why not.
Ok, great.
Vadim
[1]
http://svn.apache.org/repos/asf/cocoon/trunk/src/java/org/apache/cocoon/transformation/IncludeTransformer.java
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Vadim Gritsenko wrote:
> Sylvain Wallez wrote:
>
>> Leszek Gawron wrote:
>>
>>> Sylvain Wallez wrote:
>>
>>
>>>> As a side note, the refactored NamespacesTable I committed
>>>> yesterday is a killer tool to cleanly handle namespaces (see
>>>> RedundantNamespacesFilter). I plan to use it in some transformers
>>>> that "consume" namespaces such as i18n, xinclude, etc to ensure the
>>>> consumed namespaces never passes through the transformer. That will
>>>> make cleaner and smaller web pages!
>>>
>
> If transformer consumes its namespace completely, it's way more
> efficient to simply filter out the namespace completely.
It's not always that easy, as you have to remove the startPrefixMapping
and the endPrefixMapping. The start is easy because you've got the URI,
but the end isn't so easy as you have to know which prefix to filter
out, and several prefixes can be used for the same URI (or the same
prefix can also hide a previous one).
>> I will also modify AbtractProcessingPipeline so that it dumps the
>> full chain of locations of the pipeline when an error occurs.
>>
>> That will lead to stacktraces like:
>>
>> <jx:forEach> -
>> resource://org/apache/cocoon/forms/generation/jx-macros.xml:103:10
>> <ft:repeater> - context://foo/bar.xml:23:12
>
>
> (hm, why it's context:// here - won't it usually resolve to file://?)
context:// is a convenience provided by the error2html stylesheet to
have shorter paths. But logs contain the full path with file://
>> <map:serialize> - context://foo/sitemap.xmap:45:6
>> <map:transform> - context://foo/sitemap.xmap:44:6
>> <map:generate> - context://foo/sitemap.xmap:43:6
>> showForm() - resource://org/apache/cocoon/forms/flow/js/form.js:30:-1
>> do_stuff() - context://foo/flow.js:10:-1
>> <map:call> - context://foo/sitemap.xmap:20:6
>> <map:mount> - context://sitemap.xmap:20:10
>>
>> Looks cool, eh?
>
>
> It is probably good idea to add some more context info like:
>
> <map:transform type="bar"> - context://foo/sitemap.xmap:44:6
> <map:generate type="foo"> - context://foo/sitemap.xmap:43:6
>
> Or may that is too much... Dunno.
Thought about this also. Actually, we can put there any information that
is statically known. So why not.
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Vadim Gritsenko <va...@reverycodes.com>.
Sylvain Wallez wrote:
> Leszek Gawron wrote:
>
>> Sylvain Wallez wrote:
>
>>> As a side note, the refactored NamespacesTable I committed yesterday
>>> is a killer tool to cleanly handle namespaces (see
>>> RedundantNamespacesFilter). I plan to use it in some transformers
>>> that "consume" namespaces such as i18n, xinclude, etc to ensure the
>>> consumed namespaces never passes through the transformer. That will
>>> make cleaner and smaller web pages!
If transformer consumes its namespace completely, it's way more efficient to
simply filter out the namespace completely.
<snip/>
> I will also modify AbtractProcessingPipeline so that it dumps the full
> chain of locations of the pipeline when an error occurs.
>
> That will lead to stacktraces like:
>
> <jx:forEach> -
> resource://org/apache/cocoon/forms/generation/jx-macros.xml:103:10
> <ft:repeater> - context://foo/bar.xml:23:12
(hm, why it's context:// here - won't it usually resolve to file://?)
> <map:serialize> - context://foo/sitemap.xmap:45:6
> <map:transform> - context://foo/sitemap.xmap:44:6
> <map:generate> - context://foo/sitemap.xmap:43:6
> showForm() - resource://org/apache/cocoon/forms/flow/js/form.js:30:-1
> do_stuff() - context://foo/flow.js:10:-1
> <map:call> - context://foo/sitemap.xmap:20:6
> <map:mount> - context://sitemap.xmap:20:10
>
> Looks cool, eh?
It is probably good idea to add some more context info like:
<map:transform type="bar"> - context://foo/sitemap.xmap:44:6
<map:generate type="foo"> - context://foo/sitemap.xmap:43:6
Or may that is too much... Dunno.
Vadim
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Leszek Gawron wrote:
> Sylvain Wallez wrote:
>> As a side note, the refactored NamespacesTable I committed yesterday
>> is a killer tool to cleanly handle namespaces (see
>> RedundantNamespacesFilter). I plan to use it in some transformers
>> that "consume" namespaces such as i18n, xinclude, etc to ensure the
>> consumed namespaces never passes through the transformer. That will
>> make cleaner and smaller web pages!
>
> So this means the output page won't have the nasty:
> <html xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
> xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
> xmlns:cinclude="http://apache.org/cocoon/include/1.0"
> xmlns:dir="http://apache.org/cocoon/directory/2.0">
Exactly!
> titanium hero plate again ! :)
LOL! Thanks :-)
> OT: What stage are cocoon stack traces in 2.1.x branch? I lack this
> very much in trunk.
I'm working on it as we speak, adding a description to locations so that
we can associate e.g. an element name or flowscript function name to a
location.
I will also modify AbtractProcessingPipeline so that it dumps the full
chain of locations of the pipeline when an error occurs.
That will lead to stacktraces like:
<jx:forEach> -
resource://org/apache/cocoon/forms/generation/jx-macros.xml:103:10
<ft:repeater> - context://foo/bar.xml:23:12
<map:serialize> - context://foo/sitemap.xmap:45:6
<map:transform> - context://foo/sitemap.xmap:44:6
<map:generate> - context://foo/sitemap.xmap:43:6
showForm() - resource://org/apache/cocoon/forms/flow/js/form.js:30:-1
do_stuff() - context://foo/flow.js:10:-1
<map:call> - context://foo/sitemap.xmap:20:6
<map:mount> - context://sitemap.xmap:20:10
Looks cool, eh?
I plan to finish this in 2.1.x tomorrow and then port to trunk.
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Leszek Gawron <lg...@mobilebox.pl>.
Sylvain Wallez wrote:
> Leszek Gawron wrote:
>
>> sylvain@apache.org wrote:
>>
>>> Author: sylvain
>>> Date: Wed Aug 10 08:38:10 2005
>>> New Revision: 231266
>>>
>>> URL: http://svn.apache.org/viewcvs?rev=231266&view=rev
>>> Log:
>>> Propagate namespace mappings in JXTemplate to JXPath expressions.
>>> Refactor and extend NamespacesTable
>>
>>
>> Thanks Sylvain, this is what I wanted to implement and got no idea how.
>
>
>
> Make sure it is annoying enough for the projects your colleagues work
> on, and ideas come quickly ;-)
In my case this was only a question on user list. I had an itch for some
hours only. I have time to post a few answers on users list these days
and nothing more. And they say holidays is usually a dead season for a
software company.
>
> Seriously, before JXPath 1.2 (which introduced namespace support) they
> could write e.g. "#{doc/document/dc:title}" whereas the new JXPath
> required to write "#{doc/document/*[name()='dc:title']}". This was
> hardly considered as an improvement :-P
>
> As a side note, the refactored NamespacesTable I committed yesterday is
> a killer tool to cleanly handle namespaces (see
> RedundantNamespacesFilter). I plan to use it in some transformers that
> "consume" namespaces such as i18n, xinclude, etc to ensure the consumed
> namespaces never passes through the transformer. That will make cleaner
> and smaller web pages!
So this means the output page won't have the nasty:
<html xmlns:fi="http://apache.org/cocoon/forms/1.0#instance"
xmlns:jx="http://apache.org/cocoon/templates/jx/1.0"
xmlns:cinclude="http://apache.org/cocoon/include/1.0"
xmlns:dir="http://apache.org/cocoon/directory/2.0">
titanium hero plate again ! :)
OT: What stage are cocoon stack traces in 2.1.x branch? I lack this very
much in trunk.
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Sylvain Wallez <sy...@apache.org>.
Leszek Gawron wrote:
> sylvain@apache.org wrote:
>
>> Author: sylvain
>> Date: Wed Aug 10 08:38:10 2005
>> New Revision: 231266
>>
>> URL: http://svn.apache.org/viewcvs?rev=231266&view=rev
>> Log:
>> Propagate namespace mappings in JXTemplate to JXPath expressions.
>> Refactor and extend NamespacesTable
>
> Thanks Sylvain, this is what I wanted to implement and got no idea how.
Make sure it is annoying enough for the projects your colleagues work
on, and ideas come quickly ;-)
Seriously, before JXPath 1.2 (which introduced namespace support) they
could write e.g. "#{doc/document/dc:title}" whereas the new JXPath
required to write "#{doc/document/*[name()='dc:title']}". This was
hardly considered as an improvement :-P
As a side note, the refactored NamespacesTable I committed yesterday is
a killer tool to cleanly handle namespaces (see
RedundantNamespacesFilter). I plan to use it in some transformers that
"consume" namespaces such as i18n, xinclude, etc to ensure the consumed
namespaces never passes through the transformer. That will make cleaner
and smaller web pages!
Sylvain
--
Sylvain Wallez Anyware Technologies
http://people.apache.org/~sylvain http://www.anyware-tech.com
Apache Software Foundation Member Research & Technology Director
Re: svn commit: r231266 - in /cocoon/branches/BRANCH_2_1_X: ./ src/java/org/apache/cocoon/generation/
src/java/org/apache/cocoon/util/jxpath/ src/java/org/apache/cocoon/xml/ src/test/org/apache/cocoon/xml/
Posted by Leszek Gawron <lg...@mobilebox.pl>.
sylvain@apache.org wrote:
> Author: sylvain
> Date: Wed Aug 10 08:38:10 2005
> New Revision: 231266
>
> URL: http://svn.apache.org/viewcvs?rev=231266&view=rev
> Log:
> Propagate namespace mappings in JXTemplate to JXPath expressions. Refactor and extend NamespacesTable
Thanks Sylvain, this is what I wanted to implement and got no idea how.
--
Leszek Gawron lgawron@mobilebox.pl
IT Manager MobileBox sp. z o.o.
+48 (61) 855 06 67 http://www.mobilebox.pl
mobile: +48 (501) 720 812 fax: +48 (61) 853 29 65