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:org.orcid.jaxb.model.notification.permission.MarshallingTest.java

@Test
public void testMarshalling() throws JAXBException, IOException, SAXException {
    NotificationPermission notification = getNotification();
    assertNotNull(notification);//from   w  w  w .j  a  v  a 2 s .com
    assertEquals(NotificationType.PERMISSION, notification.getNotificationType());
    assertEquals(2, notification.getItems().getItems().size());
    assertEquals("2014-01-01T14:45:32", notification.getSentDate().toXMLFormat());

    // Back the other way
    String expected = IOUtils.toString(getClass().getResourceAsStream(SAMPLE_PATH), "UTF-8");
    Pattern pattern = Pattern.compile("<!--.*?-->\\s*", Pattern.DOTALL);
    expected = pattern.matcher(expected).replaceAll("");
    JAXBContext context = JAXBContext.newInstance("org.orcid.jaxb.model.notification.permission");
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://www.orcid.org/ns/notification ../notification-permission-2.0_rc1.xsd");
    StringWriter writer = new StringWriter();
    marshaller.marshal(notification, writer);
    XMLUnit.setIgnoreWhitespace(true);
    Diff diff = new Diff(expected, writer.toString());
    assertTrue(diff.identical());
}

From source file:org.silverpeas.core.admin.component.WAComponentRegistry.java

private static void storeComponent(WAComponent component, File descriptor) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance("org.silverpeas.core.admin.component.model");
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
            "http://silverpeas.org/xml/ns/component http://www.silverpeas.org/xsd/component.xsd");
    ObjectFactory objectFactory = new ObjectFactory();
    marshaller.marshal(objectFactory.createWAComponent(component), descriptor);
}

From source file:org.silverpeas.core.importexport.control.ImportExport.java

/**
 * Mthode crant le fichier xml corespondant  l'arbre des objets.
 * @param silverPeasExchangeType - arbre des objets  mapper sur le fichier xml
 * @param xmlToExportPath - chemin et nom du fichier xml  crer
 * @throws ImportExportException//from   w w w .  j av  a 2s  .  c  o m
 */
void saveToSilverpeasExchangeFile(SilverPeasExchangeType silverPeasExchangeType, String xmlToExportPath)
        throws ImportExportException {
    try {
        // URI du schma et chemin du fichier XSD associ.
        String xsdPublicId = settings.getString("xsdPublicId");
        String xsdSystemId = settings.getString("xsdDefaultSystemId");

        Marshaller mar = jaxbContext.createMarshaller();
        mar.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        mar.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        mar.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, xsdPublicId + " " + xsdSystemId);
        mar.marshal(silverPeasExchangeType, new File(xmlToExportPath));

    } catch (JAXBException me) {
        throw new ImportExportException("ImportExport.loadSilverpeasExchange",
                "importExport.EX_UNMARSHALLING_FAILED", "XML Filename : ", me);
    }
}

From source file:org.tolven.plugin.repository.RepositoryMetadata.java

public static String getPluginManifest(Plugin plugin) {
    try {//w  w w  .  j  a  v a  2 s . co m
        StringWriter stringWriter = new StringWriter();
        Marshaller marshaller = getJaxbContext().createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "urn:tolven-org:tpf:1.0 http://tolven.org/xsd/tpf.xsd");
        marshaller.marshal(plugin, stringWriter);
        return stringWriter.toString();
    } catch (JAXBException ex) {
        throw new RuntimeException("Could not convert plugin manifest to string for plugin: " + plugin.getId(),
                ex);
    }
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Constructs builder of METS metadata./* w w w  . j  a  v a  2s .com*/
 * 
 * @param jaxbContext
 *            JAXB context for the METS classes
 * @param datatypeFactory
 *            factory for converting dates into XML Gregorian Calendar instances.
 * @param domBuilderFactory
 *            factory for parsing XML to DOM.
 */
