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.util;
019:
020: import java.io.IOException;
021: import java.io.Writer;
022: import java.util.*;
023: import de.finix.contelligent.*;
024: import de.finix.contelligent.render.*;
025: import de.finix.contelligent.logging.LoggingService;
026: import de.finix.contelligent.search.Metainfo;
027:
028: /**
029: * A <code>CategoryValue</code> writes the current value of a {@link Category}
030: * of the actual session when its gets {@link #render rendered}.
031: */
032: public class CategoryValue implements Component, Renderable, Renderer {
033: final static org.apache.log4j.Logger log = LoggingService
034: .getLogger(CategoryValue.class);
035:
036: final static private String PARAM_CATEGORY = "category";
037:
038: final static private ParameterDescription[] parameters = new ParameterDescription[] { new ParameterDescription(
039: PARAM_CATEGORY,
040: "The name of the category to display the value of.", true) };
041:
042: protected ComponentContext ctx;
043:
044: public ParameterDescription[] getParameterDescription() {
045: return parameters;
046: }
047:
048: /**
049: * Implementation of {@link Component#postCreate}. This implementation
050: * doesn't do anything.
051: */
052: public void postCreate() {
053: }
054:
055: /**
056: * Implementation of {@link Component#setComponentContext}.
057: */
058: public void setComponentContext(ComponentContext ctx) {
059: this .ctx = ctx;
060: }
061:
062: /**
063: * Implementation of {@link Component#getComponentContext}.
064: */
065: public ComponentContext getComponentContext() {
066: return ctx;
067: }
068:
069: /**
070: * Implementation of {@link Component#isDynamic}. This implementation
071: * always returns true.
072: */
073: public boolean isDynamic() {
074: return true;
075: }
076:
077: /**
078: * Implementation of {@link Component#mayChangeContent}. This
079: * implementation always returns false.
080: */
081: public boolean mayChangeContent() {
082: return false;
083: }
084:
085: /**
086: * Implementation of {@link Component#putSearchMetainfo}. This
087: * implementation doesn't do anything.
088: */
089: public void putSearchMetainfo(Metainfo metainfo, CallData callData) {
090: }
091:
092: /**
093: * returns the path of this component as string. (without a trailing
094: * separator!)
095: */
096: final public String toString() {
097: if (ctx != null) {
098: return ctx.getPath().toString();
099: } else {
100: return "CategoryValue (name unknown)";
101: }
102: }
103:
104: public Renderer getRenderer() {
105: return this ;
106: }
107:
108: public Collection getSensitiveCategories() {
109: return Collections.EMPTY_SET;
110: }
111:
112: public void render(Writer writer, Map parameterMap,
113: CallData callData) throws IOException,
114: MissingParameterException {
115: RenderUtils.checkParameters(parameterMap, this ); // throws
116: // MissingParameterException
117: String categoryName = ((String[]) parameterMap
118: .get(PARAM_CATEGORY))[0];
119: Map categoryMap = callData.getCategoryMap();
120: String categoryValue = (String) categoryMap.get(categoryName);
121: if (log.isDebugEnabled()) {
122: log.debug("current value for category " + categoryName
123: + " is " + categoryValue + "' ...");
124: }
125: if (categoryValue == null)
126: writer.write("undefined");
127: else
128: writer.write(categoryValue);
129: }
130:
131: }
|