org.jdom2.output.Format.getCompactFormat()方法的使用及代码示例

x33g5p2x  于2022-01-19 转载在 其他  
字(9.3k)|赞(0)|评价(0)|浏览(155)

本文整理了Java中org.jdom2.output.Format.getCompactFormat()方法的一些代码示例,展示了Format.getCompactFormat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Format.getCompactFormat()方法的具体详情如下:
包路径:org.jdom2.output.Format
类名称:Format
方法名:getCompactFormat

Format.getCompactFormat介绍

[英]Returns a new Format object that performs whitespace normalization, uses the UTF-8 encoding, doesn't expand empty elements, includes the declaration and encoding, and uses the default entity escape strategy. Tweaks can be made to the returned Format instance without affecting other instances.
[中]返回一个新的Format对象,该对象执行空白规范化,使用UTF-8编码,不展开空元素,包括声明和编码,并使用默认的实体转义策略。可以对返回的格式实例进行调整,而不会影响其他实例。

代码示例

代码示例来源:origin: usethesource/rascal

  1. public IString xmlCompact(IConstructor node) throws IOException {
  2. return xmlToString(node, Format.getCompactFormat());
  3. }

代码示例来源:origin: org.apache.jspwiki/jspwiki-main

  1. /**
  2. * Serializes the Element to a String. If <tt>pretty</tt> is true,
  3. * uses a pretty whitespace format, otherwise a compact format.
  4. *
  5. * @param element the element to serialize.
  6. * @param pretty if true, use a pretty whitespace format.
  7. * @return the serialized Element.
  8. */
  9. public static String serialize( Element element, boolean pretty ) {
  10. return serialize( element,pretty ? Format.getPrettyFormat() : Format.getCompactFormat() );
  11. }

代码示例来源:origin: com.theoryinpractise/halbuilder-xml

  1. public void write(ReadableRepresentation representation, Set<URI> flags, Writer writer) {
  2. final Element element = renderElement("self", representation, false);
  3. try {
  4. Format prettyFormat = flags.contains(RepresentationFactory.PRETTY_PRINT)
  5. ? Format.getPrettyFormat()
  6. : Format.getCompactFormat();
  7. final XMLOutputter outputter = new XMLOutputter(prettyFormat);
  8. outputter.output(element, writer);
  9. } catch (IOException e) {
  10. throw new RepresentationException(e);
  11. }
  12. }

代码示例来源:origin: bioinformatics-ua/dicoogle

  1. XMLOutputter outStream = new XMLOutputter(Format.getCompactFormat());
  2. StringWriter wr = new StringWriter();
  3. try {

代码示例来源:origin: bioinformatics-ua/dicoogle

  1. @Get
  2. public Representation representXML() {
  3. StringRepresentation sr;
  4. HashMap<String, Integer> tagList = DictionaryAccess.getInstance().getTagList();
  5. ArrayList<String> list = new ArrayList<String>();
  6. Element tags = new Element("tags");
  7. for(String tag : tagList.keySet()){
  8. int value = tagList.get(tag);
  9. Element e = new Element("tag");
  10. e.setAttribute( "id", Integer.toString(value));
  11. e.setAttribute("name", tag);
  12. tags.addContent(e);
  13. }
  14. tags.setAttribute("count", Integer.toString(tags.getChildren().size()));
  15. Document xmlDoc = new Document(tags);
  16. XMLOutputter out = new XMLOutputter(Format.getCompactFormat());
  17. String str = out.outputString(xmlDoc);
  18. StringRepresentation rep = new StringRepresentation( str, MediaType.APPLICATION_XML);
  19. return rep;
  20. }
  21. }

代码示例来源:origin: ch.epfl.bbp.nlp/bluima_pdf

  1. XMLOutputter rawOutputter = new XMLOutputter(Format.getCompactFormat());

代码示例来源:origin: org.opencadc/cadc-test-uws

  1. XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
  2. StringWriter sw = new StringWriter();
  3. PrintWriter pw = new PrintWriter(sw);

