Java Code Examples for org.dom4j.io.OutputFormat

The following examples show how to use org.dom4j.io.OutputFormat. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source Project: hermes   Source File: Identity.java    License: Apache License 2.0 6 votes vote down vote up
private static Document creXmlDoc(String xmlStr) {
	if (Strings.empty(xmlStr)) {
		throw new RuntimeException("参数不能为空");
	}
	SAXReader saxReader = new SAXReader();
	Document document = null;
	try {
		document = saxReader.read(new ByteArrayInputStream(xmlStr.getBytes("UTF-8")));
		Element rootElement = document.getRootElement();
		String getXMLEncoding = document.getXMLEncoding();
		String rootname = rootElement.getName();
		System.out.println("getXMLEncoding>>>" + getXMLEncoding + ",rootname>>>" + rootname);
		OutputFormat format = OutputFormat.createPrettyPrint();
		/** 指定XML字符集编码 */
		format.setEncoding("UTF-8");
		Logger.info(xmlStr);
	} catch (Exception e) {
		e.printStackTrace();
	}
	return document;
}
 
Example 2
Source Project: onedev   Source File: VersionedXmlDoc.java    License: MIT License 6 votes vote down vote up
public String toXML(boolean pretty) {
	ByteArrayOutputStream baos = new ByteArrayOutputStream();
	try {
		OutputFormat format = new OutputFormat();
		format.setEncoding(StandardCharsets.UTF_8.name());
		if (pretty) {
			format.setIndent(true);
			format.setIndentSize(4);
	        format.setNewlines(true);
		} else {
	        format.setIndent(false);
	        format.setNewlines(false);
		}
		new XMLWriter(baos, format).write(getWrapped());
		return baos.toString(StandardCharsets.UTF_8.name());
	} catch (Exception e) {
		throw ExceptionUtils.unchecked(e);
	}
}
 
Example 3
Source Project: Crawer   Source File: WriteXml.java    License: MIT License 6 votes vote down vote up
/**
 * 写数据到xml
 * 
 * @param datas
 * @throws Exception
 */
public static void witeXml(@SuppressWarnings("rawtypes") Map map,String xmlFilePath)
		throws Exception {
	Document doc = DomHelper.createDomFJ();
	doc.addComment("以utf-8的编码");
	Element books = DomHelper.appendChile("books", doc);
	/* 格式化输出 */
	OutputFormat format = OutputFormat.createPrettyPrint();// 紧缩
	format.setEncoding("utf-8"); // 设置utf-8编码
	Element book = DomHelper.appendChile("book", books);
	
	//构建树形结构
	rescue(book, map);
	
	//输出
	FileOutputStream fos = new FileOutputStream(xmlFilePath);
	XMLWriter writer=new XMLWriter(fos,format);
	//写结构
	writer.write(doc);
	//关闭流
	writer.close();
}
 
Example 4
Source Project: olat   Source File: FilePersister.java    License: Apache License 2.0 6 votes vote down vote up
/**
 * Persist results for this user/aiid as an XML document. dlPointer is aiid in this case.
 * 
 * @param doc
 * @param type
 * @param info
 */
public static void createResultsReporting(final Document doc, final Identity subj, final String type, final long aiid) {
    final File fUserdataRoot = new File(getQtiFilePath());
    final String path = RES_REPORTING + File.separator + subj.getName() + File.separator + type;
    final File fReportingDir = new File(fUserdataRoot, path);
    try {
        fReportingDir.mkdirs();
        final OutputStream os = new FileOutputStream(new File(fReportingDir, aiid + ".xml"));
        final Element element = doc.getRootElement();
        final XMLWriter xw = new XMLWriter(os, new OutputFormat("  ", true));
        xw.write(element);
        // closing steams
        xw.close();
        os.close();
    } catch (final Exception e) {
        throw new OLATRuntimeException(FilePersister.class,
                "Error persisting results reporting for subject: '" + subj.getName() + "'; assessment id: '" + aiid + "'", e);
    }
}
 
