当前位置: 首页>>代码示例>>Java>>正文


Java ApacheFopWorker类代码示例

本文整理汇总了Java中org.ofbiz.webapp.view.ApacheFopWorker的典型用法代码示例。如果您正苦于以下问题:Java ApacheFopWorker类的具体用法?Java ApacheFopWorker怎么用?Java ApacheFopWorker使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


ApacheFopWorker类属于org.ofbiz.webapp.view包,在下文中一共展示了ApacheFopWorker类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: createFileFromScreen

import org.ofbiz.webapp.view.ApacheFopWorker; //导入依赖的package包/类
public static Map<String, Object> createFileFromScreen(DispatchContext dctx, Map<String, ? extends Object> serviceContext) {
    Locale locale = (Locale) serviceContext.get("locale");
    Delegator delegator = dctx.getDelegator();
    String screenLocation = (String) serviceContext.remove("screenLocation");
    Map<String, Object> screenContext = UtilGenerics.checkMap(serviceContext.remove("screenContext"));
    String contentType = (String) serviceContext.remove("contentType");
    String filePath = (String) serviceContext.remove("filePath");
    String fileName = (String) serviceContext.remove("fileName");

    if (UtilValidate.isEmpty(screenContext)) {
        screenContext = FastMap.newInstance();
    }
    screenContext.put("locale", locale);
    if (UtilValidate.isEmpty(contentType)) {
        contentType = "application/pdf";
    }

    try {
        MapStack<String> screenContextTmp = MapStack.create();
        screenContextTmp.put("locale", locale);

        Writer writer = new StringWriter();
        // substitute the freemarker variables...
        ScreenStringRenderer foScreenStringRenderer = new MacroScreenRenderer(EntityUtilProperties.getPropertyValue("widget", "screenfop.name", dctx.getDelegator()),
                EntityUtilProperties.getPropertyValue("widget", "screenfop.screenrenderer", dctx.getDelegator()));
        ScreenRenderer screensAtt = ScreenRenderer.makeWithEnvAwareFetching(writer, screenContextTmp, foScreenStringRenderer);
        screensAtt.populateContextForService(dctx, screenContext);
        screenContextTmp.putAll(screenContext);
        screensAtt.getContext().put("formStringRenderer", foFormRenderer);
        screensAtt.render(screenLocation);

        // create the input stream for the generation
        StreamSource src = new StreamSource(new StringReader(writer.toString()));

        // create the output stream for the generation
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        Fop fop = ApacheFopWorker.createFopInstance(baos, MimeConstants.MIME_PDF);
        ApacheFopWorker.transform(src, null, fop);

        baos.flush();
        baos.close();

        fileName += UtilDateTime.nowAsString();
        if ("application/pdf".equals(contentType)) {
            fileName += ".pdf";
        } else if ("application/postscript".equals(contentType)) {
            fileName += ".ps";
        } else if ("text/plain".equals(contentType)) {
            fileName += ".txt";
        }
        if (UtilValidate.isEmpty(filePath)) {
            filePath = EntityUtilProperties.getPropertyValue("content.properties", "content.output.path", "/output", delegator);
        }
        File file = new File(filePath, fileName);

        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baos.toByteArray());
        fos.close();

    } catch (Exception e) {
        Debug.logError(e, "Error rendering [" + contentType + "]: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentRenderingError", UtilMisc.toMap("contentType", contentType, "errorString", e.toString()), locale));
    }

    return ServiceUtil.returnSuccess();
}
 
开发者ID:ilscipio,项目名称:scipio-erp,代码行数:68,代码来源:OutputServices.java

示例2: createFileFromScreen

import org.ofbiz.webapp.view.ApacheFopWorker; //导入依赖的package包/类
public static Map<String, Object> createFileFromScreen(DispatchContext dctx, Map<String, ? extends Object> serviceContext) {
    Locale locale = (Locale) serviceContext.get("locale");
    String screenLocation = (String) serviceContext.remove("screenLocation");
    Map<String, Object> screenContext = UtilGenerics.checkMap(serviceContext.remove("screenContext"));
    String contentType = (String) serviceContext.remove("contentType");
    String filePath = (String) serviceContext.remove("filePath");
    String fileName = (String) serviceContext.remove("fileName");

    if (UtilValidate.isEmpty(screenContext)) {
        screenContext = FastMap.newInstance();
    }
    screenContext.put("locale", locale);
    if (UtilValidate.isEmpty(contentType)) {
        contentType = "application/pdf";
    }

    try {
        MapStack<String> screenContextTmp = MapStack.create();
        screenContextTmp.put("locale", locale);

        Writer writer = new StringWriter();
        // substitute the freemarker variables...
        ScreenRenderer screensAtt = new ScreenRenderer(writer, screenContextTmp, foScreenRenderer);
        screensAtt.populateContextForService(dctx, screenContext);
        screenContextTmp.putAll(screenContext);
        screensAtt.getContext().put("formStringRenderer", foFormRenderer);
        screensAtt.render(screenLocation);

        // create the input stream for the generation
        StreamSource src = new StreamSource(new StringReader(writer.toString()));

        // create the output stream for the generation
        ByteArrayOutputStream baos = new ByteArrayOutputStream();

        Fop fop = ApacheFopWorker.createFopInstance(baos, MimeConstants.MIME_PDF);
        ApacheFopWorker.transform(src, null, fop);

        baos.flush();
        baos.close();

        fileName += UtilDateTime.nowAsString();
        if ("application/pdf".equals(contentType)) {
            fileName += ".pdf";
        } else if ("application/postscript".equals(contentType)) {
            fileName += ".ps";
        } else if ("text/plain".equals(contentType)) {
            fileName += ".txt";
        }
        if (UtilValidate.isEmpty(filePath)) {
            filePath = UtilProperties.getPropertyValue("content.properties", "content.output.path", "/output");
        }
        File file = new File(filePath, fileName);

        FileOutputStream fos = new FileOutputStream(file);
        fos.write(baos.toByteArray());
        fos.close();

    } catch (Exception e) {
        Debug.logError(e, "Error rendering [" + contentType + "]: " + e.toString(), module);
        return ServiceUtil.returnError(UtilProperties.getMessage(resource, "ContentRenderingError", UtilMisc.toMap("contentType", contentType, "errorString", e.toString()), locale));
    }

    return ServiceUtil.returnSuccess();
}
 
开发者ID:gildaslemoal,项目名称:elpi,代码行数:65,代码来源:OutputServices.java


注:本文中的org.ofbiz.webapp.view.ApacheFopWorker类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。