Author: tim Date: Thu Jan 13 12:40:05 2005 New Revision: 125099 URL: http://svn.apache.org/viewcvs?view=rev&rev=125099 Log: Add support framework for tracking source locations for the forms transformer and do minor code formatting. Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java
Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java?view=diff&rev=125099&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java&r1=125098&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java&r2=125099 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectPipe.java Thu Jan 13 12:40:05 2005 @@ -17,6 +17,7 @@ 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; @@ -26,6 +27,7 @@ import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.helpers.LocatorImpl; // TODO: Reduce the Element creation and deletion churn by providing startElement // and endElement methods which do not create or use Elements on the stack. @@ -170,6 +172,33 @@ } protected class Output extends AbstractXMLPipe { + + protected class Buffer extends SaxBuffer { + LocatorImpl myLocator = new LocatorImpl(); + + 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); + } + } + } + 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(); + } + } + private LinkedList buffers = null; private SaxBuffer saxBuffer = null; private LinkedList elements = null; @@ -280,7 +309,8 @@ } buffers.addFirst(saxBuffer); } - saxBuffer = new SaxBuffer(); + saxBuffer = (SaxBuffer)new Buffer(); + ((Buffer)saxBuffer).setDocumentLocator(locator); } protected void bufferFini() { @@ -331,6 +361,7 @@ protected LinkedList elements = null; protected Element input = null; + protected LinkedList locators = null; protected Locator locator = null; protected String name = null; protected String publicId = null; @@ -348,6 +379,7 @@ public void init() { handlers = new LinkedList(); elements = new LinkedList(); + locators = new LinkedList(); out = new Output(); } @@ -374,6 +406,8 @@ super.recycle(); handlers = null; elements = null; + locators = null; + locator = null; out = null; } @@ -386,9 +420,13 @@ } } - public void startDocument() throws SAXException { event = EVENT_START_DOCUMENT; handler = handler.process(); } + public void startDocument() throws SAXException { + event = EVENT_START_DOCUMENT; handler = handler.process(); + } - public void endDocument() throws SAXException { event = EVENT_END_DOCUMENT; handler = handler.process(); } + public void endDocument() throws SAXException { + event = EVENT_END_DOCUMENT; handler = handler.process(); + } public void startPrefixMapping(String prefix, String uri) throws SAXException { input = new Element(prefix, uri); Modified: cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Url: http://svn.apache.org/viewcvs/cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java?view=diff&rev=125099&p1=cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java&r1=125098&p2=cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java&r2=125099 ============================================================================== --- cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java (original) +++ cocoon/branches/BRANCH_2_1_X/src/blocks/forms/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Thu Jan 13 12:40:05 2005 @@ -36,6 +36,7 @@ import org.xml.sax.SAXException; import org.xml.sax.ext.LexicalHandler; import org.xml.sax.helpers.AttributesImpl; +import org.xml.sax.Locator; import java.util.HashMap; import java.util.LinkedList; @@ -161,6 +162,17 @@ classes = new HashMap(); } + protected String getLocation() { + String location = null; + if (locator != null) { + location = " (" + locator.getSystemId() + ":" + + locator.getLineNumber() + ":" + locator.getColumnNumber() + ")"; + } else { + location = "unknown"; + } + return location; + } + protected String getWidgetId(Attributes attributes) throws SAXException { String widgetId = attributes.getValue("id"); if (widgetId == null || widgetId.equals("")) { @@ -241,6 +253,7 @@ public Handler process() throws SAXException { switch (event) { case EVENT_SET_DOCUMENT_LOCATOR: + out.copy(); return this; case EVENT_START_PREFIX_MAPPING: if(Constants.TEMPLATE_NS.equals(input.uri)) { @@ -258,7 +271,7 @@ return formHandler; } else { throwSAXException("CForms template \"" + input.loc + - "\" not permitted outside \"form-template\""); + "\" not permitted outside \"form-template\" (" + getLocation() + ")"); } } else { // Pass through all others.