当前位置: 首页>>代码示例>>Java>>正文


Java OutputFormat.setIndent方法代码示例

本文整理汇总了Java中org.apache.xml.serialize.OutputFormat.setIndent方法的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat.setIndent方法的具体用法?Java OutputFormat.setIndent怎么用?Java OutputFormat.setIndent使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.apache.xml.serialize.OutputFormat的用法示例。


在下文中一共展示了OutputFormat.setIndent方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: XmlEditsVisitor

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
 * Create a processor that writes to the file named and may or may not
 * also output to the screen, as specified.
 *
 * @param filename Name of file to write output to
 * @param printToScreen Mirror output to screen?
 */
public XmlEditsVisitor(OutputStream out)
    throws IOException {
  this.out = out;
  OutputFormat outFormat = new OutputFormat("XML", "UTF-8", true);
  outFormat.setIndenting(true);
  outFormat.setIndent(2);
  outFormat.setDoctype(null, null);
  XMLSerializer serializer = new XMLSerializer(out, outFormat);
  contentHandler = serializer.asContentHandler();
  try {
    contentHandler.startDocument();
    contentHandler.startElement("", "", "EDITS", new AttributesImpl());
  } catch (SAXException e) {
    throw new IOException("SAX error: " + e.getMessage());
  }
}
 
开发者ID:naver,项目名称:hadoop,代码行数:24,代码来源:XmlEditsVisitor.java

示例2: save

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public void save() throws AtsConfigurationException {

        // save the XML file
        try {
            OutputFormat format = new OutputFormat(doc);
            format.setIndenting(true);
            format.setIndent(4);
            format.setLineWidth(1000);

            XMLSerializer serializer = new XMLSerializer(new FileOutputStream(new File(atsConfigurationFile)),
                                                         format);
            serializer.serialize(doc);
        } catch (Exception e) {
            throw new AtsConfigurationException("Error saving ATS configuration in '" + atsConfigurationFile
                                                + "'", e);
        }
    }
 
开发者ID:Axway,项目名称:ats-framework,代码行数:18,代码来源:AtsProjectConfiguration.java

示例3: formatDocumentForTesting

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
* Cette méthode permet de reformater le contenu d'une chaîne XML
* et donc de s'affranchir des problèmes liés au formatage (tabulations, espaces, retours chariot, ...).
* 
   * @param document
   * @return une chaîne de caractères "normalisée" créé à partir d'un document Document Object Model
   */
  public String formatDocumentForTesting(Document document) {
      try {
          OutputFormat format = new OutputFormat(document);
          format.setLineWidth(65);
          format.setIndenting(true);
          format.setIndent(2);
          Writer out = new StringWriter();
          XMLSerializer serializer = new XMLSerializer(out, format);
          serializer.serialize(document);

          return out.toString();
      } catch (IOException e) {
          throw new RuntimeException(e);
      }
  }
 
开发者ID:fastconnect,项目名称:tibco-fcunit,代码行数:23,代码来源:FCDiff.java

示例4: formatXml

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
 * This function will format the XML profile with intends and new lines.
 *
 * @param xmlToFormat the xml String you want to format
 * @return the formated version of teh given XML string
 */
