コード例 #1
0
  /**
   * Setup the UserAgent for FOP, from given parameters *
   *
   * @param transformer Created based on the XSLT, so containing any parameters to the XSL-FO
   *     specified in the XQuery
   * @param parameters any user defined parameters to the XSL-FO process
   * @return FOUserAgent The generated FOUserAgent to include any parameters passed in
   */
  private FOUserAgent setupFOUserAgent(
      FOUserAgent foUserAgent, Properties parameters, Transformer transformer)
      throws TransformerException {

    // setup the foUserAgent as per the parameters given
    foUserAgent.setProducer("eXist with Apache FOP");

    if (transformer.getParameter("FOPauthor") != null)
      foUserAgent.setAuthor(parameters.getProperty("author"));

    if (transformer.getParameter("FOPtitle") != null)
      foUserAgent.setTitle(parameters.getProperty("title"));

    if (transformer.getParameter("FOPkeywords") != null)
      foUserAgent.setTitle(parameters.getProperty("keywords"));

    if (transformer.getParameter("FOPdpi") != null) {
      String dpiStr = (String) transformer.getParameter("dpi");
      try {
        foUserAgent.setTargetResolution(Integer.parseInt(dpiStr));
      } catch (NumberFormatException nfe) {
        throw new TransformerException(
            "Cannot parse value of \"dpi\" - " + dpiStr + " to configure FOUserAgent");
      }
    }

    return foUserAgent;
  }
コード例 #2
0
  /**
   * @see Results
   * @param targetResolution The Target Output Resolution.
   * @param ff The FopFactory used to create the FOUserAgent used to convert.
   * @param xmlSource XML file to be used in conversion.
   * @param xsltSource XSLT file to be used in translation.
   * @return A Result Class containing the conversion results
   */
  public static Results translate(
      int targetResolution, FopFactory ff, Source xmlSource, Source xsltSource) {

    FOUserAgent fua = getFopUserAgent(ff);
    fua.setTargetResolution(targetResolution);

    return translate(fua, xmlSource, xsltSource);
  }