public void format(XdmNode doc, OutputStream out, String contentType) {
        String outputFormat = null;
        if (contentType == null || "application/pdf".equalsIgnoreCase(contentType)) {
            outputFormat = "application/pdf"; // "PDF";
        } else if ("application/PostScript".equalsIgnoreCase(contentType)) {
            outputFormat = "application/postscript"; //"PostScript";
        } else if ("application/afp".equalsIgnoreCase(contentType)) {
            outputFormat =  "application/x-afp";  //"AFP";
        } else if ("application/rtf".equalsIgnoreCase(contentType)) {
            outputFormat = "application/rtf";
        } else if ("text/plain".equalsIgnoreCase(contentType)) {
           outputFormat = "text/plain";
        } else {
            throw new XProcException(step.getNode(), "Unsupported content-type on p:xsl-formatter: " + contentType);
        }
        if (! ("1.x".equals(fopVersion) || "2.x".equals(fopVersion))) {
            throw new XProcException("Unexpected FOP version: " + fopVersion);
        }
        try {
            InputSource fodoc = S9apiUtils.xdmToInputSource(runtime, doc);
            SAXSource source = new SAXSource(fodoc);
            Object userAgent = null;
            Object fop = null;
            if ("1.x".equals(fopVersion)) {
                method = fopFactory.getClass().getMethod("newFop", String.class, OutputStream.class);
                fop = method.invoke(fopFactory, outputFormat, out);
                method = fop.getClass().getMethod("getUserAgent");
                userAgent = method.invoke(fop);
            } else {
                method = fopFactory.getClass().getMethod("newFOUserAgent");
                userAgent = method.invoke(fopFactory);
            }
            Class uaClass = userAgent.getClass();
            Boolean b = getBooleanProp("Accessibility");
            if (b != null) {
                method = uaClass.getMethod("setAccessibility", Boolean.class);
                method.invoke(userAgent, b);
            }
            String s = getStringProp("Author");
            if (s != null) {
                method = uaClass.getMethod("setAuthor", String.class);
                method.invoke(userAgent, s);
            }
            if ("1.x".equals(fopVersion)) {
                method = uaClass.getMethod("setBaseURL", String.class);
                method.invoke(userAgent, step.getNode().getBaseURI().toString());
                s = getStringProp("BaseURL");
                if (s != null) {
                    method.invoke(userAgent, s);
                }
            } else {
                // FIXME: how do I do this in 2.x?
            }
            b = getBooleanProp("ConserveMemoryPolicy");
            if (b != null) {
                method = uaClass.getMethod("setConserveMemoryPolicy", Boolean.class);
                method.invoke(userAgent, b);
            }
            s = getStringProp("CreationDate");
            if (s != null) {
                DateFormat df = DateFormat.getDateInstance();
                Date d = df.parse(s);
                method = uaClass.getMethod("setCreationDate", Date.class);
                method.invoke(userAgent, d);
            }
            s = getStringProp("Creator");
            if (s != null) {
                method = uaClass.getMethod("setCreator", String.class);
                method.invoke(userAgent, s);
            }
            s = getStringProp("Keywords");
            if (s != null) {
                method = uaClass.getMethod("setKeywords", String.class);
                method.invoke(userAgent, s);
            }
            b = getBooleanProp("LocatorEnabled");
            if (b != null) {
                method = uaClass.getMethod("setLocatorEnabled", Boolean.class);
                method.invoke(userAgent, b);
            }
            s = getStringProp("Producer");
            if (s != null) {
                method = uaClass.getMethod("setProducer", String.class);
                method.invoke(userAgent, s);
            }
            s = getStringProp("Subject");
            if (s != null) {
                method = uaClass.getMethod("setSubject", String.class);
                method.invoke(userAgent, s);
            }
            Float f = getFloatProp("TargetResolution");
            if (f != null) {
                method = uaClass.getMethod("setTargetResolution", Float.class);
                method.invoke(userAgent, f);
            }
            s = getStringProp("Title");
            if (s != null) {
                method = uaClass.getMethod("setTitle", String.class);
                method.invoke(userAgent, s);
            }
            if ("2.x".equals(fopVersion)) {
                method = uaClass.getMethod("newFop", String.class, OutputStream.class);
                fop = method.invoke(userAgent, outputFormat, out);
            }
            method = fop.getClass().getMethod("getDefaultHandler");
            Object defHandler = method.invoke(fop);
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            transformer.transform(source, new SAXResult((ContentHandler) defHandler));
        } catch (Exception e) {
            throw new XProcException(step.getNode(), "Failed to process FO document with FOP", e);
        }
    }
