List of usage examples for javax.xml.bind Marshaller setProperty
public void setProperty(String name, Object value) throws PropertyException;
From source file:com.vns.pdf.impl.PdfDocument.java
private void createTextAreaFile() { String pageXmlFileName = textAreaFilePath.toAbsolutePath().toString(); try {//w w w .ja v a2 s. c o m JAXBContext context = JAXBContext.newInstance(Doc.class); Marshaller ms = context.createMarshaller(); ms.setProperty(JAXB_FORMATTED_OUTPUT, true); ms.setProperty(CharacterEscapeHandler.class.getName(), (CharacterEscapeHandler) (ch, start, length, isAttVal, out) -> { String escape = StringEscapeUtils.escapeXml11(new String(ch)); if (!escape.contains("&#")) out.write(escape.toCharArray(), 0, escape.toCharArray().length); }); ms.marshal(doc, new File(pageXmlFileName)); } catch (JAXBException ex) { LOGGER.error(ex.getMessage(), ex); } }
From source file:net.ageto.gyrex.impex.console.internal.ImpexConsoleCommands.java
/** * * List process configurations.//from w ww. j ava2 s.com * * @param interpreter * @return */ public Object _impexListProcesses(final CommandInterpreter interpreter) { final String instanceShortcut = interpreter.nextArgument(); IRuntimeContext context = getContext(instanceShortcut); if (context == null) { interpreter.println(INSTANCE_MISSING); return null; } // determine process from database final IProcessConfigManager processManager = context.get(IProcessConfigManager.class); ArrayList<IProcessConfig> processes = (ArrayList<IProcessConfig>) processManager.findAllProcesses(); JAXBContext jaxbContext; try { for (IProcessConfig process : processes) { ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); jaxbContext = JAXBContext.newInstance(ProcessConfig.class); Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.marshal(process, outputStream); final StringBuilder sb = new StringBuilder(); sb.append("=========== " + process.getId() + " ===========\n"); sb.append("\n"); sb.append(outputStream.toString() + "\n"); sb.append("\n"); sb.append("=========== " + process.getId() + " ===========\n"); interpreter.print(sb); } } catch (JAXBException e) { interpreter.printStackTrace(e); } return null; }
From source file:mx.bigdata.sat.cfdi.CFDv33.java
@Override public void guardar(OutputStream out) throws Exception { Marshaller m = context.createMarshaller(); m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(localPrefixes)); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, getSchemaLocation()); byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8"); out.write(xmlHeaderBytes);/*from ww w. j a v a2 s . co m*/ m.marshal(document, out); }
From source file:com.dgwave.osrs.OsrsClient.java
protected String getString(OsrsRequest request) throws OsrsException { OPSEnvelope envelope = getEmptyEnvelope(); Map<String, Object> attrs = request.getAttributes(); Item pro = oj.createItem();// ww w . ja va2s . c o m pro.setKey("protocol"); pro.setStringValue(this.protocol); Item obj = oj.createItem(); obj.setKey("object"); obj.setStringValue(request.getObject()); Item act = oj.createItem(); act.setKey("action"); act.setStringValue(request.getAction()); Item att = oj.createItem(); att.setKey("attributes"); att.addDtAssoc(processAttrs(attrs)); DtAssoc c = oj.createDtAssoc(); c.addItem(pro); c.addItem(act); c.addItem(obj); c.addItem(att); ((List<Object>) envelope.getBody().getDataBlock().getDtAass()).add(c); try { Marshaller m = jc.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE); m.setProperty("com.sun.xml.internal.bind.xmlHeaders", "<?xml version='1.0' encoding='UTF-8' standalone='no'?>\n" + "<!DOCTYPE OPS_envelope SYSTEM '" + OSRSDIR + OSRSCONFIG + "ops.dtd'>"); //StringWriter writer = new StringWriter(); ByteArrayOutputStream baos = new ByteArrayOutputStream(); m.marshal(envelope, baos); return baos.toString(); } catch (Exception e) { throw new OsrsException("Error creating envelope from request", e); } }
From source file:eu.eco2clouds.scheduler.bonfire.BFClientSchedulerImpl.java
private Compute changeStateCompute(String userId, Compute compute, String state) { this.userId = userId; Boolean exception = false;//from ww w .ja va2 s .co m String computeURL = url + compute.getHref(); Compute computeMessage = new Compute(); computeMessage.setHref(compute.getHref()); computeMessage.setState(state); computeMessage.setLinks(compute.getLinks()); String payload = ""; try { JAXBContext jaxbContext = JAXBContext.newInstance(Compute.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); ByteArrayOutputStream out = new ByteArrayOutputStream(); marshaller.marshal(computeMessage, out); payload = out.toString(); } catch (JAXBException e) { logger.warn("Error trying to parse returned status of hosts: " + computeURL + " Exception: " + e.getMessage()); exception = true; } String response = putMethod(computeURL, payload, exception); logger.debug(response); try { JAXBContext jaxbContext = JAXBContext.newInstance(Compute.class); Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller(); compute = (Compute) jaxbUnmarshaller.unmarshal(new StringReader(response)); } catch (JAXBException e) { logger.warn("Error trying to parse returned status of hosts: " + computeURL + " Exception: " + e.getMessage()); exception = true; } if (exception) return new Compute(); return compute; }
From source file:de.uniwue.info6.database.jaxb.ScenarioExporter.java
/** * * * @param scenario/*from ww w.j a v a 2 s. c o m*/ */ public File generateScenarioXml(Scenario scenario) { scenario = populateScenario(scenario); File base = new File(scriptSystemPath + File.separator + Cfg.RESOURCE_PATH); File saveDir = new File(base, String.valueOf(scenario.getId())); try { if (!saveDir.exists() && saveDir.getParentFile().exists()) { saveDir.mkdir(); } SimpleDateFormat fmt = new SimpleDateFormat("yyyy_MM_dd-HH_mm_ss"); String baseName = "scenario_" + scenario.getId() + "_export_" + fmt.format(new Date()); String conflict = "VERSION_CONFLICT"; File scenarioXml = new File(saveDir, baseName + ".xml"); File scenarioXmlConflict = new File(saveDir, baseName + "_" + conflict + ".xml"); File scenarioXsd = new File(saveDir, baseName + ".xsd"); File scenarioXsdConflict = new File(saveDir, baseName + "_" + conflict + ".xsd"); File scenarioMain = new File(scriptSystemPath, "reference_schema.xsd"); File scenarioMainConflict = new File(saveDir, baseName + "_" + "REFERENCE_SCHEMA.xsd"); JAXBContext jaxbContext = JAXBContext.newInstance(Scenario.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(scenario, scenarioXml); SchemaOutputResolver sor = new CustomOutputResolver(saveDir, baseName + ".xsd"); jaxbContext.generateSchema(sor); if (!scenarioMain.exists()) { LOGGER.error("REFERENCE SCHEMA IS MISSING: " + scenarioMain); } if (!scenarioXsd.exists()) { LOGGER.error("GENERATED XSD IS MISSING: " + scenarioXsd); } if (!scenarioXml.exists()) { LOGGER.error("GENERATED XML IS MISSING: " + scenarioXml); } if (scenarioMain.exists() && scenarioXsd.exists() && scenarioXml.exists()) { String referenceMD5 = calculateMD5FromFile(scenarioMain); String newMD5 = calculateMD5FromFile(scenarioXsd); File export = null; boolean falseMD5 = !referenceMD5.equals(newMD5); File conflictReadme = new File(saveDir, conflict + "_README.txt"); if (falseMD5) { FileUtils.moveFile(scenarioXml, scenarioXmlConflict); FileUtils.moveFile(scenarioXsd, scenarioXsdConflict); FileUtils.copyFile(scenarioMain, scenarioMainConflict); scenarioXml = scenarioXmlConflict; scenarioXsd = scenarioXsdConflict; export = new File(saveDir, "scenario_" + scenario.getId() + "_export_" + conflict + ".zip"); String readme = Cfg.inst().getProp(DEF_LANGUAGE, "MISC.XSD_XML_CONFLICT") + "\n" + scenarioMainConflict.getName(); if (conflictReadme.exists()) { conflictReadme.delete(); } if (!conflictReadme.exists()) { conflictReadme.createNewFile(); } PrintWriter out = new PrintWriter(conflictReadme); out.println(readme); out.flush(); out.close(); } else { export = new File(saveDir, "scenario_" + scenario.getId() + "_export.zip"); } ArrayList<File> exportFiles = new ArrayList<File>(); if (scenarioXml.exists()) { exportFiles.add(scenarioXml); } if (scenarioXsd.exists()) { exportFiles.add(scenarioXsd); } if (falseMD5 && conflictReadme.exists() && scenarioMainConflict.exists()) { exportFiles.add(conflictReadme); exportFiles.add(scenarioMainConflict); } if (export.exists()) { export.delete(); } return zip(exportFiles, export); } } catch (Exception e) { LOGGER.error("EXPORT XSD/XML FAILED!", e); } return null; }
From source file:de.avanux.smartapplianceenabler.semp.webservice.SempController.java
private String marshall(Device2EM device2EM) { StringWriter writer = new StringWriter(); try {//from w w w. j a v a 2 s . c om JAXBContext context = JAXBContext.newInstance(Device2EM.class); Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(device2EM, writer); return writer.toString(); } catch (JAXBException e) { logger.error("Error marshalling", e); } return null; }
From source file:com.sap.prd.mobile.ios.mios.VersionInfoManager.java
private void createVersionInfoFile(final String groupId, final String artifactId, final String version, Properties versionInfo, List<Dependency> dependencies, OutputStream os) throws MojoExecutionException, JAXBException { try {// w w w. j a v a 2 s .c o m final String connectionString = "scm:perforce:" + versionInfo.getProperty("port") + ":" + getDepotPath(versionInfo.getProperty("depotpath")); final Versions versions = new Versions(); for (final Dependency dep : dependencies) versions.addDependency(dep); final SCM scm = new SCM(); scm.setConnection(connectionString); scm.setRevision(versionInfo.getProperty("changelist")); final Coordinates coordinates = new Coordinates(); coordinates.setGroupId(groupId); coordinates.setArtifactId(artifactId); coordinates.setVersion(version); versions.setScm(scm); versions.setCoordinates(coordinates); final JAXBContext context = JAXBContext.newInstance(Versions.class); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "urn:xml.sap.com:XCodePlugin:VersionInfo" + " " + NEXUS_URL + "/content/repositories/" + SCHEMA_REPOSITORY + "/" + SCHEMA_GROUP_ID.replace(".", "/") + "/" + SCHEMA_ARTIFACT_ID + "/" + SCHEMA_VERSION + "/" + SCHEMA_ARTIFACT_ID + "-" + SCHEMA_VERSION + ".xsd"); final ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); marshaller.marshal(versions, byteOs); final byte[] b = byteOs.toByteArray(); DomUtils.validateDocument( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(b))); IOUtils.write(b, os); } catch (ParserConfigurationException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } catch (IOException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } catch (SAXException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } }
From source file:com.sap.prd.mobile.ios.mios.VersionInfoXmlManager.java
private void createVersionInfoFile(final String groupId, final String artifactId, final String version, Properties versionInfo, List<Dependency> dependencies, OutputStream os) throws MojoExecutionException, JAXBException { try {// w ww. ja v a2 s.com final Versions versions = new Versions(); for (final Dependency dep : dependencies) versions.addDependency(dep); final SCM scm = new SCM(); scm.setConnection(SCMUtil.getConnectionString(versionInfo, false)); scm.setRevision(SCMUtil.getRevision(versionInfo)); final Coordinates coordinates = new Coordinates(); coordinates.setGroupId(groupId); coordinates.setArtifactId(artifactId); coordinates.setVersion(version); versions.setScm(scm); versions.setCoordinates(coordinates); final JAXBContext context = JAXBContext.newInstance(Versions.class); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "urn:xml.sap.com:XCodePlugin:VersionInfo" + " " + NEXUS_URL + "/content/repositories/" + SCHEMA_REPOSITORY + "/" + SCHEMA_GROUP_ID.replace(".", "/") + "/" + SCHEMA_ARTIFACT_ID + "/" + SCHEMA_VERSION + "/" + SCHEMA_ARTIFACT_ID + "-" + SCHEMA_VERSION + ".xsd"); final ByteArrayOutputStream byteOs = new ByteArrayOutputStream(); marshaller.marshal(versions, byteOs); final byte[] b = byteOs.toByteArray(); DomUtils.validateDocument( DocumentBuilderFactory.newInstance().newDocumentBuilder().parse(new ByteArrayInputStream(b))); IOUtils.write(b, os); } catch (ParserConfigurationException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } catch (IOException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } catch (SAXException e) { throw new MojoExecutionException("Cannot create versions.xml.", e); } }
From source file:de.thorstenberger.examServer.service.impl.ConfigManagerImpl.java
private void save() { try {/*from ww w . j a va 2 s . c o m*/ final Marshaller marshaller = jc.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, new Boolean(true)); final BufferedOutputStream bos = new BufferedOutputStream(new FileOutputStream(this.configFile)); marshaller.marshal(config, bos); bos.close(); } catch (final JAXBException e) { throw new RuntimeException(e); } catch (final IOException e1) { throw new RuntimeException(e1); } }