Example 5
/**
 * 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);
       }
}
 
Example 6
/**
 * 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();
    }
}
 
Example 7
/**
 * 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);
}
 
Example 8
Source Project: CogniCrypt   Source File: XSLConfiguration.java    License: Eclipse Public License 2.0 6 votes vote down vote up
@Override
public File persistConf() throws IOException {
	final XMLClaferParser parser = new XMLClaferParser();
	Document configInXMLFormat = parser.displayInstanceValues(instance, this.options);
	if (configInXMLFormat != null) {
		final OutputFormat format = OutputFormat.createPrettyPrint();
		final XMLWriter writer = new XMLWriter(new FileWriter(pathOnDisk), format);
		writer.write(configInXMLFormat);
		writer.close();
		configInXMLFormat = null;

		return new File(pathOnDisk);
	} else {
		Activator.getDefault().logError(Constants.NO_XML_INSTANCE_FILE_TO_WRITE);
	}
	return null;

}
 
Example 9
public static String toString(final Element el, final boolean prettyFormat)
{
  if (el == null) {
    return "";
  }
  final StringWriter out = new StringWriter();
  final OutputFormat format = new OutputFormat();
  if (prettyFormat == true) {
    format.setNewlines(true);
    format.setIndentSize(2);
  }
  final XMLWriter writer = new XMLWriter(out, format);
  String result = null;
  try {
    writer.write(el);
    result = out.toString();
    writer.close();
  } catch (final IOException ex) {
    log.error(ex.getMessage(), ex);
  }
  return result;
}
 
Example 10
Source Project: urule   Source File: FrameServletHandler.java    License: Apache License 2.0 6 votes vote down vote up
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);
}
 
Example 11
Source Project: onos   Source File: XmppStreamOpen.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String toXml() {
    StringWriter out = new StringWriter();
    XMLWriter writer = new XMLWriter(out, OutputFormat.createCompactFormat());
    try {
        out.write("<");
        writer.write(element.getQualifiedName());
        for (Attribute attr : (List<Attribute>) element.attributes()) {
            writer.write(attr);
        }
        writer.write(Namespace.get(this.element.getNamespacePrefix(), this.element.getNamespaceURI()));
        writer.write(Namespace.get("jabber:client"));
        out.write(">");
    } catch (IOException ex) {
        log.info("Error writing XML", ex);
    }
    return out.toString();
}
 
Example 12
Source Project: olat   Source File: QTIExportImportTest.java    License: Apache License 2.0 6 votes vote down vote up
private static QTIDocument exportAndImportToQTIFormat(QTIDocument qtiDocOrig) throws IOException {
    Document qtiXmlDoc = qtiDocOrig.getDocument();
    OutputFormat outformat = OutputFormat.createPrettyPrint();

    String fileName = qtiDocOrig.getAssessment().getTitle() + "QTIFormat.xml";
    OutputStreamWriter qtiXmlOutput = new OutputStreamWriter(new FileOutputStream(new File(TEMP_DIR, fileName)), Charset.forName("UTF-8"));
    XMLWriter writer = new XMLWriter(qtiXmlOutput, outformat);
    writer.write(qtiXmlDoc);
    writer.flush();
    writer.close();

    XMLParser xmlParser = new XMLParser(new IMSEntityResolver());
    Document doc = xmlParser.parse(new FileInputStream(new File(TEMP_DIR, fileName)), true);
    ParserManager parser = new ParserManager();
    QTIDocument qtiDocRestored = (QTIDocument) parser.parse(doc);
    return qtiDocRestored;
}
 
Example 13
private void write() {
    double pressLat = viewer.getLatitude(press.y);
    double pressLon = viewer.getLongitude(press.x);
    double releaseLat = viewer.getLatitude(release.y);
    double releaseLon = viewer.getLongitude(release.x);
    try {
        OSMMap newMap = new OSMMap(map,
                                   Math.min(pressLat, releaseLat),
                                   Math.min(pressLon, releaseLon),
                                   Math.max(pressLat, releaseLat),
                                   Math.max(pressLon, releaseLon));
        Document d = newMap.toXML();
        XMLWriter writer = new XMLWriter(out, OutputFormat.createPrettyPrint());
        writer.write(d);
        writer.flush();
        writer.close();
        System.out.println("Wrote map");
    }
    // CHECKSTYLE:OFF:IllegalCatch
    catch (Exception ex) {
        ex.printStackTrace();
    }
    // CHECKSTYLE:ON:IllegalCatch
}
 
Example 14
Source Project: yarg   Source File: DefaultXmlWriter.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public String buildXml(Report report) {
    try {
        Document document = DocumentFactory.getInstance().createDocument();
        Element root = document.addElement("report");

        root.addAttribute("name", report.getName());
        writeTemplates(report, root);
        writeInputParameters(report, root);
        writeValueFormats(report, root);
        writeRootBand(report, root);

        StringWriter stringWriter = new StringWriter();
        new XMLWriter(stringWriter, OutputFormat.createPrettyPrint()).write(document);
        return stringWriter.toString();
    } catch (IOException e) {
        throw new ReportingException(e);
    }
}
 
Example 15
Source Project: unitime   Source File: XmlApiHelper.java    License: Apache License 2.0 6 votes vote down vote up
@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();
	}
}
 
Example 16
Source Project: unitime   Source File: AbstractSolver.java    License: Apache License 2.0 6 votes vote down vote up
@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();
    }
}
 
Example 17
Source Project: unitime   Source File: StudentSolver.java    License: Apache License 2.0 6 votes vote down vote up
@Override
public byte[] backupXml() {
	java.util.concurrent.locks.Lock lock = currentSolution().getLock().readLock();
       lock.lock();
       try {
           ByteArrayOutputStream ret = new ByteArrayOutputStream();
           GZIPOutputStream gz = new GZIPOutputStream(ret);
           
           Document document = createCurrentSolutionBackup(false, false);
           saveProperties(document);
           
           new XMLWriter(gz, OutputFormat.createCompactFormat()).write(document);
           
           gz.flush(); gz.close();

           return ret.toByteArray();
       } catch (Exception e) {
           sLog.error(e.getMessage(),e);
           return null;
       } finally {
       	lock.unlock();
       }
}
 
Example 18
public static void exportToFile(ExportInteraction exportInteraction, ExtensionFileFilter fileFilter, DOM4JSettingsNode settingsNode) {
    File file = promptForFile(exportInteraction, fileFilter);
    if (file == null) {
        //the user canceled.
        return;
    }

    FileOutputStream fileOutputStream = null;
    try {
        fileOutputStream = new FileOutputStream(file);
    } catch (FileNotFoundException e) {
        LOGGER.error("Could not write to file: " + file.getAbsolutePath(), e);
        exportInteraction.reportError("Could not write to file: " + file.getAbsolutePath());
        return;
    }

    try {
        XMLWriter xmlWriter = new XMLWriter(fileOutputStream, OutputFormat.createPrettyPrint());
        Element rootElement = settingsNode.getElement();
        rootElement.detach();

        Document document = DocumentHelper.createDocument(rootElement);

        xmlWriter.write(document);
    } catch (Throwable t) {
        LOGGER.error("Internal error. Failed to save.", t);
        exportInteraction.reportError("Internal error. Failed to save.");
    } finally {
        closeQuietly(fileOutputStream);
    }
}
 
Example 19
Source Project: stategen   Source File: XmlUtil.java    License: GNU Affero General Public License v3.0 5 votes vote down vote up
public static void saveDocument(Document document, File xmlFile) throws IOException {
    @Cleanup
    Writer osWrite = new OutputStreamWriter(new FileOutputStream(xmlFile),StringUtil.UTF_8);// 创建输出流
    OutputFormat format = OutputFormat.createPrettyPrint(); // 获取输出的指定格式
    format.setEncoding(document.getXMLEncoding());  
    format.setNewLineAfterDeclaration(false);//解决声明下空行问题  
    
    format.setEncoding(StringUtil.UTF_8);// 设置编码 ,确保解析的xml为UTF-8格式
    @Cleanup
    XMLWriter writer = new XMLWriter(osWrite, format);// XMLWriter
    writer.write(document);// 把document写入xmlFile指定的文件(可以为被解析的文件或者新创建的文件)
    writer.flush();
}
 
Example 20
Source Project: eclipse-cs   Source File: XMLUtil.java    License: GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Creates a pretty printed representation of the document as a byte array.
 * 
 * @param document
 *          the document
 * @return the document as a byte array (UTF-8)
 * @throws IOException
 *           Exception while serializing the document
 */