private String formatXml(String xmlToFormat) {
    try {
        final Document document = generateXmlDocument(xmlToFormat);

        OutputFormat format = new OutputFormat(document);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(2);
        format.setOmitXMLDeclaration(true);
        Writer out = new StringWriter();
        XMLSerializer serializer = new XMLSerializer(out, format);
        serializer.serialize(document);

        return out.toString();
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}
 
开发者ID:customertimes,项目名称:easyrec-PoC,代码行数:25,代码来源:ProfileRenderer.java

示例5: getResponseFromFile

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
private String getResponseFromFile(String file) throws Exception {
    String filePath = this.getClass().getResource(file).getPath();
    Document xmlDocument;
    InputStream inputXML;
    inputXML = new FileInputStream(new File(filePath));
    DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = builderFactory.newDocumentBuilder();
    xmlDocument = builder.parse(inputXML);
    OutputFormat format = new OutputFormat(xmlDocument);
    format.setLineWidth(65);
    format.setIndenting(true);
    format.setIndent(2);
    Writer out = new StringWriter();
    XMLSerializer serializer = new XMLSerializer(out, format);
    serializer.serialize(xmlDocument);
    return out.toString();

}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:19,代码来源:EditXmlTest.java

示例6: saveSubscription

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public static void saveSubscription(SipSubscription sub) throws IOException, SAXException
{
	String filename = spoolPath + "/subscriptions/" + ((SipURI) sub.localParty.getURI()).getUser() + "_" + sub.callId;
	FileOutputStream fs = new FileOutputStream(new File(filename));

	OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
	of.setIndent(1);
	of.setIndenting(true);
	XMLSerializer serializer = new XMLSerializer(fs, of);
	ContentHandler hd = serializer.asContentHandler();
	hd.startDocument();
	hd.startElement("", "", "SUBSCRIPTION", null);
	sub.buildSubscriptionXML(hd);
	hd.endElement("", "", "SUBSCRIPTION");
	hd.endDocument();
	fs.close();
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:18,代码来源:SipSubscriptionManager.java

示例7: saveWatcher

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public static void saveWatcher(SipSubscription sub) throws IOException, SAXException
{
	String filename = spoolPath + "/watchers/" + ((SipURI) sub.localParty.getURI()).getUser() + "_" + sub.callId;
	FileOutputStream fs = new FileOutputStream(new File(filename));

	OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
	of.setIndent(1);
	of.setIndenting(true);
	XMLSerializer serializer = new XMLSerializer(fs, of);
	ContentHandler hd = serializer.asContentHandler();
	hd.startDocument();
	hd.startElement("", "", "SUBSCRIPTION", null);
	sub.buildSubscriptionXML(hd);
	hd.endElement("", "", "SUBSCRIPTION");
	hd.endDocument();
	fs.close();
}
 
开发者ID:idwanglu2010,项目名称:openfire,代码行数:18,代码来源:SipSubscriptionManager.java

示例8: getDocument

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public String getDocument() {
	OutputFormat of = new OutputFormat("XML", "ISO-8859-1", true);
	of.setIndent(1);
	of.setIndenting(true);
	// of.setDoctype(null, "users.dtd");
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	PrintStream ps = new PrintStream(baos);
	XMLSerializer serializer = new XMLSerializer(ps, of);
	try {
		serializer.asDOMSerializer();
		serializer.serialize(doc.getDocumentElement());
		ps.close();
		return baos.toString();
	}
	catch (IOException e) {
		return null;
	}
}
 
开发者ID:siemens,项目名称:ASLanPPConnector,代码行数:19,代码来源:ASLanXMLSerializer.java

示例9: getXml

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
@Override
public String getXml() throws IOException {
	try {
		ByteArrayOutputStream bos = new ByteArrayOutputStream();
		OutputFormat format = new OutputFormat();
		format.setLineWidth(200);
		format.setIndenting(true);
		format.setIndent(2);
		XMLSerializer serializer = new XMLSerializer(bos, format);
		serializer.serialize(((Document)this.node).getDocumentElement());
		return new String(bos.toByteArray(), "UTF-8");
	} catch(Exception e) {
		e.printStackTrace();
	}
	return null;
}
 
开发者ID:jesse-gallagher,项目名称:Couchbase-Data-for-XPages,代码行数:17,代码来源:XMLDocument.java

示例10: prettyDocumentToString

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
 * Serialize a Document to a String using JAXP with identation (4 spaces) 
 * @param doc to serialize
 * @return xml string
 */
public static String prettyDocumentToString(Document doc) {
	StringWriter writer = new StringWriter();
	OutputFormat out = new OutputFormat();
	out.setOmitXMLDeclaration(true);
	out.setIndenting(true);
	out.setIndent(4);
	out.setLineSeparator(System.getProperty("line.separator"));
	out.setLineWidth(Integer.MAX_VALUE);
	
	XMLSerializer serializer = new XMLSerializer(writer, out);
	try {
		Element rootElement = doc.getDocumentElement();
		serializer.serialize(rootElement);
	} catch (IOException e) { 
		log.error(e);
	}
	return writer.toString();
}
 
开发者ID:chelu,项目名称:jdal,代码行数:24,代码来源:XMLUtils.java

示例11: formatXML

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
public static String formatXML(String xml) {
    try {
        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
        DocumentBuilder db = dbf.newDocumentBuilder();
        InputSource is = new InputSource(new StringReader(xml));
        Document document = db.parse(is);

        OutputFormat format = new OutputFormat(document);
        format.setLineWidth(65);
        format.setIndenting(true);
        format.setIndent(2);
        Writer out = new StringWriter();
        XMLSerializer serializer = new XMLSerializer(out, format);

        serializer.serialize(document);

        return out.toString();
    } catch (Exception e) {
        return xml;
    }
}
 
开发者ID:IvyBits,项目名称:Amber-IDE,代码行数:22,代码来源:XML.java

示例12: escribirDocumento

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
private void escribirDocumento (Document doc, Writer writer) throws IOException {
	XMLSerializer xmlSerializer = new XMLSerializer();	    
	OutputFormat outFormat = new OutputFormat();

    outFormat.setEncoding (getEncoding ());
    outFormat.setVersion("1.0");
    outFormat.setIndenting (isIdentacion ());
    outFormat.setIndent (getCaracteresIdentacion ());

    xmlSerializer.setOutputCharStream (writer);
    xmlSerializer.setOutputFormat (outFormat);
    xmlSerializer.serialize (doc);
    writer.close();
}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:15,代码来源:Generador.java

示例13: formatXML

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
 * Formats a given unformatted XML string
 *
 * @param xml
 * @return A CDATA wrapped, formatted XML String
 */
public String formatXML(String xml) {

    try {
        DocumentBuilder docBuilder;
        Document xmlDoc;

        // create the factory
        DocumentBuilderFactory docFactory = IdentityUtil.getSecuredDocumentBuilderFactory();
        docFactory.setIgnoringComments(true);

        // now use the factory to create the document builder
        docBuilder = docFactory.newDocumentBuilder();
        xmlDoc = docBuilder.parse(new ByteArrayInputStream(xml.getBytes(Charsets.UTF_8)));


        OutputFormat format = new OutputFormat(xmlDoc);
        format.setLineWidth(0);
        format.setIndenting(true);
        format.setIndent(2);
        ByteArrayOutputStream baos = new ByteArrayOutputStream();
        XMLSerializer serializer = new XMLSerializer(baos, format);
        serializer.serialize(xmlDoc);

        xml = baos.toString("UTF-8");

    } catch (ParserConfigurationException pce) {
        throw new IllegalArgumentException("Failed to parse the unformatted XML String. ", pce);
    } catch (Exception e) {
        log.error("Error occured while formtting the unformatted XML String. ", e);
    }

    return "<![CDATA[" + xml + "]]>";
}
 
开发者ID:wso2,项目名称:carbon-identity-framework,代码行数:40,代码来源:PolicyEditorService.java

示例14: dropXmlFile

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
protected String dropXmlFile(Person person, org.w3c.dom.Document xmldoc) {

        //  determine file paths and names
        String filename = getBatchFilePathAndName(person);

        //  setup the file stream
        FileOutputStream fos = null;
        try {
            fos = new FileOutputStream(filename);
            try {
                //  setup the output format
                OutputFormat of = new OutputFormat("XML", "UTF-8", true);
                of.setIndent(1);
                of.setIndenting(true);

                //  setup the xml serializer and do the serialization
                Element docElement = xmldoc.getDocumentElement();
                XMLSerializer serializer = new XMLSerializer(fos, of);
                serializer.asDOMSerializer();
                serializer.serialize(docElement);
            } finally {
                // close the output stream
                if (fos != null) {
                    fos.close();
                }
            }
        }
        catch (IOException e) {
            throw new RuntimeException("Exception while writing customer invoice writeoff xml file.", e);
        }

        return filename;
    }
 
开发者ID:kuali,项目名称:kfs,代码行数:34,代码来源:CustomerInvoiceWriteoffBatchServiceImpl.java

示例15: documentToString

import org.apache.xml.serialize.OutputFormat; //导入方法依赖的package包/类
/**
 * Returns a String representation for the XML Document.
 *
 * @param xmlDocument the XML Document
 * @return String representation for the XML Document
 * @throws IOException
 */
public static String documentToString(Document xmlDocument) throws IOException {
    String encoding = (xmlDocument.getXmlEncoding() == null) ? "UTF-8" : xmlDocument.getXmlEncoding();
    OutputFormat format = new OutputFormat(xmlDocument);
    format.setLineWidth(65);
    format.setIndenting(true);
    format.setIndent(2);
    format.setEncoding(encoding);
    try (Writer out = new StringWriter()) {
        XMLSerializer serializer = new XMLSerializer(out, format);
        serializer.serialize(xmlDocument);
        return out.toString();
    }
}
 
开发者ID:CloudSlang,项目名称:cs-actions,代码行数:21,代码来源:DocumentUtils.java


注:本文中的org.apache.xml.serialize.OutputFormat.setIndent方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。