Example usage for javax.xml.bind Marshaller JAXB_ENCODING

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

Introduction

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

Prototype

String JAXB_ENCODING

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

Click Source Link

Document

The name of the property used to specify the output encoding in the marshalled XML data.

Usage

From source file:org.paxml.testng.AbstractPaxmlTestResult.java

public static String serializeXml(Object obj) {
    final String encoding = "UTF-8";
    try {/*  w w  w.ja  v  a  2 s.  c o m*/
        JAXBContext c = JAXBContext.newInstance(obj.getClass());
        Marshaller m = c.createMarshaller();
        m.setProperty(Marshaller.JAXB_ENCODING, encoding);
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        ByteArrayOutputStream out = new ByteArrayOutputStream();
        m.marshal(obj, out);
        return out.toString(encoding);
    } catch (Exception e) {
        throw new RuntimeException("Cannot serialize jaxb object of class: " + obj.getClass(), e);
    }
}

From source file:org.rhq.enterprise.server.sync.ExportingInputStream.java

/**
 * Constructs a new exporting input stream with the default buffer size of 64KB.
 * /*  ww  w  .  j a v  a2s  . c  o m*/
 * @param synchronizers the synchronizers to invoke when producing the export file
 * @param messagesPerExporter a reference to a map of messages that the exporters will use to produce additional info about the export
 * @param size the size in bytes of the intermediate buffer
 * @param zip whether to zip the export data
 * @throws IOException on failure
 */
public ExportingInputStream(Set<Synchronizer<?, ?>> synchronizers,
        Map<String, ExporterMessages> messagesPerExporter, int size, boolean zip) throws IOException {
    this.synchronizers = synchronizers;
    this.messagesPerExporter = messagesPerExporter;
    inputStream = new PipedInputStream(size);
    exportOutput = new PipedOutputStream(inputStream);
    zipOutput = zip;

    try {
        JAXBContext context = JAXBContext.newInstance(DefaultImportConfigurationDescriptor.class);

        configurationMarshaller = context.createMarshaller();
        configurationMarshaller.setProperty(Marshaller.JAXB_FRAGMENT, true);
        configurationMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        configurationMarshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");

    } catch (JAXBException e) {
        throw new IOException(e);
    }
}

From source file:org.rhq.plugins.jbossas5.util.PluginDescriptorGenerator.java

private static void writeToFile(PluginDescriptor pluginDescriptor, File file) throws Exception {
    LOG.info("Writing plugin descriptor to [" + file + "]...");
    OutputStream outputStream = new BufferedOutputStream(new FileOutputStream(file));
    JAXBContext jaxbContext = JAXBContext.newInstance(DescriptorPackages.PC_PLUGIN);
    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setProperty("com.sun.xml.bind.namespacePrefixMapper", new RhqNamespacePrefixMapper());
    marshaller.marshal(pluginDescriptor, outputStream);
    outputStream.close();//from  www . jav a 2  s  .c  om
}

From source file:org.silverpeas.core.contribution.template.publication.PublicationTemplateImpl.java

/**
 * Save a recordTemplate to xml file//from  w  w w.jav a 2s  .  c  om
 *
 * @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
        PublicationTemplateManager templateManager = PublicationTemplateManager.getInstance();
        String xmlFilePath = templateManager.makePath(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_UNMARSHALL_PUBLICATION_TEMPLATE", "Publication Template FileName : " + xmlFileName,
                e);
    }
}

From source file:org.silverpeas.core.contribution.template.publication.PublicationTemplateManager.java

/**
 * Save a publicationTemplate definition from java objects to xml file
 * @param template the PublicationTemplate to save
 * @throws PublicationTemplateException/*from w  ww.  j  av  a  2s. c om*/
 * @throws CryptoException
 */
