List of usage examples for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT
String JAXB_FORMATTED_OUTPUT
To view the source code for javax.xml.bind Marshaller JAXB_FORMATTED_OUTPUT.
Click Source Link
From source file:com.openthinks.webscheduler.service.WebSecurityService.java
/** * save changes to disk file/*from w w w . ja v a2 s . c om*/ */ public void saveToDisk() { Checker.require(this.securityConfig).notNull(); Checker.require(this.webSecurity).notNull(); File file = this.securityConfig.getConfigFile(); try { FileOutputStream fos = new FileOutputStream(file); JAXBContext jaxbContext = JAXBContext.newInstance(WebSecurity.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(this.webSecurity, fos); fos.close(); this.webSecurity.moveToSaved(); } catch (Exception e) { throw new RuntimeException(e); } }
From source file:org.opennms.features.vaadin.pmatrix.manual.PmatrixDpdCalculatorSimpleMovingAverageImplMarshalTest.java
public void testMarshalData() { System.out.println("start of test:testMarshalData()"); // check slf4j settings LOG.debug("debug message"); LOG.warn("warn message"); LOG.info("info message"); try {//from www. java2 s . com String testFileName = this.getClass().getSimpleName() + "_File.xml"; File file = new File("target/" + testFileName); PrintWriter writer = new PrintWriter(file, "UTF-8"); writer.close(); System.out.println("file location:" + file.getAbsolutePath()); JAXBContext jaxbContext = JAXBContext.newInstance("org.opennms.features.vaadin.pmatrix.calculator"); // ***************** // create calculator // ***************** PmatrixDpdCalculatorSimpleMovingAvgImpl simpleMovingAvgCalc = new PmatrixDpdCalculatorSimpleMovingAvgImpl(); simpleMovingAvgCalc.setLatestDataValue(1010d); simpleMovingAvgCalc.setLatestTimestamp(new Date().getTime()); simpleMovingAvgCalc.setPrevDataValue(3040d); simpleMovingAvgCalc.setPreviousTimestamp(new Date().getTime()); NameValuePair property = new NameValuePair( PmatrixDpdCalculatorSimpleMovingAvgImpl.MAX_SAMPLE_NO_PROPERTY_NAME, "10"); simpleMovingAvgCalc.getConfiguration().add(property); for (int i = 1; i < 15; i++) { Double latestDataValue = Double.valueOf(i); Long latestTimestamp = new Date().getTime() + i; // adding to show small increment in time simpleMovingAvgCalc.updateCalculation(latestDataValue, latestTimestamp); } // ********************** // marshal test file // ********************** Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd"); jaxbMarshaller.marshal(simpleMovingAvgCalc, file); //jaxbMarshaller.marshal(pmatrixSpecificationList_context, file); // ********************** // unmarshal test file // ********************** Unmarshaller jaxbUnMarshaller = jaxbContext.createUnmarshaller(); //Object o = jaxbUnMarshaller.unmarshal( new StringReader( marshalledXml ) ); Object o = jaxbUnMarshaller.unmarshal(file); System.out.println("o.tostring:" + o.toString()); if (o instanceof PmatrixDpdCalculatorSimpleMovingAvgImpl) { System.out.println("unmarshalled list:"); System.out.println((PmatrixDpdCalculatorSimpleMovingAvgImpl) o); } else System.out.println("cant unmarshal object:"); } catch (JAXBException e) { e.printStackTrace(); } catch (Exception e) { e.printStackTrace(); } System.out.println("end of test:testMarshalData()"); }
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 {// ww w . ja va 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:eu.europa.ec.markt.dss.signature.xades.XAdESProfileT.java
/** * The default constructor for XAdESProfileT. * /* w w w. ja v a2 s . c o m*/ */ public XAdESProfileT() { super(); Init.init(); try { JAXBContext context = JAXBContext.newInstance(eu.europa.ec.markt.jaxb.xades141.ObjectFactory.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); unmarshaller = context.createUnmarshaller(); } catch (JAXBException e) { throw new RuntimeException(e); } }
From source file:it.cnr.icar.eric.server.event.EmailNotifier.java
protected void sendNotification(ServerRequestContext context, NotifyActionType notifyAction, NotificationType notification, AuditableEventType ae) throws RegistryException { log.trace("Sending email notification"); String endpoint = notifyAction.getEndPoint(); if ((endpoint == null) || !endpoint.startsWith("mailto:")) { throw new RegistryException(ServerResourceBundle.getInstance() .getString("message.emailNotificationWOmailto", new Object[] { endpoint })); }/* ww w .j a v a 2s. c o m*/ try { // get the body of the message , not yet defined ! StringWriter sw = new StringWriter(); // Marshaller marshaller = BindingUtility.getInstance().rimFac.createMarshaller(); Marshaller marshaller = BindingUtility.getInstance().getJAXBContext().createMarshaller(); marshaller.setProperty(javax.xml.bind.Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); //marshaller.marshal(notification, sw); ObjectFactory of = new ObjectFactory(); marshaller.marshal(of.createNotification(notification), sw); //Now get the RegistryResponse as a String //Produce verbose response String notif = sw.toString(); String action = ae.getEventType(); String userId = ae.getUser(); String userInfo; if (userId != null) { UserType user = (UserType) context.getRegistryObject(userId, "User_"); userInfo = ServerResourceBundle.getInstance().getString("message.user", new String[] { getUserInfo(user) }); } else { userInfo = ServerResourceBundle.getInstance().getString("message.userUnknown"); } SubscriptionType subscription = (SubscriptionType) context .getRegistryObject(notification.getSubscription(), "Subscription"); String xsltId = getStyleSheetId(subscription); RepositoryItem repositoryItem = null; // empty string for notification property == use old format if (!"".equals(xsltId)) { //Dont use transform if there are any problems try { repositoryItem = RepositoryManagerFactory.getInstance().getRepositoryManager() .getRepositoryItem(xsltId); } catch (Exception e) { log.warn(ServerResourceBundle.getInstance().getString("message.rawEmailNotification"), e); } } String contentType; String message; if (repositoryItem == null) { //No style sheet so skip the tranformation contentType = "text/xml"; message = sw.toString(); } else { contentType = "text/html"; try { message = transformContent(context, xsltId, notif, action, userInfo); } catch (RegistryException e) { contentType = "text/xml"; message = sw.toString(); } } // set parameters and send the mail String subject = ServerResourceBundle.getInstance().getString("message.registryNotification", new Object[] { notification.getId() }); postMail(endpoint, message, subject, contentType); } catch (MessagingException e) { throw new RegistryException(e); } catch (JAXBException e) { throw new RegistryException(e); } }
From source file:com.moss.veracity.core.config.ConfigManager.java
private void write(Configuration config) throws Exception { Marshaller m = jaxbContext.createMarshaller(); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); m.marshal(config, new FileWriter(file)); if (monitor != null) { monitor.reset();//from ww w.j av a2 s.c o m } }
From source file:com.u2apple.tool.dao.DeviceXmlDaoJaxbImpl.java
private void flushVids() throws JAXBException, PropertyException { String vidFileFormat = Configuration.getProperty(Constants.VID_FILE_FORMAT); for (String vid : changedVids) { File file = new File(String.format(vidFileFormat, vid)); JAXBContext jaxbContext = JAXBContext.newInstance(VID.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); // output pretty printed jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); VID v = getVid(getStaticMapFile().getVids(), vid); jaxbMarshaller.marshal(v, file); }// w w w .j a va 2 s . c om changedVids.clear(); }
From source file:mx.bigdata.sat.cfdi.TFDv11.java
public void guardar(OutputStream out) throws Exception { Marshaller m = CONTEXT.createMarshaller(); m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv3.PREFIXES)); m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, "http://www.sat.gob.mx/cfd/3 http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv33.xsd"); m.marshal(document.getComprobante(), out); }
From source file:com.hp.octane.integrations.uft.items.UftTestDiscoveryResult.java
public void writeToFile(File fileToWriteTo) throws JAXBException { JAXBContext jaxbContext = JAXBContext.newInstance(UftTestDiscoveryResult.class); Marshaller jaxbMarshaller = jaxbContext.createMarshaller(); jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); jaxbMarshaller.marshal(this, fileToWriteTo); }
From source file:br.gov.frameworkdemoiselle.behave.integration.alm.objects.util.GenerateXMLString.java
public static String getTestcaseString(String urlServer, String projectAreaAlias, String encoding, String name, String steps, Testcase currentTestCase) throws JAXBException { Richtext textDesgin = new Richtext(); textDesgin.getContent().add(escapeHTMLForAlm(steps)); currentTestCase.setTitle(name);/*from w w w . j a v a 2s .c om*/ currentTestCase.setSuspect(false); currentTestCase.setWeight(100); currentTestCase.setComIbmRqmPlanningEditorSectionTestCaseDesign(textDesgin); // Valor da Categoria String categoryTipoExecucao = BehaveConfig.getIntegration_CategoryTipoExecucao(); // Verifica se no caso de teste vindo da ALM existe a categoria // "Tipo de Execuo", se no existe cria. boolean objExists = false; for (Testcase.Category c : currentTestCase.getCategory()) { if (c.getTerm().toLowerCase().trim().equals("tipo de execuo")) { objExists = true; // Altera para "Automtica" c.setValue(categoryTipoExecucao); break; } } if (!objExists) { Testcase.Category newC = new Testcase.Category(); newC.setTerm("Tipo de Execuo"); newC.setValue(categoryTipoExecucao); currentTestCase.getCategory().add(newC); } JAXBContext jaxb = JAXBContext.newInstance(Testcase.class); Marshaller marshaller = jaxb.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, encoding); StringWriter testCaseString = new StringWriter(); marshaller.marshal(currentTestCase, testCaseString); return testCaseString.toString(); }