Esempio n. 1
0
  /**
   * Writes the model to DOT.
   *
   * @param bw The writer
   * @throws IOException If writing fails
   */
  public void writeToDot(Writer bw) throws IOException {
    // super.writeToDot(bw);

    // Preamble of dot file
    bw.write(
        "digraph G {ranksep=\".3\"; fontsize=\"8\"; remincross=true; margin=\"0.0,0.0\"; rankdir=TB; ");
    bw.write("fontname=\"Arial\"; \n");
    bw.write("edge [arrowsize=\"0.5\"];\n");
    bw.write("node [fontname=\"Arial\",fontsize=\"8\"];\n");

    // Add the Data Element nodes
    Iterator it = getVerticeList().iterator();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof PDMDataElement) {
        ((PDMDataElement) object).writeToDot(bw, this);
      }
    }

    // Add all edges
    it = operations.values().iterator();
    while (it.hasNext()) {
      Object object = it.next();
      if (object instanceof PDMOperation) {
        ((PDMOperation) object).writeToDot(bw, this);
      }
    }

    bw.write("\n}\n");
  }
Esempio n. 2
0
 public static String formatDoc(Document document) {
   try {
     OutputFormat format = new OutputFormat(document);
     format.setLineWidth(65);
     format.setIndenting(true);
     format.setIndent(2);
     Writer out = new StringWriter();
     XMLSerializer serializer = new XMLSerializer(out, format);
     serializer.serialize(document);
     System.out.println(out.toString());
     return out.toString();
   } catch (IOException e) {
     log.error("XmlWorks::formatDoc()", e);
     throw new RuntimeException(e);
   }
 }
Esempio n. 3
0
  /**
   * XMLをファイルに出力する。
   *
   * @param my_doc XMLの Document Node 。
   * @param os 出力先のストリーム。
   * @param sortflag ソートするか否か。
   */
  public static void output(Document my_doc, OutputStream os, boolean sortflag, UDF_Env env) {
    if (sortflag) {
      try {
        com.udfv.util.UDF_XML.sortDocumentbyEnv(my_doc, env);
      } catch (Exception e1) {
        e1.printStackTrace();
      }
    }

    try {
      OutputFormat format = new OutputFormat(my_doc, "UTF-8", true);
      format.setLineWidth(0);
      //            Writer out = new OutputStreamWriter(new FileOutputStream(file), "UTF-8");
      Writer out = new OutputStreamWriter(os, "UTF-8");
      XMLSerializer serial = new XMLSerializer(out, format);
      serial.serialize(my_doc.getDocumentElement());
      out.close();
    } catch (Exception e2) {
      e2.printStackTrace();
    }
  }
