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:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Messages.class);

    Messages messages = new Messages();
    messages.getMessages().add(new Message());
    messages.getMessages().add(new Message());
    messages.getMessages().add(new Message());

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.setAdapter(new IDAdapter());
    marshaller.marshal(messages, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Root.class);
    Unmarshaller unmarshaller = jc.createUnmarshaller();
    File xml = new File("input.xml");
    Root root = (Root) unmarshaller.unmarshal(xml);

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(root, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Compound.class);

    Unmarshaller unmarshaller = jc.createUnmarshaller();
    Compound compound = (Compound) unmarshaller.unmarshal(new File("input.xml"));
    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(compound, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    Main customer = new Main();
    customer.setId(100);//from   ww  w . j  a  va2 s.c  om
    customer.setName("java2s.com");
    customer.setAge(29);

    File file = new File("file.xml");
    JAXBContext jaxbContext = JAXBContext.newInstance(Main.class);
    Marshaller jaxbMarshaller = jaxbContext.createMarshaller();

    jaxbMarshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    jaxbMarshaller.marshal(customer, file);
    jaxbMarshaller.marshal(customer, System.out);

}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Parent.class, IntegerChild.class, StringChild.class);

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    IntegerChild integerChild = new IntegerChild();
    integerChild.getItem().add(1);//from   w w  w  . j  ava 2s. com
    integerChild.getItem().add(2);
    marshaller.marshal(integerChild, System.out);

    StringChild stringChild = new StringChild();
    stringChild.getItem().add("A");
    stringChild.getItem().add("B");
    marshaller.marshal(stringChild, System.out);
}

From source file:Main.java

public static void main(String[] args) throws JAXBException {
    JAXBContext context = JAXBContext.newInstance(Vehicals.class);
    Marshaller m = context.createMarshaller();
    m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);

    Vehicals vehicals = new Vehicals();

    List<Car> cars = new ArrayList<Car>();
    Car c = new Car();
    c.setName("Mercedes");
    cars.add(c);/*from w ww  .  j av a 2  s  . c o m*/

    c = new Car();
    c.setName("BMW");
    cars.add(c);
    vehicals.setCar(cars);
    m.marshal(vehicals, System.out);
}

From source file:AuthenticationHeader.java

public static void main(String[] args) {

    try {//  w  w w.j a v a  2  s.co  m
        URL marketoSoapEndPoint = new URL("CHANGE ME" + "?WSDL");
        String marketoUserId = "CHANGE ME";
        String marketoSecretKey = "CHANGE ME";

        QName serviceName = new QName("http://www.marketo.com/mktows/", "MktMktowsApiService");
        MktMktowsApiService service = new MktMktowsApiService(marketoSoapEndPoint, serviceName);
        MktowsPort port = service.getMktowsApiSoapPort();

        // Create Signature
        DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ssZ");
        String text = df.format(new Date());
        String requestTimestamp = text.substring(0, 22) + ":" + text.substring(22);
        String encryptString = requestTimestamp + marketoUserId;

        SecretKeySpec secretKey = new SecretKeySpec(marketoSecretKey.getBytes(), "HmacSHA1");
        Mac mac = Mac.getInstance("HmacSHA1");
        mac.init(secretKey);
        byte[] rawHmac = mac.doFinal(encryptString.getBytes());
        char[] hexChars = Hex.encodeHex(rawHmac);
        String signature = new String(hexChars);

        // Set Authentication Header
        AuthenticationHeader header = new AuthenticationHeader();
        header.setMktowsUserId(marketoUserId);
        header.setRequestTimestamp(requestTimestamp);
        header.setRequestSignature(signature);

        JAXBContext context = JAXBContext.newInstance(AuthenticationHeader.class);
        Marshaller m = context.createMarshaller();
        m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
        m.marshal(header, System.out);

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

From source file:Person1Test.java

public static void main(String[] args) throws JAXBException {
    Person person = new Person();
    person.setFirstName("L");
    person.setLastName("H");

    JAXBContext context = JAXBContext.newInstance(Person.class);
    Marshaller marshaller = context.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(person, System.out);
}

From source file:Main.java

public static void main(String[] args) throws Exception {
    JAXBContext jc = JAXBContext.newInstance(Foo.class);

    Foo foo = new Foo();
    List<Bar> bars = new ArrayList<Bar>();
    foo.setBars(bars);// www .  ja v  a2s.co m

    Bar<String> stringBar = new Bar<String>();
    stringBar.setValue("string data");
    bars.add(stringBar);

    Bar<byte[]> binaryBar = new Bar<byte[]>();
    binaryBar.setValue("binary data".getBytes());
    bars.add(binaryBar);

    Marshaller marshaller = jc.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(foo, System.out);
}

From source file:JAXBTest.java

public static void main(String[] args) throws JAXBException {
    JAXBContext jaxbContext = JAXBContext.newInstance(Root.class);
    Root root = new Root();

    Person fred = new Person();
    fred.setName("Fred");
    root.setFriend(Arrays.asList(fred));

    Thing xbox = new Thing();
    xbox.setDescription("Xbox 360");
    root.setStuff(Arrays.asList(xbox));

    Marshaller marshaller = jaxbContext.createMarshaller();
    marshaller.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshaller.marshal(root, System.out);
}