public void savePublicationTemplate(PublicationTemplate template)
        throws PublicationTemplateException, CryptoException {

    String xmlFileName = template.getFileName();

    PublicationTemplate previousTemplate = loadPublicationTemplate(xmlFileName);
    boolean encryptionChanged = previousTemplate != null
            && template.isDataEncrypted() != previousTemplate.isDataEncrypted();

    if (encryptionChanged) {
        if (template.isDataEncrypted()) {
            getGenericRecordSetManager().encryptData(xmlFileName);
        } else {
            getGenericRecordSetManager().decryptData(xmlFileName);
        }
    }

    // save template into XML file
    try {
        // Format this URL
        String xmlFilePath = makePath(xmlFileName);
        Marshaller marshaller = JAXB_CONTEXT.createMarshaller();
        marshaller.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        marshaller.marshal(template, new File(xmlFilePath));

    } catch (JAXBException e) {
        throw new PublicationTemplateException("PublicationTemplateManager.loadPublicationTemplate",
                "form.EX_ERR_UNMARSHALL_PUBLICATION_TEMPLATE", "Publication Template FileName : " + xmlFileName,
                e);
    }
}

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//  w  ww.j  a  v  a 2s.  co  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.techytax.digipoort.XbrlNtp8Helper.java

public String createXbrlInstance(VatDeclarationData vatDeclarationData) {
    ObjectFactory xbrlObjectFactory = null;
    JAXBContext jc = null;/*from   w  w  w. j ava2  s.c o m*/
    Marshaller m = null;
    try {
        xbrlObjectFactory = new ObjectFactory();
        jc = JAXBContext.newInstance(new Class[] { org.xbrl._2003.instance.ObjectFactory.class,
                nl.nltaxonomie._8_0.domein.bd.tuples.bd_ob_tuples.ObjectFactory.class,
                nl.nltaxonomie._8_0.basis.bd.types.bd_types.ObjectFactory.class,
                org.xbrl._2006.xbrldi.ObjectFactory.class, org.xbrl._2003.xlink.ObjectFactory.class,
                nl.nltaxonomie._2011.xbrl.xbrl_syntax_extension.ObjectFactory.class,
                org.xbrl._2003.linkbase.ObjectFactory.class, org.xbrl._2005.xbrldt.ObjectFactory.class,
                nl.nltaxonomie._8_0.domein.bd.axes.bd_axes.ObjectFactory.class,
                nl.nltaxonomie._8_0.basis.bd.domains.bd_domains.ObjectFactory.class,
                nl.nltaxonomie.iso.iso4217.ObjectFactory.class,
                nl.nltaxonomie._8_0.basis.bd.items.bd_algemeen.ObjectFactory.class,
                nl.nltaxonomie._8_0.basis.bd.items.bd_omzetbelasting.ObjectFactory.class });
        m = jc.createMarshaller();
        StringWriter writer = new StringWriter();
        m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        Xbrl xbrl = xbrlObjectFactory.createXbrl();

        org.xbrl._2003.xlink.ObjectFactory xlinkObjectFactory = new org.xbrl._2003.xlink.ObjectFactory();
        SimpleType simpleType = xlinkObjectFactory.createSimpleType();
        simpleType.setType("simple");
        simpleType.setHref("http://www.nltaxonomie.nl/8.0/report/bd/entrypoints/bd-rpt-ob-aangifte-2014.xsd");
        xbrl.getSchemaRef().add(simpleType);
        xbrl.getOtherAttributes().put(new QName("xml:lang"), "nl");

        Context context = xbrlObjectFactory.createContext();
        context.setId(CONTEXT_ID);

        ContextEntityType contextEntityType = xbrlObjectFactory.createContextEntityType();
        Identifier identifier = xbrlObjectFactory.createContextEntityTypeIdentifier();
        identifier.setScheme("www.belastingdienst.nl/omzetbelastingnummer");
        identifier.setValue(vatDeclarationData.getFiscalNumber());
        ContextPeriodType period = xbrlObjectFactory.createContextPeriodType();
        period.setStartDate(DateHelper.getDate(vatDeclarationData.getStartDate()));
        period.setEndDate(DateHelper.getDate(vatDeclarationData.getEndDate()));
        contextEntityType.setIdentifier(identifier);
        context.setEntity(contextEntityType);
        context.setPeriod(period);
        xbrl.getItemOrTupleOrContext().add(context);

        Unit unit = xbrlObjectFactory.createUnit();
        unit.setId(UNIT_ID);
        QName qName = new QName(ISO_EURO);
        unit.getMeasure().add(qName);
        xbrl.getItemOrTupleOrContext().add(unit);

        nl.nltaxonomie._8_0.basis.bd.types.bd_types.ObjectFactory bdTypeObjectFactory = new nl.nltaxonomie._8_0.basis.bd.types.bd_types.ObjectFactory();
        nl.nltaxonomie._8_0.basis.bd.items.bd_omzetbelasting.ObjectFactory bdItemObjectFactory = new nl.nltaxonomie._8_0.basis.bd.items.bd_omzetbelasting.ObjectFactory();
        nl.nltaxonomie._8_0.basis.bd.items.bd_algemeen.ObjectFactory bdAlgemeenObjectFactory = new nl.nltaxonomie._8_0.basis.bd.items.bd_algemeen.ObjectFactory();

        ContactItemType contactType = new ContactItemType();
        contactType.setValue(BELASTING_PLICHTIGE);
        contactType.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory.createContactType(contactType));

        Anstring10VItemType initials = bdTypeObjectFactory.createAnstring10VItemType();
        initials.setValue(vatDeclarationData.getInitials());
        initials.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactInitials(initials));

        if (StringUtils.isNotEmpty(vatDeclarationData.getPrefix())) {
            Anstring10VItemType prefix = bdTypeObjectFactory.createAnstring10VItemType();
            prefix.setValue(vatDeclarationData.getPrefix());
            prefix.setContextRef(context);
            xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactPrefix(prefix));
        }

        Anstring200VItemType surname = bdTypeObjectFactory.createAnstring200VItemType();
        surname.setValue(vatDeclarationData.getSurname());
        surname.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactSurname(surname));

        Anstring14VItemType telephoneNumber = bdTypeObjectFactory.createAnstring14VItemType();
        telephoneNumber.setValue(vatDeclarationData.getPhoneNumber());
        telephoneNumber.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createContactTelephoneNumber(telephoneNumber));

        DateTimeItemType dateTime = bdTypeObjectFactory.createDateTimeItemType();
        dateTime.setValue(DateHelper.getTimeStamp(new Date()));
        dateTime.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createDateTimeCreation(dateTime));

        MessageReferenceSupplierVATItemType supplier = bdTypeObjectFactory
                .createMessageReferenceSupplierVATItemType();
        supplier.setValue("OB-TXTAX-01");
        supplier.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createMessageReferenceSupplierVAT(supplier));

        Anstring20VItemType packageVersion = bdTypeObjectFactory.createAnstring20VItemType();
        packageVersion.setValue(PACKAGE_VERSION);
        packageVersion.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createSoftwarePackageVersion(packageVersion));

        Anstring30VItemType packageName = bdTypeObjectFactory.createAnstring30VItemType();
        packageName.setValue(PACKAGE_NAME);
        packageName.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createSoftwarePackageName(packageName));

        String softwareVendorAccountNumber = environment.getProperty("software.vendor.account.number");
        Anstring8FItemType softwareVendor = bdTypeObjectFactory.createAnstring8FItemType();
        softwareVendor.setValue(softwareVendorAccountNumber);
        softwareVendor.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createSoftwareVendorAccountNumber(softwareVendor));

        MonetaryNoDecimals10VItemType valueAddedTaxOnInput = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        valueAddedTaxOnInput.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOnInput.setContextRef(context);
        valueAddedTaxOnInput.setUnitRef(unit);
        valueAddedTaxOnInput.setValue(vatDeclarationData.getValueAddedTaxOnInput());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOnInput(valueAddedTaxOnInput));

        MonetaryNoDecimals10VItemType valueAddedTaxOwed = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        valueAddedTaxOwed.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOwed.setContextRef(context);
        valueAddedTaxOwed.setUnitRef(unit);
        valueAddedTaxOwed.setValue(vatDeclarationData.getValueAddedTaxOwed());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory.createValueAddedTaxOwed(valueAddedTaxOwed));

        MonetaryNoDecimals9VItemType valueAddedTaxOwedToBePaidBack = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxOwedToBePaidBack.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOwedToBePaidBack.setContextRef(context);
        valueAddedTaxOwedToBePaidBack.setUnitRef(unit);
        valueAddedTaxOwedToBePaidBack.setValue(vatDeclarationData.getValueAddedTaxOwedToBePaidBack());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOwedToBePaidBack(valueAddedTaxOwedToBePaidBack));

        MonetaryNoDecimals9VItemType valueAddedTaxPrivateUse = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxPrivateUse.setDecimals(DECIMALS_TYPE);
        valueAddedTaxPrivateUse.setContextRef(context);
        valueAddedTaxPrivateUse.setUnitRef(unit);
        valueAddedTaxPrivateUse.setValue(vatDeclarationData.getValueAddedTaxPrivateUse());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxPrivateUse(valueAddedTaxPrivateUse));

        MonetaryNoDecimals9VItemType valueAddedTaxSuppliesServicesGeneralTariff = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxSuppliesServicesGeneralTariff.setDecimals(DECIMALS_TYPE);
        valueAddedTaxSuppliesServicesGeneralTariff.setContextRef(context);
        valueAddedTaxSuppliesServicesGeneralTariff.setUnitRef(unit);
        valueAddedTaxSuppliesServicesGeneralTariff
                .setValue(vatDeclarationData.getValueAddedTaxSuppliesServicesGeneralTariff());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory
                .createValueAddedTaxSuppliesServicesGeneralTariff(valueAddedTaxSuppliesServicesGeneralTariff));

        MonetaryNoDecimals10VItemType turnoverSuppliesServicesGenerallTariff = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        turnoverSuppliesServicesGenerallTariff.setDecimals(DECIMALS_TYPE);
        turnoverSuppliesServicesGenerallTariff.setContextRef(context);
        turnoverSuppliesServicesGenerallTariff.setUnitRef(unit);
        turnoverSuppliesServicesGenerallTariff
                .setValue(vatDeclarationData.getTaxedTurnoverSuppliesServicesGeneralTariff());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory
                .createTaxedTurnoverSuppliesServicesGeneralTariff(turnoverSuppliesServicesGenerallTariff));

        MonetaryNoDecimals10VItemType turnoverFromTaxedSuppliesFromCountriesWithinTheEC = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setDecimals(DECIMALS_TYPE);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setContextRef(context);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setUnitRef(unit);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC
                .setValue(vatDeclarationData.getTurnoverFromTaxedSuppliesFromCountriesWithinTheEC());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createTurnoverFromTaxedSuppliesFromCountriesWithinTheEC(
                        turnoverFromTaxedSuppliesFromCountriesWithinTheEC));

        MonetaryNoDecimals9VItemType valueAddedTaxOnSuppliesFromCountriesWithinTheEC = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setContextRef(context);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setUnitRef(unit);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC
                .setValue(vatDeclarationData.getValueAddedTaxOnSuppliesFromCountriesWithinTheEC());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOnSuppliesFromCountriesWithinTheEC(
                        valueAddedTaxOnSuppliesFromCountriesWithinTheEC));

        m.marshal(xbrl, writer);

        System.out.println(writer.toString());
        return writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.techytax.digipoort.XbrlNtp9Helper.java

