Example usage for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION

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

Introduction

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

Prototype

String JAXB_SCHEMA_LOCATION

To view the source code for javax.xml.bind Marshaller JAXB_SCHEMA_LOCATION.

Click Source Link

Document

The name of the property used to specify the xsi:schemaLocation attribute value to place in the marshalled XML output.

Usage

From source file:mx.bigdata.sat.cfd.CFDv2.java

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,
            "http://www.sat.gob.mx/cfd/2 " + "http://www.sat.gob.mx/sitio_internet/cfd/2/cfdv2.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from www.  j  a  v a2s .  co m
    m.marshal(document, out);
}

From source file:mx.bigdata.sat.cfdi.CFDv32.java

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,
            "http://www.sat.gob.mx/cfd/3  " + "http://www.sat.gob.mx/sitio_internet/cfd/3/cfdv32.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//from w  ww . j  a v a 2  s .c  o  m
    m.marshal(document, out);
}

From source file:mx.bigdata.sat.cfdi.TFDv11c33.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);//from w  ww .  j a  va2 s  . com
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv3.PREFIXES));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital TimbreFiscalDigitalv11.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:mx.bigdata.sat.cfd.CFDv22.java

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,
            "http://www.sat.gob.mx/cfd/2 " + "http://www.sat.gob.mx/sitio_internet/cfd/2/cfdv22.xsd");
    byte[] xmlHeaderBytes = XML_HEADER.getBytes("UTF8");
    out.write(xmlHeaderBytes);//  ww w . j  av  a  2s .  c o m
    m.marshal(document, out);
}

From source file:net.sf.taverna.t2.maven.plugins.TavernaProfileGenerateMojo.java

/**
 * Generates the application profile file.
 *
 * @return the <code>File</code> that the application profile has been written to
 * @throws JAXBException//from   www .  ja va 2 s . co  m
 *             if the application profile cannot be created
 * @throws MojoExecutionException
 */
private File createApplicationProfile() throws JAXBException, MojoExecutionException {
    String groupId = project.getGroupId();
    String artifactId = project.getArtifactId();
    String version = maven2OsgiConverter.getVersion(project.getVersion());
    if (version.endsWith("SNAPSHOT")) {
        version = version.substring(0, version.indexOf("SNAPSHOT")) + buildNumber;
    }

    tempDirectory.mkdirs();
    File applicationProfileFile = new File(tempDirectory, APPLICATION_PROFILE_FILE);

    ApplicationProfile applicationProfile = new ApplicationProfile();
    applicationProfile.setId(groupId + "." + artifactId);
    applicationProfile.setName(project.getName());
    applicationProfile.setVersion(version);

    Updates updates = new Updates();
    updates.setUpdateSite(updateSite);
    updates.setUpdatesFile(updatesFile);
    updates.setLibDirectory(libDirectory);
    updates.setPluginSite(pluginSite);
    updates.setPluginsFile(pluginsFile);
    applicationProfile.setUpdates(updates);

    List<FrameworkConfiguration> frameworkConfiguration = applicationProfile.getFrameworkConfiguration();
    for (FrameworkConfiguration configuration : frameworkConfigurations) {
        frameworkConfiguration.add(configuration);
    }

    Set<BundleArtifact> bundleDependencies = osgiUtils.getBundleDependencies(Artifact.SCOPE_COMPILE,
            Artifact.SCOPE_RUNTIME);
    List<BundleInfo> runtimeBundles = osgiUtils.getBundles(bundleDependencies);
    if (!runtimeBundles.isEmpty()) {
        List<BundleInfo> bundles = applicationProfile.getBundle();
        for (BundleInfo bundle : runtimeBundles) {
            bundles.add(bundle);
        }
    }

    JAXBContext jaxbContext = JAXBContext.newInstance(ApplicationProfile.class);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, SCHEMA_LOCATION);
    marshaller.marshal(applicationProfile, applicationProfileFile);

    return applicationProfileFile;
}

From source file:mx.bigdata.sat.cfdi.TFDv1_v32.java

private Element marshalTFD() throws Exception {
    DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
    dbf.setNamespaceAware(true);/*  w w w.j  a  v a  2s.  com*/
    DocumentBuilder db = dbf.newDocumentBuilder();
    Document doc = db.newDocument();
    Marshaller m = CONTEXT.createMarshaller();
    m.setProperty("com.sun.xml.bind.namespacePrefixMapper", new NamespacePrefixMapperImpl(CFDv32.PREFIXES));
    m.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
    m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.sat.gob.mx/TimbreFiscalDigital http://www.sat.gob.mx/sitio_internet/TimbreFiscalDigital/TimbreFiscalDigital.xsd");
    m.marshal(tfd, doc);
    return doc.getDocumentElement();
}

From source file:org.opennms.features.vaadin.pmatrix.manual.ManualSpecificationMarshalTest.java