public MetsMetadataBuilder(JAXBContext jaxbContext, DatatypeFactory datatypeFactory,
        DocumentBuilderFactory domBuilderFactory) {
    try {
        this.marshaller = jaxbContext.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                MetsConsts.METS_NAMESPACE_URI + " " + MetsConsts.METS_SCHEMA_LOCATION);
    } catch (JAXBException e) {
        logger.error("JAXB - METS marshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    try {
        this.unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    this.datatypeFactory = datatypeFactory;
    this.domBuilderFactory = domBuilderFactory;
    this.idGenerators = new MetsIdGenerators();
    this.premisAdmId = null;
    this.premisDpId = null;
    this.dataFileMap = new HashMap<String, String>();
    this.mets = new Mets();
}

From source file:pl.psnc.synat.wrdz.common.metadata.mets.MetsMetadataBuilder.java

/**
 * Constructs builder of METS metadata.//from w w w .  j  a  v  a2  s.c om
 * 
 * @param jaxbContext
 *            JAXB context for the METS classes
 * @param datatypeFactory
 *            factory for converting dates into XML Gregorian Calendar instances.
 * @param domBuilderFactory
 *            factory for parsing XML to DOM.
 * @param tmpMetsFileUri
 *            URI to tmpMets file.
 */
public MetsMetadataBuilder(JAXBContext jaxbContext, DatatypeFactory datatypeFactory,
        DocumentBuilderFactory domBuilderFactory, URI tmpMetsFileUri) {
    try {
        this.marshaller = jaxbContext.createMarshaller();
        this.marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_FRAGMENT, Boolean.TRUE);
        this.marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                MetsConsts.METS_NAMESPACE_URI + " " + MetsConsts.METS_SCHEMA_LOCATION);
    } catch (JAXBException e) {
        logger.error("JAXB - METS marshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    try {
        this.unmarshaller = jaxbContext.createUnmarshaller();
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller creation failed.", e);
        throw new RuntimeException(e);
    }
    this.datatypeFactory = datatypeFactory;
    this.domBuilderFactory = domBuilderFactory;
    this.idGenerators = new MetsIdGenerators();
    this.premisAdmId = null;
    this.premisDpId = null;
    this.dataFileMap = new HashMap<String, String>();

    try {
        File tmpMetsFile = new File(tmpMetsFileUri.getPath());
        this.mets = (Mets) unmarshaller.unmarshal(tmpMetsFile);
    } catch (JAXBException e) {
        logger.error("JAXB - METS unmarshaller - tmpMets file unmarshalling failed.", e);
        throw new RuntimeException(e);
    }
}

From source file:psidev.psi.mi.xml.io.impl.PsimiXmlWriter253.java

private Marshaller getMarshaller(psidev.psi.mi.xml253.jaxb.EntrySet jEntrySet) throws PsimiXmlWriterException {

    try {/*from  w  ww. ja  v  a 2 s  .co m*/
        // create a JAXBContext capable of handling classes generated into the jaxb package
        ClassLoader cl = ObjectFactory.class.getClassLoader();
        JAXBContext jc = JAXBContext
                .newInstance(psidev.psi.mi.xml253.jaxb.EntrySet.class.getPackage().getName(), cl);

        // setup customized converter
        DatatypeConverter.setDatatypeConverter(new PsiJaxbConverter());

        // create and return Unmarshaller
        Marshaller marshaller = jc.createMarshaller();
        // configure marshaller
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, calculateSchemaLocation(jEntrySet.getLevel(),
                jEntrySet.getVersion(), jEntrySet.getMinorVersion()));

        return marshaller;
    } catch (Exception e) {
        throw new PsimiXmlWriterException("En error occured while writing EntrySet", e);
    }
}

From source file:psidev.psi.mi.xml.io.impl.PsimiXmlWriter254.java