public static byte[] toByteArray(Document document) throws IOException {

  ByteArrayOutputStream byteOut = new ByteArrayOutputStream(512);

  // Pretty print the document to System.out
  OutputFormat format = OutputFormat.createPrettyPrint();
  XMLWriter writer = new XMLWriter(byteOut, format);
  writer.write(document);

  return byteOut.toByteArray();
}
 
Example 21
private static void write(Argument arg) throws Exception {
	try {
		Document document = DocumentHelper.createDocument();
		Element persistence = document.addElement("persistence", "http://java.sun.com/xml/ns/persistence");
		persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
				"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
		persistence.addAttribute("version", "2.0");
		for (Class<?> cls : scanContainerEntity(arg.getProject())) {
			Element unit = persistence.addElement("persistence-unit");
			unit.addAttribute("name", cls.getCanonicalName());
			unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
			Element provider = unit.addElement("provider");
			provider.addText(PersistenceProviderImpl.class.getCanonicalName());
			for (Class<?> o : scanMappedSuperclass(cls)) {
				Element mapped_element = unit.addElement("class");
				mapped_element.addText(o.getCanonicalName());
			}
			Element slice_unit_properties = unit.addElement("properties");
			Map<String, String> properties = new LinkedHashMap<String, String>();
			for (Entry<String, String> entry : properties.entrySet()) {
				Element property = slice_unit_properties.addElement("property");
				property.addAttribute("name", entry.getKey());
				property.addAttribute("value", entry.getValue());
			}
		}
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("UTF-8");
		File file = new File(arg.getPath());
		XMLWriter writer = new XMLWriter(new FileWriter(file), format);
		writer.write(document);
		writer.close();
		System.out.println("create persistence.xml at path:" + arg.getPath());
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
Example 22
public static List<String> directWrite(String path, List<String> classNames) throws Exception {
	try {
		Document document = DocumentHelper.createDocument();
		Element persistence = document.addElement("persistence", "http://java.sun.com/xml/ns/persistence");
		persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
				"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
		persistence.addAttribute("version", "2.0");
		for (String className : classNames) {
			Element unit = persistence.addElement("persistence-unit");
			unit.addAttribute("name", className);
			unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
			Element provider = unit.addElement("provider");
			provider.addText(PersistenceProviderImpl.class.getName());
			Element mapped_element = unit.addElement("class");
			mapped_element.addText(className);
			Element sliceJpaObject_element = unit.addElement("class");
			sliceJpaObject_element.addText("com.x.base.core.entity.SliceJpaObject");
			Element jpaObject_element = unit.addElement("class");
			jpaObject_element.addText("com.x.base.core.entity.JpaObject");
		}
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("UTF-8");
		File file = new File(path);
		FileUtils.touch(file);
		XMLWriter writer = new XMLWriter(new FileWriter(file), format);
		writer.write(document);
		writer.close();
		return classNames;
	} catch (Exception e) {
		throw new Exception("registContainerEntity error.className:" + ListTools.toStringJoin(classNames), e);
	}
}
 
Example 23
public static List<String> write(String path, List<String> entities) throws Exception {
	List<String> names = new ArrayList<>();
	String name = "";
	try {
		names.addAll((List<String>) Config.resource(Config.RESOURCE_CONTAINERENTITYNAMES));
		names = ListTools.includesExcludesWildcard(names, entities, null);
		Document document = DocumentHelper.createDocument();
		Element persistence = document.addElement("persistence", "http://java.sun.com/xml/ns/persistence");
		persistence.addAttribute(QName.get("schemaLocation", "xsi", "http://www.w3.org/2001/XMLSchema-instance"),
				"http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd");
		persistence.addAttribute("version", "2.0");
		for (String className : names) {
			name = className;
			Class<? extends JpaObject> clazz = (Class<JpaObject>) Class.forName(className);
			Element unit = persistence.addElement("persistence-unit");
			unit.addAttribute("name", className);
			unit.addAttribute("transaction-type", "RESOURCE_LOCAL");
			Element provider = unit.addElement("provider");
			provider.addText(PersistenceProviderImpl.class.getName());
			for (Class<?> o : JpaObjectTools.scanMappedSuperclass(clazz)) {
				Element mapped_element = unit.addElement("class");
				mapped_element.addText(o.getName());
			}
		}
		OutputFormat format = OutputFormat.createPrettyPrint();
		format.setEncoding("UTF-8");
		File file = new File(path);
		FileUtils.touch(file);
		XMLWriter writer = new XMLWriter(new FileWriter(file), format);
		writer.write(document);
		writer.close();
		return names;
	} catch (Exception e) {
		throw new Exception("write error.className:" + name, e);
	}
}
 
Example 24
private InputStream processModelDocType(InputStream is, String dtdSchemaUrl) throws DocumentException, IOException
{
    SAXReader reader = new SAXReader();
    // read document without validation
    Document doc = reader.read(is);
    DocumentType docType = doc.getDocType();
    if (docType != null)
    {
        // replace DOCTYPE setting the full path to the xsd
        docType.setSystemID(dtdSchemaUrl);
    }
    else
    {
        // add the DOCTYPE
        docType = new DefaultDocumentType(doc.getRootElement().getName(), dtdSchemaUrl);
        doc.setDocType(docType);
    }

    ByteArrayOutputStream fos = new ByteArrayOutputStream();
    try
    {
        OutputFormat format = OutputFormat.createPrettyPrint(); // uses UTF-8
        XMLWriter writer = new XMLWriter(fos, format);
        writer.write(doc);
        writer.flush();
    }
    finally
    {
        fos.close();
    }
    
    return new ByteArrayInputStream(fos.toByteArray());
}
 
Example 25
public XMLTransferRequsiteWriter(Writer out)
{
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding("UTF-8");

    this.writer = new XMLWriter(out, format);
}
 
Example 26
public XMLWriter(OutputStream outputStream, boolean prettyPrint, String encoding)
        throws UnsupportedEncodingException
{
    OutputFormat format = prettyPrint ? OutputFormat.createPrettyPrint() : OutputFormat.createCompactFormat();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding(encoding);
    output = outputStream;
    this.dom4jWriter = new org.dom4j.io.XMLWriter(outputStream, format);
}
 
Example 27
private XMLWriter createXMLExporter(Writer writer)
{
    // Define output format
    OutputFormat format = OutputFormat.createPrettyPrint();
    format.setNewLineAfterDeclaration(false);
    format.setIndentSize(3);
    format.setEncoding("UTF-8");

    // Construct an XML Exporter

    XMLWriter xmlWriter = new XMLWriter(writer, format);
    return xmlWriter;
}
 
Example 28
Source Project: CogniCrypt   Source File: XMLClaferParser.java    License: Eclipse Public License 2.0 5 votes vote down vote up
/**
 * Writes XML document to file. Before calling this method {@link de.cognicrypt.codegenerator.utilities.XMLClaferParser#displayInstanceValues(InstanceClafer, HashMap)
 * displayInstanceValues()} should have been called to create document.
 *
 * @param path
 *        path the XML file is written to
 * @throws IOException
 *         See {@link org.dom4j.io.XMLWriter#write(Document) write()} and {@link org.dom4j.io.XMLWriter#close() close()}
 */
public void writeXMLToFile(final String path) throws IOException {
	if (this.document != null) {
		final OutputFormat format = OutputFormat.createPrettyPrint();
		final XMLWriter writer = new XMLWriter(new FileWriter(path), format);
		writer.write(this.document);
		writer.close();
		this.document = null;
	} else {
		Activator.getDefault().logError(Constants.NO_XML_INSTANCE_FILE_TO_WRITE);
	}
}
 
Example 29
Source Project: ats-framework   Source File: XmlText.java    License: Apache License 2.0 5 votes vote down vote up
@Override
@PublicAtsApi
public String toString() {

    try {
        return getFormattedString(OutputFormat.createCompactFormat());
    } catch (XMLException e) {
        log.error(e.getMessage(), e.getCause());
        return "";
    }
}
 
Example 30
Source Project: ats-framework   Source File: XmlText.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * @return the XML as nicely formatted text
 */
@PublicAtsApi
public String toFormattedString() {

    try {
        return getFormattedString(OutputFormat.createPrettyPrint());
    } catch (XMLException e) {
        log.error(e.getMessage(), e.getCause());
        return "";
    }

}