Example #1
0
  private byte[] generateXml(
      Integer demographicNo, Integer rourkeFdid, Integer nddsFdid, Integer report18mFdid) {
    HashMap<String, String> suggestedPrefixes = new HashMap<String, String>();
    suggestedPrefixes.put("http://www.w3.org/2001/XMLSchema-instance", "xsi");
    XmlOptions opts = new XmlOptions();
    opts.setSaveSuggestedPrefixes(suggestedPrefixes);
    opts.setSavePrettyPrint();
    opts.setSaveNoXmlDecl();
    opts.setUseDefaultNamespace();
    opts.setSaveNamespacesFirst();
    ByteArrayOutputStream os = null;
    PrintWriter pw = null;
    boolean xmlCreated = false;

    BORN18MFormToXML xml = new BORN18MFormToXML(demographicNo);
    try {
      os = new ByteArrayOutputStream();
      pw = new PrintWriter(os, true);
      pw.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
      xmlCreated = xml.addXmlToStream(pw, opts, rourkeFdid, nddsFdid, report18mFdid);

      pw.close();
      if (xmlCreated) return os.toByteArray();
    } catch (Exception e) {
      logger.warn("Unable to add record", e);
    }

    return null;
  }
  @Override
  public InputStream generateStream(IData data, String mimeType, String schema) throws IOException {

    if (data instanceof GenericXMLDataBinding) {

      XmlObject xmlData = ((GenericXMLDataBinding) data).getPayload();

      XmlOptions xmlOptions = new XmlOptions();

      xmlOptions.setSaveNoXmlDecl();

      return xmlData.newInputStream(xmlOptions);
    }

    return XmlObject.Factory.newInstance().newInputStream();
  }