Ejemplo n.º 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;
  }
Ejemplo n.º 2
0
 public final String modelToXmlString() {
   TiersInformationsType object = (TiersInformationsType) this.modelToXml();
   XmlOptions opts = new XmlOptions();
   opts.setSavePrettyPrint();
   opts.setSavePrettyPrintIndent(4);
   opts.setUseDefaultNamespace();
   opts.setCharacterEncoding("UTF-8");
   return object.xmlText(opts);
 }
 @Override
 public final String modelToXmlString() {
   TechnicalInterventionRequestDocument object = this.modelToXml();
   XmlOptions opts = new XmlOptions();
   opts.setSavePrettyPrint();
   opts.setSavePrettyPrintIndent(4);
   opts.setUseDefaultNamespace();
   opts.setCharacterEncoding("UTF-8");
   return object.xmlText(opts);
 }
Ejemplo n.º 4
0
 /**
  * Generate the ExceptionReport as an XML string.
  *
  * @return the ExceptionReport as an XML string
  */
 public String getXMLExceptionReport() {
   Map<String, String> suggestedPrefixes = new HashMap<String, String>();
   suggestedPrefixes.put("http://www.opengis.net/ows/2.0", "ows");
   XmlOptions opts = new XmlOptions();
   opts.setSavePrettyPrint();
   opts.setSaveSuggestedPrefixes(suggestedPrefixes);
   opts.setSaveNamespacesFirst();
   opts.setSaveAggressiveNamespaces();
   opts.setUseDefaultNamespace();
   return exceptionReportDoc.xmlText(opts);
 }
Ejemplo n.º 5
0
  private void createConfigFile(
      String issuer,
      String nameQualifier,
      String ksType,
      String ksFile,
      String ksPassword,
      String privKeyAlias,
      String privKeyPassword,
      String certAlias)
      throws IOException {

    String SSO_CONFIG_FILE = "/WEB-INF/guanxi_idp/config/idp.xml";
    String KEYSTORE_KEY_TYPE = "dsa";

    IdpDocument idpDoc = null;
    try {
      idpDoc = IdpDocument.Factory.parse(new File(servletContext.getRealPath(SSO_CONFIG_FILE)));
    } catch (XmlException xe) {
      logger.error("Can't create config file", xe);
      return;
    }

    IdpDocument.Idp idp = idpDoc.getIdp();

    idp.getServiceProviderArray(0).setIdentity("exampleIdentity");
    idp.getServiceProviderArray(0).setCreds("exampleCreds");
    idp.getServiceProviderArray(0).setName("REPLACE_WITH_PROVIDER_ID_OF_SERVICE_PROVIDER");

    idp.getIdentityArray(0).setName("exampleIdentity");
    idp.getIdentityArray(0).setNameQualifier(nameQualifier);
    idp.getIdentityArray(0).setIssuer(issuer);

    idp.getCredsArray(0).setName("exampleCreds");
    idp.getCredsArray(0).setKeystoreType("jks");
    idp.getCredsArray(0).setKeyType(ksType);
    idp.getCredsArray(0).setKeystoreFile(ksFile);
    idp.getCredsArray(0).setKeystorePassword(ksPassword);
    idp.getCredsArray(0).setPrivateKeyAlias(privKeyAlias);
    idp.getCredsArray(0).setPrivateKeyPassword(privKeyPassword);
    idp.getCredsArray(0).setCertificateAlias(certAlias);
    idp.getCredsArray(0).setKeyType(KEYSTORE_KEY_TYPE);

    XmlOptions xmlOptions = new XmlOptions();
    xmlOptions.setSavePrettyPrint();
    xmlOptions.setSavePrettyPrintIndent(2);
    xmlOptions.setUseDefaultNamespace();

    idpDoc.save(new File(servletContext.getRealPath(SSO_CONFIG_FILE)), xmlOptions);

    servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_CONFIG_DOC, idpDoc);
    servletContext.setAttribute(Guanxi.CONTEXT_ATTR_IDP_CONFIG, idpDoc.getIdp());
  }
