當前位置: 首頁>>代碼示例>>Java>>正文


Java Format.setOmitDeclaration方法代碼示例

本文整理匯總了Java中org.jdom2.output.Format.setOmitDeclaration方法的典型用法代碼示例。如果您正苦於以下問題:Java Format.setOmitDeclaration方法的具體用法?Java Format.setOmitDeclaration怎麽用?Java Format.setOmitDeclaration使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.jdom2.output.Format的用法示例。


在下文中一共展示了Format.setOmitDeclaration方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: sloppyPrint

import org.jdom2.output.Format; //導入方法依賴的package包/類
/**
 * Creates an outputter and writes an XML tree.
 *
 * The encoding argument here only sets an attribute in the
 * XML declaration. It's up to the caller to ensure the writer
 * is encoding bytes to match. If encoding is null, the default
 * is "UTF-8".
 *
 * If XML character entity escaping is allowed, otherwise unmappable
 * characters may be written without errors. If disabled, an
 * UnmappableCharacterException will make their presence obvious and fatal.
 *
 * LineEndings will be CR-LF. Except for comments!?
 *
 * @param doc
 * @param writer
 * @param disableEscaping
 */
public static void sloppyPrint( Document doc, Writer writer, String encoding, boolean allowEscaping ) throws IOException {
	Format format = Format.getPrettyFormat();
	format.setTextMode( Format.TextMode.PRESERVE );  // Permit leading/trailing space.
	format.setExpandEmptyElements( false );
	format.setOmitDeclaration( false );
	format.setIndent( "\t" );
	format.setLineSeparator( LineSeparator.CRNL );

	if ( encoding != null ) {
		format.setEncoding( encoding );
	}

	if ( !allowEscaping ) {
		format.setEscapeStrategy(new EscapeStrategy() {
			@Override
			public boolean shouldEscape( char ch ) {
				return false;
			}
		});
	}

	XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
	outputter.output( doc, writer );
}
 
開發者ID:Vhati,項目名稱:Slipstream-Mod-Manager,代碼行數:43,代碼來源:SloppyXMLOutputProcessor.java

示例2: saveDocument

import org.jdom2.output.Format; //導入方法依賴的package包/類
private void saveDocument(String path, String filename, XML mode, Document document) {
  if (path != null) {
    filename = fileJoin(path, filename);
  }

  if (dryRun) {
    stderr("Writing %s\n", filename);
    return;
  }

  Format prettyFormat = Format.getPrettyFormat();
  prettyFormat.setOmitDeclaration(mode == XML.NO_DECLARATION);
  XMLOutputter outputter = new XMLOutputter(prettyFormat);
  try (Writer writer = new FileWriter(filename)) {
    outputter.output(document, writer);
  } catch (IOException e) {
    stderr("%s exception writing %s\n", e.getClass().getSimpleName(), filename);
  }
}
 
開發者ID:facebook,項目名稱:buck,代碼行數:20,代碼來源:ProjectView.java

示例3: saveToTempFile

import org.jdom2.output.Format; //導入方法依賴的package包/類
private File saveToTempFile(Element diff) throws IOException {
    Format format = Format.getRawFormat();
    format.setOmitDeclaration(true);
    XMLOutputter outputter = new XMLOutputter(format);

    File temp = File.createTempFile("xml-patch-diff-", ".xml");
    try (FileOutputStream os = new FileOutputStream(temp)) {
        outputter.output(diff, os);
    }

    Log.debug("created temp file: " + temp.getAbsolutePath());

    return temp;
}
 
開發者ID:dnault,項目名稱:xml-patch,代碼行數:15,代碼來源:XmlMultiPatch.java

示例4: getTransformedXml

