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.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsBaseHandlerXHTML.java
protected void handleLabelHintHelpAlert(LHHAAnalysis lhhaAnalysis, String targetControlEffectiveId, String forEffectiveId, XFormsBaseHandler.LHHAC lhhaType, XFormsControl control, boolean isTemplate, boolean isExternal) throws SAXException { final AttributesImpl staticLHHAAttributes = Dom4jUtils.getSAXAttributes(lhhaAnalysis.element()); final boolean isLabel = lhhaType == LHHAC.LABEL; final boolean isHelp = lhhaType == LHHAC.HELP; final boolean isHint = lhhaType == LHHAC.HINT; final boolean isAlert = lhhaType == LHHAC.ALERT; if (staticLHHAAttributes != null || isAlert) { // If no attributes were found, there is no such label / help / hint / alert if (handlerContext.isNoScript() && isHelp) { if (control != null) { final ContentHandler contentHandler = handlerContext.getController().getOutput(); final String xhtmlPrefix = handlerContext.findXHTMLPrefix(); // <a href="#my-control-id-help"> final AttributesImpl aAttributes = new AttributesImpl(); aAttributes.addAttribute("", "href", "href", XMLReceiverHelper.CDATA, "#" + getLHHACId(containingDocument, targetControlEffectiveId, LHHAC_CODES.get(LHHAC.HELP))); aAttributes.addAttribute("", "class", "class", XMLReceiverHelper.CDATA, "xforms-help-anchor"); final String aQName = XMLUtils.buildQName(xhtmlPrefix, "a"); contentHandler.startElement(XMLConstants.XHTML_NAMESPACE_URI, "a", aQName, aAttributes); contentHandler.endElement(XMLConstants.XHTML_NAMESPACE_URI, "a", aQName); }//from w ww .jav a 2 s . c o m } else { final String labelHintHelpAlertValue; final boolean mustOutputHTMLFragment; if (control != null) { // Get actual value from control if (isLabel) { labelHintHelpAlertValue = control.getLabel(); mustOutputHTMLFragment = control.isHTMLLabel(); } else if (isHelp) { // NOTE: Special case here where we get the escaped help to facilitate work below. Help is a special // case because it is stored as escaped HTML within a <label> element. labelHintHelpAlertValue = control.getEscapedHelp(); mustOutputHTMLFragment = false; } else if (isHint) { labelHintHelpAlertValue = control.getHint(); mustOutputHTMLFragment = control.isHTMLHint(); } else if (isAlert) { labelHintHelpAlertValue = control.getAlert(); mustOutputHTMLFragment = control.isHTMLAlert(); } else { throw new IllegalStateException("Illegal type requested"); } } else { // Placeholder labelHintHelpAlertValue = null; mustOutputHTMLFragment = false; } final String elementName; { if (isLabel) { elementName = handlerContext.getLabelElementName(); } else if (isHelp) { elementName = handlerContext.getHelpElementName(); } else if (isHint) { elementName = handlerContext.getHintElementName(); } else if (isAlert) { elementName = handlerContext.getAlertElementName(); } else { throw new IllegalStateException("Illegal type requested"); } } final StringBuilder classes = new StringBuilder(30); // Put user classes first if any if (staticLHHAAttributes != null) { final String userClass = staticLHHAAttributes.getValue("class"); if (userClass != null) classes.append(userClass); } // Mark alert as active if needed if (isAlert) { if (control instanceof XFormsSingleNodeControl) { final XFormsSingleNodeControl singleNodeControl = (XFormsSingleNodeControl) control; final scala.Option<ValidationLevels.ValidationLevel> constraintLevel = singleNodeControl .alertLevel(); if (constraintLevel.isDefined()) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-active"); } // Constraint classes are placed on the control if the alert is not external if (isExternal) addConstraintClasses(classes, constraintLevel); } } // Handle visibility // TODO: It would be great to actually know about the relevance of help, hint, and label. Right now, we just look at whether the value is empty if (control != null) { if (isAlert || isLabel) { // Allow empty labels and alerts if (!control.isRelevant()) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } } else { // For help and hint, consider "non-relevant" if empty final boolean isHintHelpRelevant = control.isRelevant() && StringUtils.isNotEmpty(labelHintHelpAlertValue); if (!isHintHelpRelevant) { if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } } } else if (!isTemplate || isHelp) { // Null control outside of template OR help within template if (classes.length() > 0) classes.append(' '); classes.append("xforms-disabled"); } // LHHA name if (classes.length() > 0) classes.append(' '); classes.append("xforms-"); classes.append(lhhaType.name().toLowerCase()); // We handle null attributes as well because we want a placeholder for "alert" even if there is no xf:alert final Attributes newAttributes = (staticLHHAAttributes != null) ? staticLHHAAttributes : new AttributesImpl(); lhhaAnalysis.encodeAndAppendAppearances(classes); outputLabelFor(handlerContext, getIdClassXHTMLAttributes(newAttributes, classes.toString(), null), targetControlEffectiveId, forEffectiveId, lhhaType, elementName, labelHintHelpAlertValue, mustOutputHTMLFragment, isExternal); } } }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsControlLifecyleHandler.java
@Override public final void end(String uri, String localname, String qName) throws SAXException { if (isMustOutputControl(currentControlOrNull())) { // Process everything after the control has been shown if (endConfig != null) { for (final String current : endConfig) { if ("control".equals(current)) { // Handle control handleControlEnd(uri, localname, qName, attributes, getEffectiveId(), currentControlOrNull()); } else if ("label".equals(current)) { // xf:label if (hasLocalLabel()) handleLabel();//from w w w . j a v a 2 s . com } else if ("alert".equals(current)) { // xf:alert if (hasLocalAlert()) handleAlert(); } else if ("hint".equals(current)) { // xf:hint if (hasLocalHint()) handleHint(); } else { // xf:help if (hasLocalHelp()) handleHelp(); } } } if (isMustOutputContainerElement()) { // Close control element, usually <span> final ContentHandler contentHandler = handlerContext.getController().getOutput(); contentHandler.endElement(XMLConstants.XHTML_NAMESPACE_URI, getContainingElementName(), getContainingElementQName()); } } }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XFormsGroupFieldsetHandler.java
@Override public void handleControlStart(String uri, String localname, String qName, Attributes attributes, final String effectiveId, XFormsControl control) throws SAXException { final XFormsGroupControl groupControl = (XFormsGroupControl) control; final String xhtmlPrefix = handlerContext.findXHTMLPrefix(); final ElementHandlerController controller = handlerContext.getController(); final ContentHandler contentHandler = controller.getOutput(); // Output an xhtml:legend element if and only if there is an xf:label element. This help with // styling in particular. final boolean hasLabel = LHHASupport.hasLabel(containingDocument, getPrefixedId()); if (hasLabel) { // Handle label classes reusableAttributes.clear();//from w w w . jav a 2 s .c om reusableAttributes.addAttribute("", "class", "class", XMLReceiverHelper.CDATA, getLabelClasses(groupControl)); reusableAttributes.addAttribute("", "id", "id", XMLReceiverHelper.CDATA, getLHHACId(containingDocument, effectiveId, LHHAC_CODES.get(LHHAC.LABEL))); // Output xhtml:legend with label content final String legendQName = XMLUtils.buildQName(xhtmlPrefix, "legend"); contentHandler.startElement(XMLConstants.XHTML_NAMESPACE_URI, "legend", legendQName, reusableAttributes); { final String labelValue = getLabelValue(groupControl); if (StringUtils.isNotEmpty(labelValue)) contentHandler.characters(labelValue.toCharArray(), 0, labelValue.length()); } contentHandler.endElement(XMLConstants.XHTML_NAMESPACE_URI, "legend", legendQName); } }
From source file:org.orbeon.oxf.xforms.processor.handlers.xhtml.XHTMLBodyHandler.java
public void end(String uri, String localname, String qName) throws SAXException { // Add global top-level XBL markup final scala.collection.Iterator<XBLBindings.Global> i = containingDocument.getStaticOps().getGlobals() .values().iterator();// www . j a va2 s.co m while (i.hasNext()) XXFormsComponentHandler.processShadowTree(handlerContext.getController(), i.next().templateTree()); // Close xhtml:form helper.endElement(); // Close xhtml:body final ContentHandler contentHandler = handlerContext.getController().getOutput(); contentHandler.endElement(uri, localname, qName); }
From source file:org.tizzit.util.xml.SAXHelper.java
/** * @since tizzit-common 15.10.2009/*from w w w . j av a 2s . c o m*/ */ public static void addElement(ContentHandler handler, String namespaceUri, String elementName, String elementValue, Attributes attr) throws SAXException { if (elementName != null) { handler.startElement(namespaceUri, elementName, elementName, attr); String saveVal = (elementValue == null) ? "" : elementValue; char[] ca = saveVal.toCharArray(); handler.characters(ca, 0, ca.length); handler.endElement(namespaceUri, elementName, elementName); } }
From source file:org.xchain.example.namespaces.xhtml.OptionCommand.java
public boolean execute(JXPathContext context) throws Exception { String value = getValue(context); String currentValue = (String) ((ScopedQNameVariables) context.getVariables()) .getVariable(SelectCommand.SELECTED_VARIABLE_NAME, Scope.execution); // get the xhtml prefix and make sure that there is a mapping for it. String xhtmlPrefix = context.getPrefix(XHTML_NAMESPACE); if (xhtmlPrefix == null) { throw new IllegalStateException("There is no mapping defined for " + XHTML_NAMESPACE); }//from w ww . j a v a 2s .com AttributesImpl attributes = new AttributesImpl(); if (value != null) { attributes.addAttribute("", VALUE_LOCAL_NAME, VALUE_LOCAL_NAME, "CDATA", value); } if (value != null && value.equals(currentValue)) { attributes.addAttribute("", SELECTED_LOCAL_NAME, SELECTED_LOCAL_NAME, "CDATA", SELECTED_VALUE); } ContentHandler handler = getContentHandler(); handler.startElement(XHTML_NAMESPACE, OPTION_LOCAL_NAME, qNameString(xhtmlPrefix, OPTION_LOCAL_NAME), attributes); boolean result = false; Exception exception = null; try { result = super.execute(context); } catch (Exception e) { exception = e; } if (exception == null || !(exception instanceof SAXException)) { handler.endElement(XHTML_NAMESPACE, OPTION_LOCAL_NAME, qNameString(xhtmlPrefix, OPTION_LOCAL_NAME)); } if (exception != null) { throw exception; } return result; }
From source file:org.xchain.example.namespaces.xhtml.SelectCommand.java
public boolean execute(JXPathContext context) throws Exception { // get the request and the name from the context. HttpServletRequest request = getRequest(context); String name = getName(context); // get the original value of the name. String currentValue = request.getParameter(name); // get the xhtml prefix and make sure that there is a mapping for it. String xhtmlPrefix = context.getPrefix(XHTML_NAMESPACE); if (xhtmlPrefix == null) { throw new IllegalStateException("There is no mapping defined for " + XHTML_NAMESPACE); }// w ww . ja v a 2s . com // create the attributes for the element we are going to output. AttributesImpl attributes = new AttributesImpl(); if (hasId()) { attributes.addAttribute("", ID_LOCAL_NAME, ID_LOCAL_NAME, "CDATA", getId(context)); } attributes.addAttribute("", NAME_LOCAL_NAME, NAME_LOCAL_NAME, "CDATA", getName(context)); ((ScopedQNameVariables) context.getVariables()).declareVariable(SELECTED_VARIABLE_NAME, currentValue, Scope.execution); ContentHandler handler = getContentHandler(); handler.startElement(XHTML_NAMESPACE, SELECT_LOCAL_NAME, qNameString(xhtmlPrefix, SELECT_LOCAL_NAME), attributes); boolean result = false; Exception exception = null; // execute the children and catch any exceptions. try { result = super.execute(context); } catch (Exception e) { exception = e; } // if there was not an exception, or the exception is not a sax exception, then we need to finish the output. if (exception == null || !(exception instanceof SAXException)) { handler.endElement(XHTML_NAMESPACE, SELECT_LOCAL_NAME, qNameString(xhtmlPrefix, SELECT_LOCAL_NAME)); } // rethrow the exception. if (exception != null) { throw exception; } return result; }
From source file:org.xchain.examples.tutorial.TraceUtil.java
public static void endDiv(ContentHandler handler, String xhtmlPrefix) throws SAXException { handler.endElement(XHTML_NAMESPACE_URI, DIV_ELEMENT, createQName(xhtmlPrefix, DIV_ELEMENT)); }
From source file:org.xchain.examples.tutorial.TraceUtil.java
public static void endSpan(ContentHandler handler, String xhtmlPrefix) throws SAXException { handler.endElement(XHTML_NAMESPACE_URI, SPAN_ELEMENT, createQName(xhtmlPrefix, SPAN_ELEMENT)); }
From source file:org.xchain.namespaces.test.FilterElement.java
public boolean postProcess(JXPathContext context, Exception exception) { boolean handled = false; try {/* ww w . jav a 2s. c o m*/ handled = super.postProcess(context, exception); QName name = getName(context); String postProcessChars = getPostProcessChars(context); ContentHandler handler = getContentHandler(); if (postProcessChars != null) { char[] characters = postProcessChars.toCharArray(); handler.characters(characters, 0, characters.length); } if (name != null) { handler.endElement(name.getNamespaceURI(), name.getLocalPart(), name.getPrefix()); } } catch (Exception e) { // this exception should propigate. } return handled; }