private Marshaller getMarshaller(psidev.psi.mi.xml254.jaxb.EntrySet jEntrySet) throws PsimiXmlWriterException {

    try {/*from  w ww .j  a  v  a2 s.  c  om*/
        // create a JAXBContext capable of handling classes generated into the jaxb package
        ClassLoader cl = ObjectFactory.class.getClassLoader();
        JAXBContext jc = JAXBContext
                .newInstance(psidev.psi.mi.xml254.jaxb.EntrySet.class.getPackage().getName(), cl);

        // setup customized converter
        DatatypeConverter.setDatatypeConverter(new PsiJaxbConverter());

        // create and return Unmarshaller
        Marshaller marshaller = jc.createMarshaller();

        // configure marshaller
        marshaller.setProperty(Marshaller.JAXB_SCHEMA_LOCATION, calculateSchemaLocation(jEntrySet.getLevel(),
                jEntrySet.getVersion(), jEntrySet.getMinorVersion()));

        return marshaller;
    } catch (Exception e) {
        throw new PsimiXmlWriterException("En error occured while writing EntrySet", e);
    }
}

From source file:sh.isaac.pombuilder.FileUtil.java

/**
 * Write pom file./*from  w w  w.j ava 2s .com*/
 *
 * @param model the model
 * @param projectFolder the project folder
 * @throws Exception the exception
 */
public static void writePomFile(Model model, File projectFolder) throws Exception {
    try {
        final JAXBContext ctx = JAXBContext.newInstance(Model.class);
        final Marshaller ma = ctx.createMarshaller();

        ma.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd");
        ma.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        ma.marshal(new ObjectFactory().createProject(model), new File(projectFolder, "pom.xml"));
    } catch (final JAXBException e) {
        LOG.error("Error writing", e);
        throw new Exception("Error writing pom: " + e);
    }
}

From source file:ws.michalski.sepa.pain.writers.SEPAWriterPain_001_002_03.java

