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.core.impl.model.content.portlet;
023:
024: import org.jboss.portal.Mode;
025: import org.jboss.portal.common.i18n.LocalizedString;
026: import org.jboss.portal.common.i18n.ResourceBundleFactory;
027: import org.jboss.portal.common.i18n.ResourceBundleManager;
028: import org.jboss.portal.common.i18n.SimpleResourceBundleFactory;
029: import org.jboss.portal.common.util.EmptyResourceBundle;
030: import org.jboss.portal.core.impl.model.content.InternalContentProvider;
031: import org.jboss.portal.core.model.CustomizationManager;
032: import org.jboss.portal.core.model.content.Content;
033: import org.jboss.portal.core.model.content.ContentType;
034: import org.jboss.portal.core.model.content.spi.ContentProvider;
035: import org.jboss.portal.core.model.content.spi.handler.ContentHandler;
036: import org.jboss.portal.core.model.content.spi.handler.ContentState;
037: import org.jboss.portal.core.model.content.spi.portlet.ContentPortlet;
038: import org.jboss.portal.core.model.instance.Instance;
039: import org.jboss.portal.core.model.instance.InstanceContainer;
040: import org.jboss.portal.core.model.portal.Window;
041: import org.jboss.portal.core.model.portal.content.ContentRendererContext;
042: import org.jboss.portal.identity.User;
043:
044: /**
045: * @author <a href="mailto:julien@jboss.org">Julien Viet</a>
046: * @version $Revision: 9006 $
047: */
048: public class InternalPortletContentProvider extends
049: InternalContentProvider implements ContentHandler {
050:
051: /** . */
052: private InstanceContainer instanceContainer;
053:
054: /** . */
055: private CustomizationManager customizationManager;
056:
057: /** . */
058: private ResourceBundleManager bundleManager;
059:
060: /** . */
061: private LocalizedString displayName;
062:
063: /** . */
064: private LocalizedString description;
065:
066: public InstanceContainer getInstanceContainer() {
067: return instanceContainer;
068: }
069:
070: public void setInstanceContainer(InstanceContainer instanceContainer) {
071: this .instanceContainer = instanceContainer;
072: }
073:
074: public CustomizationManager getCustomizationManager() {
075: return customizationManager;
076: }
077:
078: public void setCustomizationManager(
079: CustomizationManager customizationManager) {
080: this .customizationManager = customizationManager;
081: }
082:
083: public void start() throws Exception {
084: ResourceBundleFactory factory = new SimpleResourceBundleFactory(
085: "conf/bundles/PortletContent", Thread.currentThread()
086: .getContextClassLoader());
087: bundleManager = new ResourceBundleManager(
088: EmptyResourceBundle.INSTANCE, factory);
089:
090: // displayName = new LocalizedString();
091:
092: //
093: super .start();
094: }
095:
096: public void stop() {
097: super .stop();
098:
099: //
100: // bundle = null;
101: }
102:
103: protected ContentProvider createProvider() {
104: return new ContentProvider() {
105: public ContentType getContentType() {
106: return getRegisteredContentType();
107: }
108:
109: public LocalizedString getDisplayName() {
110: return null;
111: }
112:
113: public LocalizedString getDescription() {
114: return null;
115: }
116:
117: public ContentHandler getHandler() {
118: return InternalPortletContentProvider.this ;
119: }
120:
121: public ContentPortlet getPortletInfo() {
122: return new ContentPortlet() {
123: public String getPortletName(Mode mode) {
124: if (EDIT_CONTENT_MODE.equals(mode)) {
125: return "PortletContentEditorInstance";
126: } else {
127: return null;
128: }
129: }
130: };
131: }
132: };
133: }
134:
135: // ContentHandler implementation ************************************************************************************
136:
137: public Content newContent(String contextId, ContentState state) {
138: return new PortletContent(this , contextId, state);
139: }
140:
141: public void contentDestroyed(String contextId, ContentState state) {
142: String instanceRef = state.getURI();
143:
144: // Do we have a related instance ?
145: if (instanceRef != null) {
146: Instance instance = instanceContainer
147: .getDefinition(instanceRef);
148:
149: // Destroy related instance customization if possible
150: if (instance != null) {
151: instance.destroyCustomization(contextId);
152: }
153: }
154: }
155:
156: public void contentCreated(String contextId, ContentState state) {
157: }
158:
159: // ContentRenderer implementation ***********************************************************************************
160:
161: protected Instance getPortletInstance(
162: ContentRendererContext rendererContext) {
163: // The window
164: Window window = rendererContext.getWindow();
165:
166: // We need the user id
167: User user = rendererContext.getUser();
168:
169: // Get instance
170: return customizationManager.getInstance(window, user);
171: }
172:
173: }
|