List of usage examples for org.xml.sax.helpers AttributesImpl AttributesImpl
public AttributesImpl()
From source file:Main.java
public static void start(final ContentHandler handler, final String... elementAndAttributes) throws SAXException { if (elementAndAttributes == null || elementAndAttributes.length == 0 || elementAndAttributes.length % 2 != 1) { throw new IllegalArgumentException( "elementAndAttributes must contains element name and 0..n pais of attr name-value"); }//from w w w .j ava2 s. c om final String elementName = elementAndAttributes[0]; AttributesImpl attributes = EMPTY_ATTRIBUTES; if (elementAndAttributes.length > 1) { attributes = new AttributesImpl(); for (int i = 1; i + 1 < elementAndAttributes.length;) { String attributeName = elementAndAttributes[i++]; String attributeValue = elementAndAttributes[i++]; attributes.addAttribute("", attributeName, attributeName, NULL_TYPE, attributeValue); } } start(handler, elementName, attributes); }
From source file:ParseNonXML.java
public void parse(Properties props) throws SAXException { handler = getContentHandler();//ww w . ja va2 s .c om handler.startDocument(); Enumeration e = props.propertyNames(); while (e.hasMoreElements()) { String key = (String) e.nextElement(); String val = (String) props.getProperty(key); handler.startElement("", key, key, new AttributesImpl()); char[] chars = getChars(val); handler.characters(chars, 0, chars.length); handler.endElement("", key, key); } handler.endDocument(); }
From source file:it.polito.tellmefirst.web.rest.interfaces.VideoInterface.java
private String produceXML(String videoURL) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;/*from ww w. j a v a 2 s .c om*/ try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "videoURL", "", videoURL); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.AbstractInterface.java
private String produceXML(String abstracto) throws TMFOutputException { String xml;/*ww w.j a va 2s. c o m*/ LOG.debug("[produceXML] - BEGIN"); try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "abstract", "", abstracto); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); System.out.println(xml); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.TextInterface.java
private String produceXML(String title) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;// w w w .j a va 2s . co m try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "title", "", title); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.MapInterface.java
private String produceXML(String[] coordinates) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;//from w w w . ja v a2s. c o m String res1 = ""; String res2 = ""; try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); if (coordinates[0] != null) { res1 = coordinates[0]; } if (coordinates[1] != null) { res2 = coordinates[1]; } atts.addAttribute("", "", "lat", "", res1); atts.addAttribute("", "", "long", "", res2); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Map", atts); hd.endElement("", "", "Map"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:it.polito.tellmefirst.web.rest.interfaces.ImageInterface.java
private String produceXML(String imageURL) throws TMFOutputException { LOG.debug("[produceXML] - BEGIN"); String xml;//from w w w . j av a 2s . co m try { ByteArrayOutputStream out = new ByteArrayOutputStream(); TransformerHandler hd = initXMLDoc(out); AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "", "imageURL", "", imageURL); hd.startElement("", "", "Enhancement", null); hd.startElement("", "", "Result", atts); hd.endElement("", "", "Result"); hd.endElement("", "", "Enhancement"); hd.endDocument(); xml = out.toString("utf-8"); } catch (Exception e) { throw new TMFOutputException("Error creating XML output.", e); } LOG.debug("[produceXML] - END"); return xml; }
From source file:org.orbeon.oxf.processor.JFreeChartProcessor.java
public ProcessorOutput createOutput(String name) { return new ProcessorOutputImpl(JFreeChartProcessor.this, name) { public void readImpl(PipelineContext context, XMLReceiver xmlReceiver) { JFreeChartSerializer.ChartConfig chartConfig = readChartConfig(context); ChartInfo info = createChart(context, chartConfig); try { xmlReceiver.startDocument(); xmlReceiver.startElement("", "chart-info", "chart-info", new AttributesImpl()); xmlReceiver.startElement("", "file", "file", new AttributesImpl()); xmlReceiver.characters(info.file.toCharArray(), 0, info.file.length()); xmlReceiver.endElement("", "file", "file"); if (chartConfig.getMap() != null) { AttributesImpl atts = new AttributesImpl(); atts.addAttribute("", "name", "name", "CDATA", chartConfig.getMap()); xmlReceiver.startElement("", "map", "map", atts); EntityCollection entities = info.getInfo().getEntityCollection(); Iterator iterator = entities.iterator(); while (iterator.hasNext()) { ChartEntity entity = (ChartEntity) iterator.next(); AttributesImpl attr = new AttributesImpl(); attr.addAttribute("", "shape", "shape", "CDATA", entity.getShapeType()); attr.addAttribute("", "coords", "coords", "CDATA", entity.getShapeCoords()); if (entity.getURLText() != null && !entity.getURLText().equals("")) { attr.addAttribute("", "href", "href", "CDATA", entity.getURLText()); }//from w ww . j a va 2 s . co m if (entity.getToolTipText() != null && !entity.getToolTipText().equals("")) { attr.addAttribute("", "title", "title", "CDATA", entity.getToolTipText()); } xmlReceiver.startElement("", "area", "area", attr); xmlReceiver.endElement("", "area", "area"); } xmlReceiver.endElement("", "map", "map"); } xmlReceiver.endElement("", "chart-info", "chart-info"); xmlReceiver.endDocument(); } catch (SAXException e) { throw new OXFException(e); } } }; }
From source file:com.jaeksoft.searchlib.util.XmlWriter.java
public XmlWriter(PrintWriter out, String encoding) throws TransformerConfigurationException, SAXException { StreamResult streamResult = new StreamResult(out); SAXTransformerFactory tf = (SAXTransformerFactory) SAXTransformerFactory.newInstance(); transformerHandler = tf.newTransformerHandler(); Transformer serializer = transformerHandler.getTransformer(); serializer.setOutputProperty(OutputKeys.ENCODING, encoding); serializer.setOutputProperty(OutputKeys.INDENT, "yes"); serializer.setOutputProperty(OutputKeys.METHOD, "xml"); transformerHandler.setResult(streamResult); startedElementStack = new Stack<String>(); transformerHandler.startDocument();/* www .j a va2 s . c o m*/ elementAttributes = new AttributesImpl(); Pattern p = Pattern.compile("\\p{Cntrl}"); controlMatcher = p.matcher(""); }
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 {/* w w w .java 2s . 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; }