List of usage examples for org.xml.sax ContentHandler endElement
public void endElement(String uri, String localName, String qName) throws SAXException;
From source file:org.apache.cocoon.forms.formmodel.Output.java
protected void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { // the value/* ww w .j a va 2 s .c o m*/ if (value != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); String stringValue; stringValue = definition.getDatatype().convertToString(value, locale); contentHandler.characters(stringValue.toCharArray(), 0, stringValue.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL); } }
From source file:org.apache.cocoon.forms.formmodel.Upload.java
public void generateItemSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { if (this.part != null) { String name = (String) this.part.getHeaders().get("filename"); contentHandler.startElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL, XMLUtils.EMPTY_ATTRIBUTES); contentHandler.characters(name.toCharArray(), 0, name.length()); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALUE_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALUE_EL); }// ww w . java 2s .co m // validation message element: only present if the value is not valid if (this.validationError != null) { contentHandler.startElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL, XMLUtils.EMPTY_ATTRIBUTES); this.validationError.generateSaxFragment(contentHandler); contentHandler.endElement(FormsConstants.INSTANCE_NS, VALIDATION_MSG_EL, FormsConstants.INSTANCE_PREFIX_COLON + VALIDATION_MSG_EL); } }
From source file:org.apache.cocoon.forms.generation.JXMacrosHelper.java
/** * Generate a <code><fi:styling></code> element holding the attributes of a <code>ft:*</code> * element that are in the "fi:" namespace. * // w ww . ja v a 2 s. c o m * @param attributes the template instruction attributes * @return true if a <code><fi:styling></code> was produced * @throws SAXException */ public static boolean generateStyling(ContentHandler handler, Map attributes) throws SAXException { AttributesImpl attr = null; Iterator entries = attributes.entrySet().iterator(); while (entries.hasNext()) { Map.Entry entry = (Map.Entry) entries.next(); String key = (String) entry.getKey(); // FIXME: JXTG only gives the local name of attributes, so we can't distinguish namespaces... if (!"id".equals(key) && !"widget-id".equals(key)) { if (attr == null) attr = new AttributesImpl(); attr.addCDATAAttribute(key, (String) entry.getValue()); } } if (attr != null) { // There were some styling attributes handler.startElement(FormsConstants.INSTANCE_NS, "styling", FormsConstants.INSTANCE_PREFIX_COLON + "styling", attr); handler.endElement(FormsConstants.INSTANCE_NS, "styling", FormsConstants.INSTANCE_PREFIX_COLON + "styling"); return true; } else { return false; } }
From source file:org.apache.cocoon.forms.util.I18nMessage.java
public void toSAX(ContentHandler contentHandler) throws SAXException { contentHandler.startPrefixMapping("i18n", I18nTransformer.I18N_NAMESPACE_URI); if (parameters != null) { contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT, XMLUtils.EMPTY_ATTRIBUTES); }/*from w w w. j a v a 2s .c o m*/ AttributesImpl i18nAttrs = new AttributesImpl(); if (catalogue != null) { i18nAttrs.addCDATAAttribute(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, "i18n:" + I18nTransformer.I18N_CATALOGUE_ATTRIBUTE, catalogue); } contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs); contentHandler.characters(key.toCharArray(), 0, key.length()); contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT); // the parameters if (parameters != null) { for (int i = 0; i < parameters.length; i++) { contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT, XMLUtils.EMPTY_ATTRIBUTES); if (keys != null && keys[i]) { contentHandler.startElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT, i18nAttrs); } final String aParam = String.valueOf(parameters[i]); contentHandler.characters(aParam.toCharArray(), 0, aParam.length()); if (keys != null && keys[i]) { contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TEXT_ELEMENT, "i18n:" + I18nTransformer.I18N_TEXT_ELEMENT); } contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_PARAM_ELEMENT, "i18n:" + I18nTransformer.I18N_PARAM_ELEMENT); } contentHandler.endElement(I18nTransformer.I18N_NAMESPACE_URI, I18nTransformer.I18N_TRANSLATE_ELEMENT, "i18n:" + I18nTransformer.I18N_TRANSLATE_ELEMENT); } contentHandler.endPrefixMapping("i18n"); }
From source file:org.apache.cocoon.generation.ExceptionGenerator.java
public static void toSAX(Throwable thr, ContentHandler handler) throws SAXException { Throwable root = ExceptionUtils.getRootCause(thr); if (root == null) root = thr;/*ww w. j a v a2s . com*/ AttributesImpl attr = new AttributesImpl(); handler.startPrefixMapping("ex", EXCEPTION_NS); attr.addCDATAAttribute("class", root.getClass().getName()); handler.startElement(EXCEPTION_NS, "exception-report", "ex:exception-report", attr); // Root exception location Location loc = LocationUtils.getLocation(root); if (LocationUtils.isKnown(loc)) { attr.clear(); dumpLocation(loc, attr, handler); } // Root exception message attr.clear(); String message = root instanceof LocatableException ? ((LocatableException) root).getRawMessage() : root.getMessage(); simpleElement("message", attr, message, handler); // Cocoon stacktrace: dump all located exceptions in the exception stack handler.startElement(EXCEPTION_NS, "cocoon-stacktrace", "ex:cocoon-stacktrace", attr); Throwable current = thr; while (current != null) { loc = LocationUtils.getLocation(current); if (LocationUtils.isKnown(loc)) { // One or more locations: dump it handler.startElement(EXCEPTION_NS, "exception", "ex:exception", attr); message = current instanceof LocatableException ? ((LocatableException) current).getRawMessage() : current.getMessage(); simpleElement("message", attr, message, handler); attr.clear(); handler.startElement(EXCEPTION_NS, "locations", "ex:locations", attr); dumpLocation(loc, attr, handler); if (current instanceof MultiLocatable) { List locations = ((MultiLocatable) current).getLocations(); for (int i = 1; i < locations.size(); i++) { // start at 1 because we already dumped the first one attr.clear(); dumpLocation((Location) locations.get(i), attr, handler); } } handler.endElement(EXCEPTION_NS, "locations", "ex:locations"); handler.endElement(EXCEPTION_NS, "exception", "ex:exception"); } // Dump parent location current = ExceptionUtils.getCause(current); } handler.endElement(EXCEPTION_NS, "cocoon-stacktrace", "ex:cocoon-stacktrace"); // Root exception stacktrace attr.clear(); simpleElement("stacktrace", attr, ExceptionUtils.getStackTrace(root), handler); // Full stack trace (if exception is chained) if (thr != root) { String trace = SystemUtils.isJavaVersionAtLeast(140) ? ExceptionUtils.getStackTrace(thr) : ExceptionUtils.getFullStackTrace(thr); simpleElement("full-stacktrace", attr, trace, handler); } handler.endElement(EXCEPTION_NS, "exception-report", "ex:exception-report"); handler.endPrefixMapping("ex"); }
From source file:org.apache.cocoon.generation.ExceptionGenerator.java
private static void simpleElement(String name, Attributes attr, String value, ContentHandler handler) throws SAXException { handler.startElement(EXCEPTION_NS, name, "ex:" + name, attr); if (value != null && value.length() > 0) { handler.characters(value.toCharArray(), 0, value.length()); }/* w ww.ja v a 2s .c o m*/ handler.endElement(EXCEPTION_NS, name, "ex:" + name); }
From source file:org.apache.cocoon.portal.wsrp.adapter.WSRPAdapter.java
/** * Checks the values of the <tt>portlet-key</tt> and the <tt>user</tt> for current portlet-instance<br/> * After that all passed the <tt>getMarkup()</tt>-call will be initiated<br /> * //from w w w .j a v a 2s. com * @see org.apache.cocoon.portal.coplet.adapter.impl.AbstractCopletAdapter#streamContent(org.apache.cocoon.portal.coplet.CopletInstanceData, org.xml.sax.ContentHandler) */ public void streamContent(CopletInstanceData coplet, ContentHandler contentHandler) throws SAXException { try { // set the coplet in the thread local variable to give other components access to // the instance this.setCurrentCopletInstanceData(coplet); // get the portlet key and the user final PortletKey portletKey = (PortletKey) coplet.getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_KEY); if (portletKey == null) { throw new SAXException("WSRP configuration is missing: portlet key."); } final User user = (User) coplet.getTemporaryAttribute(ATTRIBUTE_NAME_USER); if (user == null) { throw new SAXException("WSRP configuration is missing: user."); } final String portletInstanceKey = (String) coplet .getTemporaryAttribute(ATTRIBUTE_NAME_PORTLET_INSTANCE_KEY); // getMarkup() final WSRPPortlet wsrpportlet = consumerEnvironment.getPortletRegistry().getPortlet(portletKey); SimplePortletWindowSession windowSession = getSimplePortletWindowSession(wsrpportlet, portletInstanceKey, user); final MarkupContext markupContext = this.getMarkupContext(wsrpportlet, windowSession, user); if (markupContext == null || markupContext.getMarkupString() == null) { throw new SAXException("No markup received from wsrp coplet " + coplet.getId()); } final String content = markupContext.getMarkupString(); final Boolean usePipeline; final boolean usesGet; // If the portlet uses the method get we always have to rewrite form elements final Producer producer = this.consumerEnvironment.getProducerRegistry() .getProducer(portletKey.getProducerId()); final PortletDescription desc = producer.getPortletDescription(portletKey.getPortletHandle()); if (desc.getUsesMethodGet() != null && desc.getUsesMethodGet().booleanValue()) { usePipeline = Boolean.TRUE; usesGet = true; } else { usePipeline = (Boolean) this.getConfiguration(coplet, "use-pipeline", Boolean.FALSE); usesGet = false; } if (usePipeline.booleanValue()) { if (usesGet) { contentHandler = new FormRewritingHandler(contentHandler); } HtmlSaxParser.parseString(content, HtmlSaxParser.getContentFilter(contentHandler)); } else { // stream out the include for the serializer IncludingHTMLSerializer.addPortlet(portletInstanceKey, content); contentHandler.startPrefixMapping("portal", IncludingHTMLSerializer.NAMESPACE); final AttributesImpl attr = new AttributesImpl(); attr.addCDATAAttribute("portlet", portletInstanceKey); contentHandler.startElement(IncludingHTMLSerializer.NAMESPACE, "include", "portal:include", attr); contentHandler.endElement(IncludingHTMLSerializer.NAMESPACE, "include", "portal:include"); contentHandler.endPrefixMapping("portal"); } } catch (WSRPException e) { throw new SAXException("Exception during getMarkup of wsrp coplet: " + coplet.getId(), e); } catch (SAXException se) { throw se; } finally { this.setCurrentCopletInstanceData(null); } }
From source file:org.apache.cocoon.woody.datatype.FlowJXPathSelectionList.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { JXPathContext ctx = null;//ww w .j a v a 2 s .co m Iterator iter = null; if (model == null) { Object flowData = FlowHelper.getContextObject(ContextHelper.getObjectModel(this.context)); if (flowData == null) { throw new SAXException("No flow data to produce selection list"); } // Move to the list location ctx = JXPathContext.newContext(flowData); // Iterate on all elements of the list iter = ctx.iteratePointers(this.listPath); } else { // Move to the list location ctx = JXPathContext.newContext(model); // Iterate on all elements of the list iter = ctx.iteratePointers("."); } // Start the selection-list contentHandler.startElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL, Constants.EMPTY_ATTRS); while (iter.hasNext()) { String stringValue = ""; Object label = null; // Get a context on the current item Pointer ptr = (Pointer) iter.next(); if (ptr.getValue() != null) { JXPathContext itemCtx = ctx.getRelativeContext(ptr); // Get the value as a string Object value = itemCtx.getValue(this.valuePath); // List may contain null value, and (per contract with convertors), // convertors are not invoked on nulls. if (value != null) { stringValue = this.datatype.convertToString(value, locale); } // Get the label (can be ommitted) itemCtx.setLenient(true); label = itemCtx.getValue(this.labelPath); if (label == null) { label = stringValue; } } // Output this item AttributesImpl itemAttrs = new AttributesImpl(); itemAttrs.addCDATAAttribute("value", stringValue); contentHandler.startElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL, itemAttrs); if (label != null) { contentHandler.startElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL, Constants.EMPTY_ATTRS); if (label instanceof XMLizable) { ((XMLizable) label).toSAX(contentHandler); } else { String stringLabel = label.toString(); contentHandler.characters(stringLabel.toCharArray(), 0, stringLabel.length()); } contentHandler.endElement(Constants.WI_NS, LABEL_EL, Constants.WI_PREFIX_COLON + LABEL_EL); } contentHandler.endElement(Constants.WI_NS, ITEM_EL, Constants.WI_PREFIX_COLON + ITEM_EL); } // End the selection-list contentHandler.endElement(Constants.WI_NS, SELECTION_LIST_EL, Constants.WI_PREFIX_COLON + SELECTION_LIST_EL); }
From source file:org.apache.cocoon.woody.formmodel.Form.java
public void generateSaxFragment(ContentHandler contentHandler, Locale locale) throws SAXException { AttributesImpl formAttrs = new AttributesImpl(); formAttrs.addCDATAAttribute("id", definition.getId()); contentHandler.startElement(Constants.WI_NS, FORM_EL, Constants.WI_PREFIX_COLON + FORM_EL, Constants.EMPTY_ATTRS);/*from w w w.j a v a 2 s . c o m*/ definition.generateLabel(contentHandler); contentHandler.startElement(Constants.WI_NS, CHILDREN_EL, Constants.WI_PREFIX_COLON + CHILDREN_EL, Constants.EMPTY_ATTRS); Iterator widgetIt = widgets.iterator(); while (widgetIt.hasNext()) { Widget widget = (Widget) widgetIt.next(); widget.generateSaxFragment(contentHandler, locale); } contentHandler.endElement(Constants.WI_NS, CHILDREN_EL, Constants.WI_PREFIX_COLON + CHILDREN_EL); contentHandler.endElement(Constants.WI_NS, FORM_EL, Constants.WI_PREFIX_COLON + FORM_EL); }
From source file:org.apache.fop.events.model.EventModel.java
/** {@inheritDoc} */ public void toSAX(ContentHandler handler) throws SAXException { AttributesImpl atts = new AttributesImpl(); String elName = "event-model"; handler.startElement("", elName, elName, atts); Iterator iter = getProducers(); while (iter.hasNext()) { ((XMLizable) iter.next()).toSAX(handler); }//from ww w . j a v a2 s . com handler.endElement("", elName, elName); }