/*******************************************************************************
* Copyright 2009, 2010 Innovation Gate GmbH. All Rights Reserved.
*
* This file is part of the OpenWGA server platform.
*
* OpenWGA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* In addition, a special exception is granted by the copyright holders
* of OpenWGA called "OpenWGA plugin exception". You should have received
* a copy of this exception along with OpenWGA in file COPYING.
* If not, see <http://www.openwga.com/gpl-plugin-exception>.
*
* OpenWGA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with OpenWGA in file COPYING.
* If not, see <http://www.gnu.org/licenses/>.
******************************************************************************/
package de.innovationgate.wgpublisher.webtml;
import java.io.IOException;
import java.io.OutputStream;
import java.io.UnsupportedEncodingException;
import java.io.Writer;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.PageContext;
import javax.servlet.jsp.tagext.BodyTag;
import javax.servlet.jsp.tagext.BodyTagSupport;
import javax.servlet.jsp.tagext.Tag;
import org.apache.log4j.Logger;
import org.dom4j.Element;
import de.innovationgate.utils.FormattingChain;
import de.innovationgate.utils.FormattingException;
import de.innovationgate.utils.ObjectFormatter;
import de.innovationgate.utils.ReplaceProcessor;
import de.innovationgate.utils.WGUtils;
import de.innovationgate.webgate.api.WGAPIException;
import de.innovationgate.webgate.api.WGContent;
import de.innovationgate.webgate.api.WGDatabase;
import de.innovationgate.webgate.api.WGDocument;
import de.innovationgate.webgate.api.WGException;
import de.innovationgate.webgate.api.WGExpressionException;
import de.innovationgate.webgate.api.WGStructEntry;
import de.innovationgate.wgpublisher.WGACore;
import de.innovationgate.wgpublisher.WGAVersion;
import de.innovationgate.wgpublisher.WGPDispatcher;
import de.innovationgate.wgpublisher.WGACore.DomainConfiguration;
import de.innovationgate.wgpublisher.expressions.ExpressionEngineFactory;
import de.innovationgate.wgpublisher.expressions.ExpressionResult;
import de.innovationgate.wgpublisher.webtml.utils.AjaxActionDefinition;
import de.innovationgate.wgpublisher.webtml.utils.HTMLHeadInclusion;
import de.innovationgate.wgpublisher.webtml.utils.TMLAction;
import de.innovationgate.wgpublisher.webtml.utils.TMLActionLink;
import de.innovationgate.wgpublisher.webtml.utils.TMLContext;
import de.innovationgate.wgpublisher.webtml.utils.TMLException;
import de.innovationgate.wgpublisher.webtml.utils.TMLOption;
import de.innovationgate.wgpublisher.webtml.utils.TMLPortlet;
import de.innovationgate.wgpublisher.webtml.utils.TMLSilentCancelException;
import de.innovationgate.wgpublisher.webtml.utils.TMLUserProfile;
import de.innovationgate.wgpublisher.webtml.utils.TagOutputFormatter;
public abstract class Base extends BodyTagSupport {
public class MixedAttributeResolver implements ReplaceProcessor {
public int replace(String text, int from, int to, Writer out) throws IOException {
// find end position
int endPos = text.indexOf("}", from);
if (endPos == -1) {
out.write("{");
return to + 1;
}
// Cut out dynamic part
String dynamicPart = text.substring(from, endPos + 1);
// Resolve
out.write(Base.this.resolveDynamicAttribute(dynamicPart));
// Continue after dynamic part
return endPos + 1;
}
}
protected static final Logger log = Logger.getLogger("wga");
public static final DateFormat DEBUG_TIMESTAMP_FORMAT = new SimpleDateFormat("HH:mm:ss SSSS");
public static final String OPTION_DEFAULT_XPLANGUAGE = "$defaultxpl";
public static final String OPTION_DESIGNDB = "$designdb";
public static final String OPTION_LINK_ACTION = "$linkaction";
public static final String OPTION_LINK_MEDIUM = "$linkmedium";
public static final String OPTION_DEFAULT_MEDIAKEY = "$mediakey";
public static final String OPTION_PORTLET_NAMESPACE = "$PORTLETNS";
public static final String OPTION_CURRENT_MEDIAKEY = "$currentmediakey";
public static final String OPTION_TMLMODULE_NAME = "$tmlmoduleName";
public static final String OPTION_TMLMODULE_MEDIAKEY = "$tmlmoduleMediakey";
public static final String OPTION_DEFAULT_LABELFILE = "$defaultlabelbundle:";
public static final String OPTION_DEFAULT_LABELCONTAINER = "$defaultlabelcontainer:";
public static final String OPTION_PORTLET_EVENT_STARTINDEX = "$PORTLET_EVENT_STARTINDEX";
public static final String OPTION_WEBTML_SCOPE = "$webtmlScope";
public static final String URL_VERSION_PARAMETER = "?version=" + WGAVersion.WGAPUBLISHER_MAJOR_VERSION + "-" + WGAVersion.WGAPUBLISHER_MINOR_VERSION + "-" + WGAVersion.WGAPUBLISHER_MAINTENANCE_VERSION;
public static final String TAGVALUE_STATUS = "TagStatus";
public static final String TAGVALUE_DYNAMIC_ATTRIBUTES = "TagDynamicAttributes";
public BaseTagStatus getStatus() {
return (BaseTagStatus) getValue(TAGVALUE_STATUS);
}
protected BaseTagStatus createTagStatus() {
return new BaseTagStatus();
}
// Generic tag attributes
private String context = null;
private String privateContext = null;
private String output = null;
private String var = null;
private String sessionvar = null;
private String divider = null;
private String format = null;
protected String encode = null;
private String sourceline = null;
private String trim = null;
// Tags environment
public void setResult(Object result) {
getStatus().result = result;
}
protected Base appendResult(String tmlResult) {
if (tmlResult != null && stringToBoolean(getTrim()) == true) {
tmlResult = tmlResult.trim();
}
BaseTagStatus status = getStatus();
if (status.result == null || !de.innovationgate.utils.WGUtils.isCollection(status.result)) {
ArrayList resultList = new ArrayList();
resultList.add(tmlResult);
status.result = resultList;
}
else {
java.util.Collection resultCollection = (java.util.Collection) status.result;
resultCollection.add(tmlResult);
}
return this;
}
protected void clearResult() {
getStatus().result = null;
}
public void addWarning(String message, boolean cancelTag) {
getStatus().addWarning(message, cancelTag);
}
public void addWarning(String message) {
getStatus().addWarning(message, false);
}
public void clearWarnings() {
this.pageContext.setAttribute(Base.class.getName() + ":Warnings", null, PageContext.REQUEST_SCOPE);
}
public TMLContext getMainContext() {
// Wayyyyyy easier and faster....
return getTMLContext().getmaincontext();
//return this.getTMLContextForDocument((WGContent) this.pageContext.getRequest().getAttribute(WGACore.ATTRIB_MAINCONTEXT));
}
public TMLContext getTMLContextForDocument(WGDocument doc) {
return getTMLContext().getTMLContextForDocument(doc);
}
public boolean stringToBoolean(String expr) {
try {
return WGUtils.stringToBoolean(expr);
}
catch (IllegalArgumentException e) {
addWarning(e.getMessage(), false);
return false;
}
}
public int stringToInteger(String expr, int defaultValue) {
if (expr == null) {
return defaultValue;
}
try {
return new Double(expr).intValue();
}
catch (NumberFormatException exc) {
this.addWarning("Cannot interpret WebTML attribute as number: " + expr + ". Falling back to default: " + defaultValue);
return defaultValue;
}
}
public BaseTagStatus getTagStatusById(String id) {
return getStatus().getTagStatusById(id);
}
public BaseTagStatus getTagStatusById(String id, Class tagClass) {
return getStatus().getTagStatusById(id, tagClass);
}
/**
* @see BodyTagSupport#doStartTag()
*/
public final int doStartTag() throws JspException {
try {
// Basic initializations of status
BaseTagStatus status = initializeStatus();
// Eventually create debug node
Element parentDebugNode = getParentTagDebugNode();
if (parentDebugNode != null) {
createDebugNode(parentDebugNode);
status.iterationDebugNode = debugNode.addElement("starttag");
}
// First get tml context to allow script execution (maybe already needed in id-calculation)
TMLContext parentContext = this.getParentTagContext();
TMLContext baseContext = null;
// We have no parent tag, so we are absolute root: Construct main context
if (parentContext == null) {
baseContext = new TMLContext((WGContent) this.pageContext.getRequest().getAttribute(WGACore.ATTRIB_MAINCONTEXT), this);
TMLContext.clearThreadMainContext();
baseContext.makeThreadMainContext();
}
else {
baseContext = new TMLContext(parentContext, status);
}
this.setTMLContext(baseContext);
// Register status with id
String id = this.getId();
if (id != null) {
status.id = id;
Map tagIds = status.getTagIds();
tagIds.put(id, status);
}
TMLContext tmlContext = null;
// Set tag contexts
status.childTMLContext = baseContext;
if (this.getContext() != null) {
tmlContext = baseContext.context(this.getContext(), false);
if (tmlContext != null) {
this.setTMLContext(tmlContext);
this.setChildTagContext(tmlContext);
}
else {
status.subContextError = true;
// Tag should not be canceled if the context validity
// is checked via iscontextvalid
boolean cancelTag = true;
if (this instanceof ConditionBase) {
ConditionBase conditionTag = (ConditionBase) this;
if (conditionTag.getIscontextvalid() != null) {
cancelTag = false;
}
}
if (cancelTag == true) {
String msg = "Failed context change: " + getContext();
if (baseContext.getlasterror() != null) {
msg += ". Reason: " + baseContext.getlasterror();
}
this.addWarning(msg, true);
setCancelTag(true);
return Tag.SKIP_BODY;
}
}
}
if (this.getPrivatecontext() != null) {
tmlContext = baseContext.context(this.getPrivatecontext());
if (baseContext.getlasterror() == null) {
this.setTMLContext(tmlContext);
}
else {
this.addWarning(tmlContext.getlasterror(), false);
}
}
// Set boolean flags
this.setEvalBody(true);
if (this.getVar() != null || this.getSessionvar() != null) {
if (this.getOutput() != null && this.stringToBoolean(this.getOutput()) == true) {
this.setResultOutput(true);
}
else {
this.setResultOutput(false);
}
}
else {
if (this.getOutput() != null && this.stringToBoolean(this.getOutput()) == false) {
this.setResultOutput(false);
}
else {
this.setResultOutput(true);
}
}
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("startedTagSpecific", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
// Let status object initialize its attribute delegates, needed for tag-specific processing
status.initAttributeDelegates(this);
// Execute specialized tml function
try {
this.tmlStartTag();
}
catch (TMLException exc) {
handleTMLException(exc);
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
}
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("endedTagSpecific", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
// Evaluate body, if not denied
if (this.isEvalBody() && this.getCancelTag() == false) {
return BodyTag.EVAL_BODY_BUFFERED;
}
else {
return Tag.SKIP_BODY;
}
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return Tag.SKIP_BODY;
}
catch (Error exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return Tag.SKIP_BODY;
}
}
private BaseTagStatus initializeStatus() {
BaseTagStatus status = createTagStatus();
setValue(TAGVALUE_STATUS, status);
status.tagClass = getClass();
status.retrieveParentTag(this);
status.tagOptions = this.getParentTagAttributes();
status.localTagOptions = new HashMap();
String sourceLineStr = getSourceline();
if (sourceLineStr != null) {
status.sourceLine = Integer.parseInt(getSourceline());
}
Map<String,Object> dynaAtts = (Map<String, Object>) getValue(TAGVALUE_DYNAMIC_ATTRIBUTES);
if (dynaAtts != null) {
status.dynamicOptions = dynaAtts;
removeValue(TAGVALUE_DYNAMIC_ATTRIBUTES);
}
return status;
}
public BaseTagStatus getParentTag() {
return getStatus().getParentTag();
}
/**
* @return
*/
private Element getParentTagDebugNode() {
BaseTagStatus parent = getParentTag();
if (parent != null) {
return parent.iterationDebugNode;
}
else {
return null;
}
}
private void writeOutput() {
try {
String result = this.getResultString();
this.pageContext.getOut().write(result);
if (debugNode != null && debugNode.getDocument().getRootElement().attributeValue("traceresults", "false").equals("true")) {
debugNode.addElement("result").addCDATA(result);
}
}
catch (java.io.IOException exc) {
log.error("Error writing tml output", exc);
}
}
private TMLContext getParentTagContext() throws WGAPIException {
BaseTagStatus parent = this.getParentTag();
if (parent != null) {
return parent.childTMLContext;
}
else {
return null;
}
}
private HashMap getParentTagAttributes() {
BaseTagStatus parent = this.getParentTag();
if (parent != null) {
return new HashMap(parent.tagOptions);
}
else {
return new HashMap();
}
}
protected String getTagAttributeValue(String att, String value, String defaultValue) {
String attResult = null;
// Nonexistent attribute
if (value == null) {
return defaultValue;
}
// Empty attribute
if (value.length() == 0) {
return value;
}
char firstChar = value.charAt(0);
char lastChar = value.charAt(value.length() - 1);
// Normal dynamic attribute
if (firstChar == '{' && lastChar == '}') {
attResult = resolveDynamicAttribute(value);
}
// Mixed attribute: Dynamic parts are contained in {}
else if (firstChar == '[' && lastChar == ']') {
attResult = resolveMixedAttribute(value);
}
else {
attResult = value;
}
// Trace debug information
if (debugNode != null && attResult != null) {
Element attElement = (Element) debugNode.selectSingleNode("attribute[@name='" + att + "']");
if (attElement == null) {
attElement = debugNode.addElement("attribute");
attElement.addAttribute("name", att);
attElement.addCDATA(attResult);
}
}
return attResult;
}
private String resolveMixedAttribute(String value) {
// Cutoff []
value = value.substring(1, value.length() - 1);
MixedAttributeResolver resolver = new MixedAttributeResolver();
return WGUtils.strReplace(value, "{", resolver, true);
}
private String resolveDynamicAttribute(String value) {
String attResult = null;
String lcValue = value.toLowerCase();
if (lcValue.startsWith("{tag:")) {
String tagId = value.substring(5, value.length() - 1).trim();
BaseTagStatus tag = this.getTagStatusById(tagId);
if (tag == null) {
this.addWarning("Could not retrieve tag: " + tagId, false);
attResult = "";
}
if (tag.result instanceof java.util.Collection) {
attResult = WGUtils.serializeCollection((java.util.Collection) tag.result, ",");
}
else {
attResult = String.valueOf(tag.result);
}
}
else if (lcValue.startsWith("{item:")) {
String itemName = value.substring(6, value.length() - 1).trim();
Object obj = null;
try {
obj = this.getTMLContext().itemlist(itemName);
attResult = de.innovationgate.utils.WGUtils.serializeCollection((List) obj, ",");
}
catch (WGAPIException e) {
this.addWarning("Could not retrieve item: " + itemName + " bc. of exception: " + e.getClass().getName() + " message: " + e.getMessage(), false);
attResult = "";
}
if (obj == null) {
this.addWarning("Could not retrieve item: " + itemName, false);
attResult = "";
}
}
else if (lcValue.startsWith("{meta:")) {
String metaType ="content";
String metaName = value.substring(6, value.length() - 1).trim();
int slashPos = metaName.indexOf("/");
if (slashPos != -1) {
metaType = metaName.substring(0, slashPos).trim();
metaName = metaName.substring(slashPos + 1).trim();
}
Object obj = null;
try {
obj = this.getTMLContext().metalist(metaType, metaName);
attResult = de.innovationgate.utils.WGUtils.serializeCollection((List) obj, ",");
}
catch (WGAPIException e) {
this.addWarning("Could not retrieve meta: " + metaType + "/" + metaName + " bc. of exception: " + e.getClass().getName() + " message: " + e.getMessage(), false);
attResult = "";
}
if (obj == null) {
this.addWarning("Could not retrieve meta: " + metaType + "/" + metaName, false);
attResult = "";
}
}
else if (lcValue.startsWith("{label:")) {
String labelName = value.substring(7, value.length() - 1).trim();
int paramStartPos = labelName.indexOf("(");
int paramEndPos = labelName.indexOf(")");
List params = null;
if (paramStartPos != -1 && paramEndPos != -1) {
params = WGUtils.deserializeCollection(labelName.substring(paramStartPos + 1, paramEndPos), ",", true);
labelName = labelName.substring(0, paramStartPos);
}
attResult = getTMLContext().label(labelName, params);
}
else if (lcValue.startsWith("{option:")) {
String optionName = value.substring(8, value.length() - 1).trim();
Object option = this.getTMLContext().option(optionName);
if (option == null) {
this.addWarning("Could not retrieve option: " + optionName, false);
attResult = "";
}
else {
attResult = String.valueOf(option);
}
}
else if (lcValue.startsWith("{plugin:")) {
String pluginName = value.substring(8, value.length() - 1).trim();
attResult = getTMLContext().plugindbkey(pluginName);
}
else if (lcValue.startsWith("{scoped:")) {
String str = value.substring(8, value.length() - 1).trim();
return getStatus().getScopedString(str);
}
else if (value.length() > 0) {
String expression = value.substring(1, value.length() - 1);
de.innovationgate.wgpublisher.expressions.ExpressionEngine engine = de.innovationgate.wgpublisher.expressions.ExpressionEngineFactory.getEngine(this.getDefaultExpressionLanguage());
de.innovationgate.wgpublisher.expressions.ExpressionResult result = engine.evaluateExpression(expression, this.getTMLContext(),
de.innovationgate.wgpublisher.expressions.ExpressionEngine.TYPE_EXPRESSION, null);
if (result.isError()) {
addExpressionWarning(expression, result);
attResult = "";
}
Object resultValue = result.getResult();
if (resultValue == null) {
attResult = "";
}
else if (resultValue instanceof java.util.Collection) {
attResult = de.innovationgate.utils.WGUtils.serializeCollection((java.util.Collection) resultValue, ",");
}
else {
attResult = resultValue.toString();
}
}
else {
attResult = "";
}
return attResult;
}
/**
* @see BodyTagSupport#doEndTag()
*/
public final int doEndTag() throws JspException {
try {
BaseTagStatus status = getStatus();
if (getTMLContext() == null) {
if (this instanceof Root) {
return SKIP_PAGE;
}
else {
return EVAL_PAGE;
}
}
if (this.getCancelTag() == true) {
return EVAL_PAGE;
}
if (debugNode != null) {
status.iterationDebugNode = debugNode.addElement("endtag");
status.iterationDebugNode.addAttribute("started", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("startedTagSpecific", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
try {
this.tmlEndTag();
}
catch (TMLException exc) {
handleTMLException(exc);
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
}
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("endedTagSpecific", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
if (this.getCancelTag() == true) {
return EVAL_PAGE;
}
if (this.getVar() != null) {
this.getTMLContext().setvar(this.getVar(), status.result, false);
}
if (this.getSessionvar() != null) {
this.getTMLContext().setSessionVar(this.getSessionvar(), status.result, false, false);
}
if (this.isResultOutput() == true && status.result != null) {
this.writeOutput();
}
if (this.getId() == null && status.keepResult == false) {
status.result = null;
}
if (debugNode != null) {
debugNode.addAttribute("ended", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
debugNode.addAttribute("subtags", new Integer(status.subtags).toString());
status.duration = (System.currentTimeMillis() - status.starttime);
status.processingTime += status.duration;
debugNode.addAttribute("duration", new Long(status.duration).toString());
debugNode.addAttribute("processingtime", new Long(status.processingTime).toString());
BaseTagStatus parent = getParentTag();
if (parent != null) {
parent.addSubtags(status.subtags + 1);
parent.processingTime -= status.duration;
}
}
return EVAL_PAGE;
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return EVAL_PAGE;
}
catch (Error exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return EVAL_PAGE;
}
finally {
// Absolute must-do cleanup operations of the tag
try {
tmlCleanup();
}
catch (Exception e) {
log.error("Error in tml tag cleanup", e);
this.addWarning("Exception on tag cleanup: " + e.getClass().getName() + ":" + e.getMessage(), true);
}
}
}
/**
* Method to overwrite for cleanup operations of the tag, that should be executed in any case
* after tag processing, even when an error occurs
*/
protected void tmlCleanup() {
}
/**
* @see BodyTagSupport#doAfterBody()
*/
public final int doAfterBody() throws JspException {
try {
BaseTagStatus status = getStatus();
if (getTMLContext() == null) {
return SKIP_BODY;
}
this.appendResult(this.getBodyContent().getString());
this.getBodyContent().clearBody();
this.setEvalBody(false);
try {
this.tmlAfterBody();
}
catch (TMLException exc) {
handleTMLException(exc);
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
}
if (this.isEvalBody() && this.getCancelTag() == false) {
iterationIncrement();
return EVAL_BODY_BUFFERED;
}
else {
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("ended", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
return SKIP_BODY;
}
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return SKIP_BODY;
}
catch (Error exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
return SKIP_BODY;
}
}
private void handleTMLException(TMLException exc) {
if (!(exc instanceof TMLSilentCancelException)) {
this.addWarning(exc.getMessage(), exc.isCancelTag());
if (exc.getRootCause() != null) {
log.error("Exception in WebTML warning: " + exc.getMessage(), exc.getRootCause());
}
}
if (exc.isCancelTag()) {
this.setCancelTag(true);
}
}
public void tmlStartTag() throws TMLException, WGAPIException {
}
;
public void tmlAfterBody() throws TMLException, WGAPIException {
};
public void tmlInitBody() throws TMLException {
};
public void tmlEndTag() throws TMLException, WGAPIException {
};
/**
* Gets the context
*
* @return Returns a String
*/
public String getContext() {
return this.getTagAttributeValue("context", context, null);
}
/**
* Sets the context
*
* @param context
* The context to set
*/
public void setContext(String context) {
this.context = context;
}
/**
* Gets the id
*
* @return Returns a String
*/
public String getId() {
return this.getTagAttributeValue("id", id, null);
}
/**
* Gets the output
*
* @return Returns a String
*/
public String getOutput() {
return this.getTagAttributeValue("output", output, null);
}
/**
* Sets the output
*
* @param output
* The output to set
*/
public void setOutput(String output) {
this.output = output;
}
/**
* Gets the privateContext
*
* @return Returns a String
*/
public String getPrivatecontext() {
return this.getTagAttributeValue("privatecontext", privateContext, null);
}
/**
* Sets the privateContext
*
* @param privateContext
* The privateContext to set
*/
public void setPrivatecontext(String tmlContext) {
this.privateContext = tmlContext;
}
/**
* Gets the var
*
* @return Returns a String
*/
public String getVar() {
// Retrieve portlet variable name + prefix, if present
String pvar = getPvar();
if (pvar != null && getTMLContext() != null) {
TMLPortlet portlet;
try {
portlet = getTMLContext().getportlet();
}
catch (WGAPIException e) {
log.error("Exception retrieving portlet variable name", e);
return null;
}
if (portlet != null && !portlet.isroot()) {
return portlet.getVarPrefix() + pvar;
}
}
return this.getTagAttributeValue("var", var, null);
}
/**
* Sets the var
*
* @param var
* The var to set
*/
public void setVar(String var) {
this.var = var;
}
/**
* Gets the result
*
* @return Returns a String
*/
protected Object getResult() {
return getStatus().result;
}
public String getResultString() {
return getResultString(true);
}
public String getResultString(boolean includeFormatting) {
BaseTagStatus status = getStatus();
if (status.result == null) {
return "";
}
// Convert result to a list
List results;
if (status.result instanceof List) {
results = (List) status.result;
}
else if (status.result instanceof Collection) {
results = new ArrayList((java.util.Collection) status.result);
}
else {
results = Collections.singletonList(status.result);
}
FormattingChain formatters = new FormattingChain();
if (includeFormatting == true) {
// Get formatter objects regarding the Attributes format and
// encoding
// format Attribute
formatters.addFormatter(new TagOutputFormatter(status.format, getTMLContext(), stringToBoolean(getTrim())));
// Encode the result regarding the encode attribute
String encodersList = getStatus().encode;
if (encodersList != null && !encodersList.equals("none")) {
Iterator encoders = WGUtils.deserializeCollection(encodersList, ",", true).iterator();
while (encoders.hasNext()) {
String encoder = (String) encoders.next();
try {
ObjectFormatter formatter = getCore().getEncodingFormatter(encoder, getTMLContext());
formatters.addFormatter(formatter);
}
catch (FormattingException e) {
addWarning("No encoding formatter registered under encoding key '" + encoder + "'");
}
}
}
}
// Get a string from it. Serialize if it is a collection. Format output
String result = de.innovationgate.utils.WGUtils.serializeCollection(results, (includeFormatting ? status.divider : ""), formatters);
// Set formatting errors as warnings
Iterator errors = formatters.getErrors().iterator();
while (errors.hasNext()) {
FormattingException e = (FormattingException) errors.next();
addWarning("Formatting/Encoding error: " + WGUtils.getRootCause(e).getMessage());
}
// Append prefix and suffix and return, maybe trimmed
String prefix = getPrefix();
String suffix = getSuffix();
StringBuffer completeResult = new StringBuffer(prefix.length() + result.length() + suffix.length());
completeResult.append(prefix);
completeResult.append(result);
completeResult.append(suffix);
if (stringToBoolean(getTrim()) == true) {
return completeResult.toString().trim();
}
else {
return completeResult.toString();
}
}
/**
* @see BodyTagSupport#doInitBody()
*/
public final void doInitBody() throws JspException {
try {
this.tmlInitBody();
this.iterationIncrement();
}
catch (TMLException exc) {
handleTMLException(exc);
}
catch (Exception exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
}
catch (Error exc) {
log.error("Error in tml processing", exc);
this.addWarning(exc.getClass().getName() + ":" + exc.getMessage(), true);
this.setCancelTag(true);
}
}
public java.util.Collection getDatabaseKeys() {
return ((java.util.HashMap) this.pageContext.getServletContext().getAttribute(WGACore.ATTRIB_CONTENTDBS)).keySet();
}
public WGDatabase openContentDB(String key) throws WGException {
return this.getCore().openContentDB(getTMLContext().resolveDBKey(key), (HttpServletRequest) pageContext.getRequest());
}
public javax.servlet.jsp.PageContext getPageContext() {
return this.pageContext;
}
public void iterationIncrement() {
BaseTagStatus status = getStatus();
status.iteration++;
if (debugNode != null) {
if (status.iterationDebugNode != null) {
status.iterationDebugNode.addAttribute("ended", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
}
status.iterationDebugNode = debugNode.addElement("body");
status.iterationDebugNode.addAttribute("started", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
status.iterationDebugNode.addAttribute("iteration", String.valueOf(status.iteration));
try {
status.iterationDebugNode.addAttribute("childcontext", getChildTagContext().getpath());
}
catch (WGAPIException e) {
status.iterationDebugNode.addAttribute("childcontext", "Error: " + e.getClass().getName()+ " message: " + e.getMessage());
}
status.iterationDebugNode.addAttribute("ccloadeddocs", String.valueOf(getChildTagContext().db().getSessionContext().getTotalFetchedCores()));
}
}
/**
* Gets the childTmlContext
*
* @return Returns a TmlContext
*/
public TMLContext getChildTagContext() {
return getStatus().childTMLContext;
}
/**
* Sets the childTagContext
*
* @param childTagContext
* The childTagContext to set
*/
public void setChildTagContext(TMLContext childTagContext) {
this.getStatus().childTMLContext = childTagContext;
}
/**
* Gets the tagContext
*
* @return Returns a TagContext
*/
public TMLContext getTMLContext() {
return getStatus().tmlContext;
}
/**
* Sets the tagContext
*
* @param tagContext
* The tagContext to set
*/
public void setTMLContext(TMLContext tagContext) {
getStatus().tmlContext = tagContext;
if (debugNode != null) {
try {
debugNode.addAttribute("context", getTMLContext().getpath());
}
catch (WGAPIException e) {
debugNode.addAttribute("context", "Error: " + e.getClass().getName()+ " message: " + e.getMessage());
}
}
}
/**
* Gets the evalBody
*
* @return Returns a boolean
*/
public boolean isEvalBody() {
return getStatus().evalBody;
}
/**
* Sets the evalBody
*
* @param evalBody
* The evalBody to set
*/
public void setEvalBody(boolean evalBody) {
getStatus().evalBody = evalBody;
}
/**
* Gets the iteration
*
* @return Returns a int
*/
public int getIteration() {
return getStatus().iteration;
}
/**
* Sets the iteration
*
* @param iteration
* The iteration to set
*/
public void setIteration(int iteration) {
getStatus().iteration = iteration;
}
/**
* Gets the resultOutput
*
* @return Returns a boolean
*/
public boolean isResultOutput() {
return getStatus().resultOutput;
}
/**
* Sets the resultOutput
*
* @param resultOutput
* The resultOutput to set
*/
public void setResultOutput(boolean resultOutput) {
getStatus().resultOutput = resultOutput;
}
/**
* Gets the divider
*
* @return Returns a String
*/
public String getDivider() {
return this.getTagAttributeValue("divider", divider, "");
}
/**
* Sets the divider
*
* @param divider
* The divider to set
*/
public void setDivider(String divider) {
this.divider = divider;
}
/**
* Gets the format
*
* @return Returns a String
*/
public String getFormat() {
return this.getTagAttributeValue("format", format, null);
}
/**
* Sets the format
*
* @param format
* The format to set
*/
public void setFormat(String format) {
this.format = format;
}
public de.innovationgate.wgpublisher.WGPDispatcher getDispatcher() {
return (de.innovationgate.wgpublisher.WGPDispatcher) this.pageContext.getServletContext().getAttribute(WGACore.ATTRIB_DISPATCHER);
}
public de.innovationgate.wgpublisher.WGACore getCore() {
return (de.innovationgate.wgpublisher.WGACore) this.pageContext.getServletContext().getAttribute(WGACore.ATTRIB_CORE);
}
public de.innovationgate.wgpublisher.WGPDeployer getDeployer() {
return (de.innovationgate.wgpublisher.WGPDeployer) this.pageContext.getServletContext().getAttribute(WGACore.ATTRIB_DEPLOYER);
}
public String getMimeType() {
return this.pageContext.getAttribute(WGACore.ATTRIB_MIMETYPE, PageContext.REQUEST_SCOPE).toString();
}
/**
* Gets the encode
*
* @return Returns a String
*/
public String getEncode() {
return this.getTagAttributeValue("encode", encode, null);
}
/**
* Sets the encode
*
* @param encode
* The encode to set
*/
public void setEncode(String encode) {
this.encode = encode;
}
public Integer getLevel() {
BaseTagStatus status = getStatus();
if (status.level == null) {
BaseTagStatus parent = this.getParentTag();
if (parent != null) {
if (this instanceof Root) {
status.level = parent.level;
}
else {
status.level = new Integer(parent.level + 1);
}
}
else {
status.level = new Integer(0);
}
}
return status.level;
}
public String getWGPPath() {
return getTMLContext().getEnvironment().getPublisherURL();
}
public boolean isCollectionsShowReleasedOnly() {
if (!getStatus().isBrowserInterface()) {
return true;
}
Boolean colReleasedOnly = (Boolean) this.pageContext.getSession().getAttribute(WGACore.ATTRIB_BI_COLLECTIONS_SHOW_RELEASED_ONLY);
if (colReleasedOnly != null && colReleasedOnly.booleanValue() == true) {
return true;
}
else {
return false;
}
}
public boolean includeBI3Scripts() {
Boolean bi = (Boolean) this.pageContext.getSession().getAttribute(WGACore.ATTRIB_BI_INCLUDE_BI3_SCRIPTS);
if (bi != null && bi.booleanValue() == false) {
return false;
}
else {
return true; // defaults to "true" if attribute is not set
}
}
protected boolean isChildContextErrornous() {
return getStatus().subContextError;
}
/**
* Gets the cancelTag
*
* @return Returns a boolean
*/
public boolean getCancelTag() {
return getStatus().cancelTag;
}
/**
* Sets the cancelTag
*
* @param cancelTag
* The cancelTag to set
*/
public void setCancelTag(boolean cancelTag) {
getStatus().cancelTag = cancelTag;
}
public OutputStream getOutputStream() {
try {
return this.getResponse().getOutputStream();
}
catch (IOException e) {
log.error("Error retrieving output stream", e);
return null;
}
}
public HttpServletResponse getResponse() {
HttpServletResponse response = (HttpServletResponse) this.pageContext.getRequest().getAttribute(WGACore.ATTRIB_SERVLETRESPONSE);
if (response != null) {
return response;
}
else {
return (HttpServletResponse) getPageContext().getResponse();
}
}
public Object getOption(String optionName) {
return getStatus().getOption(optionName);
}
/**
* @see javax.servlet.jsp.tagext.Tag#release()
*/
public void release() {
removeValue(TAGVALUE_STATUS);
super.release();
}
public TMLUserProfile getUserProfile(WGDatabase db) {
DomainConfiguration domainConfig = getCore().getDomainConfigForDatabase(db);
TMLUserProfile profile = (TMLUserProfile) getPageContext().getRequest().getAttribute(WGACore.ATTRIB_PROFILE + db.getDbReference());
if (profile == null) {
try {
return getDispatcher().fetchUserProfile((HttpServletRequest) getPageContext().getRequest(), (HttpServletResponse) getPageContext().getResponse(), db, getPageContext().getSession());
}
catch (WGAPIException e) {
getCore().getLog().error("Unable to retrieve user profile", e);
}
}
return profile;
}
public TMLUserProfile getUserProfile() {
return this.getUserProfile(this.getTMLContext().getdocument().getDatabase());
}
/**
* Returns the sessionvar.
*
* @return String
*/
public String getSessionvar() {
// Retrieve portlet variable name + prefix, if present
String pvar = getPsessionvar();
if (pvar != null && getTMLContext() != null) {
TMLPortlet portlet;
try {
portlet = getTMLContext().getportlet();
}
catch (WGAPIException e) {
log.error("Exception retrieving portlet variable name", e);
return null;
}
if (portlet != null && !portlet.isroot()) {
return portlet.getVarPrefix() + pvar;
}
}
return this.getTagAttributeValue("sessionvar", sessionvar, null);
}
/**
* Sets the sessionvar.
*
* @param sessionvar
* The sessionvar to set
*/
public void setSessionvar(String sessionvar) {
this.sessionvar = sessionvar;
}
public String getDefaultExpressionLanguage() {
// Static tml has always expression language tmlscript, as this works for all DB implementations
String requestType =
(String) this.pageContext.getRequest().getAttribute(WGACore.ATTRIB_REQUESTTYPE);
if(requestType.equals(WGPDispatcher.REQUESTTYPE_STATICTML)) {
return ExpressionEngineFactory.ENGINE_TMLSCRIPT;
}
// Try to retrieve XPL set by Attrib defaultxpl in Range-Tag
String xplang = (String) this.getOption(Base.OPTION_DEFAULT_XPLANGUAGE);
// Get XPL by current design db
if (xplang == null) {
WGDatabase db = null;
try {
db = openContentDB(getDesignDBKey());
}
catch (WGException e) {
}
if (db != null) {
xplang = (String) db.getAttribute(WGACore.DBATTRIB_EXPRESSION_DEFAULT);
}
else {
return ExpressionEngineFactory.ENGINE_TMLSCRIPT;
}
}
return xplang;
}
public String buildActionURL(TMLAction action, List params, String portletMode, String portletContext) throws UnsupportedEncodingException, WGAPIException {
return getTMLContext().getURLBuilder().buildActionURL(getTMLContext(), action, params, portletMode, portletContext);
}
protected String buildActionURL(TMLAction action, String portletMode, String portletContext) throws UnsupportedEncodingException, WGAPIException {
return buildActionURL(action, null, portletMode, portletContext);
}
/*
* public TMLActionLink createCustomActionLink(Integer actionKey, List
* params, TMLContext context) { return
* createActionLink(String.valueOf(actionKey), params, context); }
*/
/**
* @see Base#tmlStartTag()
*/
protected Element debugNode = null;
private String pvar;
private String psessionvar;
/**
* @param rootElement
*/
protected void createDebugNode(Element parent) {
BaseTagStatus status = getStatus();
status.starttime = System.currentTimeMillis();
String className = getClass().getName();
className = className.substring(className.lastIndexOf(".") + 1).toLowerCase();
debugNode = parent.addElement("tmltag");
debugNode.addAttribute("name", className);
if (this instanceof Root) {
debugNode.addAttribute("resource", ((Root) this).getResource());
debugNode.addAttribute("path", debugNode.getUniquePath());
}
debugNode.addAttribute("sourceline", getSourceline());
debugNode.addAttribute("started", DEBUG_TIMESTAMP_FORMAT.format(new Date()));
debugNode.addAttribute("level", getLevel().toString());
if (debugNode.getDocument().getRootElement().attributeValue("traceroptions", "false").equals("false")) {
return;
}
Element options = debugNode.addElement("options");
Iterator opts = status.tagOptions.keySet().iterator();
String key;
Element optionElem;
TMLOption tmloption;
while (opts.hasNext()) {
key = (String) opts.next();
if (!key.startsWith("$")) {
tmloption = (TMLOption) status.tagOptions.get(key);
optionElem = options.addElement("option");
optionElem.addAttribute("name", tmloption.getName());
optionElem.addAttribute("type", (tmloption.getValue() != null ? tmloption.getValue().getClass().getName() : "(none)"));
optionElem.addText(String.valueOf(tmloption.getValue()));
}
}
}
/**
* @param string
*/
public void setSuffix(String string) {
getStatus().suffix = string;
}
/**
* @param string
*/
public void setPrefix(String string) {
getStatus().prefix = string;
}
public String getSuffix() {
return getStatus().suffix;
}
public String getPrefix() {
return getStatus().prefix;
}
public Element getDebugNode() {
return debugNode;
}
public Element getIterationDebugNode() {
return getStatus().iterationDebugNode;
}
public String getSourceline() {
return sourceline;
}
public void setSourceline(String string) {
sourceline = string;
}
protected String buildCallActionLink(String sAction, String formID, List params, String portletMode, String portletContext) throws WGAPIException {
TMLAction tmlAction = getTMLContext().getActionByID(sAction, getDesignDBKey());
if (tmlAction != null) {
TMLActionLink actionLinkObj = tmlAction.createActionLink(params, getTMLContext());
actionLinkObj.setPortletmode(portletMode);
if (portletContext != null) {
actionLinkObj.setPortletContextPath(getTMLContext(), portletContext);
}
String actionLink;
//if (formBase != null && formBase.getMode().equals(FormInfo.EDIT_MODE)) {
//--> none editable forms should be submitted to ensure access in tml:action
if (formID != null) {
actionLink = actionLinkObj.getJavascriptLink(getCore(), formID);
}
else {
actionLink = actionLinkObj.getJavascriptLink(getCore(), null);
}
return actionLink;
}
else {
return null;
}
}
protected void addExpressionWarning(String expression, ExpressionResult result) {
WGExpressionException exc = result.getException();
// Put out as WebTML Warning
String warningMessage = exc.getMessage() + (exc.getExpression() != null ? "\nExpression line: " + exc.getExpression() : "\nExpression:\n" + expression);
if (!WGUtils.isEmpty(exc.getNativeStackTrace())) {
warningMessage += "\n" + exc.getNativeStackTrace();
}
this.addWarning(warningMessage);
// Put out on log
if (exc.getCause() != null) {
getTMLContext().getlog().error("Exception executing tmlscript", exc.getCause());
}
else if (!WGUtils.isEmpty(exc.getNativeStackTrace())) {
getTMLContext().getlog().error("Exception executing tmlscript: " + exc.getMessage() + "\n" + exc.getNativeStackTrace());
}
}
/**
* @return Returns the trim.
*/
public String getTrim() {
return getTagAttributeValue("trim", trim, "false");
}
/**
* @param trim
* The trim to set.
*/
public void setTrim(String trim) {
this.trim = trim;
}
public String includeScript(String script) {
StringBuffer scriptresult = new StringBuffer("");
WGContent content = this.getTMLContext().content();
script = script.toLowerCase();
List includedscripts = (List) getPageContext().getRequest().getAttribute("includedscripts");
if (includedscripts != null && includedscripts.contains(script))
return "";
if (script.equals("htmlhead")) {
scriptresult.append("<script type=\"text/javascript\" language=\"Javascript\" src=\"" + getWGPPath() + "/static/js/htmlhead.js" + URL_VERSION_PARAMETER + "\"></script>\n");
}
if (includedscripts == null) {
includedscripts = new ArrayList();
}
includedscripts.add(script);
getPageContext().getRequest().setAttribute("includedscripts", includedscripts);
return scriptresult.toString();
}
public WGDatabase openDesignDB() throws WGException {
String designKey = (String) getDesignDBKey();
if (designKey != null) {
return this.openContentDB(designKey);
}
else {
return this.getTMLContext().db();
}
}
/**
* creates an javascript functioncall
* to call the given action with given params as ajaxAction
* @param action
* @param params
* @param ajaxMode the ajax mode for this action call - valid values: ActionBase.AJAX_MODE_NO_PORTLET_REFRESH
* @param portletMode the portlet mode to set after action call
* @return Javascript-Function call
* @throws WGAPIException
*/
protected String getAjaxJSFunction(TMLAction action, List params, String ajaxMode, String portletMode, String portletContext) throws WGAPIException {
TMLActionLink actionLink = action.createActionLink(params, getTMLContext());
//F00004242
if (ajaxMode != null && ajaxMode.equalsIgnoreCase(ActionBase.AJAX_MODE_NO_PORTLET_REFRESH)) {
actionLink.setMode(TMLActionLink.MODE_AJAX_NO_PORTLET_REFRESH);
}
actionLink.setPortletmode(portletMode);
if (portletContext != null) {
actionLink.setPortletContextPath(getTMLContext(), portletContext);
}
String id = (String) this.getOption(Include.OPTION_AJAX_DIVTAG_ID);
String strAction = actionLink.getJavascriptLink(getCore(), getStatus().getRelevantForm());
AjaxActionDefinition actionDef = new AjaxActionDefinition(strAction, id);
//F00004242
if (ajaxMode != null && ajaxMode.equalsIgnoreCase(ActionBase.AJAX_MODE_NO_PORTLET_REFRESH)) {
actionDef.setGraydiv(false);
actionDef.setMode(ActionBase.AJAX_MODE_NO_PORTLET_REFRESH);
}
return "WGA.ajax.action(" + actionDef.toJavaScriptObject() + ")";
}
/**
* creates an javascript functioncall
* to call the given action as ajaxAction
* @param action
* @param ajaxMode the ajax mode for this action call - valid values: ActionBase.AJAX_MODE_NO_PORTLET_REFRESH
* @param protletMode the portletmode to set after action call
* @return Javascript-Function call
* @throws WGAPIException
*/
protected String getAjaxJSFunction(TMLAction action, String ajaxMode, String portletMode, String portletContext) throws WGAPIException {
return this.getAjaxJSFunction(action, null, ajaxMode, portletMode, portletContext);
}
/**
* creates an javascript functioncall
* to call the given action with given params as simple action.
* @param action
* @param params
* @param portletMode the portletmode to set after action call
* @return Javascript-Function call
* @throws WGAPIException
*/
protected String getJSFunction(TMLAction action, List params, String portletMode, String portletContext) throws WGAPIException {
TMLActionLink actionLink = action.createActionLink(params, getTMLContext());
String strAction = actionLink.getJavascriptLink(getCore(), getStatus().getRelevantForm());
actionLink.setPortletmode(portletMode);
if (portletContext != null) {
actionLink.setPortletContextPath(getTMLContext(), portletContext);
}
return "callAction('" + strAction + "')";
}
/**
* creates an javascript functioncall
* to call the given action as simple action.
* @param action
* @param params
* @param portletMode the portletmode to set after action call
* @return Javascript-Function call
* @throws WGAPIException
*/
protected String getJSFunction(TMLAction action, String portletMode, String portletContext) throws WGAPIException {
return getJSFunction(action, null, portletMode, portletContext);
}
public String getPvar() {
return getTagAttributeValue("pvar", pvar, null);
}
public String getPsessionvar() {
return getTagAttributeValue("psessionvar", psessionvar, null);
}
public void setPvar(String pvar) {
this.pvar = pvar;
}
public void setPsessionvar(String pvar) {
this.psessionvar = pvar;
}
public String getTagName() {
String className = getClass().getName();
return className.substring(className.lastIndexOf(".") + 1).toLowerCase();
}
public void buildHTMLHead(boolean metaOutput, String scripts) throws WGAPIException {
TMLContext context = this.getTMLContext();
WGContent content = context.content();
if( content != null ){
// Eventually put out meta tags
this.appendResult("<meta name=\"generator\" content=\"").appendResult(WGACore.getReleaseString()).appendResult("\">\n");
if (metaOutput == true ) {
this.appendResult("<meta name=\"keywords\" content=\"").appendResult(de.innovationgate.utils.WGUtils.serializeCollection(content.getKeywords(), ",")).appendResult("\">\n");
}
}
this.appendResult(includeScript("htmlhead"));
this.appendResult("<script type=\"text/javascript\">");
this.appendResult("WGA.contextpath=\"" + getWGPPath() + "\";"); // used by htmlhead.js since wga-4
this.appendResult("WGA.emptyActionParam =\"" + TMLActionLink.EMPTY_PARAM + "\";");
this.appendResult("</script>\n");
BaseTagStatus status = getStatus();
if(status.isBrowserInterface() && status.isBrowserInterface4()){
// new Content Manager (wga-4-bi) stuff:
this.appendResult("<script type=\"text/javascript\">");
this.appendResult("\nWGA.contentinfo={");
this.appendResult("\n\tdbkey:\"" + content.getDatabase().getDbReference() + "\"");
if(!content.isDummy()){
this.appendResult(",");
WGStructEntry structentry = content.getStructEntry();
this.appendResult("\n\tstructkey:\"" + structentry.getStructKey() + "\",");
this.appendResult("\n\tcontentkey:\"" + content.getContentKey(true) + "\",");
//this.appendResult("\n\ttitle:\"" + WGUtils.strReplace(content.getTitle(), "\"", "\\\"", true));
this.appendResult("\n\ttitle:\"" + WGUtils.strReplace(WGUtils.strReplace(content.getTitle(), "\"", "\\\"", true), "script", "sc\"+\"ript", true));
this.appendResult("\",");
this.appendResult("\n\tlanguage:\"" + content.getLanguage().getName() + "\"");
}
this.appendResult("\n}");
this.appendResult("\n</script>\n");
String prefLanguage = content.getLanguage().getName();
getPageContext().getSession().setAttribute("PreferredLanguage", prefLanguage);
}
// optional includes for input fields
if (scripts!=null){
java.util.StringTokenizer options = new java.util.StringTokenizer(scripts, ",");
while (options.hasMoreTokens()) {
this.appendResult(includeScript(options.nextToken().trim()));
}
}
// Process HTML head inclusion modules
for (HTMLHeadInclusion inc : getCore().getHtmlHeadInclusions()) {
try {
CharSequence result = inc.processInclusion(getTMLContext());
if (result != null) {
appendResult(String.valueOf(result));
}
}
catch (Throwable e) {
getTMLContext().getlog().error("Exception processing HTML head inclusion " + inc.getClass().getName(), e);
}
}
}
public String getTagDescription() {
String requestType = (String) getPageContext().getRequest().getAttribute(WGACore.ATTRIB_REQUESTTYPE);
if (requestType.equals(WGPDispatcher.REQUESTTYPE_STATICTML)) {
return "tml:" + getTagName() + " in static WebTML-Module " + getStatus().getRootTag().resource;
}
else {
return "tml:" + getTagName() + " on line " + getSourceline() + " in WebTML-Module " + getStatus().getTMLModuleName() + "/" + getStatus().getTMLModuleMediaKey() + " (" + getDesignDBKey() + ")";
}
}
public boolean isAjaxRequest() {
return (getPageContext().getRequest().getAttribute(WGACore.ATTRIB_AJAXINFO) != null);
}
protected StringBuffer createItemEditorDeclaration(String itemName, String editor, String label) {
StringBuffer prefix = new StringBuffer("<span class=\"WGA-Item\">\n");
prefix.append("<span class=\"WGA-Item-Info\" style=\"display:none\">");
prefix.append(itemName+"|"+editor);
prefix.append("</span>\n");
if (!editor.equalsIgnoreCase("custom")) {
prefix.append("<span class=\"WGA-Editor-Options\" style=\"display:none\">");
prefix.append("{" + getResultString(false) +"}");
prefix.append("</span>\n");
// Old Style WGA4 Options:
if (editor.equalsIgnoreCase("rtf")) {
prefix.append("<span class=\"WGA4-Editor-Options\" style=\"display:none\">");
prefix.append("{");
String opt;
opt = (String) getTMLContext().option("tabelStyleList");
if(opt != null)
prefix.append("tabelStyleList:[" + opt + "],");
opt = (String) getTMLContext().option("trStyleList");
if(opt != null)
prefix.append("trStyleList:[" + opt + "],");
opt = (String) getTMLContext().option("tdStyleList");
if(opt != null)
prefix.append("tdStyleList:[" + opt + "],");
opt = (String) getTMLContext().option("paragraphStyleList");
if(opt != null)
prefix.append("paragraphStyleList:[" + opt + "],");
opt = (String) getTMLContext().option("showoptions");
if(opt != null)
prefix.append("showoptions:\"" + opt + "\",");
opt = (String) getTMLContext().option("hideoptions");
if(opt != null)
prefix.append("hideoptions:\"" + opt + "\",");
prefix.append("dummy:true");
prefix.append("}");
prefix.append("</span>\n");
}
}
prefix.append("<span class=\"WGA-Item-Edit\" style=\"display:none\"></span>");
prefix.append("<span class=\"WGA-Item-Label\" style=\"display:none\">");
prefix.append(label);
prefix.append("</span>\n");
return prefix;
}
public String getDesignDBKey() {
return getStatus().getDesignDBKey();
}
}