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 java.util.Collections;
020: import java.util.Iterator;
021:
022: import org.apache.avalon.framework.parameters.ParameterException;
023: import org.apache.avalon.framework.parameters.Parameters;
024: import org.apache.cocoon.portal.PortalService;
025: import org.apache.cocoon.portal.aspect.impl.DefaultAspectDescription;
026: import org.apache.cocoon.portal.layout.Layout;
027: import org.apache.cocoon.portal.layout.impl.FrameLayout;
028: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
029: import org.xml.sax.ContentHandler;
030: import org.xml.sax.SAXException;
031:
032: /**
033: * Adds a cinclude tag for a FrameLayout's source to the resulting stream.
034: *
035: * <h2>Example XML:</h2>
036: * <pre>
037: * <xy:z src="coplet://copletID"/>
038: * </pre>
039: *
040: * <h2>Applicable to:</h2>
041: * <ul>
042: * <li>{@link org.apache.cocoon.portal.layout.impl.FrameLayout}</li>
043: * </ul>
044: *
045: * <h2>Parameters</h2>
046: * <table><tbody>
047: * <tr><th>aspect-name</th><td></td><td></td><td>String</td><td><code>"frame"</code></td></tr>
048: * <tr><th>store</th><td></td><td>req</td><td>String</td><td><code>null</code></td></tr>
049: * </tbody></table>
050: *
051: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
052: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
053: *
054: * @version CVS $Id: FrameAspect.java 433543 2006-08-22 06:22:54Z crossley $
055: */
056: public class FrameAspect extends AbstractCIncludeAspect {
057:
058: public void toSAX(RendererAspectContext context, Layout layout,
059: PortalService service, ContentHandler handler)
060: throws SAXException {
061: PreparedConfiguration config = (PreparedConfiguration) context
062: .getAspectConfiguration();
063:
064: if (!(layout instanceof FrameLayout)) {
065: throw new SAXException(
066: "Wrong layout type, FrameLayout expected: "
067: + layout.getClass().getName());
068: }
069:
070: String source = (String) layout
071: .getAspectData(config.aspectName);
072: if (source == null) {
073: source = ((FrameLayout) layout).getSource();
074: }
075:
076: this .createCInclude(source, handler);
077: }
078:
079: protected static class PreparedConfiguration {
080: public String aspectName;
081: public String store;
082:
083: public void takeValues(PreparedConfiguration from) {
084: this .aspectName = from.aspectName;
085: this .store = from.store;
086: }
087: }
088:
089: /* (non-Javadoc)
090: * @see org.apache.cocoon.portal.layout.renderer.aspect.RendererAspect#prepareConfiguration(org.apache.avalon.framework.parameters.Parameters)
091: */
092: public Object prepareConfiguration(Parameters configuration)
093: throws ParameterException {
094: PreparedConfiguration pc = new PreparedConfiguration();
095: pc.aspectName = configuration.getParameter("aspect-name",
096: "frame");
097: pc.store = configuration.getParameter("store");
098: return pc;
099: }
100:
101: /**
102: * Return the aspects required for this renderer
103: * @return An iterator for the aspect descriptions or null.
104: */
105: public Iterator getAspectDescriptions(Object configuration) {
106: PreparedConfiguration pc = (PreparedConfiguration) configuration;
107:
108: DefaultAspectDescription desc = new DefaultAspectDescription();
109: desc.setName(pc.aspectName);
110: desc.setClassName("java.lang.String");
111: desc.setPersistence(pc.store);
112: desc.setAutoCreate(false);
113:
114: return Collections.singletonList(desc).iterator();
115: }
116: }
|