public String createXbrlInstance(VatDeclarationData vatDeclarationData) {
    ObjectFactory xbrlObjectFactory;
    JAXBContext jc;/*from  www.j av a 2  s.c o m*/
    Marshaller m;
    try {
        xbrlObjectFactory = new ObjectFactory();
        jc = JAXBContext.newInstance(ObjectFactory.class,
                nl.nltaxonomie._9_0.domein.bd.tuples.bd_ob_tuples.ObjectFactory.class,
                nl.nltaxonomie._9_0.basis.bd.types.bd_types.ObjectFactory.class,
                org.xbrl._2006.xbrldi.ObjectFactory.class, org.xbrl._2003.xlink.ObjectFactory.class,
                nl.nltaxonomie._2011.xbrl.xbrl_syntax_extension.ObjectFactory.class,
                org.xbrl._2003.linkbase.ObjectFactory.class, org.xbrl._2005.xbrldt.ObjectFactory.class,
                nl.nltaxonomie._9_0.domein.bd.axes.bd_axes.ObjectFactory.class,
                nl.nltaxonomie._9_0.basis.bd.domains.bd_domains.ObjectFactory.class,
                nl.nltaxonomie.iso.iso4217.ObjectFactory.class,
                nl.nltaxonomie._9_0.basis.bd.items.bd_algemeen.ObjectFactory.class,
                nl.nltaxonomie._9_0.basis.bd.items.bd_omzetbelasting.ObjectFactory.class);
        m = jc.createMarshaller();
        StringWriter writer = new StringWriter();
        m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        Xbrl xbrl = xbrlObjectFactory.createXbrl();

        org.xbrl._2003.xlink.ObjectFactory xlinkObjectFactory = new org.xbrl._2003.xlink.ObjectFactory();
        SimpleType simpleType = xlinkObjectFactory.createSimpleType();
        simpleType.setType("simple");
        simpleType.setHref("http://www.nltaxonomie.nl/9.0/report/bd/entrypoints/bd-rpt-ob-aangifte-2015.xsd");
        xbrl.getSchemaRef().add(simpleType);
        xbrl.getOtherAttributes().put(new QName("xml:lang"), "nl");

        Context context = xbrlObjectFactory.createContext();
        context.setId(CONTEXT_ID);

        ContextEntityType contextEntityType = xbrlObjectFactory.createContextEntityType();
        Identifier identifier = xbrlObjectFactory.createContextEntityTypeIdentifier();
        identifier.setScheme("www.belastingdienst.nl/omzetbelastingnummer");
        identifier.setValue(vatDeclarationData.getFiscalNumber());
        ContextPeriodType period = xbrlObjectFactory.createContextPeriodType();
        period.setStartDate(DateHelper.getDate(vatDeclarationData.getStartDate()));
        period.setEndDate(DateHelper.getDate(vatDeclarationData.getEndDate()));
        contextEntityType.setIdentifier(identifier);
        context.setEntity(contextEntityType);
        context.setPeriod(period);
        xbrl.getItemOrTupleOrContext().add(context);

        Unit unit = xbrlObjectFactory.createUnit();
        unit.setId(UNIT_ID);
        QName qName = new QName(ISO_EURO);
        unit.getMeasure().add(qName);
        xbrl.getItemOrTupleOrContext().add(unit);

        nl.nltaxonomie._9_0.basis.bd.types.bd_types.ObjectFactory bdTypeObjectFactory = new nl.nltaxonomie._9_0.basis.bd.types.bd_types.ObjectFactory();
        nl.nltaxonomie._9_0.basis.bd.items.bd_omzetbelasting.ObjectFactory bdItemObjectFactory = new nl.nltaxonomie._9_0.basis.bd.items.bd_omzetbelasting.ObjectFactory();
        nl.nltaxonomie._9_0.basis.bd.items.bd_algemeen.ObjectFactory bdAlgemeenObjectFactory = new nl.nltaxonomie._9_0.basis.bd.items.bd_algemeen.ObjectFactory();

        ContactItemType contactType = new ContactItemType();
        contactType.setValue(BELASTING_PLICHTIGE);
        contactType.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory.createContactType(contactType));

        Anstring10VItemType initials = bdTypeObjectFactory.createAnstring10VItemType();
        initials.setValue(vatDeclarationData.getInitials());
        initials.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactInitials(initials));

        if (StringUtils.isNotEmpty(vatDeclarationData.getPrefix())) {
            Anstring10VItemType prefix = bdTypeObjectFactory.createAnstring10VItemType();
            prefix.setValue(vatDeclarationData.getPrefix());
            prefix.setContextRef(context);
            xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactPrefix(prefix));
        }

        Anstring200VItemType surname = bdTypeObjectFactory.createAnstring200VItemType();
        surname.setValue(vatDeclarationData.getSurname());
        surname.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createContactSurname(surname));

        Anstring14VItemType telephoneNumber = bdTypeObjectFactory.createAnstring14VItemType();
        telephoneNumber.setValue(vatDeclarationData.getPhoneNumber());
        telephoneNumber.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createContactTelephoneNumber(telephoneNumber));

        DateTimeItemType dateTime = bdTypeObjectFactory.createDateTimeItemType();
        dateTime.setValue(DateHelper.getTimeStamp(new Date()));
        dateTime.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createDateTimeCreation(dateTime));

        Anstring20VItemType supplier = bdTypeObjectFactory.createAnstring20VItemType();
        supplier.setValue("OB-TechyTax-Ref-1");
        supplier.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createMessageReferenceSupplierVAT(supplier));

        Anstring20VItemType packageVersion = bdTypeObjectFactory.createAnstring20VItemType();
        packageVersion.setValue(PACKAGE_VERSION);
        packageVersion.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createSoftwarePackageVersion(packageVersion));

        Anstring30VItemType packageName = bdTypeObjectFactory.createAnstring30VItemType();
        packageName.setValue(PACKAGE_NAME);
        packageName.setContextRef(context);
        xbrl.getItemOrTupleOrContext().add(bdAlgemeenObjectFactory.createSoftwarePackageName(packageName));

        String softwareVendorAccountNumber = environment.getProperty("software.vendor.account.number");
        Anstring8FItemType softwareVendor = bdTypeObjectFactory.createAnstring8FItemType();
        softwareVendor.setValue(softwareVendorAccountNumber);
        softwareVendor.setContextRef(context);
        xbrl.getItemOrTupleOrContext()
                .add(bdAlgemeenObjectFactory.createSoftwareVendorAccountNumber(softwareVendor));

        MonetaryNoDecimals10VItemType valueAddedTaxOnInput = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        valueAddedTaxOnInput.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOnInput.setContextRef(context);
        valueAddedTaxOnInput.setUnitRef(unit);
        valueAddedTaxOnInput.setValue(vatDeclarationData.getValueAddedTaxOnInput());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOnInput(valueAddedTaxOnInput));

        MonetaryNoDecimals10VItemType valueAddedTaxOwed = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        valueAddedTaxOwed.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOwed.setContextRef(context);
        valueAddedTaxOwed.setUnitRef(unit);
        valueAddedTaxOwed.setValue(vatDeclarationData.getValueAddedTaxOwed());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory.createValueAddedTaxOwed(valueAddedTaxOwed));

        MonetaryNoDecimals9VItemType valueAddedTaxOwedToBePaidBack = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxOwedToBePaidBack.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOwedToBePaidBack.setContextRef(context);
        valueAddedTaxOwedToBePaidBack.setUnitRef(unit);
        valueAddedTaxOwedToBePaidBack.setValue(vatDeclarationData.getValueAddedTaxOwedToBePaidBack());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOwedToBePaidBack(valueAddedTaxOwedToBePaidBack));

        MonetaryNoDecimals9VItemType valueAddedTaxPrivateUse = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxPrivateUse.setDecimals(DECIMALS_TYPE);
        valueAddedTaxPrivateUse.setContextRef(context);
        valueAddedTaxPrivateUse.setUnitRef(unit);
        valueAddedTaxPrivateUse.setValue(vatDeclarationData.getValueAddedTaxPrivateUse());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxPrivateUse(valueAddedTaxPrivateUse));

        MonetaryNoDecimals9VItemType valueAddedTaxSuppliesServicesGeneralTariff = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxSuppliesServicesGeneralTariff.setDecimals(DECIMALS_TYPE);
        valueAddedTaxSuppliesServicesGeneralTariff.setContextRef(context);
        valueAddedTaxSuppliesServicesGeneralTariff.setUnitRef(unit);
        valueAddedTaxSuppliesServicesGeneralTariff
                .setValue(vatDeclarationData.getValueAddedTaxSuppliesServicesGeneralTariff());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory
                .createValueAddedTaxSuppliesServicesGeneralTariff(valueAddedTaxSuppliesServicesGeneralTariff));

        MonetaryNoDecimals10VItemType turnoverSuppliesServicesGenerallTariff = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        turnoverSuppliesServicesGenerallTariff.setDecimals(DECIMALS_TYPE);
        turnoverSuppliesServicesGenerallTariff.setContextRef(context);
        turnoverSuppliesServicesGenerallTariff.setUnitRef(unit);
        turnoverSuppliesServicesGenerallTariff
                .setValue(vatDeclarationData.getTaxedTurnoverSuppliesServicesGeneralTariff());
        xbrl.getItemOrTupleOrContext().add(bdItemObjectFactory
                .createTaxedTurnoverSuppliesServicesGeneralTariff(turnoverSuppliesServicesGenerallTariff));

        MonetaryNoDecimals10VItemType turnoverFromTaxedSuppliesFromCountriesWithinTheEC = bdTypeObjectFactory
                .createMonetaryNoDecimals10VItemType();
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setDecimals(DECIMALS_TYPE);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setContextRef(context);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC.setUnitRef(unit);
        turnoverFromTaxedSuppliesFromCountriesWithinTheEC
                .setValue(vatDeclarationData.getTurnoverFromTaxedSuppliesFromCountriesWithinTheEC());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createTurnoverFromTaxedSuppliesFromCountriesWithinTheEC(
                        turnoverFromTaxedSuppliesFromCountriesWithinTheEC));

        MonetaryNoDecimals9VItemType valueAddedTaxOnSuppliesFromCountriesWithinTheEC = bdTypeObjectFactory
                .createMonetaryNoDecimals9VItemType();
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setDecimals(DECIMALS_TYPE);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setContextRef(context);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC.setUnitRef(unit);
        valueAddedTaxOnSuppliesFromCountriesWithinTheEC
                .setValue(vatDeclarationData.getValueAddedTaxOnSuppliesFromCountriesWithinTheEC());
        xbrl.getItemOrTupleOrContext()
                .add(bdItemObjectFactory.createValueAddedTaxOnSuppliesFromCountriesWithinTheEC(
                        valueAddedTaxOnSuppliesFromCountriesWithinTheEC));

        m.marshal(xbrl, writer);

        System.out.println(writer.toString());
        return writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.techytax.helper.DutchAuditFileHelper.java

