dims 01/09/18 09:23:46
Modified: src/org/apache/cocoon/components/xslt XSLTProcessorImpl.java
src/org/apache/cocoon/serialization
AbstractTextSerializer.java
Log:
- Patch for "Bug in XSLTProcessorImpl" from Joerg Henne <[EMAIL PROTECTED]>
- Patch for "Incorrect serialization to XML" Joerg Henne <[EMAIL PROTECTED]>
Revision Changes Path
1.6 +1 -1
xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java
Index: XSLTProcessorImpl.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/components/xslt/XSLTProcessorImpl.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- XSLTProcessorImpl.java 2001/09/06 14:04:11 1.5
+++ XSLTProcessorImpl.java 2001/09/18 16:23:46 1.6
@@ -337,7 +337,7 @@
else {
File parent = new File(base.substring(5));
File parent2 = new File(parent.getParentFile(), href);
- xslSource = resolver.resolve("file:/" + parent2.getAbsolutePath());
+ xslSource = resolver.resolve(parent2.toURL().toExternalForm());
}
}
InputSource is = xslSource.getInputSource();
1.4 +52 -2
xml-cocoon2/src/org/apache/cocoon/serialization/AbstractTextSerializer.java
Index: AbstractTextSerializer.java
===================================================================
RCS file:
/home/cvs/xml-cocoon2/src/org/apache/cocoon/serialization/AbstractTextSerializer.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- AbstractTextSerializer.java 2001/08/20 13:55:16 1.3
+++ AbstractTextSerializer.java 2001/09/18 16:23:46 1.4
@@ -26,6 +26,8 @@
import javax.xml.transform.sax.SAXTransformerFactory;
import java.util.ArrayList;
import java.util.List;
+import java.util.Map;
+import java.util.HashMap;
import java.util.Properties;
/**
@@ -33,7 +35,7 @@
* (Apache Software Foundation, Exoffice Technologies)
* @author <a href="mailto:[EMAIL PROTECTED]">Stefano Mazzocchi</a>
* @author <a href="mailto:[EMAIL PROTECTED]">Sylvain Wallez</a>
- * @version CVS $Revision: 1.3 $ $Date: 2001/08/20 13:55:16 $
+ * @version CVS $Revision: 1.4 $ $Date: 2001/09/18 16:23:46 $
*/
public abstract class AbstractTextSerializer extends AbstractSerializer implements
Configurable, Cacheable, Poolable {
@@ -58,6 +60,13 @@
private List uriList = new ArrayList();
/**
+ * Maps of URI<->prefix mappings. Used to work around a bug in the Xalan
+ * serializer.
+ */
+ private Map uriToPrefixMap = new HashMap();
+ private Map prefixToUriMap = new HashMap();
+
+ /**
* True if there has been some startPrefixMapping() for the coming element.
*/
private boolean hasMappings = false;
@@ -152,6 +161,8 @@
*/
public void recycle() {
clearMappings();
+ this.uriToPrefixMap.clear();
+ this.prefixToUriMap.clear();
super.recycle();
}
@@ -176,10 +187,32 @@
this.prefixList.add(prefix);
this.uriList.add(uri);
+ // store mappings for xalan-bug-workaround.
+ // append the prefix colon now, in order to save concatenations later.
+ this.uriToPrefixMap.put(uri, prefix + ":");
+ this.prefixToUriMap.put(prefix, uri);
+
super.startPrefixMapping(prefix, uri);
}
/**
+ * End the scope of a prefix-URI mapping:
+ * remove entry from mapping tables.
+ */
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+ // remove mappings for xalan-bug-workaround.
+ // Unfortunately, we're not passed the uri, but the prefix here,
+ // so we need to maintain maps in both directions.
+ if(this.prefixToUriMap.containsKey(prefix)) {
+ this.uriToPrefixMap.remove((String) this.prefixToUriMap.get(prefix));
+ this.prefixToUriMap.remove(prefix);
+ }
+
+ super.endPrefixMapping(prefix);
+ }
+
+ /**
* Ensure all namespace declarations are present as <code>xmlns:</code>
attributes
* and add those needed before calling superclass. This is a workaround for a
Xalan bug
* (at least in version 2.0.1) :
<code>org.apache.xalan.serialize.SerializerToXML</code>
@@ -187,7 +220,11 @@
*/
public void startElement(String eltUri, String eltLocalName, String eltQName,
Attributes attrs)
throws SAXException {
-
+
+ // try to restore the qName. The map already contains the colon
+ if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
+ eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+
if (this.hasMappings) {
// Add xmlns* attributes where needed
@@ -247,6 +284,19 @@
// Normal job
super.startElement(eltUri, eltLocalName, eltQName, attrs);
}
+ }
+
+ /**
+ * Receive notification of the end of an element.
+ * Try to restore the element qName.
+ */
+ public void endElement(String eltUri, String eltLocalName, String eltQName)
+ throws SAXException {
+ // try to restore the qName. The map already contains the colon
+ if(eltUri.length() != 0 && this.uriToPrefixMap.containsKey(eltUri) )
+ eltQName = (String) this.uriToPrefixMap.get(eltUri) + eltLocalName;
+
+ super.endElement(eltUri, eltLocalName, eltQName);
}
private void clearMappings()
----------------------------------------------------------------------
In case of troubles, e-mail: [EMAIL PROTECTED]
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]