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.PortalThemeMetaData;
025: import org.jboss.portal.theme.metadata.ThemeLinkMetaData;
026: import org.jboss.portal.theme.metadata.ThemeScriptMetaData;
027:
028: import java.util.ArrayList;
029: import java.util.List;
030:
031: /**
032: * @author <a href="mailto:mholzner@novell.com">Martin Holzner</a>
033: * @author <a href="mailto:roy@jboss.org">Roy Russo</a>
034: * @version $Revision: 8784 $
035: */
036: public final class ThemeInfo {
037:
038: /** . */
039: private final RuntimeContext ctx;
040:
041: /** . */
042: private final PortalThemeMetaData meta;
043:
044: /** . */
045: private final ServerRegistrationID registrationId;
046:
047: /** . */
048: private final List scripts;
049:
050: /** . */
051: private final List links;
052:
053: /** . */
054: private final List elements;
055:
056: public ThemeInfo(RuntimeContext ctx, PortalThemeMetaData meta) {
057: this .ctx = ctx;
058: this .meta = meta;
059: this .registrationId = ServerRegistrationID.createID(
060: ServerRegistrationID.TYPE_THEME, new String[] {
061: ctx.getAppId(), meta.getName() });
062:
063: // Initialise elements
064: scripts = new ArrayList(meta.getScripts());
065: links = new ArrayList(meta.getLinks());
066: for (int i = 0; i < scripts.size(); i++) {
067: ThemeScriptMetaData scriptMD = (ThemeScriptMetaData) scripts
068: .get(i);
069: ThemeScript script = new ThemeScript(ctx.getContextPath(),
070: scriptMD.getSrc(), scriptMD.getId(), scriptMD
071: .getType(), scriptMD.getBodyContent(),
072: scriptMD.getCharset());
073: scripts.set(i, script);
074: }
075: for (int i = 0; i < links.size(); i++) {
076: ThemeLinkMetaData linkMD = (ThemeLinkMetaData) links.get(i);
077: ThemeLink link = new ThemeLink(ctx.getContextPath(), linkMD
078: .getRel(), linkMD.getType(), linkMD.getHref(),
079: linkMD.getId(), linkMD.getTitle(), linkMD
080: .getMedia());
081: links.set(i, link);
082: }
083: elements = new ArrayList(scripts.size() + links.size());
084: elements.addAll(scripts);
085: elements.addAll(links);
086: }
087:
088: /**
089: * Get the context path of the servlet context in which the theme is contained.
090: *
091: * @return the context path of the WAR that contains this theme
092: */
093: public String getContextPath() {
094: return ctx.getContextPath();
095: }
096:
097: /**
098: * Get the application name of the WAR that contains this theme
099: *
100: * @return the application name of the WAR that contains this theme
101: */
102: public String getAppId() {
103: return ctx.getAppId();
104: }
105:
106: /**
107: * Get the name of this theme.
108: *
109: * @return the name of this theme
110: */
111: public String getName() {
112: return meta.getName();
113: }
114:
115: /**
116: * Get all script elements that are defined as part of this layout
117: *
118: * @return a <code>java.util.List</code> of script elements that are defined as part of this theme
119: */
120: public List getScripts() {
121: return scripts;
122: }
123:
124: /**
125: * Get all link elements that are defined as part of this theme
126: *
127: * @return a <code>java.util.List</code> of link elements that are defined as part of this theme
128: */
129: public List getLinks() {
130: return links;
131: }
132:
133: /**
134: * Get all elements of this theme. <p>Elements of a theme are all the child nodes in the HEAD tag that are part of
135: * this theme. A theme can currently have script and link tags
136: *
137: * @return a <code>java.util.List</code> of all elements of the theme
138: */
139: public List getElements() {
140: return elements;
141: }
142:
143: /** @see java.lang.Object#toString */
144: public String toString() {
145: return meta.getName();
146: }
147:
148: public ServerRegistrationID getRegistrationId() {
149: return registrationId;
150: }
151: }
|