001: /*
002: * $Id: RenderWrappedTextTransform.java,v 1.4 2004/01/17 03:57:46 byersa Exp $
003: *
004: * Copyright (c) 2001-2003 The Open For Business Project - www.ofbiz.org
005: *
006: * Permission is hereby granted, free of charge, to any person obtaining a
007: * copy of this software and associated documentation files (the "Software"),
008: * to deal in the Software without restriction, including without limitation
009: * the rights to use, copy, modify, merge, publish, distribute, sublicense,
010: * and/or sell copies of the Software, and to permit persons to whom the
011: * Software is furnished to do so, subject to the following conditions:
012: *
013: * The above copyright notice and this permission notice shall be included
014: * in all copies or substantial portions of the Software.
015: *
016: * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
017: * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
018: * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
019: * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
020: * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT
021: * OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
022: * THE USE OR OTHER DEALINGS IN THE SOFTWARE.
023: *
024: */
025: package org.ofbiz.content.webapp.ftl;
026:
027: import java.io.IOException;
028: import java.io.Writer;
029: import java.io.StringReader;
030: import java.util.*;
031: import java.sql.*;
032:
033: import javax.servlet.ServletContext;
034: import javax.servlet.http.HttpServletRequest;
035: import javax.servlet.http.HttpServletResponse;
036: import javax.servlet.http.HttpSession;
037:
038: import org.ofbiz.content.webapp.control.RequestHandler;
039:
040: import freemarker.ext.beans.BeansWrapper;
041: import freemarker.ext.servlet.HttpRequestHashModel;
042: import freemarker.ext.servlet.HttpSessionHashModel;
043: import freemarker.template.Configuration;
044: import freemarker.template.SimpleHash;
045: import freemarker.template.TemplateException;
046: import freemarker.template.WrappingTemplateModel;
047: import freemarker.template.Environment;
048:
049: import freemarker.ext.beans.BeanModel;
050: import freemarker.template.SimpleScalar;
051: import freemarker.template.TemplateModelException;
052: import freemarker.template.TemplateScalarModel;
053: import freemarker.template.TemplateTransformModel;
054: import freemarker.template.TemplateHashModel;
055:
056: import org.jpublish.SiteContext;
057: import org.jpublish.Page;
058: import org.jpublish.JPublishContext;
059: import org.jpublish.Template;
060: import org.jpublish.TemplateMergeException;
061:
062: import org.ofbiz.base.util.Debug;
063: import org.ofbiz.base.util.UtilDateTime;
064: import org.ofbiz.base.util.UtilMisc;
065: import org.ofbiz.base.util.UtilValidate;
066: import org.ofbiz.base.util.UtilHttp;
067: import org.ofbiz.entity.GenericDelegator;
068: import org.ofbiz.entity.GenericEntityException;
069: import org.ofbiz.entity.GenericValue;
070: import org.ofbiz.entity.condition.EntityCondition;
071: import org.ofbiz.entity.condition.EntityConditionList;
072: import org.ofbiz.entity.condition.EntityExpr;
073: import org.ofbiz.entity.condition.EntityOperator;
074: import org.ofbiz.security.Security;
075: import org.ofbiz.service.DispatchContext;
076: import org.ofbiz.service.ServiceUtil;
077: import org.ofbiz.service.GenericServiceException;
078: import org.ofbiz.service.LocalDispatcher;
079: import org.ofbiz.content.data.DataServices;
080: import org.ofbiz.content.webapp.view.JPublishWrapper;
081:
082: /**
083: * RenderWrappedTextTransform - Freemarker Transform for URLs (links)
084: *
085: * @author <a href="mailto:byersa@automationgroups.com">Al Byers</a>
086: * @version $Revision: 1.4 $
087: * @since 3.0
088: */
089: public class RenderWrappedTextTransform implements
090: TemplateTransformModel {
091:
092: public static final String module = RenderWrappedTextTransform.class
093: .getName();
094:
095: public Writer getWriter(final Writer out, Map args) {
096: final Environment env = Environment.getCurrentEnvironment();
097: Map ctx = (Map) FreeMarkerWorker.getWrappedObject("context",
098: env);
099: final String wrappedFTL = FreeMarkerWorker.getArg(args,
100: "wrappedFTL", ctx);
101: Debug.logVerbose("in RenderWrappedText, wrappedFTL:"
102: + wrappedFTL, "");
103:
104: return new Writer(out) {
105:
106: public void write(char cbuf[], int off, int len) {
107: }
108:
109: public void flush() throws IOException {
110: out.flush();
111: }
112:
113: public void close() throws IOException {
114: if (UtilValidate.isNotEmpty(wrappedFTL)) {
115: out.write(wrappedFTL);
116: } else {
117: Debug.logInfo(
118: "wrappedFTL was empty. skipping write.",
119: module);
120: }
121: }
122: };
123: }
124: }
|