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


Java Serializer.setIndent方法代码示例

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


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

示例1: prettyXml

import nu.xom.Serializer; //导入方法依赖的package包/类
public static String prettyXml(String xml, String firstLine){
      try {
         
         ByteArrayOutputStream out = new ByteArrayOutputStream();
         Serializer serializer = new Serializer(out);
         serializer.setIndent(2);
         if(firstLine != null){
            serializer.write(new Builder().build(firstLine + xml, ""));            
         } else {
            serializer.write(new Builder().build(xml, ""));
         }
         String ret =  out.toString("UTF-8");
         if(firstLine != null){
            return ret.substring(firstLine.length() , ret.length()).trim();
         } else {
            return ret;            
         }
      } catch (Exception e) {
//         ExceptionHandler.handle(e);
         return xml;
      }
   }
 
开发者ID:nextinterfaces,项目名称:http4e,代码行数:23,代码来源:JunkUtils.java

示例2: outputDocument

import nu.xom.Serializer; //导入方法依赖的package包/类
@Override
public void outputDocument(Document pNode, OutputStream pOutputStream, boolean pPrettyPrint) {
  //Use the standard XOM Serializer to serialize document nodes because we don't need any special features
  try {
    Serializer lSerializer = new Serializer(pOutputStream);

    if(pPrettyPrint) {
      lSerializer.setIndent(2);
    }

    lSerializer.setLineSeparator("\n");
    lSerializer.write(pNode);
  }
  catch (IOException e) {
    throw new ExInternal("Failed to serialize XML document", e);
  }
}
 
开发者ID:Fivium,项目名称:FOXopen,代码行数:18,代码来源:ActuateReadOnly.java

示例3: writeDocument

import nu.xom.Serializer; //导入方法依赖的package包/类
public static void writeDocument(
        @Nonnull Document document, @Nonnull OutputStream outputStream, @Nonnull Charset encoding)
        throws IOException {

    Preconditions.checkNotNull(document, "xmlDoc");
    Preconditions.checkNotNull(outputStream, "outputStream");
    Preconditions.checkNotNull(encoding, "encoding");

    Serializer ser = new Serializer(outputStream, encoding.name());
    ser.setIndent(2);
    ser.setMaxLength(0);
    ser.setLineSeparator("\n");

    // XXX all elements inherit root elements base uri unless explicitly set (even if an
    // ancestor overrides that base.) Not sure this is correct.
    ser.setPreserveBaseURI(true);
    ser.write(document);
    ser.flush();
}
 
开发者ID:hamishmorgan,项目名称:XomB,代码行数:20,代码来源:XomUtil.java

示例4: saveFile

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * Saves the valid resource to a file.
 * 
 * @param filename the filename
 * @throws IOException
 */
private void saveFile(String filename, Resource resource) throws IOException {
	FileOutputStream os = null;
	try {
		Document doc = new Document(resource.getXOMElementCopy());
		doc.insertChild(new Comment(" Generated by Escort in DDMSence v" + PropertyReader.getProperty("version")
			+ " "), 0);
		File outputFile = new File(PropertyReader.getProperty("sample.data"), filename);
		os = new FileOutputStream(outputFile);
		Serializer serializer = new Serializer(os);
		serializer.setIndent(3);
		serializer.write(doc);
		println("File saved at \"" + outputFile.getAbsolutePath() + "\".");
	}
	finally {
		if (os != null)
			os.close();
	}
}
 
开发者ID:imintel,项目名称:ddmsence,代码行数:25,代码来源:Escort.java

示例5: toZipData

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * @return this container as compressed data
 * @throws IOException in case of any failure
 */
