01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one or more
03: * contributor license agreements. See the NOTICE file distributed with
04: * this work for additional information regarding copyright ownership.
05: * The ASF licenses this file to You under the Apache License, Version 2.0
06: * (the "License"); you may not use this file except in compliance with
07: * the License. You may obtain a copy of the License at
08: *
09: * http://www.apache.org/licenses/LICENSE-2.0
10: *
11: * Unless required by applicable law or agreed to in writing, software
12: * distributed under the License is distributed on an "AS IS" BASIS,
13: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14: * See the License for the specific language governing permissions and
15: * limitations under the License.
16: */
17: package org.apache.cocoon.portal.layout.renderer.aspect.impl;
18:
19: import org.apache.cocoon.portal.PortalService;
20: import org.apache.cocoon.portal.coplet.CopletInstanceData;
21: import org.apache.cocoon.portal.event.impl.LayoutRemoveEvent;
22: import org.apache.cocoon.portal.layout.Layout;
23: import org.apache.cocoon.portal.layout.impl.CopletLayout;
24: import org.apache.cocoon.portal.layout.renderer.aspect.RendererAspectContext;
25: import org.apache.cocoon.xml.XMLUtils;
26: import org.xml.sax.ContentHandler;
27: import org.xml.sax.SAXException;
28:
29: /**
30: * Add a tag holding a URI used to remove a coplet from a layout to the
31: * output stream if the coplet is not set to mandatory.
32: *
33: * <h2>Example XML:</h2>
34: * <pre>
35: * <remove-uri>layout-remove-event</remove-uri>
36: * <!-- output from following renderers -->
37: * </pre>
38: *
39: * <h2>Applicable to:</h2>
40: * <ul>
41: * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
42: * </ul>
43: *
44: * @author <a href="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
45: * @author <a href="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
46: *
47: * @version CVS $Id: RemovableAspect.java 433543 2006-08-22 06:22:54Z crossley $
48: */
49: public class RemovableAspect extends AbstractAspect {
50:
51: /* (non-Javadoc)
52: * @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)
53: */
54: public void toSAX(RendererAspectContext context, Layout layout,
55: PortalService service, ContentHandler handler)
56: throws SAXException {
57:
58: CopletInstanceData cid = ((CopletLayout) layout)
59: .getCopletInstanceData();
60:
61: Boolean mandatory = (Boolean) cid.getCopletData()
62: .getAspectData("mandatory");
63: if (!mandatory.booleanValue()) {
64: LayoutRemoveEvent lre = new LayoutRemoveEvent(layout);
65: XMLUtils.createElement(handler, "remove-uri", service
66: .getComponentManager().getLinkService().getLinkURI(
67: lre));
68: }
69: context.invokeNext(layout, service, handler);
70: }
71:
72: }
|