Ejemplo n.º 6
0
 public void saveConfiguration() {
   File file = getDefaultConfigurationFile();
   log.info("Storing current configuration in file: " + file.getAbsolutePath());
   try {
     XmlOptions opts = new XmlOptions();
     opts.setSavePrettyPrint();
     opts.setSavePrettyPrintIndent(4);
     configuration.save(file, opts);
   } catch (IOException e) {
     log.error("Unable to save the updated configuration in file: " + file.getAbsolutePath());
     throw new RuntimeException("Unable to save the updated configuration: " + e.getMessage());
   }
 }
  private File createXMLMetadata(HashMap<String, Object> inputs) {

    ArrayList<?> validationErrors = new ArrayList<Object>();
    XmlOptions options;
    options = new XmlOptions();
    options.setSavePrettyPrint();
    options.setSaveAggressiveNamespaces();

    HashMap<String, String> suggestedPrefixes = new HashMap<String, String>();
    suggestedPrefixes.put("http://www.geoviqua.org/QualityInformationModel/4.0", "gvq");
    options.setSaveSuggestedPrefixes(suggestedPrefixes);

    options.setErrorListener(validationErrors);

    GVQMetadataDocument doc = GVQMetadataDocument.Factory.newInstance();
    GVQMetadataType gvqMetadata = doc.addNewGVQMetadata();
    gvqMetadata.addNewLanguage().setCharacterString("en");
    gvqMetadata.addNewMetadataStandardName().setCharacterString("GVQ");
    gvqMetadata.addNewMetadataStandardVersion().setCharacterString("1.0.0");
    gvqMetadata.addNewDateStamp().setDate(Calendar.getInstance());
    DQDataQualityType quality = gvqMetadata.addNewDataQualityInfo2().addNewDQDataQuality();
    GVQDataQualityType gvqQuality =
        (GVQDataQualityType)
            quality.substitute(
                new QName("http://www.geoviqua.org/QualityInformationModel/4.0", "GVQ_DataQuality"),
                GVQDataQualityType.type);
    GVQDiscoveredIssueType issue = gvqQuality.addNewDiscoveredIssue().addNewGVQDiscoveredIssue();

    issue.addNewKnownProblem().setCharacterString(inputs.get("element").toString());
    issue.addNewWorkAround().setCharacterString("solution");

    // validate schema conformity
    boolean isValid = doc.validate();
    if (!isValid) System.out.println(Arrays.toString(validationErrors.toArray()));

    // print out as XML
    System.out.println(doc.xmlText(options));

    try {
      File tempFile = File.createTempFile("wpsMetdataTempFile", "xml");

      doc.save(tempFile);

      return tempFile;

    } catch (Exception e) {

      LOGGER.error("createXMLMetadataError " + e);
    }
    return null;
  }
Ejemplo n.º 8
0
  /**
   * Dumps an XML document to disk.
   *
   * @param doc The document to dump to disk
   * @param filePath The full path and name of the file
   */
  public static void dumpXML(XmlObject doc, String filePath) {
    HashMap<String, String> namespaces = new HashMap<String, String>();
    namespaces.put("http://www.w3.org/1999/02/22-rdf-syntax-ns#", "rdf");
    namespaces.put("http://www.nsdl.org/ontologies/relationships#", "myns");
    XmlOptions xmlOptions = new XmlOptions();
    xmlOptions.setSavePrettyPrint();
    xmlOptions.setSavePrettyPrintIndent(2);
    // xmlOptions.setUseDefaultNamespace();
    // xmlOptions.setSaveAggressiveNamespaces();
    xmlOptions.setSaveSuggestedPrefixes(namespaces);
    // xmlOptions.setSaveNamespacesFirst();

    try {
      doc.save(new File(filePath), xmlOptions);
    } catch (Exception e) {
    }
  }
Ejemplo n.º 9
0
 public ReginfoHandler() {
   _xmlOptions = new XmlOptions();
   _xmlOptions.setUseDefaultNamespace();
   _xmlOptions.setSavePrettyPrint();
 }