代码示例来源:origin: org.opencadc/cadc-test-uws

  1. XMLOutputter outputter = new XMLOutputter(Format.getCompactFormat());
  2. StringWriter sw = new StringWriter();
  3. PrintWriter pw = new PrintWriter(sw);

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

  1. /**
  2. * Writes to an Writer the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure the Writer instance is using the same charset encoding.
  6. * <p>
  7. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  8. * <p>
  9. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  10. * the type given to the FeedOuptut constructor.
  11. * @param writer Writer to write the XML representation for the given WireFeed.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  14. * @throws IOException thrown if there was some problem writing to the Writer.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. outputter.output(doc,writer);
  27. }

代码示例来源:origin: rometools/rome

  1. format = Format.getPrettyFormat();
  2. } else {
  3. format = Format.getCompactFormat();

代码示例来源:origin: org.apache.marmotta/sesame-tools-rio-rss

  1. /**
  2. * Creates a String with the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
  6. * the feed encoding property.
  7. * <p>
  8. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  9. * <p>
  10. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  11. * the type given to the FeedOuptut constructor.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @return a String with the XML representation for the given WireFeed.
  14. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. return outputter.outputString(doc);
  27. }

代码示例来源:origin: apache/marmotta

  1. /**
  2. * Writes to an Writer the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure the Writer instance is using the same charset encoding.
  6. * <p>
  7. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  8. * <p>
  9. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  10. * the type given to the FeedOuptut constructor.
  11. * @param writer Writer to write the XML representation for the given WireFeed.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  14. * @throws IOException thrown if there was some problem writing to the Writer.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public void output(WireFeed feed,Writer writer,boolean prettyPrint) throws IllegalArgumentException,IOException, FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. outputter.output(doc,writer);
  27. }

代码示例来源:origin: apache/marmotta

  1. /**
  2. * Creates a String with the XML representation for the given WireFeed.
  3. * <p>
  4. * If the feed encoding is not NULL, it will be used in the XML prolog encoding attribute. It is the responsibility
  5. * of the developer to ensure that if the String is written to a character stream the stream charset is the same as
  6. * the feed encoding property.
  7. * <p>
  8. * NOTE: This method delages to the 'Document WireFeedOutput#outputJDom(WireFeed)'.
  9. * <p>
  10. * @param feed Abstract feed to create XML representation from. The type of the WireFeed must match
  11. * the type given to the FeedOuptut constructor.
  12. * @param prettyPrint pretty-print XML (true) oder collapsed
  13. * @return a String with the XML representation for the given WireFeed.
  14. * @throws IllegalArgumentException thrown if the feed type of the WireFeedOutput and WireFeed don't match.
  15. * @throws FeedException thrown if the XML representation for the feed could not be created.
  16. *
  17. */
  18. public String outputString(WireFeed feed, boolean prettyPrint) throws IllegalArgumentException,FeedException {
  19. Document doc = outputJDom(feed);
  20. String encoding = feed.getEncoding();
  21. Format format = prettyPrint ? Format.getPrettyFormat() : Format.getCompactFormat();
  22. if (encoding!=null) {
  23. format.setEncoding(encoding);
  24. }
  25. XMLOutputter outputter = new XMLOutputter(format);
  26. return outputter.outputString(doc);
  27. }

代码示例来源:origin: rometools/rome

  1. format = Format.getPrettyFormat();
  2. } else {
  3. format = Format.getCompactFormat();

代码示例来源:origin: com.rometools/rome

  1. format = Format.getPrettyFormat();
  2. } else {
  3. format = Format.getCompactFormat();

代码示例来源:origin: com.rometools/rome

  1. format = Format.getPrettyFormat();
  2. } else {
  3. format = Format.getCompactFormat();

代码示例来源:origin: pwm-project/pwm

  1. String toXml( )
  2. {
  3. final Element rootElement = new Element( XML_NODE_ROOT );
  4. for ( final StoredEvent loopEvent : records )
  5. {
  6. if ( loopEvent.getAuditEvent() != null )
  7. {
  8. final Element hrElement = new Element( XML_NODE_RECORD );
  9. hrElement.setAttribute( XML_ATTR_TIMESTAMP, String.valueOf( loopEvent.getTimestamp() ) );
  10. hrElement.setAttribute( XML_ATTR_TRANSACTION, loopEvent.getAuditEvent().getMessage().getKey() );
  11. if ( loopEvent.getSourceAddress() != null && loopEvent.getSourceAddress().length() > 0 )
  12. {
  13. hrElement.setAttribute( XML_ATTR_SRC_IP, loopEvent.getSourceAddress() );
  14. }
  15. if ( loopEvent.getSourceHost() != null && loopEvent.getSourceHost().length() > 0 )
  16. {
  17. hrElement.setAttribute( XML_ATTR_SRC_HOST, loopEvent.getSourceHost() );
  18. }
  19. if ( loopEvent.getMessage() != null )
  20. {
  21. hrElement.setContent( new CDATA( loopEvent.getMessage() ) );
  22. }
  23. rootElement.addContent( hrElement );
  24. }
  25. }
  26. final Document doc = new Document( rootElement );
  27. final XMLOutputter outputter = new XMLOutputter();
  28. outputter.setFormat( Format.getCompactFormat() );
  29. return outputter.outputString( doc );
  30. }

相关文章