You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@cocoon.apache.org by vg...@apache.org on 2005/05/19 16:32:14 UTC
svn commit: r170933 [2/2] - in
/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation:
EffectPipe.java EffectWidgetReplacingPipe.java FormsPipelineConfig.java
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=170933&r1=170932&r2=170933&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 May 19 07:32:13 2005
@@ -1,5 +1,5 @@
/*
- * Copyright 1999-2004 The Apache Software Foundation.
+ * Copyright 1999-2005 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.
@@ -44,21 +44,18 @@
import java.util.Locale;
import java.util.Map;
-// TODO: Reduce the Element creation and deletion churn by using startElement
-// and endElement methods which do not create or use Elements on the stack.
-// The corresponding TODO in the EffectPipe needs to be completed first.
-
/**
- * The basic operation of this Pipe is that it replaces ft:widget (in the
- * {@link Constants#TEMPLATE_NS} namespace) tags (having an id attribute)
+ * The basic operation of this Pipe is that it replaces <code>ft:widget</code>
+ * (in the {@link Constants#TEMPLATE_NS} namespace) tags (having an id attribute)
* by the XML representation of the corresponding widget instance.
*
- * <p>These XML fragments (normally all in the {@link Constants#INSTANCE_NS "CForms Instance"} namespace), can
- * then be translated to a HTML presentation by an XSL. This XSL will then only have to style
- * individual widget, and will not need to do the whole page layout.
+ * <p>These XML fragments (normally all in the {@link Constants#INSTANCE_NS "CForms Instance"}
+ * namespace), can then be translated to a HTML presentation by an XSLT.
+ * This XSLT will then only have to style individual widget, and will not
+ * need to do the whole page layout.
*
- * <p>For more information about the supported tags and their function, see the user documentation
- * for the forms template transformer.</p>
+ * <p>For more information about the supported tags and their function,
+ * see the user documentation for the forms template transformer.</p>
*
* @version $Id$
*/
@@ -92,45 +89,39 @@
protected Widget contextWidget;
protected LinkedList contextWidgets;
protected LinkedList chooseWidgets;
- protected String widgetPath;
protected Widget widget;
protected Map classes;
- private final AggregateWidgetHandler aggregateWidgetHandler = new AggregateWidgetHandler();
- private final ChooseHandler chooseHandler = new ChooseHandler();
- private final ChoosePassThruHandler choosePassThruHandler = new ChoosePassThruHandler();
- private final ClassHandler classHandler = new ClassHandler();
- private final ContinuationIdHandler continuationIdHandler = new ContinuationIdHandler();
- private final DocHandler docHandler = new DocHandler();
- private final FormHandler formHandler = new FormHandler();
- private final GroupHandler groupHandler = new GroupHandler();
- private final NestedHandler nestedHandler = new NestedHandler();
- private final NewHandler newHandler = new NewHandler();
- private final RepeaterSizeHandler repeaterSizeHandler = new RepeaterSizeHandler();
- private final RepeaterWidgetHandler repeaterWidgetHandler = new RepeaterWidgetHandler();
- private final RepeaterWidgetLabelHandler repeaterWidgetLabelHandler = new RepeaterWidgetLabelHandler();
- private final SkipHandler skipHandler = new SkipHandler();
- private final StructHandler structHandler = new StructHandler();
- private final StylingContentHandler stylingHandler = new StylingContentHandler();
- private final UnionHandler unionHandler = new UnionHandler();
- private final UnionPassThruHandler unionPassThruHandler = new UnionPassThruHandler();
- private final ValidationErrorHandler validationErrorHandler = new ValidationErrorHandler();
- private final WidgetHandler widgetHandler = new WidgetHandler();
- private final WidgetLabelHandler widgetLabelHandler = new WidgetLabelHandler();
+ private final AggregateWidgetHandler hAggregate = new AggregateWidgetHandler();
+ private final ChooseHandler hChoose = new ChooseHandler();
+ private final ChoosePassThruHandler hChoosePassThru = new ChoosePassThruHandler();
+ private final ClassHandler hClass = new ClassHandler();
+ private final ContinuationIdHandler hContinuationId = new ContinuationIdHandler();
+ private final DocHandler hDocument = new DocHandler();
+ private final FormHandler hForm = new FormHandler();
+ private final GroupHandler hGroup = new GroupHandler();
+ private final NestedHandler hNested = new NestedHandler();
+ private final NewHandler hNew = new NewHandler();
+ private final RepeaterSizeHandler hRepeaterSize = new RepeaterSizeHandler();
+ private final RepeaterWidgetHandler hRepeaterWidget = new RepeaterWidgetHandler();
+ private final RepeaterWidgetLabelHandler hRepeaterWidgetLabel = new RepeaterWidgetLabelHandler();
+ private final SkipHandler hSkip = new SkipHandler();
+ private final StructHandler hStruct = new StructHandler();
+ private final StylingContentHandler hStyling = new StylingContentHandler();
+ private final UnionHandler hUnion = new UnionHandler();
+ private final UnionPassThruHandler hUnionPassThru = new UnionPassThruHandler();
+ private final ValidationErrorHandler hValidationError = new ValidationErrorHandler();
+ private final WidgetHandler hWidget = new WidgetHandler();
+ private final WidgetLabelHandler hWidgetLabel = new WidgetLabelHandler();
/**
* Map containing all handlers
*/
- private final Map templates = new HashMap();
+ private final Map templates;
protected FormsPipelineConfig pipeContext;
/**
- * Have we encountered a <wi:style> element in a widget ?
- */
- protected boolean gotStylingElement;
-
- /**
* Namespace prefix used for the namespace <code>Constants.FT_NS</code>.
*/
protected String namespacePrefix;
@@ -138,73 +129,90 @@
public EffectWidgetReplacingPipe() {
// Setup map of templates.
- templates.put(AGGREGATE_WIDGET, aggregateWidgetHandler);
- templates.put(CHOOSE, chooseHandler);
- templates.put(CLASS, classHandler);
- templates.put(CONTINUATION_ID, continuationIdHandler);
- templates.put(GROUP, groupHandler);
- templates.put(NEW, newHandler);
- templates.put(REPEATER_SIZE, repeaterSizeHandler);
- templates.put(REPEATER_WIDGET, repeaterWidgetHandler);
- templates.put(REPEATER_WIDGET_LABEL, repeaterWidgetLabelHandler);
- templates.put(STRUCT, structHandler);
- templates.put(UNION, unionHandler);
- templates.put(VALIDATION_ERROR, validationErrorHandler);
- templates.put(WIDGET, widgetHandler);
- templates.put(WIDGET_LABEL, widgetLabelHandler);
- }
-
- private void throwSAXException(String message) throws SAXException{
- throw new SAXException("EffectFormTemplateTransformer: " + message);
+ templates = new HashMap();
+ templates.put(AGGREGATE_WIDGET, hAggregate);
+ templates.put(CHOOSE, hChoose);
+ templates.put(CLASS, hClass);
+ templates.put(CONTINUATION_ID, hContinuationId);
+ templates.put(GROUP, hGroup);
+ templates.put(NEW, hNew);
+ templates.put(REPEATER_SIZE, hRepeaterSize);
+ templates.put(REPEATER_WIDGET, hRepeaterWidget);
+ templates.put(REPEATER_WIDGET_LABEL, hRepeaterWidgetLabel);
+ templates.put(STRUCT, hStruct);
+ templates.put(UNION, hUnion);
+ templates.put(VALIDATION_ERROR, hValidationError);
+ templates.put(WIDGET, hWidget);
+ templates.put(WIDGET_LABEL, hWidgetLabel);
}
public void init(Widget contextWidget, FormsPipelineConfig pipeContext) {
- super.init();
+ // Document handler is top level handler
+ super.init(hDocument);
this.pipeContext = pipeContext;
- // Attach document handler
- handler = docHandler;
-
// Initialize widget related variables
contextWidgets = new LinkedList();
chooseWidgets = new LinkedList();
classes = new HashMap();
}
- protected String getWidgetId(Attributes attributes) throws SAXException {
- String widgetId = attributes.getValue("id");
- if (widgetId == null || widgetId.equals("")) {
- throwSAXException("Missing required widget \"id\" attribute.");
+ /**
+ * Get value of the required attribute
+ */
+ protected String getAttributeValue(String loc, Attributes attrs, String name) throws SAXException {
+ String value = attrs.getValue(name);
+ if (value == null) {
+ throw new SAXException("Element '" + loc + "' missing required '" + name + "' attribute, " +
+ "at " + getLocation());
}
- return widgetId;
+ return value;
}
- protected String getWidgetPath(Attributes attributes) throws SAXException {
- String widgetPath = attributes.getValue("path");
- if (widgetPath == null || widgetPath.equals("")) {
- throwSAXException("Missing required widget \"path\" attribute.");
+ /**
+ * Get non-empty value of the required attribute
+ */
+ protected String getRequiredAttributeValue(String loc, Attributes attrs, String name) throws SAXException {
+ String value = attrs.getValue(name);
+ if (value == null || value.equals("")) {
+ throw new SAXException("Element '" + loc + "' missing required '" + name + "' attribute, " +
+ "at " + getLocation());
}
- return widgetPath;
+ return value;
+ }
+
+ /**
+ * Set the widget by the id attribute
+ */
+ protected void setWidget(String loc, Attributes attrs) throws SAXException {
+ setWidget(loc, getRequiredAttributeValue(loc, attrs, "id"));
}
- protected Widget getWidget(String widgetPath) throws SAXException {
- Widget widget = contextWidget.lookupWidget(widgetPath);
+ /**
+ * Set the widget by its path
+ */
+ protected void setWidget(String loc, String path) throws SAXException {
+ widget = contextWidget.lookupWidget(path);
if (widget == null) {
if (contextWidget.getRequestParameterName().equals("")) {
- throwSAXException("No widget exists at the path \"" + widgetPath + "\", relative to the form container.");
+ throw new SAXException("Element '" + loc + "' refers to unexistent widget path '" + path + "', " +
+ "relative to the form container, at " + getLocation());
} else {
- throwSAXException("No widget exists at the path \"" + widgetPath + "\", relative to the container \"" +
- contextWidget.getRequestParameterName() + "\".");
+ throw new SAXException("Element '" + loc + "' refers to unexistent widget path '" + path + "', " +
+ "relative to the '" + contextWidget.getRequestParameterName() + "', " +
+ "at " + getLocation());
}
}
- return widget;
}
- protected void getRepeaterWidget(String handler) throws SAXException {
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- if (!(widget instanceof Repeater)) {
- throwWrongWidgetType("RepeaterWidgetLabelHandler", input.loc, "repeater");
+ /**
+ * Set typed widget by the id attribute
+ */
+ protected void setTypedWidget(String loc, Attributes attrs, Class wclass, String wname) throws SAXException {
+ setWidget(loc, attrs);
+ if (!wclass.isInstance(widget)) {
+ throw new SAXException("Element '" + loc + "' can only be used with " + wname + " widgets, " +
+ "at " + getLocation());
}
}
@@ -212,10 +220,6 @@
return widget.getCombinedState().isDisplayingValues();
}
- public void throwWrongWidgetType(String pipeName, String element, String widget) throws SAXException {
- throwSAXException(pipeName + ": Element \"" + element + "\" can only be used for " + widget + " widgets.");
- }
-
/**
* Needed to get things working with JDK 1.3. Can be removed once we
* don't support that platform any more.
@@ -232,610 +236,491 @@
return this.lexicalHandler;
}
- public Handler nestedTemplate() throws SAXException {
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- // Element in forms template namespace.
- Handler handler = (Handler)templates.get(input.loc);
- if (handler != null) {
- return handler;
- } else if (FORM_TEMPLATE_EL.equals(input.loc)) {
- throwSAXException("Element \"form-template\" must not be nested.");
- return null; // Keep the compiler happy.
- } else {
- throwSAXException("Unrecognized template: " + input.loc);
- return null; // Keep the compiler happy.
+ //
+ // Handler classes to transform CForms template elements
+ //
+
+ protected class NestedHandler extends CopyHandler {
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ // Is it forms namespace?
+ if (!Constants.TEMPLATE_NS.equals(uri)) {
+ return hNested;
}
- } else {
- // Element not in forms namespace.
- return nestedHandler;
+
+ Handler handler = (Handler) templates.get(loc);
+ if (handler == null) {
+ throw new SAXException("Element '" + loc + "' was not recognized, " +
+ "at " + getLocation());
+ }
+
+ return handler;
}
}
- //==============================================
- // Handler classes to transform CForms templates
- //==============================================
+ /**
+ * Top level handler for the forms template
+ */
+ protected class DocHandler extends CopyHandler {
+ public void startPrefixMapping(String prefix, String uri)
+ throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ // We consume this namespace completely.
+ EffectWidgetReplacingPipe.this.namespacePrefix = prefix;
+ return;
+ }
- protected class DocHandler extends Handler {
- 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)) {
- // We consume this namespace completely.
- EffectWidgetReplacingPipe.this.namespacePrefix = input.prefix;
- return this;
- } else {
- // Pass through all others.
- out.copy();
- return this;
- }
- case EVENT_ELEMENT:
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- if (FORM_TEMPLATE_EL.equals(input.loc)) {
- return formHandler;
- } else {
- throwSAXException("CForms template \"" + input.loc +
- "\" not permitted outside \"form-template\" (" + getLocation() + ")");
- }
- } else {
- // Pass through all others.
- out.copy();
- return this;
+ // Pass through all others.
+ super.startPrefixMapping(prefix, uri);
+ }
+
+ public void endPrefixMapping(String prefix)
+ throws SAXException {
+ if (prefix.equals(EffectWidgetReplacingPipe.this.namespacePrefix)) {
+ // We consume this namespace completely.
+ EffectWidgetReplacingPipe.this.namespacePrefix = null;
+ return;
+ }
+
+ // Pass through all others.
+ super.endPrefixMapping(prefix);
+ }
+
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ if (!FORM_TEMPLATE_EL.equals(loc)) {
+ throw new SAXException("Element '" + loc + "' is not permitted outside of " +
+ "'form-template', at " + getLocation());
}
- case EVENT_END_PREFIX_MAPPING:
- // We consume this namespace completely
- return this;
- default:
- out.copy();
- return this;
+
+ return hForm;
}
+
+ return super.nestedElement(uri, loc, raw, attrs);
}
}
- protected class FormHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- if (contextWidget != null) {
- throwSAXException("Detected nested ft:form-template elements, this is not allowed.");
+ /**
+ * <code>ft:form-template</code> element handler.
+ * <pre>
+ * <ft:form-template locale="..." location="...">
+ * ...
+ * </ft:form-template>
+ * </pre>
+ */
+ protected class FormHandler extends NestedHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ if (contextWidget != null) {
+ throw new SAXException("Element 'form-template' can not be nested, " +
+ "at " + getLocation());
+ }
+
+ AttributesImpl newAttrs = attrs == null || attrs.getLength() == 0?
+ new AttributesImpl():
+ new AttributesImpl(attrs);
+
+ // ====> Retrieve the form
+ String formLocation = attrs.getValue(LOCATION);
+ if (formLocation != null) {
+ // Remove the location attribute
+ newAttrs.removeAttribute(newAttrs.getIndex(LOCATION));
+ }
+ contextWidget = pipeContext.findForm(formLocation);
+
+ // ====> Check if form visible (and skip it if it's not)
+ if (!isVisible(contextWidget)) {
+ return hNull;
+ }
+
+ // ====> Determine the Locale
+ // TODO pull this locale stuff also up in the Config object?
+ String localeAttr = attrs.getValue("locale");
+ if (localeAttr != null) { // first use value of locale attribute if any
+ localeAttr = pipeContext.translateText(localeAttr);
+ pipeContext.setLocale(I18nUtils.parseLocale(localeAttr));
+ } else if (pipeContext.getLocaleParameter() != null) { // then use locale specified as transformer parameter, if any
+ pipeContext.setLocale(pipeContext.getLocaleParameter());
+ } else {
+ // use locale specified in bizdata supplied for form
+ Object locale = null;
+ try {
+ locale = pipeContext.evaluateExpression("/locale");
+ } catch (JXPathException e) {}
+ if (locale != null) {
+ pipeContext.setLocale((Locale)locale);
+ } else {
+ // final solution: use locale defined in the server machine
+ pipeContext.setLocale(Locale.getDefault());
}
+ }
- // ====> Retrieve the form
- // First look for the form using the location attribute, if any
- String formJXPath = input.attrs.getValue(LOCATION);
- if (formJXPath != null) {
- // remove the location attribute
- input.removeAttribute(LOCATION);
- }
- contextWidget = pipeContext.findForm(formJXPath);
+ // We need to merge input.attrs with possible overruling attributes
+ // from the pipeContext
+ pipeContext.addFormAttributes(newAttrs);
+ String[] namesToTranslate = {"action"};
+ Attributes transAttrs = translateAttributes(newAttrs, namesToTranslate);
+
+ getContentHandler().startPrefixMapping(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS);
+ getContentHandler().startElement(Constants.INSTANCE_NS, "form-template", Constants.INSTANCE_PREFIX_COLON + "form-template", transAttrs);
+ return this;
+ }
- if (!isVisible(contextWidget)) {
- // Skip widget and its content
- return nullHandler;
- }
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ getContentHandler().endElement(Constants.INSTANCE_NS, "form-template", Constants.INSTANCE_PREFIX_COLON + "form-template");
+ getContentHandler().endPrefixMapping(Constants.INSTANCE_PREFIX);
+ contextWidget = null;
+ }
+ }
- // ====> Determine the Locale
- //TODO pull this locale stuff also up in the Config object?
- String localeAttr = input.attrs.getValue("locale");
- if (localeAttr != null) { // first use value of locale attribute if any
- localeAttr = pipeContext.translateText(localeAttr);
- pipeContext.setLocale(I18nUtils.parseLocale(localeAttr));
- } else if (pipeContext.getLocaleParameter() != null) { // then use locale specified as transformer parameter, if any
- pipeContext.setLocale(pipeContext.getLocaleParameter());
- } else {
- //TODO pull this locale stuff also up in the Config object?
- // use locale specified in bizdata supplied for form
- Object locale = null;
- try {
- locale = pipeContext.evaluateExpression("/locale");
- } catch (JXPathException e) {}
- if (locale != null) {
- pipeContext.setLocale((Locale)locale);
- }
- else {
- // final solution: use locale defined in the server machine
- pipeContext.setLocale(Locale.getDefault());
- }
- }
+ protected class SkipHandler extends NestedHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ return this;
+ }
- out.startPrefixMapping(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS);
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ }
+ }
- // we need to merge input.attrs with possible overruling attributes
- // from the pipeContext
- input.addAttributes(pipeContext.getFormAttributes());
-
- String[] namesToTranslate = {"action"};
- Attributes transAttrs = translateAttributes(input.attrs, namesToTranslate);
- out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "form-template", transAttrs);
- out.startElement();
- return this;
- case EVENT_ELEMENT:
- return nestedTemplate();
- case EVENT_END_ELEMENT:
- out.copy();
- out.endPrefixMapping(Constants.INSTANCE_PREFIX);
- contextWidget = null;
- return this;
- default:
- out.copy();
- return this;
- }
+ protected class WidgetLabelHandler extends ErrorHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setWidget(loc, attrs);
+ widget.generateLabel(getContentHandler());
+ return this;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
}
}
- protected class NestedHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_ELEMENT:
- return nestedTemplate();
- default:
- out.copy();
- return this;
+ protected class WidgetHandler extends NullHandler {
+ private boolean hasStyling;
+
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setWidget(loc, attrs);
+ if (!isVisible(widget)) {
+ return hNull;
}
+
+ hasStyling = false;
+ return this;
}
- }
- protected class SkipHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- return this;
- case EVENT_ELEMENT:
- return nestedTemplate();
- case EVENT_END_ELEMENT:
- return this;
- default:
- out.copy();
- return this;
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ if (Constants.INSTANCE_NS.equals(uri)) {
+ if (!STYLING_EL.equals(loc)) {
+ throw new SAXException("Element '" + loc + "' is not permitted within 'widget', " +
+ "at " + getLocation());
+ }
+ hasStyling = true;
+ beginBuffer();
+ // Buffer styling elements
+ return hBuffer;
}
+ return hNull;
}
- }
- protected class WidgetLabelHandler extends Handler {
- public Handler process() throws SAXException {
- switch (event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- Widget widget = getWidget(widgetPath);
- widget.generateLabel(getContentHandler());
- widget = null;
- return this;
- case EVENT_ELEMENT:
- return nullHandler;
- case EVENT_END_ELEMENT:
- return this;
- default:
- out.copy();
- return this;
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ if (hasStyling) {
+ hasStyling = false;
+ hStyling.recycle();
+ hStyling.setSaxFragment(endBuffer());
+ hStyling.setContentHandler(getContentHandler());
+ hStyling.setLexicalHandler(getLexicalHandler());
+ widget.generateSaxFragment(hStyling, pipeContext.getLocale());
+ } else {
+ widget.generateSaxFragment(getContentHandler(), pipeContext.getLocale());
}
+ widget = null;
}
}
- protected class WidgetHandler extends Handler {
- public Handler process() throws SAXException {
- switch (event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
-
- if (isVisible(widget)) {
- gotStylingElement = false;
- out.bufferInit();
- return this;
- } else {
- // Skip widget and its content
- return nullHandler;
- }
- case EVENT_ELEMENT:
- if (Constants.INSTANCE_NS.equals(input.uri) && STYLING_EL.equals(input.loc)) {
- gotStylingElement = true;
- }
- return bufferHandler;
-
- case EVENT_END_ELEMENT:
- stylingHandler.recycle();
- stylingHandler.setSaxFragment(out.getBuffer());
- stylingHandler.setContentHandler(getContentHandler());
- stylingHandler.setLexicalHandler(getLexicalHandler());
- widget.generateSaxFragment(stylingHandler, pipeContext.getLocale());
- widget = null;
- out.bufferFini();
- return this;
+ protected class RepeaterSizeHandler extends ErrorHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Repeater.class, "repeater");
+ ((Repeater) widget).generateSize(getContentHandler());
+ widget = null;
+ return this;
+ }
- default:
- out.copy();
- return this;
- }
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
}
}
- protected class RepeaterSizeHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- getRepeaterWidget("RepeaterSizeHandler");
- ((Repeater)widget).generateSize(getContentHandler());
- widget = null;
- return this;
- case EVENT_ELEMENT:
- return nullHandler;
- case EVENT_END_ELEMENT:
- return this;
- default:
- out.copy();
- return this;
- }
+ protected class RepeaterWidgetLabelHandler extends ErrorHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Repeater.class, "repeater");
+ String path = getRequiredAttributeValue(loc, attrs, "widget-id");
+ ((Repeater) widget).generateWidgetLabel(path, getContentHandler());
+ widget = null;
+ return this;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
}
}
- protected class RepeaterWidgetLabelHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- getRepeaterWidget("RepeaterWidgetLabelHandler");
- String widgetPath = input.attrs.getValue("widget-id");
- if (widgetPath == null || widgetPath.equals(""))
- throwSAXException("Element repeater-widget-label missing required widget-id attribute.");
- ((Repeater)widget).generateWidgetLabel(widgetPath, getContentHandler());
- widget = null;
- return this;
- case EVENT_ELEMENT:
- return nullHandler;
- case EVENT_END_ELEMENT:
- return this;
- default:
- out.copy();
+ protected class RepeaterWidgetHandler extends BufferHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Repeater.class, "repeater");
+ if (isVisible(widget)) {
+ beginBuffer();
return this;
}
+ return hNull;
}
- }
- protected class RepeaterWidgetHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- getRepeaterWidget("RepeaterWidgetHandler");
- if (isVisible(widget)) {
- out.bufferInit();
- return this;
- } else {
- return nullHandler;
- }
- case EVENT_ELEMENT:
- return bufferHandler;
- case EVENT_END_ELEMENT:
- Repeater repeater = (Repeater)widget;
- int rowCount = repeater.getSize();
- handlers.addFirst(handler);
- handler = nestedHandler;
- contextWidgets.addFirst(contextWidget);
- for (int i = 0; i < rowCount; i++) {
- Repeater.RepeaterRow row = repeater.getRow(i);
- contextWidget = row;
- if (isVisible(contextWidget)) {
- out.getBuffer().toSAX(EffectWidgetReplacingPipe.this);
- }
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ return hBuffer;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ SaxBuffer buffer = endBuffer();
+ final Repeater repeater = (Repeater) widget;
+ final int rowCount = repeater.getSize();
+ pushHandler(hNested);
+ contextWidgets.addFirst(contextWidget);
+ for (int i = 0; i < rowCount; i++) {
+ contextWidget = repeater.getRow(i);
+ if (isVisible(contextWidget)) {
+ buffer.toSAX(EffectWidgetReplacingPipe.this);
}
- contextWidget = (Widget)contextWidgets.removeFirst();
- handler = (Handler)handlers.removeFirst();
- widget = null;
- out.bufferFini();
- return this;
- default:
- out.buffer();
- return this;
}
+ contextWidget = (Widget) contextWidgets.removeFirst();
+ popHandler();
+ widget = null;
}
}
- protected class AggregateWidgetHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- if (!(widget instanceof AggregateField)) {
- throwWrongWidgetType("AggregateWidgetHandler", input.loc, "aggregate");
- }
-
- if (isVisible(widget)) {
- contextWidgets.addFirst(contextWidget);
- contextWidget = widget;
- return this;
- } else {
- return nullHandler;
- }
- case EVENT_ELEMENT:
- return nestedTemplate();
- case EVENT_END_ELEMENT:
- contextWidget = (Widget)contextWidgets.removeFirst();
- return this;
- default:
- out.copy();
- return this;
+ protected class AggregateWidgetHandler extends NestedHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, AggregateField.class, "aggregate");
+ if (!isVisible(widget)) {
+ return hNull;
}
+
+ contextWidgets.addFirst(contextWidget);
+ contextWidget = widget;
+ return this;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ contextWidget = (Widget) contextWidgets.removeFirst();
}
}
- protected class GroupHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- if (!(widget instanceof Group)) {
- throwWrongWidgetType("GroupHandler", input.loc, "group");
- }
- if (isVisible(widget)) {
- contextWidgets.addFirst(contextWidget);
- contextWidget = widget;
- return this;
- } else {
- return nullHandler;
- }
- case EVENT_ELEMENT:
- return nestedTemplate();
- case EVENT_END_ELEMENT:
- contextWidget = (Widget)contextWidgets.removeFirst();
- return this;
- default:
- out.copy();
- return this;
+ protected class GroupHandler extends AggregateWidgetHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Group.class, "group");
+ if (!isVisible(widget)) {
+ return hNull;
}
+
+ contextWidgets.addFirst(contextWidget);
+ contextWidget = widget;
+ return this;
}
}
- protected class StructHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- if (!(widget instanceof Struct)) {
- throwWrongWidgetType("StructHandler", input.loc, "struct");
- }
- if (isVisible(widget)) {
- contextWidgets.addFirst(contextWidget);
- contextWidget = widget;
- //Don't output fi:struct
- // out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "union");
- // out.attributes();
- // out.startElement();
- return this;
- } else {
- return nullHandler;
+ protected class ChooseHandler extends CopyHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
+ setWidget(loc, getRequiredAttributeValue(loc, attrs, "path"));
+ // TODO: Should instead check for datatype convertable to String.
+ if (!(widget instanceof DataWidget)) {
+ throw new SAXException("Element '" + loc + "' can only be used with DataWidget widgets, " +
+ "at " + getLocation());
+ }
+ // Choose does not change the context widget like Union does.
+ chooseWidgets.addFirst(widget);
+ return this;
+ }
+
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ if ("when".equals(loc)) {
+ String testValue = getAttributeValue(loc, attrs, "value");
+ String value = (String) ((Widget) chooseWidgets.get(0)).getValue();
+ return testValue.equals(value) ? hSkip : hNull;
}
- case EVENT_ELEMENT:
- return nestedTemplate();
- case EVENT_END_ELEMENT:
- // don't output fi:struct
- // out.endElement();
- contextWidget = (Widget)contextWidgets.removeFirst();
- return this;
- default:
- out.copy();
- return this;
+ throw new SAXException("Element '" + loc + "' is not permitted within 'choose', " +
+ "at " + getLocation());
}
+ return hChoosePassThru;
+ }
+
+ public void endElement(String uri, String loc, String raw) throws SAXException {
+ chooseWidgets.removeFirst();
}
}
- protected class ChooseHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetPath(input.attrs);
- widget = getWidget(widgetPath);
- // TODO: Should instead check for datatype convertable to String.
- if (!(widget instanceof DataWidget)) {
- throwWrongWidgetType("ChooseHandler", input.loc, "DataWidget");
+ protected class ChoosePassThruHandler extends CopyHandler {
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs) throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ if ("when".equals(loc)) {
+ String testValue = getAttributeValue(loc, attrs, "value");
+ String value = (String) ((Widget) chooseWidgets.get(0)).getValue();
+ return testValue.equals(value)? hSkip: hNull;
}
- contextWidgets.addFirst(contextWidget);
- // Choose does not change the context widget like Union does:
- // contextWidget = widget;
- chooseWidgets.addFirst(widget);
- return this;
- case EVENT_ELEMENT:
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- if ("when".equals(input.loc)) {
- String testValue = input.attrs.getValue("value");
- if (testValue == null) throwSAXException("Element \"when\" missing required \"value\" attribute.");
- String value = (String)((Widget)chooseWidgets.get(0)).getValue();
- if (testValue.equals(value)) {
- return skipHandler;
- } else {
- return nullHandler;
- }
- } else if (FORM_TEMPLATE_EL.equals(input.loc)) {
- throwSAXException("Element \"form-template\" must not be nested.");
- } else {
- throwSAXException("Unrecognized template: " + input.loc);
- }
- } else {
- return choosePassThruHandler;
- }
- case EVENT_END_ELEMENT:
- chooseWidgets.removeFirst();
- contextWidget = (Widget)contextWidgets.removeFirst();
- return this;
- default:
- out.copy();
- return this;
+ throw new SAXException("Element '" + loc + "' is not permitted within 'choose', " +
+ "at " + getLocation());
}
+ return this;
}
}
- protected class ChoosePassThruHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_ELEMENT:
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- if ("when".equals(input.loc)) {
- String testValue = input.attrs.getValue("value");
- if (testValue == null) throwSAXException("Element \"when\" missing required \"value\" attribute.");
- String value = (String)((Widget)chooseWidgets.get(0)).getValue();
- if (testValue.equals(value)) {
- return skipHandler;
- } else {
- return nullHandler;
- }
- } else if (FORM_TEMPLATE_EL.equals(input.loc)) {
- throwSAXException("Element \"form-template\" must not be nested.");
- } else {
- throwSAXException("Unrecognized template: " + input.loc);
- }
- } else {
- return this;
- }
- default:
- out.copy();
- return this;
+ protected class StructHandler extends AggregateWidgetHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Struct.class, "struct");
+ if (!isVisible(widget)) {
+ return hNull;
}
+
+ contextWidgets.addFirst(contextWidget);
+ contextWidget = widget;
+ return this;
}
}
- protected class UnionHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- if (!(widget instanceof Union)) {
- throwWrongWidgetType("UnionHandler", input.loc, "union");
- }
- if (isVisible(widget)) {
- contextWidgets.addFirst(contextWidget);
- contextWidget = widget;
- return this;
- } else {
- return nullHandler;
- }
- case EVENT_ELEMENT:
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- if ("case".equals(input.loc)) {
- String id = input.attrs.getValue("id");
- if (id == null) throwSAXException("Element \"case\" missing required \"id\" attribute.");
- String value = (String)contextWidget.getValue();
- if (id.equals(value != null ? value : "")) {
- return skipHandler;
- } else {
- return nullHandler;
- }
- } else if (FORM_TEMPLATE_EL.equals(input.loc)) {
- throwSAXException("Element \"form-template\" must not be nested.");
- } else {
- throwSAXException("Unrecognized template: " + input.loc);
+ protected class UnionHandler extends CopyHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setTypedWidget(loc, attrs, Union.class, "union");
+ if (!isVisible(widget)) {
+ return hNull;
+ }
+
+ contextWidgets.addFirst(contextWidget);
+ contextWidget = widget;
+ return this;
+ }
+
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ if ("case".equals(loc)) {
+ String id = getAttributeValue(loc, attrs, "id");
+ String value = (String) contextWidget.getValue();
+ if (id.equals(value != null ? value : "")) {
+ return hSkip;
}
- } else {
- return unionPassThruHandler;
+ return hNull;
}
- case EVENT_END_ELEMENT:
- contextWidget = (Widget)contextWidgets.removeFirst();
- return this;
- default:
- out.copy();
- return this;
+ throw new SAXException("Element '" + loc + "' is not permitted within 'union', " +
+ "at " + getLocation());
}
+ return hUnionPassThru;
+ }
+
+ public void endElement(String uri, String loc, String raw) throws SAXException {
+ contextWidget = (Widget)contextWidgets.removeFirst();
}
}
- protected class UnionPassThruHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_ELEMENT:
- if (Constants.TEMPLATE_NS.equals(input.uri)) {
- if ("case".equals(input.loc)) {
- if (contextWidget.getValue().equals(input.attrs.getValue("id"))) {
- return skipHandler;
- } else {
- return nullHandler;
- }
- } else if (FORM_TEMPLATE_EL.equals(input.loc)) {
- throwSAXException("Element \"form-template\" must not be nested.");
- } else {
- throwSAXException("Unrecognized template: " + input.loc);
+ protected class UnionPassThruHandler extends CopyHandler {
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ if (Constants.TEMPLATE_NS.equals(uri)) {
+ if ("case".equals(loc)) {
+ if (contextWidget.getValue().equals(attrs.getValue("id"))) {
+ return hSkip;
}
- } else {
- return this;
+ return hNull;
}
- default:
- out.copy();
- return this;
+ throw new SAXException("Element '" + loc + "' is not permitted within 'union', " +
+ "at " + getLocation());
}
+ return this;
}
}
- protected class NewHandler extends Handler {
- public Handler process() throws SAXException {
- switch (event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- SaxBuffer classBuffer = (SaxBuffer)classes.get(widgetPath);
- if (classBuffer == null) {
- throwSAXException("New: Class \"" + widgetPath + "\" does not exist.");
- }
- handlers.addFirst(handler);
- handler = nestedHandler;
- classBuffer.toSAX(EffectWidgetReplacingPipe.this);
- handler = (Handler)handlers.removeFirst();
- return this;
- case EVENT_ELEMENT:
- return nullHandler;
- case EVENT_END_ELEMENT:
- return this;
- default:
- out.copy();
- return this;
- }
+ protected class NewHandler extends CopyHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ String id = getRequiredAttributeValue(loc, attrs, "id");
+ SaxBuffer buffer = (SaxBuffer) classes.get(id);
+ if (buffer == null) {
+ throw new SAXException("New: Class '" + id + "' does not exist, " +
+ "at " + getLocation());
+ }
+ pushHandler(hNested);
+ buffer.toSAX(EffectWidgetReplacingPipe.this);
+ popHandler();
+ return this;
+ }
+
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ return hNull;
+ }
+
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
}
}
- protected class ClassHandler extends Handler {
- public Handler process() throws SAXException {
- switch (event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- out.bufferInit();
- return this;
- case EVENT_ELEMENT:
- return bufferHandler;
- case EVENT_END_ELEMENT:
- classes.put(widgetPath, out.getBuffer());
- out.bufferFini();
- return this;
- default:
- out.buffer();
- return this;
- }
+ protected class ClassHandler extends BufferHandler {
+ // FIXME What if <class> is nested within <class>?
+ private String widgetPath;
+
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ widgetPath = getRequiredAttributeValue(loc, attrs, "id");
+ beginBuffer();
+ return this;
+ }
+
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ return hBuffer;
+ }
+
+ public void endElement(String uri, String loc, String raw) throws SAXException {
+ classes.put(widgetPath, endBuffer());
}
}
- protected class ContinuationIdHandler extends Handler {
- public Handler process() throws SAXException {
- switch(event) {
- case EVENT_START_ELEMENT:
- // Insert the continuation id
- // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel here.
- Object idObj = pipeContext.evaluateExpression("$cocoon/continuation/id");
- if (idObj == null) {
- throwSAXException("No continuation found");
- }
+ protected class ContinuationIdHandler extends ErrorHandler {
+ protected String getName() {
+ return "continuation-id";
+ }
- String id = idObj.toString();
- out.element(Constants.INSTANCE_PREFIX, Constants.INSTANCE_NS, "continuation-id", input.attrs);
- out.startElement();
- out.characters(id.toCharArray(), 0, id.length());
- out.endElement();
- return this;
- case EVENT_END_ELEMENT:
- return this;
- case EVENT_IGNORABLE_WHITESPACE:
- return this;
- default:
- throwSAXException("ContinuationIdHandler: No content allowed in \"continuation-id\" element");
- return null; // Keep the compiler happy.
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ // Insert the continuation id
+ // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel here.
+ Object idObj = pipeContext.evaluateExpression("$cocoon/continuation/id");
+ if (idObj == null) {
+ throw new SAXException("No continuation found");
}
+
+ String id = idObj.toString();
+ getContentHandler().startElement(Constants.INSTANCE_NS, "continuation-id", Constants.INSTANCE_PREFIX_COLON + "continuation-id", attrs);
+ getContentHandler().characters(id.toCharArray(), 0, id.length());
+ getContentHandler().endElement(Constants.INSTANCE_NS, "continuation-id", Constants.INSTANCE_PREFIX_COLON + "continuation-id");
+ return this;
+ }
+
+ public void endElement(String uri, String loc, String raw) throws SAXException {
}
}
@@ -843,18 +728,20 @@
* This ContentHandler helps in inserting SAX events before the closing tag of the root
* element.
*/
- protected class StylingContentHandler extends AbstractXMLPipe implements Recyclable {
+ protected class StylingContentHandler extends AbstractXMLPipe
+ implements Recyclable {
+
private int elementNesting;
- private SaxBuffer saxBuffer;
+ private SaxBuffer styling;
public void setSaxFragment(SaxBuffer saxFragment) {
- saxBuffer = saxFragment;
+ styling = saxFragment;
}
public void recycle() {
super.recycle();
elementNesting = 0;
- saxBuffer = null;
+ styling = null;
}
public void startElement(String uri, String loc, String raw, Attributes a)
@@ -866,16 +753,8 @@
public void endElement(String uri, String loc, String raw)
throws SAXException {
elementNesting--;
- if (elementNesting == 0 && saxBuffer != null) {
- if (gotStylingElement) {
- // Just deserialize
- saxBuffer.toSAX(getContentHandler());
- } else {
- // Insert an enclosing <wi:styling>
- out.startElement(Constants.INSTANCE_NS, STYLING_EL, Constants.INSTANCE_PREFIX_COLON + STYLING_EL, XMLUtils.EMPTY_ATTRIBUTES);
- saxBuffer.toSAX(getContentHandler());
- out.endElement(Constants.INSTANCE_NS, STYLING_EL, Constants.INSTANCE_PREFIX_COLON + STYLING_EL);
- }
+ if (elementNesting == 0) {
+ styling.toSAX(getContentHandler());
}
super.endElement(uri, loc, raw);
}
@@ -884,38 +763,42 @@
/**
* Inserts validation errors (if any) for the Field widgets
*/
- protected class ValidationErrorHandler extends Handler {
- public Handler process() throws SAXException {
- switch (event) {
- case EVENT_START_ELEMENT:
- widgetPath = getWidgetId(input.attrs);
- widget = getWidget(widgetPath);
- out.bufferInit();
- return this;
+ protected class ValidationErrorHandler extends NullHandler {
+ public Handler startElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ setWidget(loc, attrs);
+ return this;
+ }
- case EVENT_ELEMENT:
- return bufferHandler;
+ public Handler nestedElement(String uri, String loc, String raw, Attributes attrs)
+ throws SAXException {
+ return hNull;
+ }
- case EVENT_END_ELEMENT:
- if (widget instanceof ValidationErrorAware) {
- ValidationError error = ((ValidationErrorAware)widget).getValidationError();
- if (error != null) {
- out.startElement(Constants.INSTANCE_NS, VALIDATION_ERROR, Constants.INSTANCE_PREFIX_COLON + VALIDATION_ERROR, XMLUtils.EMPTY_ATTRIBUTES);
- error.generateSaxFragment(stylingHandler);
- out.endElement(Constants.INSTANCE_NS, VALIDATION_ERROR, Constants.INSTANCE_PREFIX_COLON + VALIDATION_ERROR);
- }
+ public void endElement(String uri, String loc, String raw)
+ throws SAXException {
+ if (widget instanceof ValidationErrorAware) {
+ ValidationError error = ((ValidationErrorAware)widget).getValidationError();
+ if (error != null) {
+ getContentHandler().startElement(Constants.INSTANCE_NS, VALIDATION_ERROR, Constants.INSTANCE_PREFIX_COLON + VALIDATION_ERROR, XMLUtils.EMPTY_ATTRIBUTES);
+ error.generateSaxFragment(hStyling);
+ getContentHandler().endElement(Constants.INSTANCE_NS, VALIDATION_ERROR, Constants.INSTANCE_PREFIX_COLON + VALIDATION_ERROR);
}
- widget = null;
- out.bufferFini();
- return this;
-
- default:
- out.copy();
- return this;
}
+ widget = null;
}
}
+
+ public void recycle() {
+ super.recycle();
+ this.contextWidget = null;
+ this.widget = null;
+ this.pipeContext = null;
+ this.namespacePrefix = null;
+ }
+
+
private Attributes translateAttributes(Attributes attributes, String[] names) {
AttributesImpl newAtts = new AttributesImpl(attributes);
if (names!= null) {
@@ -927,14 +810,5 @@
}
}
return newAtts;
- }
-
- public void recycle() {
- super.recycle();
- this.contextWidget = null;
- this.widget = null;
- this.widgetPath = null;
- this.pipeContext = null;
- this.namespacePrefix = null;
}
}
Modified: cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java
URL: http://svn.apache.org/viewcvs/cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java?rev=170933&r1=170932&r2=170933&view=diff
==============================================================================
--- cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java (original)
+++ cocoon/blocks/core/forms/trunk/java/org/apache/cocoon/forms/transformation/FormsPipelineConfig.java Thu May 19 07:32:13 2005
@@ -1,12 +1,12 @@
/*
* Copyright 1999-2005 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,13 +15,8 @@
*/
package org.apache.cocoon.forms.transformation;
-import java.io.IOException;
-import java.io.StringReader;
-import java.util.HashMap;
-import java.util.Locale;
-import java.util.Map;
-
import org.apache.avalon.framework.parameters.Parameters;
+
import org.apache.cocoon.components.flow.FlowHelper;
import org.apache.cocoon.components.flow.WebContinuation;
import org.apache.cocoon.environment.ObjectModelHelper;
@@ -29,12 +24,19 @@
import org.apache.cocoon.environment.Session;
import org.apache.cocoon.forms.formmodel.Form;
import org.apache.cocoon.i18n.I18nUtils;
-import org.apache.cocoon.xml.AttributesImpl;
+
import org.apache.commons.jxpath.JXPathContext;
import org.apache.commons.jxpath.JXPathException;
import org.apache.commons.jxpath.Variables;
import org.xml.sax.Attributes;
import org.xml.sax.SAXException;
+import org.xml.sax.helpers.AttributesImpl;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.HashMap;
+import java.util.Locale;
+import java.util.Map;
/**
* @version $Id$
@@ -46,24 +48,28 @@
*/
public static final String CFORMSKEY = "CocoonFormsInstance";
- /**
+ /**
* Name of the request attribute under which the Cocoon Form is stored (optional). */
private final String attributeName;
/**
- * Pointer to the current request object. */
+ * Pointer to the current request object.
+ */
private final Request request;
/**
- * Initialized jxpathcontext to evaluate passed expressions with. */
+ * Initialized jxpathcontext to evaluate passed expressions with.
+ */
private final JXPathContext jxpathContext;
- /**
- * Containts locale specified as a parameter to the transformer, if any. */
+ /**
+ * Containts locale specified as a parameter to the transformer, if any.
+ */
private final Locale localeParameter;
- /**
- * The locale currently used by the transformer. */
+ /**
+ * The locale currently used by the transformer.
+ */
private Locale locale;
/**
@@ -76,8 +82,9 @@
*/
private String formMethod;
- private FormsPipelineConfig(JXPathContext jxpc, Request req, Locale localeParam,
- String attName, String actionExpression, String method) {
+
+ private FormsPipelineConfig(JXPathContext jxpc, Request req, Locale localeParam,
+ String attName, String actionExpression, String method) {
this.attributeName = attName;
this.request = req;
this.jxpathContext =jxpc;
@@ -89,10 +96,10 @@
/**
* Creates and initializes a FormsPipelineConfig object based on the passed
* arguments of the setup() of the specific Pipeline-component.
- *
+ *
* @param objectModel the objectmodel as passed in the setup()
* @param parameters the parameters as passed in the setup()
- * @return an instance of FormsPipelineConfig initialized according to the
+ * @return an instance of FormsPipelineConfig initialized according to the
* settings in the sitemap.
*/
public static FormsPipelineConfig createConfig(Map objectModel, Parameters parameters) {
@@ -112,10 +119,10 @@
cocoonOM.put("session", session);
}
cocoonOM.put("parameters", parameters);
-
+
Variables vars = jxpc.getVariables();
vars.declareVariable("cocoon", cocoonOM);
-
+
Locale localeParameter = null;
String localeStr = parameters.getParameter("locale", null);
if (localeStr != null) {
@@ -126,10 +133,10 @@
String actionExpression = parameters.getParameter("form-action", null);
String formMethod = parameters.getParameter("form-method", null);
//TODO (20031223 mpo)think about adding form-encoding for the Generator.
- // Note generator will also need some text to go on the submit-button?
+ // Note generator will also need some text to go on the submit-button?
// Alternative to adding more here is to apply xinclude ?
- return new FormsPipelineConfig(jxpc, request, localeParameter,
+ return new FormsPipelineConfig(jxpc, request, localeParameter,
attributeName, actionExpression, formMethod);
}
@@ -141,23 +148,23 @@
}
/**
- * Finds the form from the current request-context based on the settings of
+ * Finds the form from the current request-context based on the settings of
* this configuration object. The fall-back search-procedure is as follows:
* <ol><li>Use the provided jxpathExpression (if not null)</li>
* <li>Use the setting of the 'attribute-name' parameter on the request</li>
* <li>Obtain the form from it's default location in the flow context</li>
- * </ol>
- *
+ * </ol>
+ *
* @param jxpathExpression that should be pointing to the form
* @return the found form if found
* @throws SAXException in any of the following cases:
* <ul><li>The provided jxpathExpression (if not null) not point to a
* {@link Form} instance.</li>
- * <li>The request is not holding a {@link Form} instance under the key
+ * <li>The request is not holding a {@link Form} instance under the key
* specified by 'attribute-name' (if specified)</li>
* <li>Both jxpathExpression and 'attribute-name' were not specified AND
* also the default location was not holding a valid {@link Form} instance.</li>
- * </ol>
+ * </ol>
*/
public Form findForm(String jxpathExpression) throws SAXException {
Object form = null;
@@ -191,7 +198,7 @@
* Replaces JXPath expressions embedded inside #{ and } by their value.
* This will parse the passed String looking for #{} occurences and then
* uses the {@link #evaluateExpression(String)} to evaluate the found expression.
- *
+ *
* @return the original String with it's #{}-parts replaced by the evaulated results.
*/
public String translateText(String original) {
@@ -242,19 +249,19 @@
}
/**
- * Evaluates the passed xpath expression using the internal jxpath context
+ * Evaluates the passed xpath expression using the internal jxpath context
* holding the declared variables:
* <ol><li>continuation: as made available by flowscript</li>
* <li>request: as present in the cocoon processing environment</li>
* <li>session: as present in the cocoon processing environment</li>
* <li>parameters: as present in the cocoon sitemap node of the pipeline component</li></ol>
- *
+ *
* @param expression
* @return the object-value resulting the expression evaluation.
*/
public Object evaluateExpression(String expression) {
return this.jxpathContext.getValue(expression);
- }
+ }
public Locale getLocale() {
return locale;
@@ -269,10 +276,10 @@
}
/**
- * The value for the wi:form-generated/@action.
+ * The value for the wi:form-generated/@action.
* Note: wi:form-template copies this from its wt:form-template counterpart.
- *
- * @return the {@link #translateText(String)} result of the 'form-action' sitemap
+ *
+ * @return the {@link #translateText(String)} result of the 'form-action' sitemap
* parameter to the pipeline component, or null if that parameter was not set.
*/
public String getFormAction() {
@@ -282,18 +289,18 @@
/**
* The value for the wi:form-generated/@method.
* Note: wi:form-template copies this from its wt:form-template counterpart.
- *
- * @return the value of the 'form-method' sitemap parameter to the pipeline
+ *
+ * @return the value of the 'form-method' sitemap parameter to the pipeline
* component. (or 'null' if it was not set.)
*/
public String getFormMethod() {
return formMethod;
}
-
-
+
+
/**
* Sets the form method to use in the generator/transformer that uses this.
- *
+ *
* @param method to use in the generated form should be "POST", "GET" or null
*/
public void setFormMethod(String method) {
@@ -303,18 +310,22 @@
/**
* The grouped attributes to set on the wi:form-generated element.
* Note: wi:form-template copies this from its wt:form-template counterpart.
- *
+ *
* @see #getFormAction()
* @see #getFormMethod()
*/
public Attributes getFormAttributes() {
- AttributesImpl formAtts = new AttributesImpl();
+ AttributesImpl attrs = new org.apache.cocoon.xml.AttributesImpl();
+ addFormAttributes(attrs);
+ return attrs;
+ }
+
+ public void addFormAttributes(AttributesImpl attrs) {
if (getFormAction() != null) {
- formAtts.addCDATAAttribute("action", getFormAction());
+ attrs.addAttribute("", "action", "action", "CDATA", getFormAction());
}
if (getFormMethod() != null){
- formAtts.addCDATAAttribute("method", getFormMethod());
+ attrs.addAttribute("", "method", "method", "CDATA", getFormMethod());
}
- return formAtts;
}
}