001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.cocoon.portal.layout.renderer.aspect.impl;
018:
019: import org.apache.avalon.framework.parameters.ParameterException;
020: import org.apache.avalon.framework.parameters.Parameters;
021: import org.apache.cocoon.portal.PortalService;
022: import org.apache.cocoon.portal.coplet.CopletInstanceData;
023: import org.apache.cocoon.portal.layout.Layout;
024: import org.apache.cocoon.portal.layout.impl.CopletLayout;
025: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
026: import org.apache.cocoon.xml.XMLUtils;
027: import org.xml.sax.ContentHandler;
028: import org.xml.sax.SAXException;
029:
030: /**
031: * Create a title tag for a coplet as well as an optional enclosing tag.
032: *
033: * <h2>Example XML:</h2>
034: * <pre>
035: * <window>
036: * <title>title</title>
037: * </window>
038: * </pre>
039: *
040: *
041: * <h2>Applicable to:</h2>
042: * <ul>
043: * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
044: * </ul>
045: *
046: * <h2>Parameters</h2>
047: * <table><tbody>
048: * <tr><th>root-tag</th><td>Should a tag enclosing the following output be generated?</td>
049: * <td></td><td>boolean</td><td><code>true</code></td></tr>
050: * <tr><th>tag-name</th><td>Name of tag enclosing follwoing output if requested.</td>
051: * <td></td><td>String</td><td><code>"window"</code></td></tr>
052: * </tbody></table>
053: *
054: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
055: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
056: *
057: * @version CVS $Id: WindowAspect.java 433543 2006-08-22 06:22:54Z crossley $
058: */
059: public final class WindowAspect extends AbstractAspect {
060:
061: /* (non-Javadoc)
062: * @see org.apache.cocoon.portal.layout.renderer.RendererAspect#toSAX(org.apache.cocoon.portal.layout.renderer.RendererAspectContext, org.apache.cocoon.portal.layout.Layout, org.apache.cocoon.portal.PortalService, org.xml.sax.ContentHandler)
063: */
064: public void toSAX(RendererAspectContext context, Layout layout,
065: PortalService service, ContentHandler contenthandler)
066: throws SAXException {
067: final PreparedConfiguration config = (PreparedConfiguration) context
068: .getAspectConfiguration();
069: final CopletInstanceData copletInstanceData = ((CopletLayout) layout)
070: .getCopletInstanceData();
071:
072: if (config.rootTag) {
073: XMLUtils.startElement(contenthandler, config.tagName);
074: }
075: XMLUtils.createElement(contenthandler, "title",
076: copletInstanceData.getTitle());
077: XMLUtils.createElement(contenthandler, "instance-id",
078: copletInstanceData.getId());
079:
080: context.invokeNext(layout, service, contenthandler);
081:
082: if (config.rootTag) {
083: XMLUtils.endElement(contenthandler, config.tagName);
084: }
085: }
086:
087: protected static class PreparedConfiguration {
088: public String tagName;
089: public boolean rootTag;
090:
091: public void takeValues(PreparedConfiguration from) {
092: this .tagName = from.tagName;
093: this .rootTag = from.rootTag;
094: }
095: }
096:
097: /* (non-Javadoc)
098: * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
099: */
100: public Object prepareConfiguration(Parameters configuration)
101: throws ParameterException {
102: PreparedConfiguration pc = new PreparedConfiguration();
103: pc.tagName = configuration.getParameter("tag-name", "window");
104: pc.rootTag = configuration.getParameterAsBoolean("root-tag",
105: true);
106: return pc;
107: }
108:
109: }
|