public void format(XdmNode doc, OutputStream out, String contentType) {
        String outputFormat = null;
        if (contentType == null || "application/pdf".equalsIgnoreCase(contentType)) {
            outputFormat = "application/pdf";
        } else if ("application/PostScript".equalsIgnoreCase(contentType)) {
            outputFormat = "application/postscript";
        } else if ("application/afp".equalsIgnoreCase(contentType)) {
            outputFormat =  "application/x-afp"; 
        } else if ("application/rtf".equalsIgnoreCase(contentType)) {
            outputFormat = "application/rtf";
        } else if ("text/plain".equalsIgnoreCase(contentType)) {
           outputFormat = "text/plain";
        } else {
            throw new XProcException(step.getNode(), "Unsupported content-type on p:xsl-formatter: " + contentType);
        }
        if (! ("1.x".equals(fopVersion) || "2.x".equals(fopVersion))) {
            throw new XProcException("Unexpected FOP version: " + fopVersion);
        }
        try {
            InputSource fodoc = S9apiUtils.xdmToInputSource(runtime, doc);
            SAXSource source = new SAXSource(fodoc);
            Object userAgent = null;
            Object fop = null;
            if ("1.x".equals(fopVersion)) {
                method = fopFactory.getClass().getMethod("newFop", String.class, OutputStream.class);
                fop = method.invoke(fopFactory, outputFormat, out);
                method = fop.getClass().getMethod("getUserAgent");
                userAgent = method.invoke(fop);
            } else {
                method = fopFactory.getClass().getMethod("newFOUserAgent");
                userAgent = method.invoke(fopFactory);
            }
            Class uaClass = userAgent.getClass();
            Boolean b = getBooleanProp("Accessibility");
            if (b != null) {
                method = uaClass.getMethod("setAccessibility", Boolean.class);
                method.invoke(userAgent, b);
            }
            String s = getStringProp("Author");
            if (s != null) {
                method = uaClass.getMethod("setAuthor", String.class);
                method.invoke(userAgent, s);
            }
            if ("1.x".equals(fopVersion)) {
                method = uaClass.getMethod("setBaseURL", String.class);
                method.invoke(userAgent, step.getNode().getBaseURI().toString());
                s = getStringProp("BaseURL");
                if (s != null) {
                    method.invoke(userAgent, s);
                }
            } else {
               
            }
            b = getBooleanProp("ConserveMemoryPolicy");
            if (b != null) {
                method = uaClass.getMethod("setConserveMemoryPolicy", Boolean.class);
                method.invoke(userAgent, b);
            }
            s = getStringProp("CreationDate");
            if (s != null) {
                DateFormat df = DateFormat.getDateInstance();
                Date d = df.parse(s);
                method = uaClass.getMethod("setCreationDate", Date.class);
                method.invoke(userAgent, d);
            }
            s = getStringProp("Creator");
            if (s != null) {
                method = uaClass.getMethod("setCreator", String.class);
                method.invoke(userAgent, s);
            }
            s = getStringProp("Keywords");
            if (s != null) {
                method = uaClass.getMethod("setKeywords", String.class);
                method.invoke(userAgent, s);
            }
            b = getBooleanProp("LocatorEnabled");
            if (b != null) {
                method = uaClass.getMethod("setLocatorEnabled", Boolean.class);
                method.invoke(userAgent, b);
            }
            s = getStringProp("Producer");
            if (s != null) {
                method = uaClass.getMethod("setProducer", String.class);
                method.invoke(userAgent, s);
            }
            s = getStringProp("Subject");
            if (s != null) {
                method = uaClass.getMethod("setSubject", String.class);
                method.invoke(userAgent, s);
            }
            Float f = getFloatProp("TargetResolution");
            if (f != null) {
                method = uaClass.getMethod("setTargetResolution", Float.class);
                method.invoke(userAgent, f);
            }
            s = getStringProp("Title");
            if (s != null) {
                method = uaClass.getMethod("setTitle", String.class);
                method.invoke(userAgent, s);
            }
            if ("2.x".equals(fopVersion)) {
                method = uaClass.getMethod("newFop", String.class, OutputStream.class);
                fop = method.invoke(userAgent, outputFormat, out);
            }
            method = fop.getClass().getMethod("getDefaultHandler");
            Object defHandler = method.invoke(fop);
            TransformerFactory transformerFactory = TransformerFactory.newInstance();
            Transformer transformer = transformerFactory.newTransformer();
            transformer.transform(source, new SAXResult((ContentHandler) defHandler));
        } catch (Exception e) {
            throw new XProcException(step.getNode(), "Failed to process FO document with FOP", e);
        }
    }
