List of usage examples for javax.xml.bind Marshaller JAXB_ENCODING
String JAXB_ENCODING
To view the source code for javax.xml.bind Marshaller JAXB_ENCODING.
Click Source Link
From source file:com.github.webapp_minifier.WebappMinifierMojo.java
/** * @see org.apache.maven.plugin.AbstractMojo#execute() *//*from w w w. ja v a2s .com*/ @Override public void execute() throws MojoExecutionException { // Copy the source directory to the target directory. try { getLog().debug("Copying " + this.sourceDirectory + " to " + this.minifiedDirectory); if (this.minifiedDirectory.exists()) { FileUtils.deleteDirectory(this.minifiedDirectory); } FileUtils.copyDirectoryStructure(this.sourceDirectory, this.minifiedDirectory); } catch (final IOException e) { throw new MojoExecutionException("Failed to copy the source directory", e); } if (!this.skipMinify) { // Process each of the requested files. final DefaultTagHandler tagHandler = new DefaultTagHandler(getLog(), this); final TagReplacer tagReplacer = TagReplacerFactory.getReplacer(this.parser, getLog(), this.encoding); for (final String fileName : getFilesToProcess()) { final File htmlFile = new File(this.minifiedDirectory, fileName); final File minifiedHtmlFile = new File(this.minifiedDirectory, fileName + ".min"); final File htmlFileBackup = new File(this.minifiedDirectory, fileName + ".bak"); InputStream inputStream = null; OutputStream outputStream = null; try { getLog().info("Processing " + htmlFile.getCanonicalFile()); final String baseUri = CommonUtils.getBaseUri(htmlFile, this.minifiedDirectory); inputStream = new BufferedInputStream(new FileInputStream(htmlFile)); outputStream = new BufferedOutputStream(new FileOutputStream(minifiedHtmlFile)); tagHandler.start(htmlFile); tagReplacer.process(inputStream, tagHandler, baseUri, outputStream); } catch (final IOException e) { throw new MojoExecutionException("Failed to process " + htmlFile, e); } finally { IOUtil.close(inputStream); IOUtil.close(outputStream); } if (!htmlFile.renameTo(htmlFileBackup)) { throw new MojoExecutionException( "Failed to rename " + htmlFile.getName() + " to " + htmlFileBackup.getName()); } if (!minifiedHtmlFile.renameTo(htmlFile)) { throw new MojoExecutionException( "Failed to rename " + minifiedHtmlFile.getName() + " to " + htmlFile.getName()); } } // Write out the summary file. final File summaryFile = new File(this.minifiedDirectory, "webapp-minifier-summary.xml"); try { final JAXBContext context = JAXBContext.newInstance(MinificationSummary.class); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, getEncoding()); marshaller.marshal(tagHandler.getReport(), summaryFile); tagHandler.getReport(); } catch (final JAXBException e) { throw new MojoExecutionException("Failed to marshal the plugin's summary to XML", e); } // Attempt to configure the maven-war-plugin. if (this.project != null) { this.project.getProperties().setProperty("war.warName", "my-name.war"); for (final Object object : this.project.getBuildPlugins()) { final Plugin plugin = (Plugin) object; if (StringUtils.equals("org.apache.maven.plugins", plugin.getGroupId()) && StringUtils.equals("maven-war-plugin", plugin.getArtifactId())) { getLog().info("Examining plugin " + plugin.getArtifactId()); final Object configuration = plugin.getConfiguration(); getLog().info("Fetched configuration " + configuration.getClass() + ": " + configuration); final Xpp3Dom document = (Xpp3Dom) configuration; final Xpp3Dom[] children = document.getChildren("warSourceDirectory"); getLog().info("Fetched children " + children.length); for (final Xpp3Dom child : children) { getLog().info("Child: " + child); getLog().info("Child Value: " + child.getValue()); child.setValue(child.getValue() + "_oops"); getLog().info("Child Value: " + child.getValue()); } } } } } }
From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java
public static <O extends ObjectType> String marshallToSting(O object, boolean formatted) throws JAXBException { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); if (formatted) { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); }/*ww w . j a v a 2s . com*/ java.io.StringWriter sw = new StringWriter(); Class<O> type = (Class<O>) object.getClass(); JAXBElement<O> element = new JAXBElement<O>(getElementName(type), type, object); marshaller.marshal(element, sw); return sw.toString(); }
From source file:com.evolveum.midpoint.model.client.ModelClientUtil.java
public static <T> String marshallToSting(QName elementName, T object, boolean formatted) throws JAXBException { Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); if (formatted) { marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); }/*from www . j a v a2 s . c o m*/ java.io.StringWriter sw = new StringWriter(); JAXBElement<T> element = new JAXBElement<T>(elementName, (Class<T>) object.getClass(), object); marshaller.marshal(element, sw); return sw.toString(); }
From source file:gov.nih.nci.cabig.caaers.esb.client.impl.CtmsCaaersMessageConsumer.java
/** * This method is used to marshal the Response objects from Individual Services to xml format * so that it can be set as the Content of the Response JMS TextMessage * @param pObject// ww w. j a v a 2 s . c om * @param marshaller * @return * @throws JAXBException */ public String responseAsString(Object pObject, Marshaller marshaller) throws JAXBException { StringWriter sw = new StringWriter(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(pObject, sw); return sw.toString(); }
From source file:com.silverpeas.publicationTemplate.PublicationTemplateImpl.java
/** * Save a recordTemplate to xml file//from www . j a v a 2 s . c o m * * @param recordTemplate the object to save as xml File * @param subDir the sub directory where saving the xml file * @param xmlFileName the xml file name * @throws PublicationTemplateException */ private void saveRecordTemplate(RecordTemplate recordTemplate, String subDir, String xmlFileName) throws PublicationTemplateException { // save record into XML file try { // Format this URL String xmlFilePath = PublicationTemplateManager.makePath(PublicationTemplateManager.templateDir, subDir + xmlFileName); Marshaller marshaller = JAXB_CONTEXT.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.marshal(recordTemplate, new File(xmlFilePath)); } catch (JAXBException e) { throw new PublicationTemplateException("PublicationTemplateManager.loadPublicationTemplate", "form.EX_ERR_CASTOR_UNMARSHALL_PUBLICATION_TEMPLATE", "Publication Template FileName : " + xmlFileName, e); } }
From source file:ca.phon.ipamap.IpaMap.java
/** * Saves the favorites data/*from w w w .j ava 2 s . co m*/ * */ private static void saveFavData() throws IOException { final ObjectFactory factory = new ObjectFactory(); final IpaGrids favMap = getFavData(); final ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { final JAXBContext ctx = JAXBContext.newInstance(factory.getClass()); final Marshaller marshaller = ctx.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.FALSE); marshaller.marshal(favMap, bos); PrefHelper.getUserPreferences().put(FAVORITES_PROP, bos.toString("UTF-8")); } catch (JAXBException e) { e.printStackTrace(); throw new IOException(e); } }
From source file:ca.phon.session.io.xml.v12.XMLSessionWriter_v12.java
@Override public void writeSession(Session session, OutputStream out) throws IOException { final JAXBElement<SessionType> ele = toSessionType(session); try {/*from w ww. j av a 2 s . c om*/ final JAXBContext context = JAXBContext.newInstance(ObjectFactory.class); final Marshaller marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8"); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE); marshaller.marshal(ele, out); } catch (JAXBException e) { LOGGER.log(Level.SEVERE, e.getMessage(), e); } }
From source file:com.snaplogic.snaps.firstdata.Create.java
private String getGMFXMLRequestData(com.snaplogic.snaps.firstdata.gmf.proxy.GMFMessageVariants gmfmv) { StringWriter stringWriter = new StringWriter(); String returnValue = ""; try {//from w w w .j a va2s.c o m JAXBContext context = null; Marshaller marshaller = null; context = JAXBContext.newInstance(GMFMessageVariants.class); marshaller = context.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_ENCODING, XML_ENCODING); marshaller.marshal(gmfmv, stringWriter); returnValue = stringWriter.toString(); } catch (JAXBException jaxe) { log.error(jaxe.getMessage(), jaxe); throw new SnapDataException(jaxe, jaxe.getMessage()); } catch (Exception e) { log.error(e.getMessage(), e); throw new SnapDataException(e, e.getMessage()); } return returnValue; }
From source file:cz.cas.lib.proarc.common.export.mets.MetsUtils.java
/** * * Generates and saves info.xml//from w ww . j av a 2s .co m * * @param path * @param mets */ public static void saveInfoFile(String path, MetsContext metsContext, String md5, String fileMd5Name, File metsFile) throws MetsExportException { File infoFile = new File(path + File.separator + metsContext.getPackageID() + File.separator + "info_" + metsContext.getPackageID() + ".xml"); GregorianCalendar c = new GregorianCalendar(); c.setTime(new Date()); XMLGregorianCalendar date2; try { date2 = DatatypeFactory.newInstance().newXMLGregorianCalendar(c); } catch (DatatypeConfigurationException e1) { throw new MetsExportException("Error while generating info.xml file", false, e1); } Info infoJaxb = new Info(); infoJaxb.setCreated(date2); infoJaxb.setMainmets("./" + metsFile.getName()); Checksum checkSum = new Checksum(); checkSum.setChecksum(md5); checkSum.setType("MD5"); addModsIdentifiersRecursive(metsContext.getRootElement(), infoJaxb); checkSum.setValue(fileMd5Name); infoJaxb.setChecksum(checkSum); Validation validation = new Validation(); validation.setValue("W3C-XML"); validation.setVersion(Float.valueOf("0.0")); infoJaxb.setValidation(validation); infoJaxb.setCreator(metsContext.getCreatorOrganization()); infoJaxb.setPackageid(metsContext.getPackageID()); if (Const.PERIODICAL_TITLE.equalsIgnoreCase(metsContext.getRootElement().getElementType())) { infoJaxb.setMetadataversion((float) 1.5); } else { infoJaxb.setMetadataversion((float) 1.1); } Itemlist itemList = new Itemlist(); infoJaxb.setItemlist(itemList); itemList.setItemtotal(BigInteger.valueOf(metsContext.getFileList().size())); List<FileMD5Info> fileList = metsContext.getFileList(); long size = 0; for (FileMD5Info fileName : fileList) { itemList.getItem() .add(fileName.getFileName().replaceAll(Matcher.quoteReplacement(File.separator), "/")); size += fileName.getSize(); } int infoTotalSize = (int) (size / 1024); infoJaxb.setSize(infoTotalSize); try { JAXBContext jaxbContext = JAXBContext.newInstance(Info.class); Marshaller marshaller = jaxbContext.createMarshaller(); // SchemaFactory factory = // SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); // factory.setResourceResolver(MetsLSResolver.getInstance()); // Schema schema = factory.newSchema(new // StreamSource(Info.class.getResourceAsStream("info.xsd"))); // marshaller.setSchema(schema); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); marshaller.marshal(infoJaxb, infoFile); } catch (Exception ex) { throw new MetsExportException("Error while generating info.xml", false, ex); } List<String> validationErrors; try { validationErrors = MetsUtils.validateAgainstXSD(infoFile, Info.class.getResourceAsStream("info.xsd")); } catch (Exception e) { throw new MetsExportException("Error while validating info.xml", false, e); } if (validationErrors.size() > 0) { MetsExportException metsException = new MetsExportException( "Invalid info file:" + infoFile.getAbsolutePath(), false, null); metsException.getExceptions().get(0).setValidationErrors(validationErrors); for (String error : validationErrors) { LOG.fine(error); } throw metsException; } }
From source file:cz.cas.lib.proarc.common.export.mets.structure.MetsElementVisitor.java
/** * * saves technical metadata/*from w ww .j ava 2 s . c o m*/ * * @param amdSecMets */ private void saveAmdSec(IMetsElement metsElement, Mets amdSecMets, HashMap<String, Object> fileNames, HashMap<String, String> mimeTypes) throws MetsExportException { try { JAXBContext jaxbContext = JAXBContext.newInstance(Mets.class); Marshaller marshaller = jaxbContext.createMarshaller(); marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true); marshaller.setProperty(Marshaller.JAXB_ENCODING, "utf-8"); // marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, // "http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema.xsd http://www.loc.gov/METS/ http://www.loc.gov/standards/mets/mets.xsd http://www.loc.gov/MIX/ http://www.loc.gov/mix/v20"); ByteArrayOutputStream bos = new ByteArrayOutputStream(); marshaller.marshal(amdSecMets, bos); byte[] byteArray = bos.toByteArray(); fileNames.put("TECHMDGRP", byteArray); mimeTypes.put("TECHMDGRP", "text/xml"); Document document = MetsUtils.getDocumentFromBytes(byteArray); MetsUtils.validateAgainstXSD(document, Mets.class.getResourceAsStream("mets.xsd")); } catch (Exception ex) { throw new MetsExportException(metsElement.getOriginalPid(), "Error while saving AMDSec file", false, ex); } }