Example #1
1
  /**
   * Serialize Maven POM object tree.
   *
   * @param outputStream
   */
  public void serialize(Project project, OutputStream outputStream) {
    StreamResult stream = new StreamResult(outputStream);

    Map<String, Object> marshallerProperties = new HashMap<String, Object>();
    marshallerProperties.put(Marshaller.JAXB_FORMATTED_OUTPUT, true);
    marshallerProperties.put(Marshaller.JAXB_NO_NAMESPACE_SCHEMA_LOCATION, "");

    marshaller.setMarshallerProperties(marshallerProperties);
    marshaller.marshal(project, stream);
  }
Example #2
0
  private byte[] createMasseutsendelse(MessageBatch messageBatch) {
    XmlMasseutsendelse xml =
        MasseutsendelseBuilder.newMasseutsendelse()
            .withAvsender(config.getSenderId())
            .withJobbId(messageBatch.digipostJobbId)
            .withRecipients(messageBatch.getMessages())
            .build();

    ByteArrayOutputStream baos = new ByteArrayOutputStream();
    marshaller.marshal(xml, new StreamResult(baos));
    return baos.toByteArray();
  }
  @Test
  public void JaxbGet03Test() {
    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomResponseHead erh = new EvcomResponseHead(324, 234, "cid string", 234, "rms string", 2989);

    GET03 erb = new GET03();

    EvcomResGet03 ergprm03 = new EvcomResGet03(erh, erb);

    jaxb2Marshaller.setClassesToBeBound(EvcomResGet03.class, EvcomResponseHead.class, GET03.class);

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(ergprm03, result);
  }
  private String newXML(IdentifiedObject resource)
      throws DatatypeConfigurationException, FeedException {
    ByteArrayOutputStream os = new ByteArrayOutputStream();
    EntryType entry = new EntryType();
    entry.getLinks().add(new LinkType(LinkType.SELF, "self"));
    entry.setTitle("entry");
    entry.setId("id");
    entry.setPublished(new DateTimeType());
    entry.setUpdated(new DateTimeType());
    ContentType content = new ContentType();
    content.setResources(Lists.<IdentifiedObject>newArrayList(resource));
    entry.setContent(content);

    fragmentMarshaller.marshal(entry, new StreamResult(os));

    return os.toString();
  }
  @Test
  public void JaxbPos14Test() {

    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomRequestHead erh = new EvcomRequestHead(32423423, 234, "cid string", 234, 2989);

    StringReader reader =
        new StringReader(
            "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n"
                + "<evcom>\n"
                + "<hd>\n"
                + " <stm v=\"20151126105322\"/>\n"
                + " <sid v=\"2\"/>\n"
                + " <cid v=\"01\"/>\n"
                + " <sts v=\"111111\"/>\n"
                + " <tid v=\"2323\"/>\n"
                + "</hd>\n"
                + "<bd>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"완속 1\"/>\n"
                + "    <ver v=\"fw ver 1.2\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"급속 2\"/>\n"
                + "    <ver v=\"fw ver 0.8\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"완속 2\"/>\n"
                + "    <ver v=\"fw ver 1.5\"/>\n"
                + "  </pg>\n"
                + "  <pg>\n"
                + "    <pg_knd v=\"급속 1\"/>\n"
                + "    <ver v=\"fw ver 0.8.1\"/>\n"
                + "  </pg>\n"
                + "</bd>\n"
                + "</evcom>");
    EvcomReqPos14 pos14 = (EvcomReqPos14) jaxb2Marshaller.unmarshal(new StreamSource(reader));

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(pos14, result);
  }
  @Test
  public void JaxbGet01Test() {
    Jaxb2Marshaller jaxb2Marshaller = (Jaxb2Marshaller) context.getBean("getJaxb2Marshaller");

    EvcomResponseHead erh = new EvcomResponseHead(324, 234, "cid string", 234, "rms string", 2989);

    GET01 erb = new GET01(123423, 2343, "ccfg");
    List<PRM> leip = new ArrayList<>();
    leip.add(new EIP("eip value"));
    leip.add(new EPT("ept value"));
    leip.add(new VIP("vip value"));
    leip.add(new VPT("vpp value"));
    erb.setPrm(leip);

    EvcomResGet01 ergprm = new EvcomResGet01(erh, erb);

    jaxb2Marshaller.setClassesToBeBound(EvcomResGet01.class, EvcomResponseHead.class, GET01.class);

    StreamResult result = new StreamResult(System.out);
    jaxb2Marshaller.marshal(ergprm, result);
  }
  @Test
  public void marshallTest()
      throws TransformerConfigurationException, TransformerException,
          TransformerFactoryConfigurationError {
    Job job = new Job();
    job.setSessionId(1);
    job.setName("Test");
    job.setDescription("Test Desc");

    List<Integer> start = new ArrayList<Integer>();
    start.add(1);
    start.add(2);

    job.setFirst(start);

    List<Integer> end = new ArrayList<Integer>();
    end.add(1);
    end.add(2);

    job.setLast(end);

    List<JobTask> tasks = new ArrayList<JobTask>();
    tasks.add(new JobTask(1, 1, "source/file/path", "result/file/path"));
    tasks.add(new JobTask(2, 1, "source/file/path", "result/file/path"));
    tasks.add(new JobTask(3, 1, "source/file/path", "result/file/path"));

    job.setTasks(tasks);

    DOMResult result = new DOMResult();
    marshaller.marshal(job, result);

    StringWriter writer = new StringWriter();
    TransformerFactory.newInstance()
        .newTransformer()
        .transform(new DOMSource(result.getNode()), new StreamResult(writer));

    String textResult = writer.toString();

    assertNotNull(textResult);
  }