public void format(xdmnode doc, outputstream out, string contenttype) { string outputformat = null; if (contenttype == null || "application/pdf".equalsignorecase(contenttype)) { outputformat = "application/pdf"; } else if ("application/postscript".equalsignorecase(contenttype)) { outputformat = "application/postscript"; } else if ("application/afp".equalsignorecase(contenttype)) { outputformat = "application/x-afp"; } else if ("application/rtf".equalsignorecase(contenttype)) { outputformat = "application/rtf"; } else if ("text/plain".equalsignorecase(contenttype)) { outputformat = "text/plain"; } else { throw new xprocexception(step.getnode(), "unsupported content-type on p:xsl-formatter: " + contenttype); } if (! ("1.x".equals(fopversion) || "2.x".equals(fopversion))) { throw new xprocexception("unexpected fop version: " + fopversion); } try { inputsource fodoc = s9apiutils.xdmtoinputsource(runtime, doc); saxsource source = new saxsource(fodoc); object useragent = null; object fop = null; if ("1.x".equals(fopversion)) { method = fopfactory.getclass().getmethod("newfop", string.class, outputstream.class); fop = method.invoke(fopfactory, outputformat, out); method = fop.getclass().getmethod("getuseragent"); useragent = method.invoke(fop); } else { method = fopfactory.getclass().getmethod("newfouseragent"); useragent = method.invoke(fopfactory); } class uaclass = useragent.getclass(); boolean b = getbooleanprop("accessibility"); if (b != null) { method = uaclass.getmethod("setaccessibility", boolean.class); method.invoke(useragent, b); } string s = getstringprop("author"); if (s != null) { method = uaclass.getmethod("setauthor", string.class); method.invoke(useragent, s); } if ("1.x".equals(fopversion)) { method = uaclass.getmethod("setbaseurl", string.class); method.invoke(useragent, step.getnode().getbaseuri().tostring()); s = getstringprop("baseurl"); if (s != null) { method.invoke(useragent, s); } } else { } b = getbooleanprop("conservememorypolicy"); if (b != null) { method = uaclass.getmethod("setconservememorypolicy", boolean.class); method.invoke(useragent, b); } s = getstringprop("creationdate"); if (s != null) { dateformat df = dateformat.getdateinstance(); date d = df.parse(s); method = uaclass.getmethod("setcreationdate", date.class); method.invoke(useragent, d); } s = getstringprop("creator"); if (s != null) { method = uaclass.getmethod("setcreator", string.class); method.invoke(useragent, s); } s = getstringprop("keywords"); if (s != null) { method = uaclass.getmethod("setkeywords", string.class); method.invoke(useragent, s); } b = getbooleanprop("locatorenabled"); if (b != null) { method = uaclass.getmethod("setlocatorenabled", boolean.class); method.invoke(useragent, b); } s = getstringprop("producer"); if (s != null) { method = uaclass.getmethod("setproducer", string.class); method.invoke(useragent, s); } s = getstringprop("subject"); if (s != null) { method = uaclass.getmethod("setsubject", string.class); method.invoke(useragent, s); } float f = getfloatprop("targetresolution"); if (f != null) { method = uaclass.getmethod("settargetresolution", float.class); method.invoke(useragent, f); } s = getstringprop("title"); if (s != null) { method = uaclass.getmethod("settitle", string.class); method.invoke(useragent, s); } if ("2.x".equals(fopversion)) { method = uaclass.getmethod("newfop", string.class, outputstream.class); fop = method.invoke(useragent, outputformat, out); } method = fop.getclass().getmethod("getdefaulthandler"); object defhandler = method.invoke(fop); transformerfactory transformerfactory = transformerfactory.newinstance(); transformer transformer = transformerfactory.newtransformer(); transformer.transform(source, new saxresult((contenthandler) defhandler)); } catch (exception e) { throw new xprocexception(step.getnode(), "failed to process fo document with fop", e); } }