當前位置: 首頁>>代碼示例>>Java>>正文


Java ApacheFopWorker.createFopInstance方法代碼示例

本文整理匯總了Java中org.ofbiz.webapp.view.ApacheFopWorker.createFopInstance方法的典型用法代碼示例。如果您正苦於以下問題:Java ApacheFopWorker.createFopInstance方法的具體用法?Java ApacheFopWorker.createFopInstance怎麽用?Java ApacheFopWorker.createFopInstance使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.ofbiz.webapp.view.ApacheFopWorker的用法示例。


在下文中一共展示了ApacheFopWorker.createFopInstance方法的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.createFopInstance方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。