You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by cz...@apache.org on 2003/12/19 09:15:03 UTC
cvs commit: cocoon-2.0/src/java/org/apache/cocoon/transformation EncodeURLTransformer.java AbstractSAXTransformer.java
cziegeler 2003/12/19 00:15:03
Modified: src/java/org/apache/cocoon/transformation
EncodeURLTransformer.java
AbstractSAXTransformer.java
Log:
Sync code with 2.1
Revision Changes Path
1.2 +6 -9 cocoon-2.0/src/java/org/apache/cocoon/transformation/EncodeURLTransformer.java
Index: EncodeURLTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/transformation/EncodeURLTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- EncodeURLTransformer.java 9 Mar 2003 00:03:21 -0000 1.1
+++ EncodeURLTransformer.java 19 Dec 2003 08:15:02 -0000 1.2
@@ -301,10 +301,9 @@
String value = new_attributes.getValue(i);
if (elementAttributeMatching.matchesElementAttribute(lname, attr_lname)) {
- // don't use simply response.encodeURL
+ // don't use simply this.response.encodeURL(value)
// but be more smart about the url encoding
- //final String new_value = this.response.encodeURL( value );
- final String new_value = this.encodeURL( value, response );
+ final String new_value = this.encodeURL(value);
if (getLogger().isDebugEnabled()) {
this.getLogger().debug("element/@attribute matches: " + name + "/@" + attr_lname);
this.getLogger().debug("encodeURL: " + value + " -> " + new_value);
@@ -329,11 +328,9 @@
* </p>
*
* @param url the URL probably without sessionid.
- * @param request the http request
- * @param response the http response
* @return String the original url inclusive the sessionid
*/
- private String encodeURL(String url, Response response) {
+ private String encodeURL(String url) {
String encoded_url;
if (this.response != null) {
// As some servlet-engine does not check if url has been already rewritten
@@ -349,7 +346,7 @@
}
return encoded_url;
}
-
+
/**
* A helper class for matching element names, and attribute names.
*
1.2 +111 -46 cocoon-2.0/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java
Index: AbstractSAXTransformer.java
===================================================================
RCS file: /home/cvs/cocoon-2.0/src/java/org/apache/cocoon/transformation/AbstractSAXTransformer.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- AbstractSAXTransformer.java 9 Mar 2003 00:03:20 -0000 1.1
+++ AbstractSAXTransformer.java 19 Dec 2003 08:15:02 -0000 1.2
@@ -201,9 +201,11 @@
*/
protected AttributesImpl emptyAttributes = new AttributesImpl();
- /** The namespaces */
+ /** The namespaces and their prefixes */
private List namespaces = new ArrayList(5);
-
+ /** The current prefix for our namespace */
+ private String ourPrefix;
+
/**
* Avalon Configurable Interface
*/
@@ -226,7 +228,7 @@
throws ProcessingException,
SAXException,
IOException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN setup resolver="+resolver+
", objectModel="+objectModel+
", src="+src+
@@ -254,7 +256,7 @@
this.ignoreWhitespaces = true;
this.ignoreEmptyCharacters = false;
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END setup");
}
}
@@ -292,12 +294,12 @@
public void startDocument()
throws SAXException {
if ( !this.isInitialized ) {
- try {
- this.setupTransforming();
- } catch (ProcessingException local) {
- throw new SAXException("ProcessingException: " + local, local);
- } catch (IOException ioe) {
- throw new SAXException("IOException: " + ioe, ioe);
+ try {
+ this.setupTransforming();
+ } catch (ProcessingException local) {
+ throw new SAXException("ProcessingException: " + local, local);
+ } catch (IOException ioe) {
+ throw new SAXException("IOException: " + ioe, ioe);
}
this.isInitialized = true;
}
@@ -443,7 +445,7 @@
*/
public void startRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN startRecording");
}
DOMBuilder builder = new DOMBuilder();
@@ -453,7 +455,7 @@
this.sendStartPrefixMapping();
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END startRecording");
}
}
@@ -465,7 +467,7 @@
*/
public DocumentFragment endRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN endRecording");
}
@@ -494,7 +496,7 @@
}
}
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
Object serializedXML = null;
try {
serializedXML = (recordedDocFrag == null ? "null" : XMLUtils.serializeNodeToXML(recordedDocFrag));
@@ -513,7 +515,7 @@
*/
public void startTextRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN startTextRecording");
}
XMLConsumer recorder = new TextRecorder();
@@ -521,7 +523,7 @@
this.sendStartPrefixMapping();
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END startTextRecording");
}
}
@@ -532,7 +534,7 @@
*/
public String endTextRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN endTextRecording");
}
@@ -541,7 +543,7 @@
TextRecorder recorder = (TextRecorder)this.removeRecorder();
String text = recorder.getText();
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END endTextRecording text="+text);
}
return text;
@@ -556,12 +558,12 @@
*/
public void startSerializedXMLRecording(Properties format)
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN startSerializedXMLRecording format="+format);
}
this.stack.push((format == null ? XMLUtils.defaultSerializeToXMLFormat() : format));
this.startRecording();
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END startSerializedXMLRecording");
}
}
@@ -573,12 +575,12 @@
*/
public String endSerializedXMLRecording()
throws SAXException, ProcessingException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN endSerializedXMLRecording");
}
DocumentFragment fragment = this.endRecording();
String text = XMLUtils.serializeNode(fragment, (Properties)this.stack.pop());
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END endSerializedXMLRecording xml="+text);
}
return text;
@@ -593,7 +595,7 @@
*/
public void startParametersRecording()
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN startParametersRecording");
}
XMLConsumer recorder = new ParametersRecorder();
@@ -601,7 +603,7 @@
this.sendStartPrefixMapping();
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END startParametersRecording");
}
}
@@ -615,14 +617,14 @@
*/
public SourceParameters endParametersRecording(Parameters source)
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN endParametersRecording source="+source);
}
this.sendEndPrefixMapping();
ParametersRecorder recorder = (ParametersRecorder)this.removeRecorder();
SourceParameters pars = recorder.getParameters(source);
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END endParametersRecording parameters="+pars);
}
return pars;
@@ -637,14 +639,14 @@
*/
public SourceParameters endParametersRecording(SourceParameters source)
throws SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN endParametersRecording source="+source);
}
this.sendEndPrefixMapping();
ParametersRecorder recorder = (ParametersRecorder)this.removeRecorder();
SourceParameters pars = recorder.getParameters(source);
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END endParametersRecording parameters="+pars);
}
return pars;
@@ -662,14 +664,14 @@
*/
public void setupTransforming()
throws IOException, ProcessingException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("BEGIN setupTransforming");
}
this.stack.clear();
this.recorderStack.clear();
this.ignoreWhitespaces = true;
this.ignoreEmptyCharacters = false;
- if (this.getLogger().isDebugEnabled() == true) {
+ if (this.getLogger().isDebugEnabled()) {
this.getLogger().debug("END setupTransforming");
}
}
@@ -687,13 +689,13 @@
String raw,
Attributes attr)
throws ProcessingException, IOException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN startTransformingElement uri=" + uri + ", name=" + name + ", raw=" + raw + ", attr=" + attr + ")");
- }
+ //if (this.getLogger().isDebugEnabled()) {
+ // this.getLogger().debug("BEGIN startTransformingElement uri=" + uri + ", name=" + name + ", raw=" + raw + ", attr=" + attr + ")");
+ //}
if (this.ignoreEventsCount == 0) super.startElement(uri, name, raw, attr);
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END startTransformingElement");
- }
+ //if (this.getLogger().isDebugEnabled()) {
+ // this.getLogger().debug("END startTransformingElement");
+ //}
}
/**
@@ -707,13 +709,13 @@
String name,
String raw)
throws ProcessingException, IOException, SAXException {
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("BEGIN endTransformingElement uri=" + uri + ", name=" + name + ", raw=" + raw + ")");
- }
+ //if (this.getLogger().isDebugEnabled()) {
+ // this.getLogger().debug("BEGIN endTransformingElement uri=" + uri + ", name=" + name + ", raw=" + raw + ")");
+ //}
if (this.ignoreEventsCount == 0) super.endElement(uri, name, raw);
- if (this.getLogger().isDebugEnabled() == true) {
- this.getLogger().debug("END endTransformingElement");
- }
+ //if (this.getLogger().isDebugEnabled()) {
+ // this.getLogger().debug("END endTransformingElement");
+ //}
}
/**
@@ -743,6 +745,20 @@
* Send SAX events to the next pipeline component.
* The startElement event for the given element is send
* to the next component in the current pipeline.
+ * The element has the namespace of the transformer,
+ * but not attributes
+ * @param localname The name of the event.
+ */
+ public void sendStartElementEventNS(String localname)
+ throws SAXException {
+ this.startElement(this.namespaceURI,
+ localname, this.ourPrefix+':' + localname, emptyAttributes);
+ }
+
+ /**
+ * Send SAX events to the next pipeline component.
+ * The startElement event for the given element is send
+ * to the next component in the current pipeline.
* The element has no namespace.
* @param localname The name of the event.
* @param attr The Attributes of the element
@@ -754,6 +770,20 @@
/**
* Send SAX events to the next pipeline component.
+ * The startElement event for the given element is send
+ * to the next component in the current pipeline.
+ * The element has the namespace of the transformer.
+ * @param localname The name of the event.
+ * @param attr The Attributes of the element
+ */
+ public void sendStartElementEventNS(String localname, Attributes attr)
+ throws SAXException {
+ this.startElement(this.namespaceURI,
+ localname, this.ourPrefix+':' + localname, attr);
+ }
+
+ /**
+ * Send SAX events to the next pipeline component.
* The endElement event for the given element is send
* to the next component in the current pipeline.
* The element has no namespace.
@@ -766,6 +796,19 @@
/**
* Send SAX events to the next pipeline component.
+ * The endElement event for the given element is send
+ * to the next component in the current pipeline.
+ * The element has the namespace of the transformer.
+ * @param localname The name of the event.
+ */
+ public void sendEndElementEventNS(String localname)
+ throws SAXException {
+ this.endElement(this.namespaceURI,
+ localname, this.ourPrefix+':' + localname);
+ }
+
+ /**
+ * Send SAX events to the next pipeline component.
* The node is parsed and the events are send to
* the next component in the pipeline.
* @param node The tree to be included.
@@ -858,6 +901,9 @@
public void startPrefixMapping(String prefix, String uri)
throws SAXException {
if (prefix != null) this.namespaces.add(new String[] {prefix, uri});
+ if ( this.namespaceURI != null && this.namespaceURI.equals(uri)) {
+ this.ourPrefix = prefix;
+ }
if (this.ignoreEventsCount == 0) super.startPrefixMapping(prefix, uri);
}
@@ -872,18 +918,37 @@
int l = this.namespaces.size();
int i = l-1;
String currentPrefix;
- while (found == false && i >= 0) {
+ while (!found && i >= 0) {
currentPrefix = ((String[])this.namespaces.get(i))[0];
- if (currentPrefix.equals(prefix) == true) {
+ if (currentPrefix.equals(prefix)) {
found = true;
} else {
i--;
}
}
- if (found == false) {
+ if (!found) {
throw new SAXException("Namespace for prefix '"+ prefix + "' not found.");
}
this.namespaces.remove(i);
+ if ( prefix.equals(this.ourPrefix) ) {
+ this.ourPrefix = null;
+ // now search if we have a different prefix for our namespace
+ found = false;
+ l = this.namespaces.size();
+ i = l-1;
+ String currentNS;
+ while (!found && i >= 0) {
+ currentNS = ((String[])this.namespaces.get(i))[1];
+ if (currentNS.equals(this.namespaceURI)) {
+ found = true;
+ } else {
+ i--;
+ }
+ }
+ if ( found ) {
+ this.ourPrefix = ((String[])this.namespaces.get(i))[0];
+ }
+ }
}
if (this.ignoreEventsCount == 0) super.endPrefixMapping(prefix);
}