public void testJaxbManual() {
    System.out.println("start of test:testJaxb()");
    try {//from w  w  w. j  a va  2 s  .c  o m
        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.model");
        // TODO these classes are listed in jaxb.index file
        //         JAXBContext jaxbContext = JAXBContext.newInstance(               
        //               PmatrixSpecificationImpl.class,
        //               DataPointDefinitionImpl.class,
        //               PmatrixSpecificationListImpl.class,
        //               NameValuePair.class,
        //               PmatrixDpdCalculatorConfigImpl.class);

        // **********************
        // marshal test file
        // **********************

        Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
        jaxbMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

        // output pretty printed
        jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        //PmatrixSpecificationList pmatrixSpecificationList_context = (PmatrixSpecificationList) appContext.getBean("pmatrixSpecificationList");
        //PmatrixSpecification pmatrixSpec_Context = (PmatrixSpecification) appContext.getBean("pmatrixSpecification");

        // manual create process
        PmatrixSpecificationImpl newspec1 = createNewSpecification();
        newspec1.setPmatrixName("spec1");
        PmatrixSpecificationImpl newspec2 = createNewSpecification();
        newspec2.setPmatrixName("spec2");

        //create new specfication list
        PmatrixSpecificationListImpl pmatrixSpecificationList = new PmatrixSpecificationListImpl();
        pmatrixSpecificationList.setRefreshRate(1000);

        //create and add new DpdCalculator specification
        PmatrixDpdCalculatorConfig pmatrixDpdCalculatorConfig = new PmatrixDpdCalculatorConfigImpl();
        pmatrixDpdCalculatorConfig
                .setPmatrixDpdCalculatorClassName(PmatrixDpdCalculatorEmaImpl.class.getName());

        List<NameValuePair> configuration = new ArrayList<NameValuePair>();
        configuration.add(new NameValuePair("file", "fred.txt"));
        pmatrixDpdCalculatorConfig.setConfiguration(configuration);

        pmatrixSpecificationList.setPmatrixDpdCalculatorConfig(pmatrixDpdCalculatorConfig);

        //add specifications of each matrix
        List<PmatrixSpecification> pmsl = new ArrayList<PmatrixSpecification>();

        pmsl.add(newspec1);
        pmsl.add(newspec2);
        pmatrixSpecificationList.setPmatrixSpecificationList(pmsl);

        //System.out.println("list to be marshalled:");
        System.out.println(pmatrixSpecificationList);

        System.out.println("marshalled list:");
        //jaxbMarshaller.marshal(testDatalist, file);

        //jaxbMarshaller.marshal(pmatrixSpec, System.out); // works
        //jaxbMarshaller.marshal(pmatrixSpecificationList, System.out); //works

        //test of marshaling context data
        //jaxbMarshaller.marshal(pmatrixSpecificationList_context, System.out);
        jaxbMarshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "http://xmlns.opennms.org/xsd/config/pmatrix pmatrixConfig.xsd");

        jaxbMarshaller.marshal(pmatrixSpecificationList, 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 PmatrixSpecificationList) {
            System.out.println("unmarshalled list:");
            System.out.println((PmatrixSpecificationList) o);
        } else
            System.out.println("cant unmarshal object:");

    } catch (JAXBException e) {
        e.printStackTrace();
    } catch (Exception e) {
        e.printStackTrace();
    }

    System.out.println("end of test:testJaxb()");
}

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 w  w w  .ja v a 2 s.c  o  m*/
    m.marshal(document, out);
}

From source file:com.silverpeas.admin.components.Instanciateur.java

public static void saveComponent(WAComponent waComponent, String fileName, boolean workflow)
        throws JAXBException {
    JAXBContext context = JAXBContext.newInstance("com.silverpeas.admin.components");
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://silverpeas.org/xml/ns/component http://www.silverpeas.org/xsd/component.xsd");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    String path = getXMLPackage() + File.separatorChar;
    if (workflow) {
        path += "workflows" + File.separatorChar;
    }/*from  w w w.j  ava2s  . c  o  m*/
    File file = new File(path + fileName);
    marshaller.marshal(objectFactory.createWAComponent(waComponent), file);
}

From source file:edu.purdue.cybercenter.dm.service.VocabularyService.java

/**
 * Convert a vocabulary object to Xml vocabulary
 *
 * @param vocabulary: a vocabulary object
 * @return: an XML version of the vocabulary
 *//*from w  w w .  java 2 s.  c  o  m*/
public String convertVocabularyToXml(Vocabulary vocabulary) {
    String xmlVocabulary = null;
    try (OutputStream os = new ByteArrayOutputStream()) {
        Marshaller marshaller = context.createMarshaller();
        marshaller.setProperty(CharacterEscapeHandler.class.getName(), CDataEscapeHandler.theInstance);
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, VOCABULARY_SCHEMA_LOCATION);
        marshaller.marshal(vocabulary, os);
        xmlVocabulary = os.toString();
    } catch (JAXBException ex) {
        throw new RuntimeException("Unable to generate xml vocabulary definition", ex);
    } catch (IOException ex) {
        throw new RuntimeException("UUnable to write xml vocabulary definition", ex);
    }
    return xmlVocabulary;
}