Example usage for javax.xml.bind Marshaller setProperty

List of usage examples for javax.xml.bind Marshaller setProperty

Introduction

In this page you can find the example usage for javax.xml.bind Marshaller setProperty.

Prototype

public void setProperty(String name, Object value) throws PropertyException;

Source Link

Document

Set the particular property in the underlying implementation of Marshaller .

Usage

From source file:com.github.webapp_minifier.WebappMinifierMojo.java

/**
 * @see org.apache.maven.plugin.AbstractMojo#execute()
 *///w w  w . ja  v  a 2 s  .c  o m
@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:gov.va.ds4p.ds4pmobileportal.pep.XACMLPolicyEnforcement.java

private String dumpRequestToString() {
    String res = "";
    JAXBElement<RequestType> element = new JAXBElement<RequestType>(
            new QName("urn:oasis:names:tc:xacml:2.0:context:schema:os", "Request"), RequestType.class, query);
    try {/*  w  ww.j  av  a  2 s .co m*/
        JAXBContext context = JAXBContext.newInstance(RequestType.class);
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(element, sw);
        res = sw.toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return res;
}

From source file:gov.va.ds4p.ds4pmobileportal.pep.XACMLPolicyEnforcement.java

private String dumpResponseToString(ResultType resp) {
    String res = "";
    JAXBElement<ResultType> element = new JAXBElement<ResultType>(
            new QName("urn:oasis:names:tc:xacml:2.0:context:schema:os", "Result"), ResultType.class, resp);
    try {//w  w w.j  a  va2  s  .  c o  m
        JAXBContext context = JAXBContext.newInstance(ResultType.class);
        Marshaller marshaller = context.createMarshaller();
        StringWriter sw = new StringWriter();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        //marshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        marshaller.marshal(element, sw);
        res = sw.toString();
    } catch (Exception ex) {
        ex.printStackTrace();
    }
    return res;
}

From source file:com.silverpeas.publicationTemplate.PublicationTemplateImpl.java

/**
 * Save a recordTemplate to xml file/*from   www  . j  a  v  a2 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:com.axelor.controller.ConnectionToPrestashop.java

@SuppressWarnings("null")
@Transactional//from w w w .ja  va  2 s.  com
public void insertGroup(int groupId) {
    com.axelor.pojo.CustomerGroup pojoCustomerGroup = new com.axelor.pojo.CustomerGroup();
    pojoCustomerGroup.setId(0);
    pojoCustomerGroup.setLanguage("NAME");
    pojoCustomerGroup.setDescription("DESCRIPTION");
    try {
        System.out.println("GROUPID :: " + groupId);
        URL url = new URL("http://localhost/client-lib/crud/action.php?resource=groups&action=retrieve&id="
                + groupId + "&Akey=" + apiKey);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        File f = new File("//home//axelor//Desktop//example//k.xml");
        connection.setRequestMethod("POST");
        JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.CustomerGroup.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        connection.setDoOutput(true);
        connection.setDoInput(true);

        OutputStream outputStream = connection.getOutputStream();
        jaxbMarshaller.marshal(pojoCustomerGroup, outputStream);

        connection.connect();
        InputStream inputStream = connection.getInputStream();
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        pojoCustomerGroup = (com.axelor.pojo.CustomerGroup) jaxbUnmarshaller
                .unmarshal(new UnmarshalInputStream(connection.getInputStream()));
        jaxbMarshaller.marshal(pojoCustomerGroup, f);
        PrestashopCustomerGroup prestashopCustomerGroup = new PrestashopCustomerGroup();
        // add this customer into ERP
        prestashopCustomerGroup.setId_group(groupId);
        prestashopCustomerGroup.setName(pojoCustomerGroup.getLanguage());
        prestashopCustomerGroup.setDescription(pojoCustomerGroup.getDescription());
        prestashopCustomerGroup.save();
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:com.axelor.controller.ConnectionToPrestashop.java

@Transactional
public Customer getCustomer(int customerId) {
    com.axelor.pojo.Customer pojoCustomer = new com.axelor.pojo.Customer();
    pojoCustomer.setFirstname("FIRSTNAME");
    pojoCustomer.setLastname("LASTNAME");
    pojoCustomer.setCompany("COMPANY");
    pojoCustomer.setPasswd("PASSWORD");
    pojoCustomer.setEmail("EMAIL");
    pojoCustomer.setBirthday("1000-01-01");
    pojoCustomer.setActive(0);//from  www  . j ava  2 s.c  om
    pojoCustomer.setDeleted(0);
    pojoCustomer.setId_default_group(0);
    pojoCustomer.setAssociations("associations");
    pojoCustomer.setDate_upd("dateUpd");
    try {
        System.out.println("API KEY :: " + apiKey);
        URL url = new URL("http://localhost/client-lib/crud/action.php?resource=customers&action=retrieve&id="
                + customerId + "&Akey=" + apiKey);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setRequestMethod("POST");
        JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.Customer.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        connection.setDoOutput(true);
        connection.setDoInput(true);

        OutputStream outputStream = connection.getOutputStream();
        jaxbMarshaller.marshal(pojoCustomer, outputStream);

        connection.connect();
        InputStream inputStream = connection.getInputStream();
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        pojoCustomer = (com.axelor.pojo.Customer) jaxbUnmarshaller
                .unmarshal(new UnmarshalInputStream(connection.getInputStream()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return pojoCustomer;
}

From source file:com.axelor.controller.ConnectionToPrestashop.java

@Transactional
public com.axelor.pojo.Address getAddress(int addressId) {
    com.axelor.pojo.Address pojoAddress = new com.axelor.pojo.Address();
    pojoAddress.setId_customer(0);/*  w  w w.j  a va  2  s.co  m*/
    pojoAddress.setId_country(0);
    pojoAddress.setId_state(0);
    pojoAddress.setPrestashopAddressId(0);
    pojoAddress.setFirstname("FIRSTNAME");
    pojoAddress.setLastname("LASTNAME");
    pojoAddress.setPhone_mobile("0000000000");
    pojoAddress.setAddress1("ADDRESS1");
    pojoAddress.setAddress2("ADDRESS2");
    pojoAddress.setCity("CITY");
    pojoAddress.setPostcode("000000");
    pojoAddress.setAlias("ALIAS");
    pojoAddress.setDate_upd("dateUpd");
    try {
        System.out.println("API KEY :: " + apiKey);
        URL url = new URL("http://localhost/client-lib/crud/action.php?resource=addresses&action=retrieve&id="
                + addressId + "&Akey=" + apiKey);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();

        connection.setRequestMethod("POST");
        JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.Address.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        connection.setDoOutput(true);
        connection.setDoInput(true);

        OutputStream outputStream = connection.getOutputStream();
        jaxbMarshaller.marshal(pojoAddress, outputStream);

        connection.connect();
        InputStream inputStream = connection.getInputStream();
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        pojoAddress = (com.axelor.pojo.Address) jaxbUnmarshaller
                .unmarshal(new UnmarshalInputStream(connection.getInputStream()));
    } catch (Exception e) {
        e.printStackTrace();
    }
    return pojoAddress;
}