@Override
public OutputStream export(SEPAMessage creditMessage) throws SEPAException {

    // bergabenachricht wird geprft
    creditMessage.validate();//  www  .  j a v a  2s  .  c om

    // Document erstellen
    Document document = objectFactory.createDocument();

    // CstmrCdtTrfInitn erstellen
    CustomerCreditTransferInitiationV03 cstmrCdtTrfInitn = objectFactory
            .createCustomerCreditTransferInitiationV03();
    document.setCstmrCdtTrfInitn(cstmrCdtTrfInitn);

    // GrpHdr erstellen
    GroupHeaderSCT grpHdr = objectFactory.createGroupHeaderSCT();
    grpHdr.setMsgId(creditMessage.getMessageId());
    grpHdr.setCreDtTm(creditMessage.getCreateDate());
    grpHdr.setNbOfTxs(String.valueOf(creditMessage.getNbrOfTransaction()));
    grpHdr.setCtrlSum(creditMessage.getCtlSum());

    grpHdr.setInitgPty(objectFactory.createPartyIdentificationSEPA1());
    grpHdr.getInitgPty().setNm(creditMessage.getName());

    cstmrCdtTrfInitn.setGrpHdr(grpHdr);

    // Pro Debitor als CreditTransaction wird PaymentInstructionInformationSCT erstellt
    // PaymentInstructionInformationSCT entspricht CreditTransaction
    for (SEPATransaction trns : creditMessage.getTransactionsList()) {

        CreditTransaction ctrns = null;
        if (trns instanceof CreditTransaction) {
            ctrns = (CreditTransaction) trns;
        }

        PaymentInstructionInformationSCT pmts = objectFactory.createPaymentInstructionInformationSCT();

        // Debitorendaten
        pmts.setPmtInfId(ctrns.getPaymentInformation());
        pmts.setPmtMtd(PaymentMethodSCTCode.TRF);
        pmts.setNbOfTxs(String.valueOf(ctrns.getNbrOfTransaction()));
        pmts.setCtrlSum(ctrns.getCtlSum());

        pmts.setPmtTpInf(objectFactory.createPaymentTypeInformationSCT1());
        pmts.getPmtTpInf().setSvcLvl(objectFactory.createServiceLevelSEPA());
        pmts.getPmtTpInf().getSvcLvl().setCd(ServiceLevelSEPACode.SEPA);

        // Ausfhrungsdatum von Gregorian auf XMLGregorian
        pmts.setReqdExctnDt(SEPAUtility.convertYearOnly(ctrns.getExecutionDate()));

        pmts.setDbtr(objectFactory.createPartyIdentificationSEPA2());
        pmts.getDbtr().setNm(ctrns.getName());

        pmts.setDbtrAcct(objectFactory.createCashAccountSEPA1());
        pmts.getDbtrAcct().setId(objectFactory.createAccountIdentificationSEPA());
        pmts.getDbtrAcct().getId().setIBAN(ctrns.getIBAN());

        pmts.setDbtrAgt(objectFactory.createBranchAndFinancialInstitutionIdentificationSEPA1());
        pmts.getDbtrAgt().setFinInstnId(objectFactory.createFinancialInstitutionIdentificationSEPA1());
        pmts.getDbtrAgt().getFinInstnId().setBIC(ctrns.getBIC());

        pmts.setChrgBr(ChargeBearerTypeSEPACode.SLEV);

        // CdtTrfTxInf
        // Hier werden die einzelne Transaktionen pro Debitor verarbeitet
        for (CreditTransactionItem ti : ctrns.getCreditTransactionList()) {

            CreditTransferTransactionInformationSCT ctts = objectFactory
                    .createCreditTransferTransactionInformationSCT();

            ctts.setPmtId(objectFactory.createPaymentIdentificationSEPA());
            ctts.getPmtId().setEndToEndId(ti.getEndToEndId());

            ctts.setAmt(objectFactory.createAmountTypeSEPA());
            ctts.getAmt().setInstdAmt(objectFactory.createActiveOrHistoricCurrencyAndAmountSEPA());
            ctts.getAmt().getInstdAmt().setCcy(ActiveOrHistoricCurrencyCodeEUR.EUR);
            ctts.getAmt().getInstdAmt().setValue(ti.getAmount());

            ctts.setCdtrAgt(objectFactory.createBranchAndFinancialInstitutionIdentificationSEPA1());
            ctts.getCdtrAgt().setFinInstnId(objectFactory.createFinancialInstitutionIdentificationSEPA1());
            ctts.getCdtrAgt().getFinInstnId().setBIC(ti.getBIC());

            ctts.setCdtr(objectFactory.createPartyIdentificationSEPA2());
            ctts.getCdtr().setNm(ti.getName());

            ctts.setCdtrAcct(objectFactory.createCashAccountSEPA2());
            ctts.getCdtrAcct().setId(objectFactory.createAccountIdentificationSEPA());
            ctts.getCdtrAcct().getId().setIBAN(ti.getIBAN());

            ctts.setRmtInf(objectFactory.createRemittanceInformationSEPA1Choice());
            ctts.getRmtInf().setUstrd(ti.getRemitanceInformation());

            if (ti.getPurposeCode() != null) {
                ctts.setPurp(objectFactory.createPurposeSEPA());
                ctts.getPurp().setCd(ti.getPurposeCode().toString());
            }

            // Einzeltransaktion einfgen
            pmts.getCdtTrfTxInf().add(ctts);
        }

        // Debitor Einfgen
        cstmrCdtTrfInitn.getPmtInf().add(pmts);

    }

    // Exportieren
    try {

        OutputStream os = new ByteArrayOutputStream();

        JAXBContext jc = JAXBContext.newInstance(Document.class);
        Marshaller m = jc.createMarshaller();
        m.setProperty(Marshaller.JAXB_SCHEMA_LOCATION,
                "urn:iso:std:iso:20022:tech:xsd:pain.001.002.03 pain.001.002.03.xsd");

        m.marshal(document, os);

        return os;

    } catch (JAXBException e) {
        log.error(e);
    }
    return null;
}