Esempio n. 4
0
 /**
  * Export to PDM file.
  *
  * @param bw Writer
  * @throws IOException If writing fails
  */
 public void writeToPDM(Writer bw) throws IOException {
   bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
   bw.write("<PDM\n");
   bw.write("\txmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n");
   bw.write(
       "\txsi:noNamespaceSchemaLocation=\"C:/Documents and Settings/ivdfeest/My Documents/Implementatie/PDM.xsd\"\n");
   bw.write(">\n");
   Iterator it = dataElements.values().iterator();
   while (it.hasNext()) {
     PDMDataElement dataElement = (PDMDataElement) it.next();
     dataElement.writeToPDM(bw);
   }
   Iterator it2 = resources.values().iterator();
   while (it2.hasNext()) {
     PDMResource resource = (PDMResource) it.next();
     resource.writeToPDM(bw);
   }
   Iterator it3 = operations.values().iterator();
   while (it3.hasNext()) {
     PDMOperation operation = (PDMOperation) it.next();
     operation.writeToPDM(bw);
   }
   bw.write("</PDM>\n");
 }
 public static void main(String args[]) {
   try {
     SeleniumHtmlClient client = new SeleniumHtmlClient();
     String testFile = null;
     String testSuite = null;
     String resultsFilename = null;
     for (int i = 0; i < args.length; i++) {
       if (args[i].equals("--host")) {
         i++;
         if (i < args.length) {
           client.setHost(args[i]);
         } else {
           throw new BadUsageException("--host must be followed by a hostname");
         }
       } else if (args[i].equals("--port")) {
         i++;
         if (i < args.length) {
           client.setPort(Integer.parseInt(args[i]));
         } else {
           throw new BadUsageException("--port must be followed by a port number");
         }
       } else if (args[i].equals("--browser")) {
         i++;
         if (i < args.length) {
           client.setBrowser(args[i]);
         } else {
           throw new BadUsageException("--browser must be followed by a browser spec");
         }
       } else if (args[i].equals("--out")) {
         i++;
         if (i < args.length) {
           resultsFilename = args[i];
         } else {
           throw new BadUsageException("--out must be followed by a filename");
         }
         /*
         } else if (args[i].equals("--outdir")) {
         	i++;
         	if (i < args.length) {
         		client.setResultsDir(new File(args[i]));
         	} else {
         		throw new BadUsageException("--outdir must be followed by a path");
         	}
         	*/
       } else if (args[i].equals("--baseurl")) {
         i++;
         if (i < args.length) {
           client.setBaseUrl(args[i]);
         } else {
           throw new BadUsageException("--baseurl must be followed by a URL");
         }
       } else if (args[i].equals("--test")) {
         i++;
         if (i < args.length) {
           if (testFile == null) {
             testFile = args[i];
           } else {
             throw new BadUsageException("only one test file permitted");
           }
         } else {
           throw new BadUsageException("--test must be followed by a test filepath");
         }
       } else if (args[i].equals("--testsuite")) {
         i++;
         if (i < args.length) {
           testSuite = args[i];
         } else {
           throw new BadUsageException("--testsuite must be followed by a testsuite filepath");
         }
       } else if (args[i].equals("--verbose") || args[i].equals("-v")) {
         client.setVerbose(true);
       } else if (args[i].equals("--help") || args[i].equals("-h")) {
         printUsage();
         System.exit(0);
       } else {
         throw new BadUsageException("Unknown parameter " + args[i]);
       }
     }
     if (testFile == null && testSuite == null) {
       throw new BadUsageException("No test or testsuite file specified");
     } else if (testFile != null && testSuite != null) {
       throw new BadUsageException("A test and testsuite file cannot both be specified");
     }
     Writer resultsWriter = null;
     if (resultsFilename != null) {
       resultsWriter = new FileWriter(resultsFilename);
     } else /* if (client.resultsDir == null) */ {
       resultsWriter = new OutputStreamWriter(System.out);
     }
     client.setResultsWriter(resultsWriter);
     if (testFile != null) {
       client.runTest(testFile);
     } else {
       client.runSuite(testSuite);
     }
     if (resultsWriter != null) resultsWriter.close();
   } catch (BadUsageException e) {
     System.err.println("Error: " + e.getMessage());
     System.err.println();
     printUsage();
     System.exit(1);
   } catch (Exception e) {
     e.printStackTrace();
     System.exit(1);
   }
 }
Esempio n. 6
0
  public void serializeNode(Node node, Writer writer, String indentLevel) throws IOException {
    // Determine action based on node type
    switch (node.getNodeType()) {
      case Node.DOCUMENT_NODE:
        writer.write("<?xml version = '1.0'?>"); // "<xml version=\"1.0\">");
        writer.write(lineSeparator);
        // recurse on each child
        NodeList nodes = node.getChildNodes();
        if (nodes != null) {
          for (int i = 0; i < nodes.getLength(); i++) {
            serializeNode(nodes.item(i), writer, "");
          }
        }

        /*
         *  Document doc = (Document)node;
         *  serializeNode(doc.getDocumentElement( ), writer, " ");
         */
        break;
      case Node.ELEMENT_NODE:
        String name = node.getNodeName();
        writer.write(indentLevel + "<" + name);
        NamedNodeMap attributes = node.getAttributes();
        for (int i = 0; i < attributes.getLength(); i++) {
          Node current = attributes.item(i);
          writer.write(" " + current.getNodeName() + "=\"" + current.getNodeValue() + "\"");
        }
        writer.write(">");
        // recurse on each child
        NodeList children = node.getChildNodes();
        if (children != null) {
          if ((children.item(0) != null) && (children.item(0).getNodeType() == Node.ELEMENT_NODE)) {
            writer.write(lineSeparator);
          }
          for (int i = 0; i < children.getLength(); i++) {
            serializeNode(children.item(i), writer, indentLevel + indent);
          }
          if ((children.item(0) != null)
              && (children.item(children.getLength() - 1).getNodeType() == Node.ELEMENT_NODE)) {
            writer.write(indentLevel);
          }
        }
        writer.write("</" + name + ">");
        writer.write(lineSeparator);
        break;
      case Node.TEXT_NODE:
        writer.write(node.getNodeValue());
        break;
      case Node.CDATA_SECTION_NODE:
        writer.write("<![CDATA[" + node.getNodeValue() + "]]>");
        break;
      case Node.COMMENT_NODE:
        writer.write(indentLevel + "<!-- " + node.getNodeValue() + " -->");
        writer.write(lineSeparator);
        break;
      case Node.PROCESSING_INSTRUCTION_NODE:
        writer.write("<?" + node.getNodeName() + " " + node.getNodeValue() + "?>");
        writer.write(lineSeparator);
        break;
      case Node.ENTITY_REFERENCE_NODE:
        writer.write("&" + node.getNodeName() + ";");
        break;
      case Node.DOCUMENT_TYPE_NODE:
        DocumentType docType = (DocumentType) node;
        writer.write("<!DOCTYPE " + docType.getName());
        if (docType.getPublicId() != null) {
          System.out.print(" PUBLIC \"" + docType.getPublicId() + "\" ");
        } else {
          writer.write(" SYSTEM ");
        }
        writer.write("\"" + docType.getSystemId() + "\">");
        writer.write(lineSeparator);
        break;
    }
  }
