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


Java OutputFormat类代码示例

本文整理汇总了Java中org.dom4j.io.OutputFormat的典型用法代码示例。如果您正苦于以下问题:Java OutputFormat类的具体用法?Java OutputFormat怎么用?Java OutputFormat使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: getWriter

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * Get the writer for the import file
 * 
 * @param destination	the destination XML import file
 * @return				the XML writer
 */
private XMLWriter getWriter(String destination)
{
	try
	{
		 // Define output format
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setNewLineAfterDeclaration(false);
        format.setIndentSize(INDENT_SIZE);
        format.setEncoding(this.fileEncoding);

        return new XMLWriter(new FileOutputStream(destination), format);
	}
       catch (Exception exception)
       {
       	throw new AlfrescoRuntimeException("Unable to create XML writer.", exception);
       }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ImportFileUpdater.java

示例2: startTransferReport

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * Start the transfer report
 */
public void startTransferReport(String encoding, Writer writer)
{
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);
    
    try 
    {
    
    this.writer = new XMLWriter(writer, format);
    this.writer.startDocument();
    
    this.writer.startPrefixMapping(PREFIX, TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI);

    // Start Transfer Manifest  // uri, name, prefix
    this.writer.startElement(TransferDestinationReportModel.TRANSFER_REPORT_MODEL_1_0_URI, TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT,  PREFIX + ":" + TransferDestinationReportModel.LOCALNAME_TRANSFER_DEST_REPORT, EMPTY_ATTRIBUTES);
    
    } 
    catch (SAXException se)
    {
        se.printStackTrace();
    }
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:28,代码来源:XMLTransferDestinationReportWriter.java

示例3: startTransferManifest

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * Start the transfer manifest
 */
public void startTransferManifest(Writer writer) throws SAXException
{
    format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding("UTF-8");

    this.writer = new XMLWriter(writer, format);
    this.writer.startDocument();

    this.writer.startPrefixMapping(PREFIX, TransferModel.TRANSFER_MODEL_1_0_URI);
    this.writer.startPrefixMapping("cm", NamespaceService.CONTENT_MODEL_1_0_URI);

    // Start Transfer Manifest // uri, name, prefix
    this.writer.startElement(TransferModel.TRANSFER_MODEL_1_0_URI,
                ManifestModel.LOCALNAME_TRANSFER_MAINIFEST, PREFIX + ":"
                            + ManifestModel.LOCALNAME_TRANSFER_MAINIFEST, EMPTY_ATTRIBUTES);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:XMLTransferManifestWriter.java

示例4: startTransferReport

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * Start the transfer report
 */
public void startTransferReport(String encoding, Writer writer) throws SAXException
{
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);
    
    this.writer = new XMLWriter(writer, format);
    this.writer.startDocument();
    
    this.writer.startPrefixMapping(PREFIX, TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI);

    // Start Transfer Manifest  // uri, name, prefix
    this.writer.startElement(TransferReportModel2.TRANSFER_REPORT_MODEL_2_0_URI, TransferReportModel.LOCALNAME_TRANSFER_REPORT,  PREFIX + ":" + TransferReportModel.LOCALNAME_TRANSFER_REPORT, EMPTY_ATTRIBUTES);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:19,代码来源:XMLTransferReportWriter.java

示例5: convertXML

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 *  Performs XML conversion from ADN to oai_dc format. Characters are encoded as UTF-8.
 *
 * @param  xml        XML input in the 'adn' format.
 * @param  docReader  A lucene doc reader for this record.
 * @param  context    The servlet context where this is running.
 * @return            XML in the converted 'oai_dc' format.
 */
public String convertXML(String xml, XMLDocReader docReader, ServletContext context) {
	getXFormFilesAndIndex(context);
	try {
					
		Transformer transformer = XSLTransformer.getTransformer(transform_file.getAbsolutePath());
		String transformed_content = XSLTransformer.transformString(xml, transformer);
		
		SAXReader reader = new SAXReader();
		Document document = DocumentHelper.parseText(transformed_content);

		// Dom4j automatically writes using UTF-8, unless otherwise specified.
		OutputFormat format = OutputFormat.createPrettyPrint();
		StringWriter outputWriter = new StringWriter();
		XMLWriter writer = new XMLWriter(outputWriter, format);
		writer.write(document);
		outputWriter.close();
		writer.close();
		return outputWriter.toString();			
	} catch (Throwable e) {
		System.err.println("NCS_ITEMToNSDL_DCFormatConverter was unable to produce transformed file: " + e);
		e.printStackTrace();
		return "";
	}
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:33,代码来源:NCS_ITEMToNSDL_DCFormatConverter.java

示例6: prettyPrint

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 *  Formats an {@link org.dom4j.Node} as a printable string
 *
 * @param  node  the Node to display
 * @return       a nicley-formatted String representation of the Node.
 */
public static String prettyPrint(Node node) {
	StringWriter sw = new StringWriter();
	OutputFormat format = OutputFormat.createPrettyPrint();

	format.setXHTML(true);
	//Default is false, this produces XHTML
	HTMLWriter ppWriter = new HTMLWriter(sw, format);
	try {
		ppWriter.write(node);
		ppWriter.flush();
	} catch (Exception e) {
		return ("Pretty Print Failed");
	}
	return sw.toString();
}
 
开发者ID:NCAR,项目名称:joai-project,代码行数:22,代码来源:Dom4jUtils.java

示例7: fileSource

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
public void fileSource(HttpServletRequest req, HttpServletResponse resp) throws Exception {
	String path=req.getParameter("path");
	path=Utils.decodeURL(path);
	InputStream inputStream=repositoryService.readFile(path,null);
	String content=IOUtils.toString(inputStream,"utf-8");
	inputStream.close();
	String xml=null;
	try{
		Document doc=DocumentHelper.parseText(content);
		OutputFormat format=OutputFormat.createPrettyPrint();
		StringWriter out=new StringWriter();
		XMLWriter writer=new XMLWriter(out, format);
		writer.write(doc);
		xml=out.toString();
	}catch(Exception ex){
		xml=content;
	}
	Map<String,Object> result=new HashMap<String,Object>();
	result.put("content", xml);
	writeObjectToJson(resp, result);
}
 
开发者ID:youseries,项目名称:urule,代码行数:22,代码来源:FrameServletHandler.java

示例8: removeHttpConfig

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * 删除配置
 *
 * @param name
 * @throws Exception
 */
public static void removeHttpConfig(String name) throws Exception {
    SAXReader reader = new SAXReader();
    File xml = new File(HTTP_CONFIG_FILE);
    Document doc;
    Element root;
    try (FileInputStream in = new FileInputStream(xml); Reader read = new InputStreamReader(in, "UTF-8")) {
        doc = reader.read(read);
        root = doc.getRootElement();
        Element cfg = (Element) root.selectSingleNode("/root/configs");
        Element e = (Element) root.selectSingleNode("/root/configs/config[@name='" + name + "']");
        if (e != null) {
            cfg.remove(e);
            CONFIG_MAP.remove(name);
        }
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setEncoding("UTF-8");
        XMLWriter writer = new XMLWriter(new FileOutputStream(xml), format);
        writer.write(doc);
        writer.close();
    }
}
 
开发者ID:ajtdnyy,项目名称:PackagePlugin,代码行数:28,代码来源:FileUtil.java

示例9: setResponse

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
@Override
public <R> void setResponse(R response) throws IOException {
	iResponse.setContentType("application/xml");
	iResponse.setCharacterEncoding("UTF-8");
	iResponse.setHeader("Pragma", "no-cache" );
	iResponse.addHeader("Cache-Control", "must-revalidate" );
	iResponse.addHeader("Cache-Control", "no-cache" );
	iResponse.addHeader("Cache-Control", "no-store" );
	iResponse.setDateHeader("Date", new Date().getTime());
	iResponse.setDateHeader("Expires", 0);
	iResponse.setHeader("Content-Disposition", "attachment; filename=\"response.xml\"" );
	Writer writer = iResponse.getWriter();
	try {
		new XMLWriter(writer, OutputFormat.createPrettyPrint()).write(response);
	} finally {
		writer.flush();
		writer.close();
	}
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:20,代码来源:XmlApiHelper.java

示例10: exportXml

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
@Override
public byte[] exportXml() throws IOException {
    Lock lock = currentSolution().getLock().readLock();
    lock.lock();
    try {
        boolean anonymize = ApplicationProperty.SolverXMLExportNames.isFalse();
        boolean idconv = ApplicationProperty.SolverXMLExportConvertIds.isTrue();

        ByteArrayOutputStream ret = new ByteArrayOutputStream();
        
        Document document = createCurrentSolutionBackup(anonymize, idconv);
        
        if (ApplicationProperty.SolverXMLExportConfiguration.isTrue())
        	saveProperties(document);
        
        (new XMLWriter(ret, OutputFormat.createPrettyPrint())).write(document);
        
        ret.flush(); ret.close();

        return ret.toByteArray();
    } finally {
    	lock.unlock();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:25,代码来源:AbstractSolver.java

示例11: sendRequest

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
protected void sendRequest(Document request) throws IOException {
    try {
        StringWriter writer = new StringWriter();
        (new XMLWriter(writer,OutputFormat.createPrettyPrint())).write(request);
        writer.flush(); writer.close();
        SessionImplementor session = (SessionImplementor)new _RootDAO().getSession();
        Connection connection = session.getJdbcConnectionAccess().obtainConnection();
        try {
            CallableStatement call = connection.prepareCall(iRequestSql);
            call.setString(1, writer.getBuffer().toString());
            call.execute();
            call.close();
        } finally {
        	session.getJdbcConnectionAccess().releaseConnection(connection);
        }
    } catch (Exception e) {
        sLog.error("Unable to send request: "+e.getMessage(),e);
    } finally {
        _RootDAO.closeCurrentThreadSessions();
    }
}
 
开发者ID:Jenner4S,项目名称:unitimes,代码行数:22,代码来源:BlobRoomAvailabilityService.java

示例12: toXML

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
public String toXML(boolean pretty) {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		OutputFormat format = new OutputFormat();
		format.setEncoding(Charsets.UTF_8.name());
		if (pretty) {
			format.setIndent(true);
	        format.setNewlines(true);
		} else {
	        format.setIndent(false);
	        format.setNewlines(false);
		}
		new XMLWriter(baos, format).write(getWrapped());
		return baos.toString(Charsets.UTF_8.name());
	} catch (Exception e) {
		throw Throwables.propagate(e);
	}
}
 
开发者ID:jmfgdev,项目名称:gitplex-mit,代码行数:19,代码来源:VersionedDocument.java

示例13: printXML

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * 打印XML
 *
 * @param document
 */
protected void printXML(Document document) {
    if (log.isInfoEnabled()) {
        OutputFormat format = OutputFormat.createPrettyPrint();
        format.setExpandEmptyElements(true);
        format.setSuppressDeclaration(true);
        StringWriter stringWriter = new StringWriter();
        XMLWriter writer = new XMLWriter(stringWriter, format);
        try {
            writer.write(document);
            log.info(stringWriter.toString());
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
 
开发者ID:minlia-projects,项目名称:minlia-iot,代码行数:21,代码来源:AbstractApiComponent.java

示例14: parseXMLToString

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * xml 2 string
 *
 * @param document xml document
 * @return
 */
public static String parseXMLToString(Document document) {
    Assert.notNull(document);

    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setEncoding("UTF-8");
    StringWriter writer = new StringWriter();
    XMLWriter xmlWriter = new XMLWriter(writer, format);
    try {
        xmlWriter.write(document);
        xmlWriter.close();
    } catch (IOException e) {
        throw new RuntimeException("XML解析发生错误");
    }
    return writer.toString();
}
 
开发者ID:lodsve,项目名称:lodsve-framework,代码行数:22,代码来源:XmlUtils.java

示例15: documentToString

import org.dom4j.io.OutputFormat; //导入依赖的package包/类
/**
 * Devuelve la representaci�n de un Document XML en String bien formateado
 * y con codificaci�n UTF-8.
 * @param doc Documento.
 * @return string representando el documento formateado y en UTF-8.
 */
private String documentToString(Document doc) {
    String result = null;
    StringWriter writer = new StringWriter();
    OutputFormat of = OutputFormat.createPrettyPrint();
    of.setEncoding("UTF-8");
    XMLWriter xmlWriter = new XMLWriter(writer, of);
    try {
        xmlWriter.write(doc);
        xmlWriter.close();
        result = writer.toString();
    } catch (IOException e) {
        log.error("Error escribiendo xml", e);
    }
    return result;
}
 
开发者ID:GovernIB,项目名称:sistra,代码行数:22,代码来源:InstanciaTelematicaProcessorEJB.java


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