Ejemplo n.º 10
0
  private void createXML(Vector<Header> headers) {
    OrdersDocument ordsDoc = null;

    ordsDoc = OrdersDocument.Factory.newInstance();

    Orders orders = ordsDoc.addNewOrders();

    Enumeration<Header> e = headers.elements();
    while (e.hasMoreElements()) {
      Header header = e.nextElement();

      Order order = orders.addNewOrder();

      noNamespace.OrdersDocument.Orders.Order.Header xHeader = order.addNewHeader();
      if (!header.getNo().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setNumber(header.getNo());
        if ("WALMART.CA".equalsIgnoreCase(header.getNumber().trim())) {
          xHeader.setNumber(header.getRefNo());
        }
      }
      if (!header.getNumber().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setRefNo(header.getNumber());
      }
      if (!header.getPoNo().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setPoNo(header.getPoNo());
      }
      if (!header.getShipOn().equalsIgnoreCase("")) { // $NON-NLS-1$
        // no shipon data
      }
      if (!header.getComment().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setComment(header.getComment());
      }
      if (!header.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setContact(header.getContact());
      }
      if (!header.getShipVia().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setShipVia(header.getShipVia());
      }
      if (!header.getService().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setService(header.getService());
      }
      if (!header.getInvoice().equalsIgnoreCase("")) { // $NON-NLS-1$
        xHeader.setInvoice(header.getInvoice());
      }

      com.order.src.objects.SoldTo headerSoldTo = getSoldTo(header.getNo(), header.getNumber());
      // SoldTo Element
      if (headerSoldTo != null) {
        Soldto soldTo = xHeader.addNewSoldto();
        if (!headerSoldTo.getAddress1().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setAddress1(headerSoldTo.getAddress1());
        }
        if (!headerSoldTo.getAddress2().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setAddress2(headerSoldTo.getAddress2());
        }
        if (!headerSoldTo.getCity().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCity(headerSoldTo.getCity());
        }
        if (!headerSoldTo.getCode().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCode(header.getNumber().trim() + "_" + headerSoldTo.getCode()); // $NON-NLS-1$
        }
        if (!headerSoldTo.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setContact(headerSoldTo.getContact());
        }
        if (!headerSoldTo.getCountry().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setCountry(headerSoldTo.getCountry());
        }
        if (!headerSoldTo.getEmail().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setEmail(headerSoldTo.getEmail());
        }
        if (!headerSoldTo.getFax().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setFax(headerSoldTo.getFax());
        }
        if (!headerSoldTo.getName().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setName(headerSoldTo.getName());
        }
        if (!headerSoldTo.getPhone().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setPhone(headerSoldTo.getPhone());
        }
        if (!headerSoldTo.getPostal().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setPostal(headerSoldTo.getPostal());
        }
        if (!headerSoldTo.getProvince().equalsIgnoreCase("")) { // $NON-NLS-1$
          soldTo.setProvince(headerSoldTo.getProvince());
        } else {
          soldTo.setProvince("XX"); // $NON-NLS-1$
        }
      }

      com.order.src.objects.ShipTo headerShipTo = getShipTo(header.getNo());
      // SoldTo Element
      if (headerShipTo != null) {
        Shipto shipTo = xHeader.addNewShipto();
        if (!headerShipTo.getAddress1().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setAddress1(headerShipTo.getAddress1());
        }
        if (!headerShipTo.getAddress2().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setAddress2(headerShipTo.getAddress2());
        }
        if (!headerShipTo.getCity().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCity(headerShipTo.getCity());
        }
        if (!headerShipTo.getCode().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCode(header.getNumber().trim() + "_" + headerShipTo.getCode()); // $NON-NLS-1$
        }
        if (!headerShipTo.getContact().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setContact(headerShipTo.getContact());
        }
        if (!headerShipTo.getCountry().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setCountry(headerShipTo.getCountry());
        }
        if (!headerShipTo.getEmail().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setEmail(headerShipTo.getEmail());
        }
        if (!headerShipTo.getFax().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setFax(headerShipTo.getFax());
        }
        if (!headerShipTo.getName().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setName(headerShipTo.getName());
        }
        if (!headerShipTo.getPhone().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setPhone(headerShipTo.getPhone());
        }
        if (!headerShipTo.getPostal().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setPostal(headerShipTo.getPostal());
        }
        if (!headerShipTo.getProvince().equalsIgnoreCase("")) { // $NON-NLS-1$
          shipTo.setProvince(headerShipTo.getProvince());
        } else {
          shipTo.setProvince("XX"); // $NON-NLS-1$
        }
      }

      // Add Details
      addDetails(header.getNo(), order);
    }

    OrdersDocument ordsDoc_TOR = OrdersDocument.Factory.newInstance();
    Orders orders_TOR = ordsDoc_TOR.addNewOrders();

    OrdersDocument ordsDoc_I2I = OrdersDocument.Factory.newInstance();
    Orders orders_I2I = ordsDoc_I2I.addNewOrders();

    Order[] ordDoc_Order = ordsDoc.getOrders().getOrderArray();
    for (int i = 0; i < ordDoc_Order.length; i++) {
      String item = ordDoc_Order[i].getDetails().getLineArray(0).getItem();
      System.out.println("item: " + item);
      if (item.contains(S + TOR)) {
        // add to TOR orders_TOR
        Order order = orders_TOR.addNewOrder();
        order.set(ordDoc_Order[i]);
        Line[] order_lines = order.getDetails().getLineArray();
        for (int j = 0; j < order_lines.length; j++) {
          String order_item = order_lines[j].getItem();
          System.out.println("  order_item_tor:before: " + order_item);
          order_item = order_item.substring(0, order_item.indexOf(S));
          System.out.println("    order_item_tor:after: " + order_item);
          order_lines[j].setItem(order_item.trim());
        }
      } else {
        Order order = orders_I2I.addNewOrder();
        order.set(ordDoc_Order[i]);
        Line[] order_lines = order.getDetails().getLineArray();
        for (int j = 0; j < order_lines.length; j++) {
          String order_item = order_lines[j].getItem();
          System.out.println("  order_item_i2i:before: " + order_item);
          order_item = order_item.substring(0, order_item.indexOf(S));
          System.out.println("    order_item_i2i:after: " + order_item);
          order_lines[j].setItem(order_item.trim());
        }
      }
    }
    System.out.println("orders tor size " + ordsDoc_TOR.getOrders().getOrderArray().length);
    System.out.println("orders i2i size " + ordsDoc_I2I.getOrders().getOrderArray().length);

    String filename1 = ""; // $NON-NLS-1$
    String filename2 = "";
    DateFormat dateFormat = new SimpleDateFormat("yyyyMMdd_HHmm"); // $NON-NLS-1$
    java.util.Date date = new java.util.Date();
    filename1 =
        "ORD" + TOR + "_" + dateFormat.format(date) + "_orders.xml"; // $NON-NLS-1$ //$NON-NLS-2$
    filename2 =
        "ORD" + I2I + "_" + dateFormat.format(date) + "_orders.xml"; // $NON-NLS-1$ //$NON-NLS-2$

    // System.out.println(ordsDoc.toString());
    System.out.println("XML Generated is Valid TOR: " + ordsDoc_TOR.validate()); // $NON-NLS-1$
    System.out.println("XML Generated is Valid I2I: " + ordsDoc_I2I.validate()); // $NON-NLS-1$
    System.out.println(
        "Writing to File: " + Messages.getString("directory") + filename1); // $NON-NLS-1$
    System.out.println(
        "Writing to File: " + Messages.getString("directory") + filename2); // $NON-NLS-1$
    XmlOptions option = new XmlOptions();
    option.setSavePrettyPrint();
    try {
      ordsDoc_TOR.save(
          new File(Messages.getString("directory") + filename1), option); // $NON-NLS-1$
      ordsDoc_I2I.save(
          new File(Messages.getString("directory") + filename2), option); // $NON-NLS-1$
    } catch (IOException e1) {
      e1.printStackTrace();
    }

    ftpFile(ordsDoc_TOR, filename1, TOR);
    ftpFile(ordsDoc_I2I, filename2, I2I);

    System.out.println("The end"); // $NON-NLS-1$
  }