Esempio n. 7
0
 public void serialize(Document doc, Writer writer) throws IOException {
   // Start serialization recursion with no indenting
   serializeNode(doc, writer, "");
   writer.flush();
 }
Esempio n. 8
0
  /**
   * Export PDM model to Declare process model.
   *
   * @param bw Writer
   * @throws IOException If writing fails
   */
  public void writePDMToDeclare(Writer bw) throws IOException {
    // write the preamble of the XML file
    bw.write("<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n");
    bw.write("<model>\n");
    bw.write("<assignment language=\"ConDec\" name=\"" + name + "\">\n");

    // write the activity definitions, i.e. each operation in the PDM is an
    // activity definition in Declare
    bw.write("<activitydefinitions>\n");
    // start with an initial activity that puts the values for the leaf
    // elements of the PDM
    bw.write("<activity id=\"Initial\" name=\"Initial\">\n");
    bw.write("<authorization/>\n");
    bw.write("<datamodel>\n");
    // all leaf elements
    HashMap leafs = getLeafElements();
    Object[] leafElts = leafs.values().toArray();
    for (int i = 0; i < leafElts.length; i++) {
      PDMDataElement data = (PDMDataElement) leafElts[i];
      data.writePDMToDeclare(bw, "output");
    }
    bw.write("</datamodel>\n");
    bw.write("<attributes/>\n");
    bw.write("</activity>\n");

    // first remove input operations from the set of operations and then
    // write all real operations
    HashMap realOps = (HashMap) operations.clone();
    HashSet inputOps = getLeafOperations();
    Iterator it7 = inputOps.iterator();
    while (it7.hasNext()) {
      PDMOperation op = (PDMOperation) it7.next();
      realOps.remove(op.getID());
    }
    Iterator it4 = realOps.values().iterator();
    while (it4.hasNext()) {
      PDMOperation operation = (PDMOperation) it4.next();
      operation.writePDMToDeclare(bw);
    }
    bw.write("\n");
    // write all input operations (i.e. producing input data elements)
    Iterator it8 = inputOps.iterator();
    while (it8.hasNext()) {
      PDMOperation op = (PDMOperation) it8.next();
      op.writePDMToDeclare(bw);
    }

    bw.write("</activitydefinitions>\n");

    // write the constraint definition, for now we do not have any
    // constraints in the PDM that are translated to Declare
    bw.write("<constraintdefinitions>\n");
    bw.write("</constraintdefinitions>\n");

    // write all dataelements
    bw.write("<data>\n");
    Iterator it5 = dataElements.values().iterator();
    while (it5.hasNext()) {
      PDMDataElement dataElement = (PDMDataElement) it5.next();
      dataElement.writePDMToDeclare(bw);
    }
    bw.write("</data>\n");

    // write the organizational information
    bw.write("<team/>\n");

    // TODO: improve graphical positioning of activities. Now they are
    // presented in one long line.
    // write the graphical positioning information of the Declare model,
    // first the initial operation, then the real operations and then the
    // input operations.
    bw.write("<graphical>\n");
    bw.write("<cells>\n");
    Iterator it6 = realOps.values().iterator();
    Double pos = 10.0;
    while (it6.hasNext()) {
      PDMOperation operation = (PDMOperation) it6.next();
      bw.write(
          "<cell activitydefinition=\""
              + operation.getOperationNR()
              + "\" height=\"40.0\" width=\"80.0\" x=\""
              + pos
              + "\" y=\"90.0\" />\n");
      pos = pos + 85.0;
    }
    Iterator it9 = inputOps.iterator();
    pos = 10.0;
    while (it9.hasNext()) {
      PDMOperation operation = (PDMOperation) it9.next();
      bw.write(
          "<cell activitydefinition=\""
              + operation.getOperationNR()
              + "\" height=\"40.0\" width=\"80.0\" x=\""
              + pos
              + "\" y=\"180.0\" />\n");
      pos = pos + 85.0;
    }

    bw.write("</cells>\n");

    // write the connectors
    bw.write("<connectors/>\n");
    // close the XML file in the right way
    bw.write("</graphical>\n");
    bw.write("</assignment>\n");
    bw.write("</model>\n");
  }