001: /*
002: * Copyright 2001-2006 C:1 Financial Services GmbH
003: *
004: * This software is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License Version 2.1, as published by the Free Software Foundation.
007: *
008: * This software is distributed in the hope that it will be useful,
009: * but WITHOUT ANY WARRANTY; without even the implied warranty of
010: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
011: * Lesser General Public License for more details.
012: *
013: * You should have received a copy of the GNU Lesser General Public
014: * License along with this library; if not, write to the Free Software
015: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA
016: */
017:
018: package de.finix.contelligent.components;
019:
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.util.ArrayList;
023: import java.util.Collection;
024: import java.util.HashMap;
025: import java.util.Iterator;
026: import java.util.Map;
027: import java.util.regex.Pattern;
028:
029: import de.finix.contelligent.CallData;
030: import de.finix.contelligent.category.CategoryException;
031: import de.finix.contelligent.category.CategoryManager;
032: import de.finix.contelligent.category.CategorySubset;
033: import de.finix.contelligent.content.ContelligentTextContent;
034: import de.finix.contelligent.content.Content;
035: import de.finix.contelligent.content.ContentProvider;
036: import de.finix.contelligent.content.TextContent;
037: import de.finix.contelligent.core.ContelligentImpl;
038: import de.finix.contelligent.exception.ContelligentException;
039: import de.finix.contelligent.logging.LoggingService;
040: import de.finix.contelligent.render.MissingParameterException;
041: import de.finix.contelligent.render.ParameterDescription;
042: import de.finix.contelligent.render.Renderable;
043: import de.finix.contelligent.render.Renderer;
044:
045: public class CStyledText extends CText implements ContentProvider,
046: Renderable, Renderer {
047: final static org.apache.log4j.Logger log = LoggingService
048: .getLogger(CStyledText.class);
049:
050: private TextContent content;
051:
052: private static Map htmlToDocbook = new HashMap();
053:
054: static {
055: htmlToDocbook.put(Pattern.compile("<b>"), "<emphasis>");
056: htmlToDocbook.put(Pattern.compile("</b>"), "</emphasis>");
057: htmlToDocbook.put(Pattern.compile("<u>"), "<emphasis>");
058: htmlToDocbook.put(Pattern.compile("</u>"), "</emphasis>");
059: htmlToDocbook.put(Pattern.compile("<i>"), "<emphasis>");
060: htmlToDocbook.put(Pattern.compile("</i>"), "</emphasis>");
061: htmlToDocbook.put(Pattern.compile("&"), "&");
062: htmlToDocbook.put(Pattern.compile("<BR>"), "<para/>");
063: }
064:
065: public void postCreate() throws Exception {
066: content = new ContelligentTextContent(this ,
067: ContelligentTextContent.EVALUATE);
068: }
069:
070: public boolean isDynamic() {
071: return false;
072: }
073:
074: public Renderer getRenderer() {
075: return this ;
076: }
077:
078: public Content getContent() {
079: return content;
080: }
081:
082: public ParameterDescription[] getParameterDescription() {
083: return new ParameterDescription[0];
084: }
085:
086: public void render(Writer writer, Map parameterMap,
087: CallData callData) throws IOException,
088: MissingParameterException, ContelligentException {
089: String stringContent = content.getText(callData);
090: if (stringContent != null) {
091: if (callData.getSystem().getCategoryManager().getChannel(
092: callData).equals(CategoryManager.XML_CHANNEL)) {
093: for (Iterator i = htmlToDocbook.entrySet().iterator(); i
094: .hasNext();) {
095: Map.Entry entry = (Map.Entry) i.next();
096: stringContent = ((Pattern) entry.getKey()).matcher(
097: stringContent).replaceAll(
098: (String) entry.getValue());
099: }
100: }
101: writer.write(stringContent);
102: }
103: }
104:
105: public Collection getSensitiveCategories() {
106: Collection categories = new ArrayList();
107: try {
108: CategorySubset category = new CategorySubset(
109: ContelligentImpl.getInstance().getCategoryManager()
110: .getCategory(CategoryManager.CHANNEL));
111: category.addValue(CategoryManager.HTML_CHANNEL);
112: category.addValue(CategoryManager.XML_CHANNEL);
113: categories.add(category);
114: } catch (CategoryException e) {
115: log.error("Error while creating supported channels!", e);
116: }
117: return categories;
118: }
119: }
|