コード例 #1
0
  private static void diffAll(
      String htmlOutputDir, String previousChangelist, String currentChangelist) throws Exception {
    ResultFileSetLoader loader = new ResultFileSetLoader();
    Map currentTests = loader.loadResultFiles(".");

    FileTestImporter imp = new FileTestImporter();
    Map previousTests = imp.getTestsForChangelist(previousChangelist);

    ArrayList diffs = new ArrayList(currentTests.keySet().size());
    Object[] keys = currentTests.keySet().toArray();
    Arrays.sort(keys);

    for (int i = 0; i < keys.length; i++) {
      String testFile = (String) keys[i];

      XMLResult previous = (XMLResult) previousTests.get(testFile);
      if (null == previous) {
        System.out.println("Null Test file: " + testFile);
        previous = new EmptyXMLResult(testFile);
        previousTests.put(testFile, previous);
      }
      previous.setChangelist(previousChangelist);
      XMLResult current = (XMLResult) currentTests.get(testFile);
      current.setChangelist(currentChangelist);
      ResultDiff diff = new ResultDiff(previous, current);
      diffs.add(diff);
    }

    String databaseType = System.getProperty("database.key");
    ReportIndex index = new ReportIndex(previousChangelist, currentChangelist, databaseType);
    XMLOutputter out = new XMLOutputter("  ", true);
    final String ACS_HOME = System.getProperty("ACS_HOME");
    Transformer tran =
        TransformerFactory.newInstance()
            .newTransformer(new StreamSource(ACS_HOME + "/test/xsl/junit.xsl"));
    for (Iterator iterator = diffs.iterator(); iterator.hasNext(); ) {
      ResultDiff resultDiff = (ResultDiff) iterator.next();
      index.addResult(resultDiff);

      String htmlFile = resultDiff.getAttributeValue("name") + ".html";
      FileWriter file = new FileWriter(htmlOutputDir + "/" + htmlFile);
      JDOMResult html = new JDOMResult();
      tran.transform(new JDOMSource(new Document(resultDiff)), html);
      out.output(html.getDocument(), file);
    }

    JDOMResult indexHtml = new JDOMResult();
    tran =
        TransformerFactory.newInstance()
            .newTransformer(new StreamSource(ACS_HOME + "/test/xsl/index.xsl"));
    tran.transform(new JDOMSource(new Document(index)), indexHtml);
    FileWriter indexFile = new FileWriter(htmlOutputDir + "/index.html");
    out.output(indexHtml.getDocument(), indexFile);

    out.output(
        new Document(index), new FileOutputStream("report_index_" + currentChangelist + ".xml"));
  }
コード例 #2
0
  protected <T> Document marshall(
      Class<T> marshalledObjectClass, String schemaPath, ServiceMessage message) {
    JDOMResult marshallResult = new JDOMResult();
    try {
      JAXBContext jaxbContext = JAXBContext.newInstance(marshalledObjectClass);
      Marshaller jaxbMarshaller = jaxbContext.createMarshaller();
      // SchemaFactory sf = SchemaFactory.newInstance( XMLConstants.W3C_XML_SCHEMA_NS_URI );
      // Schema schema = sf.newSchema( new URL( SCHEMA_PATH ) );
      // jaxbMarshaller.setSchema( schema );
      jaxbMarshaller.marshal(messageAsObject, marshallResult);
    } catch (Exception e) {
      throw new RuntimeException(e);
    }

    return marshallResult.getDocument();
  }
コード例 #3
0
ファイル: DifToArc.java プロジェクト: asascience-open/EDC
  protected List<Text> transform(Document doc, Document xsldoc) throws JDOMException {
    try {
      JDOMSource xslSource = new JDOMSource(xsldoc);

      Transformer transformer = TransformerFactory.newInstance().newTransformer(xslSource);

      JDOMSource in = new JDOMSource(doc);
      JDOMResult out = new JDOMResult();

      transformer.transform(in, out);

      return out.getResult();
    } catch (TransformerException e) {
      throw new JDOMException("XSLT Transformation failed", e);
    }
  }
コード例 #4
0
ファイル: Xml.java プロジェクト: fxprunayre/core-geonetwork
 /**
  * Transforms an xml tree into another using a stylesheet on disk and pass parameters.
  *
  * @param xml
  * @param styleSheetPath
  * @param params
  * @return
  * @throws Exception
  */
 public static Element transform(Element xml, String styleSheetPath, Map<String, String> params)
     throws Exception {
   JDOMResult resXml = new JDOMResult();
   transform(xml, styleSheetPath, resXml, params);
   return (Element) resXml.getDocument().getRootElement().detach();
 }