List of usage examples for org.w3c.dom.ls DOMImplementationLS createLSOutput
public LSOutput createLSOutput();
LSOutput.characterStream
, LSOutput.byteStream
, LSOutput.systemId
, LSOutput.encoding
are null. From source file:com.collabnet.ccf.core.recovery.HospitalArtifactReplayer.java
@SuppressWarnings("deprecation") private void loadBeanDefinitionsFromUrl(String url, GenericApplicationContext context) { BeanDefinitionReader reader = null;//from w w w. j a va2s . co m if (url.endsWith(".xml")) { reader = new XmlBeanDefinitionReader(context); } else if (url.endsWith(".properties")) { reader = new PropertiesBeanDefinitionReader(context); } if (reader != null) { try { UrlResource urlResource = new UrlResource(url); InputStream is = urlResource.getInputStream(); Document document = builder.parse(is); Element routerElement = this.getRouterElement(document); this.stripOffProcessors(routerElement); this.addGAImportComponents(document, routerElement); DOMImplementationRegistry registry = null; try { registry = DOMImplementationRegistry.newInstance(); } catch (ClassCastException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (ClassNotFoundException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (InstantiationException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } catch (IllegalAccessException e) { log.error("error", e); throw new CCFRuntimeException("error", e); } String originalConfigFileAbsolutePath = urlResource.getFile().getAbsolutePath(); String componentName = entry.getSourceComponent(); String configComponentIdentifier = "{" + originalConfigFileAbsolutePath + "}" + componentName; File outputFile = null; if (componentConfigFileMap.containsKey(configComponentIdentifier)) { outputFile = componentConfigFileMap.get(configComponentIdentifier); } else { outputFile = File.createTempFile(componentName, ".xml", replayWorkDir); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); LSOutput output = impl.createLSOutput(); FileOutputStream bas = new FileOutputStream(outputFile.getAbsolutePath()); output.setByteStream(bas); writer.write(document, output); bas.flush(); bas.close(); componentConfigFileMap.put(configComponentIdentifier, outputFile); } // FIXME Use of deprecated method UrlResource newUrlResource = new UrlResource(outputFile.toURL().toString()); ((XmlBeanDefinitionReader) reader).registerBeanDefinitions(document, newUrlResource); } catch (BeansException e) { log.error("error", e); throw new RuntimeException("BeansException : " + e.getMessage(), e); } catch (MalformedURLException e) { log.error("error", e); throw new RuntimeException("MalformedUrlException : " + e.getMessage(), e); } catch (IOException e) { log.error("error", e); throw new RuntimeException("IOExceptionException : " + e.getMessage(), e); } catch (SAXException e) { log.error("error", e); throw new RuntimeException("SAXException : " + e.getMessage(), e); } } else { throw new RuntimeException("No BeanDefinitionReader associated with " + url); } }
From source file:com.msopentech.odatajclient.engine.performance.BasicPerfTest.java
@Test public void writeAtomViaLowerlevelLibs() throws ParserConfigurationException, ClassNotFoundException, InstantiationException, IllegalAccessException { final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); final DocumentBuilder builder = factory.newDocumentBuilder(); final Document doc = builder.newDocument(); final Element entry = doc.createElement("entry"); entry.setAttribute("xmlns", "http://www.w3.org/2005/Atom"); entry.setAttribute("xmlns:m", "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata"); entry.setAttribute("xmlns:d", "http://schemas.microsoft.com/ado/2007/08/dataservices"); entry.setAttribute("xmlns:gml", "http://www.opengis.net/gml"); entry.setAttribute("xmlns:georss", "http://www.georss.org/georss"); doc.appendChild(entry);/*from www. j a va 2 s .c o m*/ final Element category = doc.createElement("category"); category.setAttribute("term", "Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"); category.setAttribute("scheme", "http://schemas.microsoft.com/ado/2007/08/dataservices/scheme"); entry.appendChild(category); final Element properties = doc.createElement("m:properties"); entry.appendChild(properties); final Element name = doc.createElement("d:Name"); name.setAttribute("m:type", "Edm.String"); name.appendChild(doc.createTextNode("A name")); properties.appendChild(name); final Element customerId = doc.createElement("d:CustomerId"); customerId.setAttribute("m:type", "Edm.Int32"); customerId.appendChild(doc.createTextNode("0")); properties.appendChild(customerId); final Element bci = doc.createElement("d:BackupContactInfo"); bci.setAttribute("m:type", "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)"); properties.appendChild(bci); final Element topelement = doc.createElement("d:element"); topelement.setAttribute("m:type", "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails"); bci.appendChild(topelement); final Element altNames = doc.createElement("d:AlternativeNames"); altNames.setAttribute("m:type", "Collection(Edm.String)"); topelement.appendChild(altNames); final Element element1 = doc.createElement("d:element"); element1.setAttribute("m:type", "Edm.String"); element1.appendChild(doc.createTextNode("myname")); altNames.appendChild(element1); final Element emailBag = doc.createElement("d:EmailBag"); emailBag.setAttribute("m:type", "Collection(Edm.String)"); topelement.appendChild(emailBag); final Element element2 = doc.createElement("d:element"); element2.setAttribute("m:type", "Edm.String"); element2.appendChild(doc.createTextNode("myname@mydomain.com")); emailBag.appendChild(element2); final Element contactAlias = doc.createElement("d:ContactAlias"); contactAlias.setAttribute("m:type", "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases"); topelement.appendChild(contactAlias); final Element altNames2 = doc.createElement("d:AlternativeNames"); altNames2.setAttribute("m:type", "Collection(Edm.String)"); contactAlias.appendChild(altNames2); final Element element3 = doc.createElement("d:element"); element3.setAttribute("m:type", "Edm.String"); element3.appendChild(doc.createTextNode("myAlternativeName")); altNames2.appendChild(element3); final StringWriter writer = new StringWriter(); final DOMImplementationRegistry reg = DOMImplementationRegistry.newInstance(); final DOMImplementationLS impl = (DOMImplementationLS) reg.getDOMImplementation("LS"); final LSSerializer serializer = impl.createLSSerializer(); final LSOutput lso = impl.createLSOutput(); lso.setCharacterStream(writer); serializer.write(doc, lso); assertFalse(writer.toString().isEmpty()); }
From source file:com.redhat.plugin.eap6.AbstractEAP6Mojo.java
/** * method to convert Document to String//from w w w. ja va 2 s . co m * * @param doc * @return */ protected String getStringFromDocument(final Document doc) { try { final StringWriter writer = new StringWriter(); final DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); final LSSerializer lsSerializer = domImplementation.createLSSerializer(); lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); final LSOutput lsOutput = domImplementation.createLSOutput(); lsOutput.setCharacterStream(writer); lsSerializer.write(doc, lsOutput); return writer.toString(); } catch (final LSException ex) { getLog().error(ex); return null; } }
From source file:com.redhat.plugin.eap6.AbstractEAP6Mojo.java
protected void writeXmlFile(final Document doc, final File workDirectory, final String fileName) throws MojoFailureException { final File destinationFile = new File(workDirectory, fileName); try {//from ww w .j a v a 2s .c om final FileOutputStream ostream = new FileOutputStream(destinationFile); final DOMImplementationLS domImplementation = (DOMImplementationLS) doc.getImplementation(); final LSSerializer lsSerializer = domImplementation.createLSSerializer(); lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); final LSOutput lsOutput = domImplementation.createLSOutput(); lsOutput.setByteStream(ostream); lsSerializer.write(doc, lsOutput); ostream.close(); refreshEclipse(destinationFile); } catch (final Exception e) { throw new MojoFailureException("Cannot write output file", e); } }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java
@Override public Document extendSignatures(Document document, Document originalData, SignatureParameters parameters) throws IOException { InputStream input = document.openStream(); if (this.tspSource == null) { throw new ConfigurationException(MSG.CONFIGURE_TSP_SERVER); }/* w w w . j a v a 2 s. c o m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(input); NodeList signatureNodeList = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); if (signatureNodeList.getLength() == 0) { throw new RuntimeException( "Impossible to perform the extension of the signature, the document is not signed."); } for (int i = 0; i < signatureNodeList.getLength(); i++) { Element signatureEl = (Element) signatureNodeList.item(i); extendSignatureTag(signatureEl, originalData, parameters.getSignatureFormat()); } DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); LSOutput output = impl.createLSOutput(); output.setByteStream(buffer); writer.write(doc, output); return new InMemoryDocument(buffer.toByteArray()); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException e) { throw new IOException("Cannot parse document", e); } catch (ClassCastException e) { throw new IOException("Cannot save document", e); } catch (ClassNotFoundException e) { throw new IOException("Cannot save document", e); } catch (InstantiationException e) { throw new IOException("Cannot save document", e); } catch (IllegalAccessException e) { throw new IOException("Cannot save document", e); } finally { if (input != null) { input.close(); } } }
From source file:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java
@Override public Document extendSignature(Object signatureId, Document document, Document originalData, SignatureParameters parameters) throws IOException { InputStream input = document.openStream(); if (this.tspSource == null) { throw new ConfigurationException(MSG.CONFIGURE_TSP_SERVER); }/*from w ww .j av a 2 s. c o m*/ try { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); dbf.setNamespaceAware(true); DocumentBuilder db = dbf.newDocumentBuilder(); org.w3c.dom.Document doc = db.parse(input); NodeList signatureNodeList = doc.getElementsByTagNameNS(XMLSignature.XMLNS, "Signature"); if (signatureNodeList.getLength() == 0) { throw new RuntimeException( "Impossible to perform the extension of the signature, the document is not signed."); } for (int i = 0; i < signatureNodeList.getLength(); i++) { Element signatureEl = (Element) signatureNodeList.item(i); String sid = signatureEl.getAttribute("Id"); if (signatureId.equals(sid)) { extendSignatureTag(signatureEl, originalData, parameters.getSignatureFormat()); } } DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSSerializer writer = impl.createLSSerializer(); ByteArrayOutputStream buffer = new ByteArrayOutputStream(); LSOutput output = impl.createLSOutput(); output.setByteStream(buffer); writer.write(doc, output); return new InMemoryDocument(buffer.toByteArray()); } catch (ParserConfigurationException ex) { throw new RuntimeException(ex); } catch (SAXException e) { throw new IOException("Cannot parse document", e); } catch (ClassCastException e) { throw new IOException("Cannot save document", e); } catch (ClassNotFoundException e) { throw new IOException("Cannot save document", e); } catch (InstantiationException e) { throw new IOException("Cannot save document", e); } catch (IllegalAccessException e) { throw new IOException("Cannot save document", e); } finally { if (input != null) { input.close(); } } }
From source file:edu.ur.ir.ir_export.service.DefaultCollectionExportService.java
/** * Generate an xml file with the specified collections. * /*from w ww .j a v a2 s .c o m*/ * @see edu.ur.dspace.export.CollectionExporter#generateCollectionXMLFile(java.io.File, java.util.Collection) */ public Set<FileInfo> createXmlFile(File f, Collection<InstitutionalCollection> collections, boolean includeChildren) throws IOException { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder; Set<FileInfo> allPictures = new HashSet<FileInfo>(); String path = FilenameUtils.getPath(f.getCanonicalPath()); if (!path.equals("")) { File pathOnly = new File(FilenameUtils.getFullPath(f.getCanonicalPath())); FileUtils.forceMkdir(pathOnly); } if (!f.exists()) { if (!f.createNewFile()) { throw new IllegalStateException("could not create file"); } } try { builder = factory.newDocumentBuilder(); } catch (ParserConfigurationException e) { throw new IllegalStateException(e); } DOMImplementation impl = builder.getDOMImplementation(); DOMImplementationLS domLs = (DOMImplementationLS) impl.getFeature("LS", "3.0"); LSSerializer serializer = domLs.createLSSerializer(); LSOutput lsOut = domLs.createLSOutput(); Document doc = impl.createDocument(null, "institutionalCollections", null); Element root = doc.getDocumentElement(); FileOutputStream fos; OutputStreamWriter outputStreamWriter; BufferedWriter writer; try { fos = new FileOutputStream(f); try { outputStreamWriter = new OutputStreamWriter(fos, "UTF-8"); } catch (UnsupportedEncodingException e) { throw new IllegalStateException(e); } writer = new BufferedWriter(outputStreamWriter); lsOut.setCharacterStream(writer); } catch (FileNotFoundException e) { throw new IllegalStateException(e); } // create XML for the child collections for (InstitutionalCollection c : collections) { Element collection = doc.createElement("collection"); this.addIdElement(collection, c.getId().toString(), doc); this.addNameElement(collection, c.getName(), doc); this.addDescription(collection, c.getDescription(), doc); this.addCopyright(collection, c.getCopyright(), doc); if (c.getPrimaryPicture() != null) { this.addPrimaryImage(collection, c.getPrimaryPicture().getFileInfo().getNameWithExtension(), doc); allPictures.add(c.getPrimaryPicture().getFileInfo()); } Set<IrFile> pictures = c.getPictures(); if (pictures.size() > 0) { Element pics = doc.createElement("pictures"); for (IrFile irFile : pictures) { Element picture = doc.createElement("picture"); this.addImage(picture, irFile.getFileInfo().getNameWithExtension(), doc); pics.appendChild(picture); allPictures.add(irFile.getFileInfo()); } collection.appendChild(pics); } if (c.getLinks().size() > 0) { Element links = doc.createElement("links"); for (InstitutionalCollectionLink l : c.getLinks()) { this.addLink(links, l, doc); } collection.appendChild(links); } if (includeChildren) { for (InstitutionalCollection child : c.getChildren()) { addChild(child, collection, doc, allPictures); } } root.appendChild(collection); } serializer.write(root, lsOut); try { fos.close(); writer.close(); outputStreamWriter.close(); } catch (Exception e) { throw new IllegalStateException(e); } return allPictures; }
From source file:edu.wfu.inotado.helper.MarshalHelper.java
/** * Pretty-Prints the XML/* ww w. j ava 2s .co m*/ * * @param xml * @return */ @SuppressWarnings("unused") private String prettyPrintXml(String xml) { DocumentBuilder documentBuilder; StringWriter stringWriter = new StringWriter(); try { documentBuilder = DocumentBuilderFactory.newInstance().newDocumentBuilder(); InputStream inputStream = new ByteArrayInputStream(xml.getBytes("UTF8")); Document document = documentBuilder.parse(inputStream); DOMImplementation domImplementation = document.getImplementation(); if (domImplementation.hasFeature("LS", "3.0") && domImplementation.hasFeature("Core", "2.0")) { DOMImplementationLS domImplementationLS = (DOMImplementationLS) domImplementation.getFeature("LS", "3.0"); LSSerializer lsSerializer = domImplementationLS.createLSSerializer(); DOMConfiguration domConfiguration = lsSerializer.getDomConfig(); if (domConfiguration.canSetParameter("format-pretty-print", Boolean.TRUE)) { lsSerializer.getDomConfig().setParameter("format-pretty-print", Boolean.TRUE); LSOutput lsOutput = domImplementationLS.createLSOutput(); lsOutput.setEncoding("UTF-8"); lsOutput.setCharacterStream(stringWriter); lsSerializer.write(document, lsOutput); return stringWriter.toString(); } else { log.warn("DOMConfiguration 'format-pretty-print' parameter isn't settable."); } } else { log.warn("DOM 3.0 LS and/or DOM 2.0 Core not supported."); } } catch (ParserConfigurationException e) { log.error("Unable to parse xml: " + xml, e); } catch (UnsupportedEncodingException e) { log.error("Encoding unspported for xml: " + xml, e); } catch (SAXException e) { log.error("SAXException occurred: " + xml, e); } catch (IOException e) { log.error("IOException occurred:" + xml, e); } // return the input string if any error occurs return xml; }
From source file:com.commander4j.thread.AutoLabellerThread.java
public void run() { logger.debug("AutoLabeller Thread running"); setSessionID(JUnique.getUniqueID()); JDBUser user = new JDBUser(getHostID(), getSessionID()); user.setUserId("interface"); user.setPassword("interface"); user.setLoginPassword("interface"); Common.userList.addUser(getSessionID(), user); Common.sd.setData(getSessionID(), "silentExceptions", "Yes", true); Boolean dbconnected = false;//from w ww. j a v a 2s .c o m if (Common.hostList.getHost(hostID).isConnected(sessionID) == false) { dbconnected = Common.hostList.getHost(hostID).connect(sessionID, hostID); } else { dbconnected = true; } if (dbconnected) { JDBViewAutoLabellerPrinter alp = new JDBViewAutoLabellerPrinter(getHostID(), getSessionID()); LinkedList<JDBViewAutoLabellerPrinter> autolabellerList = new LinkedList<JDBViewAutoLabellerPrinter>(); int noOfMessages = 0; while (true) { JWait.milliSec(500); if (allDone) { if (dbconnected) { Common.hostList.getHost(hostID).disconnect(getSessionID()); } return; } autolabellerList.clear(); autolabellerList = alp.getModifiedPrinterLines(); noOfMessages = autolabellerList.size(); if (noOfMessages > 0) { for (int x = 0; x < noOfMessages; x++) { JWait.milliSec(100); JDBViewAutoLabellerPrinter autolabview = autolabellerList.get(x); messageProcessedOK = true; messageError = ""; if (autolabview.getPrinterObj().isEnabled()) { logger.debug("Line =" + autolabview.getAutoLabellerObj().getLine()); logger.debug("Line Description =" + autolabview.getAutoLabellerObj().getDescription()); logger.debug("Printer ID =" + autolabview.getPrinterObj().getPrinterID()); logger.debug("Printer Enabled =" + autolabview.getPrinterObj().isEnabled()); logger.debug("Export Path =" + autolabview.getPrinterObj().getExportRealPath()); logger.debug("Export Enabled =" + autolabview.getPrinterObj().isExportEnabled()); logger.debug("Export Format =" + autolabview.getPrinterObj().getExportFormat()); logger.debug("Direct Print =" + autolabview.getPrinterObj().isDirectPrintEnabled()); logger.debug("Printer Type =" + autolabview.getPrinterObj().getPrinterType()); logger.debug("Printer IP =" + autolabview.getPrinterObj().getIPAddress()); logger.debug("Printer Port =" + autolabview.getPrinterObj().getPort()); logger.debug("Process Order =" + autolabview.getLabelDataObj().getProcessOrder()); logger.debug("Material =" + autolabview.getLabelDataObj().getMaterial()); logger.debug("Module ID =" + autolabview.getModuleObj().getModuleId()); logger.debug("Module Type =" + autolabview.getModuleObj().getType()); if (autolabview.getPrinterObj().isExportEnabled()) { String exportPath = JUtility.replaceNullStringwithBlank( JUtility.formatPath(autolabview.getPrinterObj().getExportRealPath())); if (exportPath.equals("") == false) { if (exportPath.substring(exportPath.length() - 1) .equals(File.separator) == false) { exportPath = exportPath + File.separator; } } else { exportPath = Common.interface_output_path + "Auto Labeller" + File.separator; } String exportFilename = exportPath + JUtility.removePathSeparators(autolabview.getAutoLabellerObj().getLine()) + "_" + JUtility.removePathSeparators(autolabview.getPrinterObj().getPrinterID()) + "." + autolabview.getPrinterObj().getExportFormat(); String exportFilenameTemp = exportFilename + ".out"; logger.debug("Export Filename =" + exportFilename); /* ================CSV================ */ if (autolabview.getPrinterObj().getExportFormat().equals("CSV")) { try { PreparedStatement stmt = null; ResultSet rs; String labelType = autolabview.getLabelDataObj().getLabelType(); stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()) .prepareStatement( Common.hostList.getHost(getHostID()).getSqlstatements() .getSQL("DBVIEW_AUTO_LABELLER_PRINTER.getProperties" + "_" + labelType)); stmt.setString(1, autolabview.getAutoLabellerObj().getLine()); stmt.setString(2, autolabview.getPrinterObj().getPrinterID()); stmt.setFetchSize(50); rs = stmt.executeQuery(); logger.debug("Writing CSV"); CSVWriter writer = new CSVWriter(new FileWriter(exportFilenameTemp), CSVWriter.DEFAULT_SEPARATOR, CSVWriter.DEFAULT_QUOTE_CHARACTER, CSVWriter.DEFAULT_ESCAPE_CHARACTER, CSVWriter.DEFAULT_LINE_END); writer.writeAll(rs, true); rs.close(); stmt.close(); writer.close(); File fromFile = new File(exportFilenameTemp); File toFile = new File(exportFilename); FileUtils.deleteQuietly(toFile); FileUtils.moveFile(fromFile, toFile); fromFile = null; toFile = null; } catch (Exception e) { messageProcessedOK = false; messageError = e.getMessage(); } } /* ================XML================ */ if (autolabview.getPrinterObj().getExportFormat().equals("XML")) { try { PreparedStatement stmt = null; ResultSet rs; stmt = Common.hostList.getHost(getHostID()).getConnection(getSessionID()) .prepareStatement(Common.hostList.getHost(getHostID()) .getSqlstatements() .getSQL("DBVIEW_AUTO_LABELLER_PRINTER.getProperties")); stmt.setString(1, autolabview.getAutoLabellerObj().getLine()); stmt.setString(2, autolabview.getPrinterObj().getPrinterID()); stmt.setFetchSize(50); rs = stmt.executeQuery(); ResultSetMetaData rsmd = rs.getMetaData(); int colCount = rsmd.getColumnCount(); DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.newDocument(); Element message = (Element) document.createElement("message"); Element hostUniqueID = addElement(document, "hostRef", Common.hostList.getHost(getHostID()).getUniqueID()); message.appendChild(hostUniqueID); Element messageRef = addElement(document, "messageRef", autolabview.getAutoLabellerObj().getUniqueID()); message.appendChild(messageRef); Element messageType = addElement(document, "interfaceType", "Auto Labeller Data"); message.appendChild(messageType); Element messageInformation = addElement(document, "messageInformation", "Unique ID=" + autolabview.getAutoLabellerObj().getUniqueID()); message.appendChild(messageInformation); Element messageDirection = addElement(document, "interfaceDirection", "Output"); message.appendChild(messageDirection); Element messageDate = addElement(document, "messageDate", JUtility.getISOTimeStampStringFormat(JUtility.getSQLDateTime())); message.appendChild(messageDate); if (rs.first()) { Element labelData = (Element) document.createElement("LabelData"); Element row = document.createElement("Row"); labelData.appendChild(row); for (int i = 1; i <= colCount; i++) { String columnName = rsmd.getColumnName(i); Object value = rs.getObject(i); Element node = document.createElement(columnName); node.appendChild(document.createTextNode(value.toString())); row.appendChild(node); } message.appendChild(labelData); document.appendChild(message); JXMLDocument xmld = new JXMLDocument(); xmld.setDocument(document); // =============================== DOMImplementationLS DOMiLS = null; FileOutputStream FOS = null; // testing the support for DOM // Load and Save if ((document.getFeature("Core", "3.0") != null) && (document.getFeature("LS", "3.0") != null)) { DOMiLS = (DOMImplementationLS) (document.getImplementation()) .getFeature("LS", "3.0"); // get a LSOutput object LSOutput LSO = DOMiLS.createLSOutput(); FOS = new FileOutputStream(exportFilename); LSO.setByteStream((OutputStream) FOS); // get a LSSerializer object LSSerializer LSS = DOMiLS.createLSSerializer(); // do the serialization LSS.write(document, LSO); FOS.close(); } // =============================== } rs.close(); stmt.close(); } catch (Exception e) { messageError = e.getMessage(); } } if (autolabview.getPrinterObj().getExportFormat().equals("LQF")) { } } if (autolabview.getPrinterObj().isDirectPrintEnabled()) { } } if (messageProcessedOK == true) { autolabview.getAutoLabellerObj().setModified(false); autolabview.getAutoLabellerObj().update(); } else { logger.debug(messageError); } autolabview = null; } } } } }
From source file:de.escidoc.core.test.EscidocTestBase.java
/** * Serialize the given Dom Object to a String. * // w w w . j a v a 2 s.c o m * @param xml * The Xml Node to serialize. * @param omitXMLDeclaration * Indicates if XML declaration will be omitted. * @return The String representation of the Xml Node. * @throws Exception * If anything fails. */ public static String toString(final Node xml, final boolean omitXMLDeclaration) throws Exception { String result = new String(); if (xml instanceof AttrImpl) { result = xml.getTextContent(); } else if (xml instanceof Document) { StringWriter stringOut = new StringWriter(); // format OutputFormat format = new OutputFormat((Document) xml); format.setIndenting(true); format.setPreserveSpace(true); format.setOmitXMLDeclaration(omitXMLDeclaration); format.setEncoding(DEFAULT_CHARSET); // serialize XMLSerializer serial = new XMLSerializer(stringOut, format); serial.asDOMSerializer(); serial.serialize((Document) xml); result = stringOut.toString(); } else { DOMImplementationRegistry registry = DOMImplementationRegistry.newInstance(); DOMImplementationLS impl = (DOMImplementationLS) registry.getDOMImplementation("LS"); LSOutput lsOutput = impl.createLSOutput(); lsOutput.setEncoding(DEFAULT_CHARSET); ByteArrayOutputStream os = new ByteArrayOutputStream(); lsOutput.setByteStream(os); LSSerializer writer = impl.createLSSerializer(); // result = writer.writeToString(xml); writer.write(xml, lsOutput); result = ((ByteArrayOutputStream) lsOutput.getByteStream()).toString(DEFAULT_CHARSET); if ((omitXMLDeclaration) && (result.indexOf("?>") != -1)) { result = result.substring(result.indexOf("?>") + 2); } // result = toString(getDocument(writer.writeToString(xml)), // true); } return result; }