List of usage examples for org.xml.sax ContentHandler startElement
public void startElement(String uri, String localName, String qName, Attributes atts) throws SAXException;
From source file:Main.java
public static void start(final ContentHandler handler, final String elementName, final AttributesImpl attributes) throws SAXException { handler.startElement("", elementName, elementName, attributes); }
From source file:Main.java
/** * Start new element on <code>contentHandler</code> with given * <code>prefix</code>, <code>localName</code> and <code>attributes</code>. * /*from w w w . j a v a2 s . co m*/ * @param contentHandler * to start element on. * @param prefix * of element * @param localName * of element * @param attributes * of element * @throws SAXException * if * {@link ContentHandler#startElement(String, String, String, Attributes)} * throws {@link SAXException}. * @since 8.1 */ static public void startElement(final ContentHandler contentHandler, final String prefix, final String localName, final AttributesImpl attributes) throws SAXException { contentHandler.startElement(XMLConstants.NULL_NS_URI, localName, prefix + ":" + localName, attributes); }
From source file:net.ontopia.persistence.rdbms.DatabaseProjectReader.java
public static void saveProject(Project project, ContentHandler dh) throws SAXException { AttributesImpl atts = new AttributesImpl(); dh.startDocument();//w ww.j av a 2s . c om dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema", EMPTY_ATTR_LIST); Iterator<String> platforms = project.getDataTypePlatforms().iterator(); if (platforms.hasNext()) { while (platforms.hasNext()) { String platform = platforms.next(); atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PLATFORM, CDATA, platform); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes", atts); Iterator<DataType> datatypes = project.getDataTypes(platform).iterator(); while (datatypes.hasNext()) { // Platform datatypes DataType datatype = datatypes.next(); atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, (datatype.getName())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, (datatype.getType())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA, (datatype.getSize() == null ? "" : datatype.getSize())); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "class", CDATA, (datatype.isVariable() ? "variable" : "constant")); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype", atts); // Datatype properties Iterator<String> properties = datatype.getProperties().iterator(); while (properties.hasNext()) { String name = properties.next(); String value = datatype.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatype"); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "datatypes"); } Iterator<Table> tables = project.getTables().iterator(); while (tables.hasNext()) { Table table = tables.next(); // Table attributes atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, table.getName()); if (table.getShortName() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "short", CDATA, table.getShortName()); if (table.getPrimaryKeys() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "pks", CDATA, StringUtils.join(table.getPrimaryKeys(), " ")); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table", atts); // Table properties Iterator<String> properties = table.getProperties().iterator(); while (properties.hasNext()) { String name = properties.next(); String value = table.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } Iterator<Column> columns = table.getColumns().iterator(); while (columns.hasNext()) { Column column = columns.next(); // Column attributes atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, column.getName()); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, TYPE, CDATA, column.getType()); if (column.isReference()) { atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "reftab", CDATA, column.getReferencedTable()); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "refcol", CDATA, column.getReferencedColumn()); } if (column.getSize() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, SIZE, CDATA, column.getName()); if (column.isNullable()) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "null", CDATA, "yes"); if (column.getDefault() != null) atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "default", CDATA, column.getDefault()); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column", atts); // Column properties Iterator<String> properties2 = column.getProperties().iterator(); while (properties2.hasNext()) { String name = properties2.next(); String value = column.getProperty(name); if (value != null) { atts.clear(); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, NAME, CDATA, name); atts.addAttribute(EMPTY_NAMESPACE, EMPTY_LOCALNAME, VALUE, CDATA, value); dh.startElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY, atts); dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, PROPERTY); } } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "column"); } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "table"); } dh.endElement(EMPTY_NAMESPACE, EMPTY_LOCALNAME, "dbschema"); dh.endDocument(); }
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 {//from w w w. ja v a2 s. co 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:com.amalto.core.load.process.ProcessedStartElement.java
public void flush(ContentHandler contentHandler) throws SAXException { contentHandler.startElement(uri, localName, qName, attributes); }
From source file:org.javelin.sws.ext.bind.SoapEncodingMarshaller.java
@Override public void marshal(Object graph, Result result) throws IOException, XmlMappingException { try {//from w w w. ja va 2s . c o m 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:com.mirth.connect.plugins.datatypes.hl7v2.ER7Reader.java
private void handleComponent(ContentHandler contentHandler, String subcomponentSeparator, String segmentId, int fieldId, int componentId, String component) throws SAXException { if (handleSubcomponents && !subcomponentSeparator.isEmpty() && (component.indexOf(subcomponentSeparator) > -1)) { contentHandler.startElement("", segmentId + "." + fieldId + "." + componentId, "", null); // check if we have subcomponents, if so add them StringTokenizer subcomponentTokenizer = new StringTokenizer(component, subcomponentSeparator, true); handleSubcomponents(contentHandler, subcomponentSeparator, segmentId, fieldId, componentId, 1, subcomponentTokenizer);/* w w w .j av a 2 s. c om*/ contentHandler.endElement("", segmentId + "." + fieldId + "." + componentId, null); } else { logger.trace("handling component: " + component); // the naming is SEG.<field#>.<component#> contentHandler.startElement("", segmentId + "." + fieldId + "." + componentId, "", null); contentHandler.characters(component.toCharArray(), 0, component.length()); contentHandler.endElement("", segmentId + "." + fieldId + "." + componentId, ""); } }
From source file:biz.taoconsulting.oxf.processor.converter.FromPdfConverter.java
/** * Adds an error element to the output//from ww w .j av a 2 s.co m * * @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: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);/* w ww. j av a 2 s . c om*/ 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 {//from w w w . ja v a2 s . c om 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"); } }