KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > cocoon > portal > layout > renderer > aspect > impl > SizingAspect


1 /*
2  * Copyright 1999-2002,2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.cocoon.portal.layout.renderer.aspect.impl;
17
18 import org.apache.cocoon.portal.PortalService;
19 import org.apache.cocoon.portal.coplet.CopletInstanceData;
20 import org.apache.cocoon.portal.coplet.status.SizingStatus;
21 import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
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 JavaDoc;
27 import org.xml.sax.SAXException JavaDoc;
28
29 /**
30  * This renderer aspect tests, if a coplet is sizable and/or maxpageable and adds
31  * tags holding URIs for switching to currently inactive modes (i.e. maximize or
32  * minimize).
33  *
34  * <h2>Example XML:</h2>
35  * <pre>
36  * &lt;minimize-uri&gt;minimize-event&lt;/minimize-uri&gt;
37  * &lt;!-- output from following renderers --&gt;
38  *
39  * or
40  *
41  * &lt;maximize-uri&gt;maximize-event&lt;/maximize-uri&gt;
42  * &lt;!-- processing stops here --&gt;
43  *
44  * </pre>
45  *
46  * <h2>Applicable to:</h2>
47  * <ul>
48  * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
49  * </ul>
50  *
51  * TODO: make the names of the aspects to test configurable
52  *
53  * @author <a HREF="mailto:cziegeler@s-und-n.de">Carsten Ziegeler</a>
54  * @author <a HREF="mailto:volker.schmitt@basf-it-services.com">Volker Schmitt</a>
55  *
56  * @version CVS $Id: SizingAspect.java 30932 2004-07-29 17:35:38Z vgritsenko $
57  */

58 public class SizingAspect extends AbstractAspect {
59
60     /* (non-Javadoc)
61      * @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)
62      */

63     public void toSAX(RendererAspectContext context,
64                         Layout layout,
65                         PortalService service,
66                         ContentHandler JavaDoc handler)
67     throws SAXException JavaDoc {
68         
69         CopletInstanceData cid = ((CopletLayout)layout).getCopletInstanceData();
70
71         boolean showContent = true;
72         
73         boolean sizable = ((Boolean JavaDoc)cid.getCopletData().getAspectData("sizable")).booleanValue();
74         Integer JavaDoc size = null;
75         
76         if ( sizable ) {
77             size = (Integer JavaDoc)cid.getAspectData("size");
78             if ( size == null ) {
79                 size = SizingStatus.STATUS_MAXIMIZED;
80             }
81
82             ChangeCopletInstanceAspectDataEvent event;
83
84             if ( size.equals(SizingStatus.STATUS_MAXIMIZED) ) {
85                 event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MINIMIZED);
86                 XMLUtils.createElement(handler, "minimize-uri", service.getComponentManager().getLinkService().getLinkURI(event));
87             }
88
89             if ( size.equals(SizingStatus.STATUS_MINIMIZED)) {
90                 event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MAXIMIZED);
91                 XMLUtils.createElement(handler, "maximize-uri", service.getComponentManager().getLinkService().getLinkURI(event));
92             }
93             
94             if (size.equals(SizingStatus.STATUS_MINIMIZED)) {
95                 showContent = false;
96             }
97         }
98 /* boolean maxPageable = ((Boolean)cid.getCopletData().getAspectData("maxpageable")).booleanValue();
99         if ( maxPageable ) {
100             if ( size == null ) {
101                 size = (Integer)cid.getAspectData("size");
102                 if ( size == null ) {
103                     size = SizingStatus.STATUS_MAXIMIZED;
104                 }
105             }
106             ChangeCopletInstanceAspectDataEvent event;
107
108             if ( size == SizingStatus.STATUS_MAXIMIZED) {
109                 event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MAXPAGED);
110                 XMLUtils.createElement(handler, "maxpage-uri", service.getComponentManager().getLinkService().getLinkURI(event));
111             }
112             if ( size == SizingStatus.STATUS_MAXPAGED) {
113                 event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MAXIMIZED);
114                 XMLUtils.createElement(handler, "minpage-uri", service.getComponentManager().getLinkService().getLinkURI(event));
115             }
116         }
117 */

118         if ( showContent ) {
119             context.invokeNext(layout, service, handler);
120         }
121     }
122
123 }
124
Popular Tags