| Method from org.apache.cocoon.transformation.SimpleFormTransformer Detail: |
public void configure(Configuration config) throws ConfigurationException {
super.configure(config);
this.defaultInputConf = config.getChild("input-module");
this.defaultInput = this.defaultInputConf.getAttribute("name", this.defaultInput);
this.separator = config.getChild("separator").getValue(this.separator);
this.defaultPrefix = config.getChild("prefix").getValue(this.defaultPrefix);
this.defaultSuffix = config.getChild("suffix").getValue(this.defaultSuffix);
this.fixedName = config.getChild("fixed-attribute").getValue(this.fixedName);
this.useFormName = config.getChild("use-form-name").getValueAsBoolean(this.useFormName);
this.useFormNameTwice =
config.getChild("use-form-name-twice").getValueAsBoolean(this.useFormNameTwice);
this.useFormName = this.useFormName || this.useFormNameTwice;
if (this.useFormName) {
this.separator =
(this.separator == null || this.separator.length() == 0 ? "/" : this.separator);
this.defaultPrefix = this.separator;
}
this.ignoreValidation =
config.getChild("ignore-validation").getValueAsBoolean(this.ignoreValidation);
this.decorationSize = config.getChild("decoration").getValueAsInteger(this.decorationSize);
this.stripNumber = config.getChild("strip-number").getValueAsBoolean(this.stripNumber);
}
Avalon Configurable Interface |
protected void endRepeatElement(String uri,
String name,
String raw) throws SAXException {
this.recordingCount--;
if (this.recordingCount == 0) {
DocumentFragment fragment = this.endRecording();
RepeaterStatus status = (RepeaterStatus) this.repeater.get(this.repeater.size() - 1);
Object[] vals = this.getValues(this.getName(status.expr));
int count = (vals != null ? vals.length : 0);
for (status.count = 1; status.count < = count; status.count++) {
DOMStreamer streamer = new DOMStreamer(this, this);
streamer.stream(fragment);
}
this.repeater.remove(this.repeater.size() - 1);
} else {
this.relayEndElement(uri, name, raw);
if (this.recordingCount < 0) {
this.recordingCount = 0;
}
}
}
Stop recording repeat contents and replay required number of times.
Stop only if outmost repeat element is ending. |
public void endTransformingElement(String uri,
String name,
String raw) throws SAXException {
if (this.ignoreEventsCount > 0) {
this.relayEndElement(uri, name, raw);
} else if (this.recordingCount > 0) {
switch (((Integer) elementNames.get(name, defaultElement)).intValue()) {
case ELEMENT_REPEAT :
this.endRepeatElement(uri, name, raw);
break;
default :
this.relayEndElement(uri, name, raw);
}
} else {
switch (((Integer) elementNames.get(name, defaultElement)).intValue()) {
case ELEMENT_SELECT :
this.values = null;
this.relayEndElement(uri, name, raw);
break;
case ELEMENT_INPUT :
case ELEMENT_OPTION :
case ELEMENT_TXTAREA :
case ELEMENT_ERROR :
this.relayEndElement(uri, name, raw);
break;
case ELEMENT_FORM :
this.fixed = this.documentFixed;
this.formName = null;
this.relayEndElement(uri, name, raw);
break;
case ELEMENT_REPEAT :
this.endRepeatElement(uri, name, raw);
break;
default :
this.relayEndElement(uri, name, raw);
}
}
}
Start processing elements of our namespace.
This hook is invoked for each sax event with our namespace. |
protected String printAttributes(Attributes attr) {
StringBuffer sb = new StringBuffer();
sb.append('[");
for (int i = 0; i < attr.getLength(); i++) {
sb.append('@").append(attr.getLocalName(i)).append("='").append(
attr.getValue(i)).append(
"' ");
}
sb.append(']");
return sb.toString();
}
Generate string representation of attributes. For debug only. |
public void recycle() {
reset();
super.recycle();
}
|
protected void relayEndElement(String uri,
String name,
String raw) throws SAXException {
if (this.ignoreEventsCount == 1 && this.skipChildrenOnly)
this.ignoreEventsCount--;
try {
super.endTransformingElement(uri, name, raw);
} catch (ProcessingException e) {
throw new SAXException(e);
} catch (IOException e) {
throw new SAXException(e);
} catch (Exception e) {
getLogger().error("exception", e);
}
if (this.ignoreEventsCount > 0)
this.ignoreEventsCount--;
}
Calls the super's method endTransformingElement and decrements the
ignoreEventsCount if larger than zero. |
protected void relayStartElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
this.relayStartElement(false, false, uri, name, raw, attr);
}
Calls the super's method startTransformingElement. |
protected void relayStartElement(boolean skip,
boolean skipChildrenOnly,
String uri,
String name,
String raw,
Attributes attr) throws SAXException {
try {
if (this.ignoreEventsCount > 0) {
this.ignoreEventsCount++;
super.startTransformingElement(uri, name, raw, attr);
} else {
if (skip)
this.skipChildrenOnly = skipChildrenOnly;
if (skip && !skipChildrenOnly)
this.ignoreEventsCount++;
super.startTransformingElement(uri, name, raw, attr);
if (skip && skipChildrenOnly)
this.ignoreEventsCount++;
}
} catch (ProcessingException e) {
throw new SAXException(e);
} catch (IOException e) {
throw new SAXException(e);
}
}
Calls the super's method startTransformingElement and increments the
ignoreEventsCount if skip is true. Increment can be done either before
invoking super's method, so that the element itself is skipped, or afterwards,
so that only the children are skipped. |
public void setup(SourceResolver resolver,
Map objectModel,
String src,
Parameters par) throws IOException, SAXException, ProcessingException {
this.reset();
super.setup(resolver, objectModel, src, par);
if (request == null) {
getLogger().debug("no request object");
throw new ProcessingException("no request object");
}
this.evaluateParameters();
this.setupInputModule();
}
Setup the next round.
The instance variables are initialised. |
protected void startCheckableElement(String aName,
String uri,
String name,
String raw,
AttributesImpl attributes) throws SAXException {
// @fixed and this.fixed already considered in startInputElement
this.values = this.getValues(aName);
String checked = attributes.getValue("checked");
String value = attributes.getValue("value");
boolean found = false;
if (getLogger().isDebugEnabled())
getLogger().debug(
"startCheckableElement "
+ name
+ " attributes "
+ this.printAttributes(attributes));
if (this.values != null) {
if (getLogger().isDebugEnabled())
getLogger().debug("replacing");
for (int i = 0; i < this.values.length; i++) {
if (this.values[i].equals(value)) {
found = true;
if (checked == null) {
attributes.addAttribute("", "checked", "checked", "CDATA", "");
}
break;
}
}
if (!found && checked != null) {
attributes.removeAttribute(attributes.getIndex("checked"));
}
}
this.relayStartElement(uri, name, raw, attributes);
}
Handle input elements that may have a "checked" attributes,
i.e. checkbox and radio. |
protected void startErrorElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
if (getLogger().isDebugEnabled())
getLogger().debug(
"startErrorElement " + name + " attributes " + this.printAttributes(attr));
if (this.ignoreValidation) {
this.relayStartElement(uri, name, raw, attr);
} else if (this.validationResults == null || this.fixed) {
this.relayStartElement(true, false, uri, name, raw, attr);
} else {
String aName = attr.getValue("name");
if (aName == null) {
this.relayStartElement(uri, name, raw, attr);
} else {
ValidatorActionResult validation =
FormValidatorHelper.getParamResult(this.objectModel, aName);
String when = attr.getValue("when");
String when_ge = attr.getValue("when-ge");
if ((when != null && when.equals(validatorResults.get(validation)))
|| (when_ge != null
&& validation.ge(
(ValidatorActionResult) validatorResultLabel.get(
when_ge,
ValidatorActionResult.MAXERROR)))) {
AttributesImpl attributes = null;
if (attr instanceof AttributesImpl) {
attributes = (AttributesImpl) attr;
} else {
attributes = new AttributesImpl(attr);
}
// remove attributes not meant for client
attributes.removeAttribute(attributes.getIndex("name"));
if (when != null)
attributes.removeAttribute(attributes.getIndex("when"));
if (when_ge != null)
attributes.removeAttribute(attributes.getIndex("when-ge"));
this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
} else {
this.relayStartElement(true, true, uri, name, raw, attr);
}
}
}
}
Handle error elements. If validation results are available,
compares validation result for parameter with the same name as
the "name" attribute with the result names is "when" and
"when-ge". Drops element and all nested events when error
condition is not met. |
protected void startFormElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
String fixed = attr.getValue(this.fixedName);
if (this.useFormName) {
this.formName = attr.getValue("name");
}
if (fixed == null) {
this.relayStartElement(uri, name, raw, attr);
} else {
if (!this.fixed && BooleanUtils.toBoolean(fixed)) {
this.fixed = true;
}
// remove attributes not meant for client
AttributesImpl attributes = null;
if (attr instanceof AttributesImpl) {
attributes = (AttributesImpl) attr;
} else {
attributes = new AttributesImpl(attr);
}
attributes.removeAttribute(attributes.getIndex(this.fixedName));
this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
}
}
Start processing a form element. Sets protection indicator if attribute
"fixed" is present and either "true" or "yes". Removes attribute "fixed"
if present. |
protected void startInputElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
// @value = request.getParameterValues(@name)
String aName = getName(attr.getValue("name"));
String fixed = attr.getValue(this.fixedName);
if (getLogger().isDebugEnabled())
getLogger().debug(
"startInputElement " + name + " attributes " + this.printAttributes(attr));
if (aName == null || this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed))) {
this.relayStartElement(uri, name, raw, attr);
} else {
if (getLogger().isDebugEnabled())
getLogger().debug("replacing");
attr = this.normalizeAttributes(attr);
AttributesImpl attributes = null;
if (attr instanceof AttributesImpl) {
attributes = (AttributesImpl) attr;
} else {
attributes = new AttributesImpl(attr);
}
String type = attributes.getValue("type");
switch (((Integer) inputTypes.get(type, defaultType)).intValue()) {
case TYPE_CHECKBOX :
case TYPE_RADIO :
this.startCheckableElement(aName, uri, name, raw, attributes);
break;
case TYPE_DEFAULT :
this.startNonCheckableElement(aName, uri, name, raw, attributes);
break;
}
this.values = null;
}
}
Handle input elements. Calls startCheckableElement or
startNonCheckableElement. |
protected void startNonCheckableElement(String aName,
String uri,
String name,
String raw,
AttributesImpl attributes) throws SAXException {
// @fixed and this.fixed already considered in startInputElement
Object fValue = this.getNextValue(aName);
String value = attributes.getValue("value");
if (getLogger().isDebugEnabled())
getLogger().debug(
"startNonCheckableElement "
+ name
+ " attributes "
+ this.printAttributes(attributes));
if (fValue != null) {
if (getLogger().isDebugEnabled())
getLogger().debug("replacing");
if (value != null) {
attributes.setValue(attributes.getIndex("value"), String.valueOf(fValue));
} else {
attributes.addAttribute("", "value", "value", "CDATA", String.valueOf(fValue));
}
}
this.relayStartElement(uri, name, raw, attributes);
}
Handle input elements that may don't have a "checked"
attributes, e.g. text, password, button. |
protected void startOptionElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
// add @selected if @value in request.getParameterValues(@name)
if (getLogger().isDebugEnabled())
getLogger().debug(
"startOptionElement " + name + " attributes " + this.printAttributes(attr));
if (this.values == null || this.fixed) {
this.relayStartElement(uri, name, raw, attr);
} else {
if (getLogger().isDebugEnabled())
getLogger().debug("replacing");
AttributesImpl attributes = null;
if (attr instanceof AttributesImpl) {
attributes = (AttributesImpl) attr;
} else {
attributes = new AttributesImpl(attr);
}
String selected = attributes.getValue("selected");
String value = attributes.getValue("value");
boolean found = false;
for (int i = 0; i < this.values.length; i++) {
if (this.values[i].equals(value)) {
found = true;
if (selected == null) {
attributes.addAttribute("", "selected", "selected", "CDATA", "");
}
break;
}
}
if (!found && selected != null) {
attributes.removeAttribute(attributes.getIndex("selected"));
}
this.relayStartElement(uri, name, raw, attributes);
}
}
Handle option elements. Uses instance variables set up by
startSelectElement. Relies on option having a "value"
attribute, i.e. does not check following characters if "value"
is not present. |
protected void startRepeatElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
if (this.recordingCount == 0) {
if (!(this.fixed || BooleanUtils.toBoolean(attr.getValue(this.fixedName)))) {
RepeaterStatus status =
new RepeaterStatus("${" + attr.getValue("using") + "}", 0, attr.getValue("on"));
this.repeater.add(status);
this.startRecording();
this.recordingCount++;
} else {
this.relayStartElement(uri, name, raw, attr);
}
} else {
this.relayStartElement(uri, name, raw, attr);
this.recordingCount++;
}
}
Start recording repeat element contents and push repeat expression and
variable to repeater stack. Only start recording, if no other recorder is
currently running. |
protected void startSelectElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
// this.values = request.getParameterValues(@name)
String aName = getName(attr.getValue("name"));
String fixed = attr.getValue(this.fixedName);
this.values = null;
if (getLogger().isDebugEnabled())
getLogger().debug(
"startSelectElement " + name + " attributes " + this.printAttributes(attr));
if (aName != null && !(this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed)))) {
if (attr.getIndex("multiple") > -1) {
this.values = this.getValues(aName);
} else {
Object val = this.getNextValue(aName);
if (val != null) {
this.values = new Object[1];
this.values[0] = val;
} else {
this.values = null;
}
}
attr = this.normalizeAttributes(attr);
}
this.relayStartElement(uri, name, raw, attr);
}
Handle select elements. Sets up some instance variables for
following option elements. |
protected void startTextareaElement(String uri,
String name,
String raw,
Attributes attributes) throws SAXException {
String aName = getName(attributes.getValue("name"));
String fixed = attributes.getValue(this.fixedName);
Object value = null;
if (getLogger().isDebugEnabled())
getLogger().debug(
"startTextareaElement " + name + " attributes " + this.printAttributes(attributes));
if (aName != null) {
value = this.getNextValue(aName);
}
if (value == null || this.fixed || (fixed != null && BooleanUtils.toBoolean(fixed))) {
this.relayStartElement(uri, name, raw, attributes);
} else {
if (getLogger().isDebugEnabled())
getLogger().debug("replacing");
this.relayStartElement(uri, name, raw, this.normalizeAttributes(attributes));
String valString = String.valueOf(value);
this.characters(valString.toCharArray(), 0, valString.length());
// well, this doesn't really work out nicely. do it the hard way.
if (this.ignoreEventsCount == 0)
this.skipChildrenOnly = true;
this.ignoreEventsCount++;
}
}
Handles textarea elements. Skips nested events if request
parameter with same name exists. |
public void startTransformingElement(String uri,
String name,
String raw,
Attributes attr) throws SAXException {
if (this.ignoreEventsCount == 0 && this.recordingCount == 0) {
switch (((Integer) elementNames.get(name, defaultElement)).intValue()) {
case ELEMENT_INPUT :
this.startInputElement(uri, name, raw, attr);
break;
case ELEMENT_SELECT :
this.startSelectElement(uri, name, raw, attr);
break;
case ELEMENT_OPTION :
this.startOptionElement(uri, name, raw, attr);
break;
case ELEMENT_TXTAREA :
this.startTextareaElement(uri, name, raw, attr);
break;
case ELEMENT_ERROR :
this.startErrorElement(uri, name, raw, attr);
break;
case ELEMENT_FORM :
this.startFormElement(uri, name, raw, attr);
break;
case ELEMENT_REPEAT :
this.startRepeatElement(uri, name, raw, attr);
break;
default :
this.relayStartElement(uri, name, raw, attr);
}
} else if (this.recordingCount > 0) {
switch (((Integer) elementNames.get(name, defaultElement)).intValue()) {
case ELEMENT_REPEAT :
this.startRepeatElement(uri, name, raw, attr);
break;
default :
this.relayStartElement(uri, name, raw, attr);
}
} else {
this.relayStartElement(uri, name, raw, attr);
}
}
Start processing elements of our namespace.
This hook is invoked for each sax event with our namespace. |