List of usage examples for org.xml.sax ContentHandler endElement
public void endElement(String uri, String localName, String qName) throws SAXException;
From source file:Main.java
public static void end(final ContentHandler handler, final String elementName) throws SAXException { handler.endElement(null, elementName, elementName); }
From source file:Main.java
/** * End element on <code>contentHandler</code> with given <code>prefix</code> * and <code>localName</code>. * /*from w w w .j av a 2 s . com*/ * @param contentHandler * to start element on. * @param prefix * of element * @param localName * of element * @throws SAXException * if {@link ContentHandler#endElement(String, String, String)} * throws {@link SAXException}. * @since 8.1 */ static public void endElement(final ContentHandler contentHandler, final String prefix, final String localName) throws SAXException { contentHandler.endElement(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName); }
From source file:com.amalto.core.load.process.ProcessedEndElement.java
public void flush(ContentHandler contentHandler) throws SAXException { contentHandler.endElement(uri, localName, qName); }
From source file:com.aurel.track.util.HTMLDiff.java
public static String makeDiff(String newValue, String oldValue, Locale locale) throws URISyntaxException { boolean htmlOut = true; if (newValue == null) { newValue = ""; } else {/* www. ja va 2s . c o m*/ newValue = newValue.replaceAll(" ", " "); } if (oldValue == null || (oldValue != null && oldValue.length() == 0)) { return newValue; } else { oldValue = oldValue.replaceAll(" ", " "); } try { SAXTransformerFactory tf = (SAXTransformerFactory) TransformerFactory.newInstance(); TransformerHandler result = tf.newTransformerHandler(); StringWriter stringWriter = new StringWriter(); result.setResult(new StreamResult(stringWriter)); XslFilter filter = new XslFilter(); ContentHandler postProcess = htmlOut ? filter.xsl(result, "com/aurel/track/util/htmlheader.xsl") : result; String prefix = "diff"; HtmlCleaner cleaner = new HtmlCleaner(); InputSource oldSource = new InputSource(new StringReader(oldValue)); InputSource newSource = new InputSource(new StringReader(newValue)); DomTreeBuilder oldHandler = new DomTreeBuilder(); cleaner.cleanAndParse(oldSource, oldHandler); TextNodeComparator leftComparator = new TextNodeComparator(oldHandler, locale); DomTreeBuilder newHandler = new DomTreeBuilder(); cleaner.cleanAndParse(newSource, newHandler); TextNodeComparator rightComparator = new TextNodeComparator(newHandler, locale); postProcess.startDocument(); postProcess.startElement("", "diffreport", "diffreport", new AttributesImpl()); postProcess.startElement("", "diff", "diff", new AttributesImpl()); HtmlSaxDiffOutput output = new HtmlSaxDiffOutput(postProcess, prefix); HTMLDiffer differ = new HTMLDiffer(output); differ.diff(leftComparator, rightComparator); postProcess.endElement("", "diff", "diff"); postProcess.endElement("", "diffreport", "diffreport"); postProcess.endDocument(); return stringWriter.toString(); } catch (Exception e) { LOGGER.error(ExceptionUtils.getStackTrace(e)); if (e.getCause() != null) { LOGGER.error(ExceptionUtils.getStackTrace(e.getCause())); } if (e instanceof SAXException) { LOGGER.error(ExceptionUtils.getStackTrace(((SAXException) e).getException())); } } return null; }
From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java
@Override public void marshal(Object graph, Result result) throws IOException, XmlMappingException { try {// ww w . j a v a 2 s .com ContentHandler contentHandler = ((SAXResult) result).getHandler(); contentHandler.startElement("", "hello", "hello", new AttributesImpl()); contentHandler.characters(((String) ((Object[]) graph)[0]).toCharArray(), 0, ((String) ((Object[]) graph)[0]).toCharArray().length); contentHandler.endElement("", "hello", "hello"); } catch (SAXException e) { throw new MarshallingFailureException(e.getMessage(), e); } }
From source file:biz.taoconsulting.oxf.processor.converter.FromPdfConverter.java
/** * Adds an error element to the output/*from w w w .j a v a 2s.com*/ * * @param contentHandler * @param eMessage */ private void addErrorTagToOutput(ContentHandler contentHandler, String eMessage) { try { contentHandler.startElement("", TAG_ERROR, TAG_ERROR, null); contentHandler.characters(eMessage.toCharArray(), 0, eMessage.length()); contentHandler.endElement("", TAG_ERROR, TAG_ERROR); } catch (SAXException e) { logger.error(e); } }
From source file:CSVXMLReader.java
private void parseLine(String curLine, ContentHandler ch) throws IOException, SAXException { String firstToken = null;/* w w w . j av a2 s . c o m*/ String remainderOfLine = null; int commaIndex = locateFirstDelimiter(curLine); if (commaIndex > -1) { firstToken = curLine.substring(0, commaIndex).trim(); remainderOfLine = curLine.substring(commaIndex + 1).trim(); } else { // no commas, so the entire line is the token firstToken = curLine; } // remove redundant quotes firstToken = cleanupQuotes(firstToken); // emit the <value> element ch.startElement("", "", "value", EMPTY_ATTR); ch.characters(firstToken.toCharArray(), 0, firstToken.length()); ch.endElement("", "", "value"); // recursively process the remainder of the line if (remainderOfLine != null) { parseLine(remainderOfLine, ch); } }
From source file:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java
private void handleField(ContentHandler contentHandler, String componentSeparator, String subcomponentSeparator, String segmentId, int fieldId, String field) throws SAXException { if ((field.indexOf(componentSeparator) > -1) || (handleSubcomponents && (field.indexOf(subcomponentSeparator) > -1))) { contentHandler.startElement("", segmentId + "." + fieldId, "", null); StringTokenizer componentTokenizer = new StringTokenizer(field, componentSeparator, true); handleComponents(contentHandler, componentSeparator, subcomponentSeparator, segmentId, fieldId, 1, componentTokenizer);//from w w w.j a v a 2 s .co m contentHandler.endElement("", segmentId + "." + fieldId, null); } else { logger.trace("handling field: " + field); contentHandler.startElement("", segmentId + "." + fieldId, "", null); contentHandler.startElement("", segmentId + "." + fieldId + ".1", "", null); contentHandler.characters(field.toCharArray(), 0, field.length()); contentHandler.endElement("", segmentId + "." + fieldId + ".1", null); contentHandler.endElement("", segmentId + "." + fieldId, null); } }
From source file:org.syncope.core.report.UserReportlet.java
private void doExtractResources(final ContentHandler handler, final AbstractAttributableTO attributableTO) throws SAXException { if (attributableTO.getResources().isEmpty()) { LOG.debug("No resources found for {}[{}]", attributableTO.getClass().getSimpleName(), attributableTO.getId()); } else {/* www.ja v a 2 s.co m*/ AttributesImpl atts = new AttributesImpl(); handler.startElement("", "", "resources", null); for (String resourceName : attributableTO.getResources()) { atts.clear(); atts.addAttribute("", "", ATTR_NAME, XSD_STRING, resourceName); handler.startElement("", "", "resource", atts); handler.endElement("", "", "resource"); } handler.endElement("", "", "resources"); } }
From source file:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java
private void handleComponents(ContentHandler contentHandler, String componentSeparator, String subcomponentSeparator, String segmentId, int fieldId, int componentId, StringTokenizer componentTokenizer) throws SAXException { boolean atLastComponent = true; while (componentTokenizer.hasMoreTokens()) { String component = componentTokenizer.nextToken(); if (component.equals(componentSeparator)) { if (atLastComponent) { contentHandler.startElement("", segmentId + "." + fieldId + "." + componentId, "", null); contentHandler.characters(EMPTY_CHAR_ARRAY, 0, 0); contentHandler.endElement("", segmentId + "." + fieldId + "." + componentId, ""); }//from ww w . j a v a 2 s.co m componentId++; atLastComponent = true; } else { atLastComponent = false; handleComponent(contentHandler, subcomponentSeparator, segmentId, fieldId, componentId, component); } } if (atLastComponent) { contentHandler.startElement("", segmentId + "." + fieldId + "." + componentId, "", null); contentHandler.characters(EMPTY_CHAR_ARRAY, 0, 0); contentHandler.endElement("", segmentId + "." + fieldId + "." + componentId, ""); } }