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.cocoon.portal.PortalService;
020: import org.apache.cocoon.portal.coplet.CopletInstanceData;
021: import org.apache.cocoon.portal.coplet.status.SizingStatus;
022: import org.apache.cocoon.portal.event.impl.ChangeCopletInstanceAspectDataEvent;
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 renderer aspect tests, if a coplet is sizable and/or maxpageable and adds
032: * tags holding URIs for switching to currently inactive modes (i.e. maximize or
033: * minimize).
034: *
035: * <h2>Example XML:</h2>
036: * <pre>
037: * <minimize-uri>minimize-event</minimize-uri>
038: * <!-- output from following renderers -->
039: *
040: * or
041: *
042: * <maximize-uri>maximize-event</maximize-uri>
043: * <!-- processing stops here -->
044: *
045: * </pre>
046: *
047: * <h2>Applicable to:</h2>
048: * <ul>
049: * <li>{@link org.apache.cocoon.portal.layout.impl.CopletLayout}</li>
050: * </ul>
051: *
052: * TODO: make the names of the aspects to test configurable
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: SizingAspect.java 433543 2006-08-22 06:22:54Z crossley $
058: */
059: public class SizingAspect 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 handler)
066: throws SAXException {
067:
068: CopletInstanceData cid = ((CopletLayout) layout)
069: .getCopletInstanceData();
070:
071: boolean showContent = true;
072:
073: boolean sizable = ((Boolean) cid.getCopletData().getAspectData(
074: "sizable")).booleanValue();
075: Integer size = null;
076:
077: if (sizable) {
078: size = (Integer) cid.getAspectData("size");
079: if (size == null) {
080: size = SizingStatus.STATUS_MAXIMIZED;
081: }
082:
083: ChangeCopletInstanceAspectDataEvent event;
084:
085: if (size.equals(SizingStatus.STATUS_MAXIMIZED)) {
086: event = new ChangeCopletInstanceAspectDataEvent(cid,
087: "size", SizingStatus.STATUS_MINIMIZED);
088: XMLUtils.createElement(handler, "minimize-uri", service
089: .getComponentManager().getLinkService()
090: .getLinkURI(event));
091: }
092:
093: if (size.equals(SizingStatus.STATUS_MINIMIZED)) {
094: event = new ChangeCopletInstanceAspectDataEvent(cid,
095: "size", SizingStatus.STATUS_MAXIMIZED);
096: XMLUtils.createElement(handler, "maximize-uri", service
097: .getComponentManager().getLinkService()
098: .getLinkURI(event));
099: }
100:
101: if (size.equals(SizingStatus.STATUS_MINIMIZED)) {
102: showContent = false;
103: }
104: }
105: /* boolean maxPageable = ((Boolean)cid.getCopletData().getAspectData("maxpageable")).booleanValue();
106: if ( maxPageable ) {
107: if ( size == null ) {
108: size = (Integer)cid.getAspectData("size");
109: if ( size == null ) {
110: size = SizingStatus.STATUS_MAXIMIZED;
111: }
112: }
113: ChangeCopletInstanceAspectDataEvent event;
114:
115: if ( size == SizingStatus.STATUS_MAXIMIZED) {
116: event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MAXPAGED);
117: XMLUtils.createElement(handler, "maxpage-uri", service.getComponentManager().getLinkService().getLinkURI(event));
118: }
119: if ( size == SizingStatus.STATUS_MAXPAGED) {
120: event = new ChangeCopletInstanceAspectDataEvent(cid, "size", SizingStatus.STATUS_MAXIMIZED);
121: XMLUtils.createElement(handler, "minpage-uri", service.getComponentManager().getLinkService().getLinkURI(event));
122: }
123: }
124: */
125: if (showContent) {
126: context.invokeNext(layout, service, handler);
127: }
128: }
129:
130: }
|