List of usage examples for org.xml.sax ContentHandler characters
public void characters(char ch[], int start, int length) throws SAXException;
From source file:org.onehippo.cms7.autoexport.Exporter.java
private void exportPropertyInstruction(DeltaInstruction instruction, ContentHandler handler, boolean override) throws SAXException, RepositoryException { Property property = session.getProperty(instruction.getContextPath()); AttributesImpl attr = new AttributesImpl(); attr.addAttribute(SV_URI, NAME, QNAME, CDATA, instruction.getName()); attr.addAttribute(SV_URI, TYPE, QTYPE, CDATA, PropertyType.nameFromValue(property.getType())); if (override) { attr.addAttribute(DELTA_URI, MERGE, QMERGE, CDATA, "override"); }// w ww . jav a 2s .c o m if (property.isMultiple()) { attr.addAttribute(SV_URI, "multiple", "sv:multiple", CDATA, "true"); } handler.startElement(SV_URI, PROPERTY, QPROPERTY, attr); attr = new AttributesImpl(); if (property.isMultiple()) { for (Value value : property.getValues()) { handler.startElement(SV_URI, VALUE, QVALUE, attr); String stringValue = value.getString(); handler.characters(stringValue.toCharArray(), 0, stringValue.length()); handler.endElement(SV_URI, VALUE, QVALUE); } } else { Value value = property.getValue(); handler.startElement(SV_URI, VALUE, QVALUE, attr); String stringValue = value.getString(); handler.characters(stringValue.toCharArray(), 0, stringValue.length()); handler.endElement(SV_URI, VALUE, QVALUE); } handler.endElement(SV_URI, PROPERTY, QPROPERTY); }
From source file:org.orbeon.oxf.processor.generator.RequestGenerator.java
public static String writeURLFileItem(PipelineContext pipelineContext, FileItem fileItem, boolean isSessionScope, ContentHandler contentHandler) throws SAXException { final String uriExpiringWithRequest = urlForFileItem(fileItem); // If the content is meant to expire with the session, and we haven't yet renamed the file, then do this here. final String uriExpiringWithScope; if (isSessionScope) { final String tempSessionURI = getContext(pipelineContext) .getSessionURIForRequestURI(uriExpiringWithRequest); if (tempSessionURI == null) { uriExpiringWithScope = NetUtils.renameAndExpireWithSession(uriExpiringWithRequest, logger).toURI() .toString();// w w w.j a v a 2s .co m getContext(pipelineContext).putSessionURIForRequestURI(uriExpiringWithRequest, uriExpiringWithScope); } else uriExpiringWithScope = tempSessionURI; } else uriExpiringWithScope = uriExpiringWithRequest; final char[] chars = uriExpiringWithScope.toCharArray(); contentHandler.characters(chars, 0, chars.length); return uriExpiringWithRequest; }
From source file:org.orbeon.oxf.processor.LDAPProcessor.java
private void addString(ContentHandler contentHandler, String string) throws Exception { char[] charArray = string.toCharArray(); contentHandler.characters(charArray, 0, charArray.length); }
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 ww w .j ava 2s. 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.tizzit.util.xml.SAXHelper.java
/** * @since tizzit-common 15.10.2009// www .j a va 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.examples.tutorial.TraceChain.java
private static void characters(ContentHandler handler, String text) throws SAXException { char[] characters = text.toCharArray(); handler.characters(characters, 0, characters.length); }
From source file:org.xchain.namespaces.test.FilterElement.java
public boolean execute(JXPathContext context) throws Exception { boolean result = false; QName name = getName(context); String executeChars = getExecuteChars(context); ContentHandler handler = getContentHandler(); if (name != null) { handler.startElement(name.getNamespaceURI(), name.getLocalPart(), name.getPrefix(), new AttributesImpl()); }/*w w w .jav a 2s .c o m*/ if (executeChars != null) { char[] characters = executeChars.toCharArray(); handler.characters(characters, 0, characters.length); } result = super.execute(context); return result; }
From source file:org.xchain.namespaces.test.FilterElement.java
public boolean postProcess(JXPathContext context, Exception exception) { boolean handled = false; try {/* ww w . ja va 2 s . 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; }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java
/** * Adds an element to the content handler. * //from w ww. java2 s .co m * @param ch * the content handler * @param ns * the name space of the element * @param lname * the local name * @param qname * the qname * @param attr * the attribute list * @param content * content of the element * @throws SAXException * if the underlying sax chain has a problem */ public void addElement(final ContentHandler ch, final String ns, final String lname, final String qname, final Attributes attr, final Object content) throws SAXException { ch.startElement(ns, lname, qname, attr); try { if (content != null) { char[] c = String.valueOf(content).toCharArray(); ch.characters(c, 0, c.length); } } finally { ch.endElement(ns, lname, qname); } }
From source file:uk.ac.cam.caret.sakai.rwiki.component.service.impl.XSLTEntityHandler.java
/** * Serialises the rendered content of the RWiki Object to SAX * /* w w w.j av a 2 s. c o m*/ * @param rwo * @param ch * @param withBreadCrumb */ public void renderToXML(RWikiObject rwo, final ContentHandler ch, boolean withBreadCrumb, boolean escapeXML) throws SAXException, IOException { String renderedPage; try { renderedPage = render(rwo, withBreadCrumb); } catch (Exception e) { renderedPage = Messages.getString("XSLTEntityHandler.32") + rwo.getName() //$NON-NLS-1$ + Messages.getString("XSLTEntityHandler.33") + e.getClass() //$NON-NLS-1$ + Messages.getString("XSLTEntityHandler.34") + e.getMessage(); //$NON-NLS-1$ log.info(renderedPage, e); } String contentDigest = DigestHtml.digest(renderedPage); if (contentDigest.length() > 500) { contentDigest = contentDigest.substring(0, 500); } if (renderedPage == null || renderedPage.trim().length() == 0) { renderedPage = Messages.getString("XSLTEntityHandler.35"); //$NON-NLS-1$ } if (contentDigest == null || contentDigest.trim().length() == 0) { contentDigest = Messages.getString("XSLTEntityHandler.36"); //$NON-NLS-1$ } String cdataEscapedRendered = renderedPage.replaceAll("]]>", "]]>]]><![CDATA["); //$NON-NLS-1$ //$NON-NLS-2$ String cdataContentDigest = contentDigest.replaceAll("]]>", "]]>]]><![CDATA["); //$NON-NLS-1$ //$NON-NLS-2$ /* http://jira.sakaiproject.org/browse/SAK-13281 * ensure all page content is escaped or double escaped before it goes into the parser, * if this is not done then the parser will unescape html entities during processing */ renderedPage = "<content><rendered>" //$NON-NLS-1$ + (escapeXML ? StringEscapeUtils.escapeXml(renderedPage) : renderedPage) + "</rendered><rendered-cdata><![CDATA[" + cdataEscapedRendered //$NON-NLS-1$ + "]]></rendered-cdata><contentdigest><![CDATA[" + cdataContentDigest //$NON-NLS-1$ + "]]></contentdigest></content>"; //$NON-NLS-1$ try { parseToSAX(renderedPage, ch); } catch (SAXException ex) { SimpleCoverage.cover("Failed to parse renderedPage from " + rwo.getName()); //$NON-NLS-1$ Attributes dummyAttributes = new AttributesImpl(); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, SchemaNames.EL_NSERROR, dummyAttributes); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, SchemaNames.EL_NSERRORDESC, dummyAttributes); String s = Messages.getString("XSLTEntityHandler.46") //$NON-NLS-1$ + ex.getMessage(); ch.characters(s.toCharArray(), 0, s.length()); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, SchemaNames.EL_NSERRORDESC); ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT, dummyAttributes); ch.characters(renderedPage.toCharArray(), 0, renderedPage.length()); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT); ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, SchemaNames.EL_NSERROR); } // SimpleCoverage.cover("Failed to parse ::\n" + renderedPage // + "\n:: from ::\n" + rwo.getContent()); // Attributes dummyAttributes = new AttributesImpl(); // ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, // SchemaNames.EL_NSERROR, dummyAttributes); // ch.startElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, // SchemaNames.EL_NSERRORDESC, dummyAttributes); // String s = "The Rendered Content did not parse correctly " // + ex.getMessage(); // ch.characters(s.toCharArray(), 0, s.length()); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERRORDESC, // SchemaNames.EL_NSERRORDESC); // ch.startElement(SchemaNames.NS_CONTAINER, // SchemaNames.EL_RAWCONTENT, SchemaNames.EL_NSRAWCONTENT, // dummyAttributes); // ch.characters(renderedPage.toCharArray(), 0, renderedPage.length()); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_RAWCONTENT, // SchemaNames.EL_NSRAWCONTENT); // ch.endElement(SchemaNames.NS_CONTAINER, SchemaNames.EL_ERROR, // SchemaNames.EL_NSERROR); }