Diff of /cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java
Parent Directory
| Revision Log
| Patch
--- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java 2005/04/28 14:11:42 165142
+++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java 2005/04/28 14:23:06 165143
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2004 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.
@@ -15,12 +15,10 @@
*/
package org.apache.cocoon.forms.transformation;
-import java.util.LinkedList;
-
-import org.apache.avalon.framework.CascadingRuntimeException;
import org.apache.cocoon.xml.AbstractXMLPipe;
import org.apache.cocoon.xml.SaxBuffer;
import org.apache.cocoon.xml.XMLConsumer;
+
import org.xml.sax.Attributes;
import org.xml.sax.ContentHandler;
import org.xml.sax.Locator;
@@ -29,6 +27,8 @@ import org.xml.sax.ext.LexicalHandler;
import org.xml.sax.helpers.AttributesImpl;
import org.xml.sax.helpers.LocatorImpl;
+import java.util.LinkedList;
+
// TODO: Reduce the Element creation and deletion churn by providing startElement
// and endElement methods which do not create or use Elements on the stack.
/*
@@ -77,8 +77,8 @@ public class EffectPipe extends Abstract
public Element(String uri, String loc, String raw, Attributes attrs) {
this(null, uri, loc, raw, attrs);
}
-
- public Element(String prefix, String uri, String loc, String raw, Attributes attrs) {
+
+ public Element(String prefix, String uri, String loc, String raw, Attributes attrs) {
this.prefix=prefix;
this.uri = uri;
this.loc = loc;
@@ -89,15 +89,15 @@ public class EffectPipe extends Abstract
} else {
this.attrs = new AttributesImpl(); // be ready to possibly add
}
- } else {
+ } else {
this.attrs = new AttributesImpl(attrs);
}
}
/**
- * Adds/overwrites the attributes from the collection in the argument
+ * Adds/overwrites the attributes from the collection in the argument
* to the ones inside this class.
- *
+ *
* @param newAttrs collection of attributes to add/overwrite
*/
public void addAttributes(Attributes newAttrs) {
@@ -109,15 +109,15 @@ public class EffectPipe extends Abstract
String raw = newAttrs.getQName(i);
String type = newAttrs.getType(i);
String value = newAttrs.getValue(i);
-
+
addAttribute(uri, loc, raw, type, value);
}
}
/**
- * Adds/overwrites one single attribute to the ones already contained
+ * Adds/overwrites one single attribute to the ones already contained
* inside this object.
- *
+ *
* @param uri the uri of the attribute to add.
* @param loc the localname of the attribute to add
* @param raw the rawname of the attribute to add
@@ -127,9 +127,9 @@ public class EffectPipe extends Abstract
public void addAttribute(String uri, String loc, String raw, String type, String value) {
int foundAttr = this.attrs.getIndex(uri, loc);
if (foundAttr == -1) {
- this.attrs.addAttribute(uri, loc, raw, type, value);
+ this.attrs.addAttribute(uri, loc, raw, type, value);
} else {
- this.attrs.setAttribute(foundAttr, uri, loc, raw, type, value);
+ this.attrs.setAttribute(foundAttr, uri, loc, raw, type, value);
}
}
@@ -140,12 +140,12 @@ public class EffectPipe extends Abstract
public void addAttribute(String loc, String value) {
this.addAttribute("", loc, loc, "CDATA", value);
}
-
+
public void removeAttribute(String raw) {
int foundAttr = this.attrs.getIndex(raw);
if (foundAttr == -1) {
- this.attrs.removeAttribute(foundAttr);
- }
+ this.attrs.removeAttribute(foundAttr);
+ }
}
}
@@ -174,28 +174,23 @@ public class EffectPipe extends Abstract
protected class Output extends AbstractXMLPipe {
protected class Buffer extends SaxBuffer {
- LocatorImpl myLocator = new LocatorImpl();
+ LocatorImpl locator;
public void setDocumentLocator(Locator locator) {
super.setDocumentLocator(locator);
if (locator != null) {
- try {
- myLocator.setPublicId(locator.getPublicId());
- myLocator.setSystemId(locator.getSystemId());
- myLocator.setLineNumber(locator.getLineNumber());
- myLocator.setColumnNumber(locator.getColumnNumber());
- } catch (Exception e) {
- throw new CascadingRuntimeException("Error while handling locator", e);
- }
+ this.locator = new LocatorImpl(locator);
}
}
+
public void toSAX(ContentHandler contentHandler) throws SAXException {
- if (locators == null)
- locators = new LinkedList();
- locators.addFirst(EffectPipe.this.locator);
- EffectPipe.this.locator = myLocator;
- super.toSAX(contentHandler);
- EffectPipe.this.locator = (Locator)locators.removeFirst();
+ final Locator saved = EffectPipe.this.locator;
+ EffectPipe.this.locator = this.locator;
+ try {
+ super.toSAX(contentHandler);
+ } finally {
+ EffectPipe.this.locator = saved;
+ }
}
}
@@ -309,8 +304,8 @@ public class EffectPipe extends Abstract
}
buffers.addFirst(saxBuffer);
}
- saxBuffer = (SaxBuffer)new Buffer();
- ((Buffer)saxBuffer).setDocumentLocator(locator);
+ saxBuffer = new Buffer();
+ saxBuffer.setDocumentLocator(locator);
}
protected void bufferFini() {
@@ -350,39 +345,52 @@ public class EffectPipe extends Abstract
}
- protected int event = 0;
+ protected int event;
protected Handler nullHandler = new NullHandler();
protected Handler bufferHandler = new BufferHandler();
- protected LinkedList handlers = null;
- protected Handler handler = null;
+ protected LinkedList handlers;
+ protected Handler handler;
- protected LinkedList elements = null;
- protected Element input = null;
+ protected LinkedList elements;
+ protected Element input;
- protected LinkedList locators = null;
- protected Locator locator = null;
- protected String name = null;
- protected String publicId = null;
- protected String systemId = null;
- protected String target = null;
- protected String data = null;
- protected String prefix = null;
- protected String uri = null;
- protected char c[] = null;
- protected int start = 0;
- protected int len = 0;
+ protected Locator locator;
+ protected String name;
+ protected String publicId;
+ protected String systemId;
+ protected String target;
+ protected String data;
+ protected String prefix;
+ protected String uri;
+ protected char c[];
+ protected int start;
+ protected int len;
+
+ public Output out;
- public Output out = null;
public void init() {
handlers = new LinkedList();
elements = new LinkedList();
- locators = new LinkedList();
out = new Output();
}
+ /**
+ * @return current location (if known)
+ */
+ protected String getLocation() {
+ if (locator != null) {
+ return "unknown";
+ }
+
+ final String location = " (" + locator.getSystemId() + ":" +
+ locator.getLineNumber() + ":" +
+ locator.getColumnNumber() + ")";
+ return location;
+ }
+
//====================================
// Methods overriding AbstractXMLPipe
//====================================
@@ -406,7 +414,6 @@ public class EffectPipe extends Abstract
super.recycle();
handlers = null;
elements = null;
- locators = null;
locator = null;
out = null;
}