@SuppressWarnings("unchecked")
  protected static List runSmooksTransform() throws IOException, SAXException, SmooksException {

    Smooks smooks = new Smooks();

    try {
      // ****
      // And here's the configuration... configuring the CSV reader and
      // the direct
      // binding config to create a List of Person objects
      // (List<Person>)...
      // ****
      smooks.setReaderConfig(
          new CSVReaderConfigurator("firstName,lastName,gender,age,country")
              .setBinding(new CSVBinding("customerList", Customer.class, CSVBindingType.LIST)));

      // Configure the execution context to generate a report...
      ExecutionContext executionContext = smooks.createExecutionContext();
      executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html"));

      JavaResult javaResult = new JavaResult();
      smooks.filterSource(executionContext, new StringSource(messageIn), javaResult);

      return (List) javaResult.getBean("customerList");
    } finally {
      smooks.close();
    }
  }
Пример #2
0
  /**
   * Run the transform for the request or response.
   *
   * @param inputJavaObject The input Java Object.
   * @return The transformed Java Object XML.
   */
  public String runSmooksTransform(Object inputJavaObject, String configFile)
      throws IOException, SAXException {
    Smooks smooks = new Smooks(configFile);
    String resultString = new String();
    try {
      ExecutionContext executionContext = smooks.createExecutionContext();
      StringWriter writer = new StringWriter();

      // Configure the execution context to generate a report...
      // executionContext.setEventListener(new HtmlReportGenerator("target/report/report.html"));

      // Filter the message to the result writer, using the execution context...
      smooks.filterSource(
          executionContext, new JavaSource(inputJavaObject), new StreamResult(writer));
      resultString = writer.toString();
      /*            resultString = this.replace(resultString, "list", "ResultSet");
                  resultString = this.replace(resultString, "<id>", "<GeneID type='entrez'>");
                  resultString = this.replace(resultString, "</id>", "</GeneID>");
                  resultString = this.replace(resultString, "<symbol>", "<GeneSymbol>");
                  resultString = this.replace(resultString, "</symbol>", "</GeneSymbol>");
                  resultString = this.replace(resultString, "org.ncibi.mimiweb.data.ResultGeneMolecule", "Result");
                  resultString = this.replace(resultString, "<taxid>", "<TaxonomyID>");
                  resultString = this.replace(resultString, "</taxid>", "</TaxonomyID>");
                  resultString = this.replace(resultString, "<description>", "<GeneDescription>");
                  resultString = this.replace(resultString, "</description>", "</GeneDescription>");
                  resultString = this.replace(resultString, "interactionGeneIds", "InteractingGeneIDSet");
                  resultString = this.replace(resultString, "<int>", "<GeneID type='entrez'>");
                  resultString = this.replace(resultString, "</int>", "</GeneID>");
                  resultString = this.replace(resultString, "interactionGeneSymbols", "InteractingGeneSymbolSet");
      */
      return resultString;

    } finally {
      smooks.close();
    }
  }