public byte[] toZipData() throws IOException {
	ByteArrayOutputStream bos = new ByteArrayOutputStream();
	
	try (ZipOutputStream zipOutputStream = new ZipOutputStream(bos)) {
		
		ZipEntry docEntry = new ZipEntry(documentName);
		zipOutputStream.putNextEntry(docEntry);
		Serializer serializer = new Serializer(zipOutputStream);
		serializer.setIndent(4);
		serializer.write(document);
		zipOutputStream.closeEntry();
		
		for (Map.Entry<String, byte[]> entry : externalResources.entrySet()) {
			ZipEntry extResourceEntry = new ZipEntry(entry.getKey());
			zipOutputStream.putNextEntry(extResourceEntry);
			zipOutputStream.write(entry.getValue());
			zipOutputStream.closeEntry();
		}
	}
	
	return bos.toByteArray();
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:27,代码来源:ZipResult.java

示例6: xmlToString

import nu.xom.Serializer; //导入方法依赖的package包/类
private String xmlToString(Document xml) throws IOException {
    String lineSeparator = System.getProperty("line.separator");
    ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
    Serializer serializer = new Serializer(outputStream, "UTF-8");
    serializer.setIndent(4);
    serializer.setLineSeparator(lineSeparator);
    serializer.write(xml);
    String xmlString = new String(outputStream.toByteArray(), "UTF-8");
    return xmlString.substring(xmlString.indexOf(lineSeparator) + lineSeparator.length());
}
 
开发者ID:SimY4,项目名称:xpath-to-xml,代码行数:11,代码来源:XmlBuilderTest.java

示例7: prettyXml

import nu.xom.Serializer; //导入方法依赖的package包/类
public static String prettyXml(Document doc) throws IOException {
  ByteArrayOutputStream out = new ByteArrayOutputStream();
  Serializer serializer = new Serializer(out);
  serializer.setIndent(2);
  serializer.write(doc);
  return out.toString("UTF-8");
}
 
开发者ID:gemxd,项目名称:gemfirexd-oss,代码行数:8,代码来源:XmlUtils.java

示例8: printXML

import nu.xom.Serializer; //导入方法依赖的package包/类
private static void printXML(Element root) throws IOException {
    Document doc = new Document(root);

    Serializer serializer= new Serializer(System.out);
    serializer.setIndent(4);
    serializer.setMaxLength(60);
    serializer.write(doc);
    serializer.flush();
}
 
开发者ID:spiffykahuna,项目名称:TIJ4-code_idea,代码行数:10,代码来源:Exercise32.java

示例9: convertToString

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * @param sourceData the input document
 * @param conversionPath a path to convert from input format to output format.
 * @param properties the conversion properties
 * @return the conversion result as a String
 * @throws IOException in case of any failure
 */
public String convertToString(
		byte[] sourceData, 
		ConversionPath conversionPath, 
		Properties properties) throws IOException {
	
	ByteArrayOutputStream buffer = new ByteArrayOutputStream();
	Serializer serializer = new Serializer(buffer);
	serializer.setIndent(2);
	serializer.write(convertToDocument(sourceData, conversionPath, properties));
	return buffer.toString("UTF-8"); //$NON-NLS-1$
}
 
开发者ID:ADHO,项目名称:dhconvalidator,代码行数:19,代码来源:OxGarageConversionClient.java

示例10: test03

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * 格式化
 */
@Test
public void test03() {
	BigInteger low  = BigInteger.ONE;
    BigInteger high = BigInteger.ONE;      

    Element root = new Element("Fibonacci_Numbers");  
    for (int i = 1; i <= 10; i++) {
        Element fibonacci = new Element("fibonacci");
        fibonacci.appendChild(low.toString());
        root.appendChild(fibonacci);
        
        BigInteger temp = high;
        high = high.add(low);
        low = temp;
    }
    Document doc = new Document(root);
      
    try {
      Serializer serializer = new Serializer(System.out, "ISO-8859-1");
      serializer.setIndent(4);
      serializer.setMaxLength(64);
      serializer.write(doc);  
    }
    catch (IOException ex) {
       System.err.println(ex); 
    }   
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:31,代码来源:XomCreateXML.java

示例11: test04

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * 屬性
 */
@Test
public void test04() {
	BigInteger low = BigInteger.ONE;
	BigInteger high = BigInteger.ONE;

	Element root = new Element("Fibonacci_Numbers");
	for (int i = 1; i <= 10; i++) {
		Element fibonacci = new Element("fibonacci");
		fibonacci.appendChild(low.toString());
		Attribute index = new Attribute("index", String.valueOf(i));
		fibonacci.addAttribute(index);
		root.appendChild(fibonacci);

		BigInteger temp = high;
		high = high.add(low);
		low = temp;
	}
	Document doc = new Document(root);
	try {
		Serializer serializer = new Serializer(System.out, "ISO-8859-1");
		serializer.setIndent(4);
		serializer.setMaxLength(64);
		serializer.write(doc);
	} catch (IOException ex) {
		System.err.println(ex);
	}
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:31,代码来源:XomCreateXML.java

示例12: test05

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * 聲明Document Type
 */
@Test
public void test05() {
	BigInteger low = BigInteger.ONE;
	BigInteger high = BigInteger.ONE;

	Element root = new Element("Fibonacci_Numbers");
	for (int i = 1; i <= 10; i++) {
		Element fibonacci = new Element("fibonacci");
		fibonacci.appendChild(low.toString());
		Attribute index = new Attribute("index", String.valueOf(i));
		fibonacci.addAttribute(index);
		root.appendChild(fibonacci);

		BigInteger temp = high;
		high = high.add(low);
		low = temp;
	}
	Document doc = new Document(root);
	DocType doctype = new DocType("Fibonacci_Numbers", "fibonacci.dtd");
	doc.insertChild(doctype, 0);
	try {
		Serializer serializer = new Serializer(System.out, "ISO-8859-1");
		serializer.setIndent(4);
		serializer.setMaxLength(64);
		serializer.write(doc);
	} catch (IOException ex) {
		System.err.println(ex);
	}
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:33,代码来源:XomCreateXML.java

示例13: test07

import nu.xom.Serializer; //导入方法依赖的package包/类
/**
 * Create elements in namespaces
 */
@Test
public void test07() throws Exception{
	BigInteger low  = BigInteger.ONE;
      BigInteger high = BigInteger.ONE;      

      String namespace = "http://www.w3.org/1998/Math/MathML";
      Element root = new Element("mathml:math", namespace);  
      for (int i = 1; i <= 10; i++) {
        Element mrow = new Element("mathml:mrow", namespace);
        Element mi = new Element("mathml:mi", namespace);
        Element mo = new Element("mathml:mo", namespace);
        Element mn = new Element("mathml:mn", namespace);
        mrow.appendChild(mi);
        mrow.appendChild(mo);
        mrow.appendChild(mn);
        root.appendChild(mrow);
        mi.appendChild("f(" + i + ")");
        mo.appendChild("=");
        mn.appendChild(low.toString());
        
        BigInteger temp = high;
        high = high.add(low);
        low = temp;
      }
      Document doc = new Document(root);

      try {
        Serializer serializer = new Serializer(System.out, "ISO-8859-1");
        serializer.setIndent(4);
        serializer.setMaxLength(64);
        serializer.write(doc);  
      }
      catch (IOException ex) {
        System.err.println(ex); 
      }  
	
}
 
开发者ID:v5developer,项目名称:maven-framework-project,代码行数:41,代码来源:XomCreateXML.java

示例14: generateXmlSchema

import nu.xom.Serializer; //导入方法依赖的package包/类
public void generateXmlSchema(OutputStream output, boolean excludeOptional) throws Exception {
    Element configEl = new Element("config", namespaceUri);
    configEl.addNamespaceDeclaration(null, namespaceUri);

    for (InjectableProperty property : new ConfigClassAnalyzer(configClass).getConfigProperties()) {
        if (excludeOptional && property.isOptional()) {
            continue;
        }

        if (property.isContextual()) {
            continue;
        }

        if (property.isArray()) {
            addArrayProperty(configEl, property);
        } else if (property.isCollection()) {
            addCollectionProperty(configEl, property);
        } else if (property.isMap()) {
            addMapProperty(configEl, property);
        } else if (property.isReference()) {
            addReferenceProperty(configEl, property);
        } else {
            addScalarProperty(configEl, property);
        }

    }

    Serializer serializer = new Serializer(output, "utf-8");
    serializer.setIndent(4);
    serializer.setMaxLength(160);
    serializer.write(new Document(configEl));
}
 
开发者ID:avast,项目名称:syringe,代码行数:33,代码来源:XmlInstanceGenerator.java

示例15: createXML

import nu.xom.Serializer; //导入方法依赖的package包/类
public void createXML(String path, String xmlFilePath) throws IOException{
    Serializer serializer = new Serializer(new BufferedOutputStream(
            new FileOutputStream(xmlFilePath)), "UTF-8");
    serializer.setIndent(4);
    serializer.setMaxLength(60);
    serializer.write(new Document(getXML(path)));
}
 
开发者ID:bodydomelight,项目名称:tij-problems,代码行数:8,代码来源:WordCalc.java


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