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: * This aspect streams a cinclude statement into the stream that
032: * will include the coplet using the coplet protocol.
033: *
034: * <h2>Resulting XML:</h2>
035: * <pre>
036: * <content>
037: * <xy:z src="coplet://copletID"/>
038: * </content>
039: * </pre>
040: * where <code>xy</code> is the CInclude namespace and <code>z</code> is
041: * the CInclude tagname.
042: * By default, the cinclude statetement is surrounded by a "content" element;
043: * this can be further controlled by parameters (see below).
044: *
045: * <h2>Applicable to:</h2>
046: * <ul>
047: * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
048: * </ul>
049: *
050: * <h2>Parameters</h2>
051: * <table><tbody>
052: * <tr><th>root-tag</th><td>Should a tag enclosing the cinclude be generated? (Default is true)</td>
053: * <td></td><td>boolean</td><td><code>true</code></td></tr>
054: * <tr><th>tag-name</th><td>Name of enclosing tag.</td>
055: * <td></td><td>String</td><td><code>"content"</code></td></tr>
056: * </tbody></table>
057: *
058: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
059: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
060: *
061: * @version CVS $Id: CIncludeCopletAspect.java 433543 2006-08-22 06:22:54Z crossley $
062: */
063: public class CIncludeCopletAspect extends AbstractCIncludeAspect {
064:
065: /* (non-Javadoc)
066: * @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)
067: */
068: public void toSAX(RendererAspectContext context, Layout layout,
069: PortalService service, ContentHandler handler)
070: throws SAXException {
071: final PreparedConfiguration config = (PreparedConfiguration) context
072: .getAspectConfiguration();
073: final CopletInstanceData cid = ((CopletLayout) layout)
074: .getCopletInstanceData();
075: if (!(context.isRendering())) {
076: context.invokeNext(layout, service, handler);
077: }
078: if (config.rootTag) {
079: XMLUtils.startElement(handler, config.tagName);
080: }
081:
082: this .createCInclude("coplet://" + cid.getId(), handler);
083:
084: if (config.rootTag) {
085: XMLUtils.endElement(handler, config.tagName);
086: }
087:
088: context.invokeNext(layout, service, handler);
089: }
090:
091: protected static class PreparedConfiguration {
092:
093: public String tagName;
094: public boolean rootTag;
095:
096: public void takeValues(PreparedConfiguration from) {
097: this .tagName = from.tagName;
098: this .rootTag = from.rootTag;
099: }
100: }
101:
102: /* (non-Javadoc)
103: * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
104: */
105: public Object prepareConfiguration(Parameters configuration)
106: throws ParameterException {
107: PreparedConfiguration pc = new PreparedConfiguration();
108: pc.tagName = configuration.getParameter("tag-name", "content");
109: pc.rootTag = configuration.getParameterAsBoolean("root-tag",
110: true);
111: return pc;
112: }
113:
114: }
|