001: /******************************************************************************
002: * JBoss, a division of Red Hat *
003: * Copyright 2006, Red Hat Middleware, LLC, and individual *
004: * contributors as indicated by the @authors tag. See the *
005: * copyright.txt in the distribution for a full listing of *
006: * individual contributors. *
007: * *
008: * This is free software; you can redistribute it and/or modify it *
009: * under the terms of the GNU Lesser General Public License as *
010: * published by the Free Software Foundation; either version 2.1 of *
011: * the License, or (at your option) any later version. *
012: * *
013: * This software is distributed in the hope that it will be useful, *
014: * but WITHOUT ANY WARRANTY; without even the implied warranty of *
015: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU *
016: * Lesser General Public License for more details. *
017: * *
018: * You should have received a copy of the GNU Lesser General Public *
019: * License along with this software; if not, write to the Free *
020: * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA *
021: * 02110-1301 USA, or see the FSF site: http://www.fsf.org. *
022: ******************************************************************************/package org.jboss.portal.theme;
023:
024: import org.jboss.portal.theme.metadata.PortalLayoutMetaData;
025: import org.jboss.portal.theme.metadata.StateURIMetaData;
026:
027: import javax.servlet.ServletContext;
028: import java.util.Collections;
029: import java.util.List;
030:
031: /**
032: * Info about the layout.
033: *
034: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
035: * @version $Revision: 8784 $
036: */
037: public final class LayoutInfo {
038:
039: /** . */
040: private final RuntimeContext ctx;
041:
042: /** . */
043: private final PortalLayoutMetaData layoutMD;
044:
045: /** . */
046: private final ServerRegistrationID registrationId;
047:
048: public LayoutInfo(RuntimeContext ctx, PortalLayoutMetaData layoutMD) {
049: this .ctx = ctx;
050: this .layoutMD = layoutMD;
051: this .registrationId = ServerRegistrationID.createID(
052: ServerRegistrationID.TYPE_LAYOUT, new String[] {
053: ctx.getAppId(), layoutMD.getName() });
054: }
055:
056: public ServerRegistrationID getRegistrationId() {
057: return registrationId;
058: }
059:
060: /**
061: * Get the name of the portal web application that contains this layout.
062: *
063: * @return the name of the portal web application that contains this layout
064: */
065: public String getAppId() {
066: return ctx.getAppId();
067: }
068:
069: /**
070: * Get the name of this layout.
071: *
072: * @return the name of the layout
073: */
074: public String getName() {
075: return layoutMD.getName();
076: }
077:
078: /**
079: * Get the servlet context that contains this layout.
080: *
081: * @return the serlvet context of this layout
082: */
083: public ServletContext getServletContext() {
084: return ctx.getServletContext();
085: }
086:
087: /**
088: * Get the generic URI for this layout. <p>The URI is the location of the layout resource inside the Servlet context
089: * that contains it. The generic URI is the one that does not depend on a state. It is the most common URI for this
090: * layout.</p>
091: *
092: * @return the URI for this layout
093: * @see #getServletContext()
094: * @see #getURI(String)
095: */
096: public String getURI() {
097: return layoutMD.getURI();
098: }
099:
100: /**
101: * Get the uri, the location of the layout, relative to its context.
102: *
103: * @param state an optional key to further separate URIs (for example for maximized window state). If a layout uri
104: * was defined for the provided state, that uri will be returned, otherwise the generic URI for this
105: * layout will be returned. If null is provided, the result is the same as calling getURI()
106: * @return the uri of the layout relative to its context
107: * @see #getServletContext()
108: * @see #getURI
109: */
110: public String getURI(String state) {
111: if (state == null) {
112: return getURI();
113: }
114: if (!layoutMD.getLayoutURIStateMap().isEmpty()) {
115: StateURIMetaData stateURI = (StateURIMetaData) layoutMD
116: .getLayoutURIStateMap().get(state);
117: if (stateURI != null) {
118: return stateURI.getURI();
119: } else {
120: return null;
121: }
122: }
123: return null;
124: }
125:
126: /**
127: * Get the context path for the servlet context (portal web application) that contains this layout.
128: *
129: * @return the context path of this layout
130: */
131: public String getContextPath() {
132: return ctx.getContextPath();
133: }
134:
135: /** @see PortalLayoutMetaData#getRegionNames */
136: public List getRegionNames() {
137: return Collections.unmodifiableList(layoutMD.getRegionNames());
138: }
139:
140: public String toString() {
141: return "PortalLayout: " + registrationId;
142: }
143: }
|