public IString xmlCompact(IConstructor node) throws IOException { return xmlToString(node, Format.getCompactFormat()); }
/** * Serializes the Element to a String. If <tt>pretty</tt> is true, * uses a pretty whitespace format, otherwise a compact format. * * @param element the element to serialize. * @param pretty if true, use a pretty whitespace format. * @return the serialized Element. */ public static String serialize( Element element, boolean pretty ) { return serialize( element,pretty ? Format.getPrettyFormat() : Format.getCompactFormat() ); }
public void write(ReadableRepresentation representation, Set<URI> flags, Writer writer) { final Element element = renderElement("self", representation, false); try { Format prettyFormat = flags.contains(RepresentationFactory.PRETTY_PRINT) ? Format.getPrettyFormat() : Format.getCompactFormat(); final XMLOutputter outputter = new XMLOutputter(prettyFormat); outputter.output(element, writer); } catch (IOException e) { throw new RepresentationException(e); } }
XMLOutputter outStream = new XMLOutputter(Format.getCompactFormat()); StringWriter wr = new StringWriter(); try {
@Get public Representation representXML() { StringRepresentation sr; HashMap<String, Integer> tagList = DictionaryAccess.getInstance().getTagList(); ArrayList<String> list = new ArrayList<String>(); Element tags = new Element("tags"); for(String tag : tagList.keySet()){ int value = tagList.get(tag); Element e = new Element("tag"); e.setAttribute( "id", Integer.toString(value)); e.setAttribute("name", tag); tags.addContent(e); } tags.setAttribute("count", Integer.toString(tags.getChildren().size())); Document xmlDoc = new Document(tags); XMLOutputter out = new XMLOutputter(Format.getCompactFormat()); String str = out.outputString(xmlDoc); StringRepresentation rep = new StringRepresentation( str, MediaType.APPLICATION_XML); return rep; } }
XMLOutputter rawOutputter = new XMLOutputter(Format.getCompactFormat());
XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);
XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat()); StringWriter sw = new StringWriter(); PrintWriter pw = new PrintWriter(sw);
/** * Writes to an Writer the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure the Writer instance is using the same charset encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding!=null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); outputter.output(doc,writer); }
format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat();
/** * Creates a String with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure that if the String is written to a character stream the stream charset is the same as * the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding!=null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(doc); }
/** * Writes to an Writer the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure the Writer instance is using the same charset encoding. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param writer Writer to write the XML representation for the given WireFeed. * @param prettyPrint pretty-print XML (true) oder collapsed * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws IOException thrown if there was some problem writing to the Writer. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding!=null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); outputter.output(doc,writer); }
/** * Creates a String with the XML representation for the given WireFeed. * <p> * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility * of the developer to ensure that if the String is written to a character stream the stream charset is the same as * the feed encoding property. * <p> * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'. * <p> * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match * the type given to the FeedOuptut constructor. * @param prettyPrint pretty-print XML (true) oder collapsed * @return a String with the XML representation for the given WireFeed. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match. * @throws FeedException thrown if the XML representation for the feed could not be created. * */ public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException { Document doc = outputJDom(feed); String encoding = feed.getEncoding(); Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat(); if (encoding!=null) { format.setEncoding(encoding); } XMLOutputter outputter = new XMLOutputter(format); return outputter.outputString(doc); }
format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat();
format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat();
format = Format.getPrettyFormat(); } else { format = Format.getCompactFormat();
String toXml( ) { final Element rootElement = new Element( XML_NODE_ROOT ); for ( final StoredEvent loopEvent : records ) { if ( loopEvent.getAuditEvent() != null ) { final Element hrElement = new Element( XML_NODE_RECORD ); hrElement.setAttribute( XML_ATTR_TIMESTAMP, String.valueOf( loopEvent.getTimestamp() ) ); hrElement.setAttribute( XML_ATTR_TRANSACTION, loopEvent.getAuditEvent().getMessage().getKey() ); if ( loopEvent.getSourceAddress() != null && loopEvent.getSourceAddress().length() > 0 ) { hrElement.setAttribute( XML_ATTR_SRC_IP, loopEvent.getSourceAddress() ); } if ( loopEvent.getSourceHost() != null && loopEvent.getSourceHost().length() > 0 ) { hrElement.setAttribute( XML_ATTR_SRC_HOST, loopEvent.getSourceHost() ); } if ( loopEvent.getMessage() != null ) { hrElement.setContent( new CDATA( loopEvent.getMessage() ) ); } rootElement.addContent( hrElement ); } } final Document doc = new Document( rootElement ); final XMLOutputter outputter = new XMLOutputter(); outputter.setFormat( Format.getCompactFormat() ); return outputter.outputString( doc ); }