import org.jdom2.output.Format; //導入方法依賴的package包/類
public static String getTransformedXml(String inputXml, String stylesheetXml, String xmlFormat, boolean omitXmlDeclaration) {
    StringWriter writer = new StringWriter();
    SAXBuilder builder = new SAXBuilder();
    builder.setXMLReaderFactory(XMLReaders.NONVALIDATING);
    builder.setFeature("http://xml.org/sax/features/validation", false);
    try {
        Document inputDoc = builder.build(new StringReader(inputXml));
        StringReader reader = new StringReader(stylesheetXml);
        XSLTransformer transformer = new XSLTransformer(reader);
        Document outputDoc = transformer.transform(inputDoc);
        XMLOutputter xmlOutput = new XMLOutputter();
        Format format = null;
        if (xmlFormat.equals(COMPACT_FORMAT)) {
            format = Format.getCompactFormat();
        } else if (xmlFormat.equals(RAW_FORMAT)) {
            format = Format.getRawFormat();
        } else {
            format = Format.getPrettyFormat();
        }
        
        format.setOmitDeclaration(omitXmlDeclaration);
        xmlOutput.setFormat(format);
        xmlOutput.output(outputDoc, writer);
        writer.close();
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    return writer.toString();
}
 
開發者ID:JumpMind,項目名稱:metl,代碼行數:30,代碼來源:XsltProcessor.java

示例5: sloppyPrint

import org.jdom2.output.Format; //導入方法依賴的package包/類
/**
 * Creates an outputter and writes an XML tree.
 *
 * The encoding argument here only sets an attribute in the
 * XML declaration. It's up to the caller to ensure the writer
 * is encoding bytes to match. If encoding is null, the default
 * is "UTF-8".
 *
 * LineEndings will be CR-LF. Except for comments!?
 */
public static void sloppyPrint( Document doc, Writer writer, String encoding ) throws IOException
{
	Format format = Format.getPrettyFormat();
	format.setExpandEmptyElements( false );
	format.setOmitDeclaration( false );
	format.setIndent( "\t" );
	format.setLineSeparator( LineSeparator.CRNL );

	if ( encoding != null ) format.setEncoding( encoding );

	XMLOutputter outputter = new XMLOutputter( format, new SloppyXMLOutputProcessor() );
	outputter.output( doc, writer );
}
 
開發者ID:kartoFlane,項目名稱:superluminal2,代碼行數:24,代碼來源:SloppyXMLOutputProcessor.java

示例6: patch

import org.jdom2.output.Format; //導入方法依賴的package包/類
private static Set<String> patch(List<Element> diffs, File srcdir, File destdir, File tempdir) throws Exception {

        Set<String> outputFilePaths = new HashSet<>();

        for (Element diff : diffs) {

            if (diff.getAttribute("file") == null) {
                throw new IllegalArgumentException("diff element missing 'file' attribute");
            }

            String srcfilePath = diff.getAttributeValue("file");

            File fileToPatch = new File(srcfilePath);
            if (fileToPatch.isAbsolute()) {
                throw new IllegalArgumentException("not a relative path: " + srcfilePath);
            }

            outputFilePaths.add(srcfilePath);

            File alreadyInTempDir = new File(tempdir, srcfilePath);
            fileToPatch = alreadyInTempDir.exists() ? alreadyInTempDir : new File(srcdir, srcfilePath);

            Log.info("patching " + srcfilePath + " [from " + fileToPatch.getAbsolutePath() + "]");

            diff.removeAttribute("file");
            Format format = Format.getRawFormat();
            format.setOmitDeclaration(true);
            XMLOutputter outputter = new XMLOutputter(format);
            String s = outputter.outputString(diff);

            InputStream diffStream = new ByteArrayInputStream(s.getBytes("UTF-8"));
            InputStream inputStream = new FileInputStream(fileToPatch);

            File outputFile = File.createTempFile("xmlpatch", ".xml");
            OutputStream outputStream = new FileOutputStream(outputFile);

            Patcher.patch(inputStream, diffStream, outputStream);

            inputStream.close();
            outputStream.close();

            File outputTemp = new File(tempdir, srcfilePath);
            File tempParentDir = outputTemp.getParentFile();

            if (!tempParentDir.exists() && !tempParentDir.mkdirs()) {
                throw new IOException("failed to create directory: " + tempParentDir.getAbsolutePath());
            }

            IoHelper.move(outputFile, outputTemp);
        }
        return outputFilePaths;
    }
 
開發者ID:dnault,項目名稱:xml-patch,代碼行數:53,代碼來源:BatchPatcher.java


注:本文中的org.jdom2.output.Format.setOmitDeclaration方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。