public String createAuditFile(List<Cost> costList, List<Customer> customers, User user)
        throws DatatypeConfigurationException {

    JAXBContext jc = null;//w ww .  ja  v a  2 s. c om
    Marshaller m = null;
    try {
        jc = JAXBContext.newInstance("nl.auditfiles.xaf._3");
        m = jc.createMarshaller();
        StringWriter writer = new StringWriter();
        m.setProperty(Marshaller.JAXB_ENCODING, "ISO-8859-1");
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

        ObjectFactory objectFactory = new ObjectFactory();
        Auditfile auditfile = objectFactory.createAuditfile();
        Company company = objectFactory.createAuditfileCompany();
        company.setCompanyName(user.getCompanyName());
        if (user.getChamberOfCommerceNumber() != null) {
            company.setCompanyIdent(Long.toString(user.getChamberOfCommerceNumber()));
        }
        company.setTaxRegIdent(user.getFiscalNumber());
        company.setTaxRegistrationCountry(CountrycodeIso3166.NL);

        nl.auditfiles.xaf._3.Auditfile.Company.StreetAddress address = objectFactory
                .createAuditfileCompanyStreetAddress();
        address.setStreetname(user.getCompanyAddress());
        address.setCity(user.getCompanyCity());
        address.setPostalCode(user.getCompanyZipCode());
        address.setCountry(CountrycodeIso3166.NL);
        company.getStreetAddress().add(address);

        CustomersSuppliers customersElement = objectFactory.createAuditfileCompanyCustomersSuppliers();
        for (Customer customer : customers) {
            CustomerSupplier customerElement = objectFactory
                    .createAuditfileCompanyCustomersSuppliersCustomerSupplier();
            customerElement.setContact(customer.getContact());
            customerElement.setEMail(customer.getEmailInvoice());
            customerElement.setCustSupName(customer.getName());
            customerElement.setContact(customer.getContact());
            if (customer.getCommerceNr() != null) {
                customerElement.setCommerceNr(customer.getCommerceNr().toString());
            }
            customerElement.setFax(customer.getFax());
            customerElement.setTelephone(customer.getTelephone());
            customerElement.setWebsite(customer.getWebsite());
            StreetAddress customerAddress = objectFactory
                    .createAuditfileCompanyCustomersSuppliersCustomerSupplierStreetAddress();
            customerAddress.setStreetname(customer.getAddress());
            customerAddress.setCity(customer.getCity());
            if (customer.getNumber() != null) {
                customerAddress.setNumber(customer.getNumber().toString());
            }
            customerAddress.setNumberExtension(customer.getNumberExtension());
            customerAddress.setPostalCode(customer.getPostalCode());
            customerAddress.setCountry(CountrycodeIso3166.NL);
            customerElement.getStreetAddress().add(customerAddress);
            customersElement.getCustomerSupplier().add(customerElement);
        }
        company.setCustomersSuppliers(customersElement);

        GeneralLedger generalLedger = objectFactory.createAuditfileCompanyGeneralLedger();

        for (CostType costType : costTypeCache.getCostTypes()) {
            LedgerAccount ledgerAccount = objectFactory.createAuditfileCompanyGeneralLedgerLedgerAccount();
            ExternalCostType externalCostType = costType.getExternalCostType();
            if (externalCostType != null) {
                ledgerAccount.setAccDesc(externalCostType.getDescription());
                ledgerAccount.setAccID(Long.toString(costType.getId()));
                if ("B".equals(externalCostType.getCode().substring(0, 1))) {
                    ledgerAccount.setAccTp(Accounttype.B);
                } else {
                    ledgerAccount.setAccTp(Accounttype.P);
                }
                ledgerAccount.setLeadCrossRef(externalCostType.getCode());
                generalLedger.getLedgerAccount().add(ledgerAccount);
            }
        }
        company.setGeneralLedger(generalLedger);

        OpeningBalance openingBalance = objectFactory.createAuditfileCompanyOpeningBalance();
        // company.setOpeningBalance(openingBalance);

        Periods periods = objectFactory.createAuditfileCompanyPeriods();
        Period period = objectFactory.createAuditfileCompanyPeriodsPeriod();
        period.setPeriodNumber(new BigInteger("1")); // referenced by
        // transactions
        period.setPeriodDesc("Period");
        periods.getPeriod().add(period);
        // company.setPeriods(periods);

        auditfile.setCompany(company);

        Header header = createHeader(costList, objectFactory);
        auditfile.setHeader(header);

        // Transactions
        Transactions transactions = objectFactory.createAuditfileCompanyTransactions();
        transactions.setLinesCount(new BigInteger(Long.toString(costList.size())));

        String currentKostenSoortOmschrijving = null;
        Journal journal = null;

        for (Cost cost : costList) {
            String kostenSoortOmschrijving = cost.getCostType().getOmschrijving();
            Transaction transaction = createTransaction(cost);
            if (!kostenSoortOmschrijving.equals(currentKostenSoortOmschrijving)) {
                currentKostenSoortOmschrijving = kostenSoortOmschrijving;
                if (journal != null) {
                    // Add the previous journal
                    transactions.getJournal().add(journal);
                }
                // Start a new journal
                journal = objectFactory.createAuditfileCompanyTransactionsJournal();
                ExternalCostType externalCostType = cost.getCostType().getExternalCostType();
                if (externalCostType != null) {
                    journal.setDesc(externalCostType.getDescription());
                    journal.setJrnID(externalCostType.getCode());
                }
                journal.setOffsetAccID(Long.toString(cost.getCostType().getId()));
            }
            journal.getTransaction().add(transaction);
        }
        if (journal != null) {
            transactions.getJournal().add(journal);
        }
        company.setTransactions(transactions);
        auditfile.setCompany(company);

        m.marshal(auditfile, writer);
        System.out.println(writer.toString());
        return writer.toString();
    } catch (Exception e) {
        e.printStackTrace();
    }
    return null;
}