From source file:com.axelor.controller.ConnectionToPrestashop.java

@SuppressWarnings("null")
@Transactional/*  w  w w  . ja v  a  2  s  . c o  m*/
public void insertCurrency(int currencyId) {
    com.axelor.pojo.Currency pojoCurrency = new com.axelor.pojo.Currency();
    pojoCurrency.setName("NAME");
    pojoCurrency.setIso_code("ISO_CODE");
    pojoCurrency.setSign("SIGN");
    try {
        System.out.println("Cuurency Id :: " + currencyId);
        URL url = new URL("http://localhost/client-lib/crud/action.php?resource=currencies&action=retrieve&id="
                + currencyId + "&Akey=" + apiKey);
        HttpURLConnection connection = (HttpURLConnection) url.openConnection();
        connection.setRequestMethod("POST");
        JAXBContext jaxbContext = JAXBContext.newInstance(com.axelor.pojo.Currency.class);
        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        connection.setDoOutput(true);
        connection.setDoInput(true);

        OutputStream outputStream = connection.getOutputStream();
        jaxbMarshaller.marshal(pojoCurrency, outputStream);

        connection.connect();
        //InputStream inputStream = connection.getInputStream();
        Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
        pojoCurrency = (com.axelor.pojo.Currency) jaxbUnmarshaller
                .unmarshal(new UnmarshalInputStream(connection.getInputStream()));
        // jaxbMarshaller.marshal(pojoCurrency, f);
        Currency checkCurrency = Currency.all().filter("code=?", pojoCurrency.getIso_code()).fetchOne();
        if (checkCurrency != null) {
            checkCurrency.setPrestashopCurrencyId(currencyId);
        } else {
            Currency currency = new Currency();
            // add this currency into ERP
            currency.setName(pojoCurrency.getName());
            currency.setCode(pojoCurrency.getIso_code());
            currency.setSymbol(pojoCurrency.getSign());
            currency.setPrestashopCurrencyId(currencyId);
            currency.save();
        }
    } catch (Exception e) {
        System.out.println(e);
    }
}

From source file:com.evolveum.midpoint.prism.util.JaxbTestUtil.java

private Marshaller createMarshaller(Map<String, Object> jaxbProperties) throws JAXBException {
    Marshaller marshaller = context.createMarshaller();
    // set default properties
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    DynamicNamespacePrefixMapper namespacePrefixMapper = getSchemaRegistry().getNamespacePrefixMapper().clone();
    namespacePrefixMapper.setAlwaysExplicit(true);
    marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", namespacePrefixMapper);
    // set custom properties
    if (jaxbProperties != null) {
        for (Entry<String, Object> property : jaxbProperties.entrySet()) {
            marshaller.setProperty(property.getKey(), property.getValue());
        }//from ww  w .j  a  va 2s.  c o  m
    }

    return marshaller;
}