List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl(Attributes atts)
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Handle input elements. Calls startCheckableElement or * startNonCheckableElement.//w ww .j a v a 2 s . c o m */ 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; } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * 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./*ww w. j a v a 2s. co m*/ */ 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); } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * 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./*from w ww. j a va2 s.com*/ */ 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); } } } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Start processing a form element. Sets protection indicator if attribute * "fixed" is present and either "true" or "yes". Removes attribute "fixed" * if present./*from w w w.j a v a 2s . c om*/ * @param uri The namespace of the element. * @param name The local name of the element. * @param raw The qualified name of the element. * @param attr The attributes of the element. */ 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)); } }
From source file:org.apache.cocoon.transformation.SimpleFormTransformer.java
/** * Remove extra information from element's attributes. Currently only removes * the repeater variable from the element's name attribute if present. * * @param attr// w ww .ja v a 2s . c o m * @return modified attributes */ private Attributes normalizeAttributes(Attributes attr) { Attributes result = attr; if (this.stripNumber && this.repeater.size() > 0) { String name = attr.getValue("name"); if (name != null) { for (Iterator i = this.repeater.iterator(); i.hasNext();) { RepeaterStatus status = (RepeaterStatus) i.next(); int pos = name.indexOf(status.var); if (pos >= 0) { AttributesImpl attributes; if (result instanceof AttributesImpl) { attributes = (AttributesImpl) result; } else { attributes = new AttributesImpl(result); } name = name.substring(0, pos - this.decorationSize) + name.substring(pos + status.var.length() + this.decorationSize); attributes.setValue(attributes.getIndex("name"), name); result = attributes; } } } } return result; }
From source file:org.apache.cocoon.woody.transformation.EffectWidgetReplacingPipe.java
private Attributes translateAttributes(Attributes attributes, String[] names) { AttributesImpl newAtts = new AttributesImpl(attributes); if (names != null) { for (int i = 0; i < names.length; i++) { String name = names[i]; int position = newAtts.getIndex(name); String newValue = pipeContext.translateText(newAtts.getValue(position)); newAtts.setValue(position, newValue); }// ww w . j av a2 s . co m } return newAtts; }
From source file:org.apache.cocoon.woody.transformation.WidgetReplacingPipe.java
public void startElement(String namespaceURI, String localName, String qName, Attributes attributes) throws SAXException { elementNestingCounter++;// ww w. j a v a2s . c om if (inWidgetElement) { if (elementNestingCounter == widgetElementNesting + 1 && Constants.WI_NS.equals(namespaceURI) && STYLING_EL.equals(localName)) { gotStylingElement = true; } saxBuffer.startElement(namespaceURI, localName, qName, attributes); } else if (Constants.WT_NS.equals(namespaceURI)) { if (localName.equals(WIDGET) || localName.equals(REPEATER_WIDGET)) { checkContextWidgetAvailable(qName); inWidgetElement = true; widgetElementNesting = elementNestingCounter; gotStylingElement = false; saxBuffer = new SaxBuffer(); // retrieve widget here, but its XML will only be streamed in the endElement call widget = getWidget(attributes); repeaterWidget = localName.equals(REPEATER_WIDGET); if (repeaterWidget && !(widget instanceof Repeater)) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget\" can only be used for repeater widgets."); } } else if (localName.equals(WIDGET_LABEL)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); widget.generateLabel(contentHandler); } else if (localName.equals(REPEATER_WIDGET_LABEL)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); if (!(widget instanceof Repeater)) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget-label\" can only be used for repeater widgets."); } String widgetId = attributes.getValue("widget-id"); if (widgetId == null || widgetId.length() == 0) { throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-widget-label\" requires a \"widget-id\" attribute."); } ((Repeater) widget).generateWidgetLabel(widgetId, contentHandler); } else if (localName.equals(REPEATER_SIZE)) { checkContextWidgetAvailable(qName); Widget widget = getWidget(attributes); if (!(widget instanceof Repeater)) throw new SAXException( "WoodyTemplateTransformer: the element \"repeater-size\" can only be used for repeater widgets."); contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); ((Repeater) widget).generateSize(contentHandler); contentHandler.endPrefixMapping(Constants.WI_PREFIX); } else if (localName.equals(FORM_TEMPLATE_EL)) { if (contextWidget != null) { throw new SAXException("Detected nested wt:form-template elements, this is not allowed."); } contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); // ====> Retrieve the form // first look for the form using the location attribute, if any String formJXPath = attributes.getValue(LOCATION); if (formJXPath != null) { // remove the location attribute AttributesImpl attrsCopy = new AttributesImpl(attributes); attrsCopy.removeAttribute(attributes.getIndex(LOCATION)); attributes = attrsCopy; } contextWidget = pipeContext.findForm(formJXPath); // ====> Determine the Locale //TODO pull this locale stuff also up in the Config object? String localeAttr = attributes.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()); } } String[] namesToTranslate = { "action" }; Attributes transAtts = translateAttributes(attributes, namesToTranslate); contentHandler.startElement(Constants.WI_NS, FORM_TEMPLATE_EL, Constants.WI_PREFIX_COLON + FORM_TEMPLATE_EL, transAtts); } else if (localName.equals(CONTINUATION_ID)) { // Insert the continuation id // FIXME(SW) we could avoid costly JXPath evaluation if we had the objectmodel here. Object idObj = pipeContext.evaluateExpression("$continuation/id"); if (idObj == null) { throw new SAXException("No continuation found"); } String id = idObj.toString(); contentHandler.startPrefixMapping(Constants.WI_PREFIX, Constants.WI_NS); contentHandler.startElement(Constants.WI_NS, CONTINUATION_ID, Constants.WI_PREFIX_COLON + CONTINUATION_ID, attributes); contentHandler.characters(id.toCharArray(), 0, id.length()); contentHandler.endElement(Constants.WI_NS, CONTINUATION_ID, Constants.WI_PREFIX_COLON + CONTINUATION_ID); contentHandler.endPrefixMapping(Constants.WI_PREFIX); } else { throw new SAXException("WoodyTemplateTransformer: Unsupported element: " + localName); } } else { super.startElement(namespaceURI, localName, qName, attributes); } }
From source file:org.apache.fop.render.afp.extensions.AFPExtensionHandler.java
/** {@inheritDoc} */ @Override//from ww w. j a va2s . c om public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { boolean handled = false; if (AFPExtensionAttachment.CATEGORY.equals(uri)) { lastAttributes = new AttributesImpl(attributes); handled = true; if (localName.equals(AFPElementMapping.NO_OPERATION) || localName.equals(AFPElementMapping.TAG_LOGICAL_ELEMENT) || localName.equals(AFPElementMapping.INCLUDE_PAGE_OVERLAY) || localName.equals(AFPElementMapping.INCLUDE_PAGE_SEGMENT) || localName.equals(AFPElementMapping.INCLUDE_FORM_MAP) || localName.equals(AFPElementMapping.INVOKE_MEDIUM_MAP)) { //handled in endElement } else { handled = false; } } if (!handled) { if (AFPExtensionAttachment.CATEGORY.equals(uri)) { throw new SAXException("Unhandled element " + localName + " in namespace: " + uri); } else { log.warn("Unhandled element " + localName + " in namespace: " + uri); } } }
From source file:org.apache.fop.render.pdf.extensions.PDFExtensionHandler.java
/** {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { boolean handled = false; if (PDFExtensionAttachment.CATEGORY.equals(uri)) { lastAttributes = new AttributesImpl(attributes); handled = false;//from w w w . jav a2 s .c o m if (localName.equals(PDFEmbeddedFileExtensionAttachment.ELEMENT)) { //handled in endElement handled = true; } } if (!handled) { if (PDFExtensionAttachment.CATEGORY.equals(uri)) { throw new SAXException("Unhandled element " + localName + " in namespace: " + uri); } else { log.warn("Unhandled element " + localName + " in namespace: " + uri); } } }
From source file:org.apache.fop.render.ps.extensions.PSExtensionHandler.java
/** {@inheritDoc} */ public void startElement(String uri, String localName, String qName, Attributes attributes) throws SAXException { boolean handled = false; if (PSExtensionAttachment.CATEGORY.equals(uri)) { lastAttributes = new AttributesImpl(attributes); handled = false;/*from ww w.j a v a 2 s . com*/ if (localName.equals(PSSetupCode.ELEMENT) || localName.equals(PSPageTrailerCodeBefore.ELEMENT) || localName.equals(PSSetPageDevice.ELEMENT) || localName.equals(PSCommentBefore.ELEMENT) || localName.equals(PSCommentAfter.ELEMENT)) { //handled in endElement handled = true; } } if (!handled) { if (PSExtensionAttachment.CATEGORY.equals(uri)) { throw new SAXException("Unhandled element " + localName + " in namespace: " + uri); } else { log.warn("Unhandled element " + localName + " in namespace: " + uri); } } }