From source file:org.tinymediamanager.core.movie.connector.MovieToKodiNfoConnector.java

static void writeNfoFiles(Movie movie, MovieToKodiNfoConnector kodi, List<MovieNfoNaming> nfoNames) {
    String nfoFilename = "";
    List<MediaFile> newNfos = new ArrayList<>(1);

    for (MovieNfoNaming name : nfoNames) {
        try {/* w w  w  .j a  v a 2s .com*/
            nfoFilename = movie.getNfoFilename(name);
            if (nfoFilename.isEmpty()) {
                continue;
            }

            Marshaller m = context.createMarshaller();
            m.setProperty(Marshaller.JAXB_ENCODING, "UTF-8");
            m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, Boolean.TRUE);

            Format formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            String dat = formatter.format(new Date());
            String comment = "<!-- created on " + dat + " - tinyMediaManager " + Globals.settings.getVersion()
                    + " -->\n";
            m.setProperty("com.sun.xml.internal.bind.xmlHeaders", comment);

            // w = new FileWriter(nfoFilename);
            Writer w = new StringWriter();
            m.marshal(kodi, w);
            StringBuilder sb = new StringBuilder(w.toString());
            w.close();

            // on windows make windows conform linebreaks
            if (SystemUtils.IS_OS_WINDOWS) {
                sb = new StringBuilder(sb.toString().replaceAll("(?<!\r)\n", "\r\n"));
            }
            Path f = movie.getPathNIO().resolve(nfoFilename);
            Utils.writeStringToFile(f, sb.toString());
            MediaFile mf = new MediaFile(f);
            mf.gatherMediaInformation(true); // force to update filedate
            newNfos.add(mf);
        } catch (Exception e) {
            LOGGER.error("setData " + movie.getPathNIO().resolve(nfoFilename), e);
            MessageManager.instance.pushMessage(new Message(MessageLevel.ERROR, movie, "message.nfo.writeerror",
                    new String[] { ":", e.getLocalizedMessage() }));
        }
    }

    if (newNfos.size() > 0) {
        movie.removeAllMediaFiles(MediaFileType.NFO);
        movie.addToMediaFiles(newNfos);
    }

}