001: /*
002: * (C) Copyright 2000 - 2006 Nabh Information Systems, Inc.
003: *
004: * This program is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU General Public License
006: * as published by the Free Software Foundation; either version 2
007: * of the License, or (at your option) any later version.
008: *
009: * This program is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
012: * GNU General Public License for more details.
013: *
014: * You should have received a copy of the GNU General Public License
015: * along with this program; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
017: *
018: */
019: package com.nabhinc.portal.model;
020:
021: import java.io.ByteArrayOutputStream;
022: import java.io.StringReader;
023: import java.util.ArrayList;
024: import java.util.Iterator;
025: import java.util.List;
026:
027: import javax.servlet.ServletContext;
028: import javax.xml.bind.JAXBContext;
029: import javax.xml.bind.Marshaller;
030: import javax.xml.bind.Unmarshaller;
031: import javax.xml.bind.annotation.XmlElement;
032: import javax.xml.bind.annotation.XmlRootElement;
033: import javax.xml.bind.annotation.XmlTransient;
034:
035: /**
036: *
037: *
038: * @author Padmanabh Dabke
039: * (c) 2006 Nabh Information Systems, Inc. All Rights Reserved.
040: */
041: @XmlRootElement(name="renderable-list")
042: public class RenderableList extends BaseCompositeRenderable {
043:
044: @XmlElement(name="portlet-window")
045: private List<PortletWindow> componentList = new ArrayList<PortletWindow>();
046:
047: public RenderableList() {
048:
049: }
050:
051: public RenderableList(PortalPage parent) {
052: super (parent);
053: }
054:
055: @XmlTransient
056: public List<PortletWindow> getPortletWindows() {
057: return this .componentList;
058: }
059:
060: public void setPortletWindows(List<PortletWindow> l) {
061: this .componentList = l;
062: }
063:
064: public void setTemplate(String template) {
065: super .setTemplate(template);
066: setComponentTemplate(template);
067: /*
068: for (int i=0; i<this.componentList.size(); i++) {
069: PortletWindow pw = this.componentList.get(i);
070: if (pw.getTemplate() == null) pw.setTemplate(template);
071: }
072: */
073: }
074:
075: public static void main(String[] args) {
076:
077: try {
078:
079: RenderableList r = new RenderableList();
080:
081: PortletWindow pw = new PortletWindow();
082:
083: r.getPortletWindows().add(pw);
084:
085: JAXBContext jc = JAXBContext
086: .newInstance("com.nabhinc.portal.model:com.nabhinc.condition");
087:
088: Marshaller m = jc.createMarshaller();
089: m.setProperty(Marshaller.JAXB_FORMATTED_OUTPUT, true);
090: ByteArrayOutputStream sos = new ByteArrayOutputStream();
091: m.marshal(r, sos);
092: String xml = sos.toString();
093: System.out.println(xml);
094: Unmarshaller um = jc.createUnmarshaller();
095: Object c = um.unmarshal(new StringReader(xml));
096: ByteArrayOutputStream sos2 = new ByteArrayOutputStream();
097: m.marshal(c, sos2);
098: System.out.println(sos2.toString());
099: } catch (Exception e) {
100: e.printStackTrace();
101: }
102:
103: }
104:
105: public Iterator<Renderable> getComponents() {
106: ArrayList<Renderable> rList = new ArrayList<Renderable>();
107: if (this .componentList != null)
108: rList.addAll(this .componentList);
109: return rList.iterator();
110: }
111:
112: public boolean removePortletWindow(PortletWindow pWindow) {
113: for (int i = 0; i < this .componentList.size(); i++) {
114: if (this .componentList.get(i) == pWindow) {
115: this .componentList.remove(i);
116: return true;
117: } else {
118: if (this .componentList.get(i).removePortletWindow(
119: pWindow))
120: return true;
121: }
122: }
123: return false;
124: }
125:
126: public void addContent(Renderable r, String optionLabel) {
127: PortletWindow pw = (PortletWindow) r;
128: this .componentList.add(pw);
129: //if (pw.getTemplate() == null) pw.setTemplate(this.template);
130: }
131:
132: public void addPortletWindow(int index, PortletWindow pw) {
133: this .componentList.add(index, pw);
134: //if (pw.getTemplate() == null) pw.setTemplate(this.template);
135: }
136:
137: public PortletWindow removePortletWindowAt(int index) {
138: return this .componentList.remove(index);
139: }
140:
141: public void reorderPortletWindows(int oldIndex, int newIndex) {
142: if (oldIndex == newIndex)
143: return;
144: PortletWindow movedElem = this .componentList.remove(oldIndex);
145: this .componentList.add(newIndex, movedElem);
146: }
147:
148: @Override
149: public void addPortletWindows(List<PortletWindow> windowList) {
150: windowList.addAll(this .componentList);
151: }
152:
153: public void afterUnmarshal(Unmarshaller um, Object parent) {
154: if (this .template != null) {
155: setTemplate(this .template);
156: /*
157: for (int i=0; i<this.componentList.size(); i++) {
158: PortletWindow pw = this.componentList.get(i);
159: if (pw.getTemplate() == null)
160: this.componentList.get(i).setTemplate(this.template);
161: }
162: */
163: }
164:
165: }
166:
167: public void addPortletWindow(PortletWindow pWindow) {
168: this .componentList.add(pWindow);
169: }
170:
171: public void computeTemplatePath(ServletContext servletContext,
172: String appPath, String theme) {
173: for (int i = 0; i < this .componentList.size(); i++) {
174: PortletWindow pw = this.componentList.get(i);
175: pw.computeTemplatePath(servletContext, appPath, theme,
176: this.template);
177: }
178: }
179:
180: }
|