Author: vgritsenko Date: Thu Apr 28 07:25:27 2005 New Revision: 165144 URL: http://svn.apache.org/viewcvs?rev=165144&view=rev Log: move getLocation to EffectPipe. remove locators stack.
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectPipe.java cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectPipe.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectPipe.java?rev=165144&r1=165143&r2=165144&view=diff ============================================================================== --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectPipe.java (original) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectPipe.java Thu Apr 28 07:25:27 2005 @@ -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.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 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 @@ } 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 @@ 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 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 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 @@ 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 @@ } buffers.addFirst(saxBuffer); } - saxBuffer = (SaxBuffer)new Buffer(); - ((Buffer)saxBuffer).setDocumentLocator(locator); + saxBuffer = new Buffer(); + saxBuffer.setDocumentLocator(locator); } protected void bufferFini() { @@ -350,39 +345,52 @@ } - 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 @@ super.recycle(); handlers = null; elements = null; - locators = null; locator = null; out = null; } Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java?rev=165144&r1=165143&r2=165144&view=diff ============================================================================== --- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java (original) +++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/EffectWidgetReplacingPipe.java Thu Apr 28 07:25:27 2005 @@ -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. @@ -16,9 +16,9 @@ package org.apache.cocoon.forms.transformation; import org.apache.avalon.excalibur.pool.Recyclable; + import org.apache.cocoon.forms.Constants; import org.apache.cocoon.forms.formmodel.AggregateField; -import org.apache.cocoon.forms.formmodel.ContainerWidget; import org.apache.cocoon.forms.formmodel.DataWidget; import org.apache.cocoon.forms.formmodel.Group; import org.apache.cocoon.forms.formmodel.Repeater; @@ -31,8 +31,8 @@ import org.apache.cocoon.xml.AbstractXMLPipe; import org.apache.cocoon.xml.SaxBuffer; import org.apache.cocoon.xml.XMLUtils; -import org.apache.commons.jxpath.JXPathException; +import org.apache.commons.jxpath.JXPathException; import org.xml.sax.Attributes; import org.xml.sax.ContentHandler; import org.xml.sax.SAXException; @@ -171,17 +171,6 @@ 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("")) { @@ -199,7 +188,7 @@ } protected Widget getWidget(String widgetPath) throws SAXException { - Widget widget = ((ContainerWidget)contextWidget).lookupWidget(widgetPath); + Widget widget = contextWidget.lookupWidget(widgetPath); if (widget == null) { if (contextWidget.getRequestParameterName().equals("")) { throwSAXException("No widget exists at the path \"" + widgetPath + "\", relative to the form container."); @@ -218,7 +207,7 @@ throwWrongWidgetType("RepeaterWidgetLabelHandler", input.loc, "repeater"); } } - + protected boolean isVisible(Widget widget) { return widget.getCombinedState().isDisplayingValues(); } @@ -350,10 +339,10 @@ pipeContext.setLocale(Locale.getDefault()); } } - + out.startPrefixMapping(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS); - // we need to merge input.attrs with possible overruling attributes + // we need to merge input.attrs with possible overruling attributes // from the pipeContext input.addAttributes(pipeContext.getFormAttributes()); @@ -613,7 +602,7 @@ //Don't output fi:struct // out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "union"); // out.attributes(); - // out.startElement(); + // out.startElement(); return this; } else { return nullHandler; @@ -927,7 +916,6 @@ } } - private Attributes translateAttributes(Attributes attributes, String[] names) { AttributesImpl newAtts = new AttributesImpl(attributes); if (names!= null) { @@ -940,56 +928,6 @@ } return newAtts; } - -// /** -// * Replaces JXPath expressions embedded inside #{ and } by their value. -// */ -// private String translateText(String original) { -// StringBuffer expression; -// StringBuffer translated = new StringBuffer(); -// StringReader in = new StringReader(original); -// int chr; -// try { -// while ((chr = in.read()) != -1) { -// char c = (char) chr; -// if (c == '#') { -// chr = in.read(); -// if (chr != -1) { -// c = (char) chr; -// if (c == '{') { -// expression = new StringBuffer(); -// boolean more = true; -// while ( more ) { -// more = false; -// if ((chr = in.read()) != -1) { -// c = (char)chr; -// if (c != '}') { -// expression.append(c); -// more = true; -// } else { -// translated.append(evaluateExpression(expression.toString())); -// } -// } else { -// translated.append('#').append('{').append(expression); -// } -// } -// } -// } else { -// translated.append((char) chr); -// } -// } else { -// translated.append(c); -// } -// } -// } catch (IOException ignored) { -// ignored.printStackTrace(); -// } -// return translated.toString(); -// } - -// private String evaluateExpression(String expression) { -// return pipeContext.evaluateExpression(expression).toString(); -// } public void recycle() { super.recycle();