001: /*
002: *
003: * Copyright 2007 Luca Molino (luca.molino@assetdata.it)
004: *
005: * Licensed under the Apache License, Version 2.0 (the "License");
006: * you may not use this file except in compliance with the License.
007: * 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.romaframework.module.portal.solo.domain;
018:
019: import java.lang.reflect.InvocationTargetException;
020: import java.util.ArrayList;
021: import java.util.List;
022:
023: import org.apache.commons.logging.Log;
024: import org.apache.commons.logging.LogFactory;
025: import org.romaframework.aspect.core.annotation.AnnotationConstants;
026: import org.romaframework.aspect.session.SessionAspect;
027: import org.romaframework.aspect.view.annotation.ViewField;
028: import org.romaframework.core.entity.EntityHelper;
029: import org.romaframework.core.flow.ObjectContext;
030: import org.romaframework.core.schema.SchemaClass;
031: import org.romaframework.core.schema.SchemaManager;
032: import org.romaframework.module.portal.PortalPage;
033: import org.romaframework.module.portal.PortalPageContainer;
034: import org.romaframework.module.users.domain.BaseAccount;
035: import org.romaframework.module.users.domain.portal.PortalPreferences;
036: import org.romaframework.module.users.domain.portal.PortalPreferencesHelper;
037:
038: /**
039: * Abstract class that implements the <code>PortalPageContainer</code> commands
040: *
041: * @author l.molino
042: * @see PortalPageContainer
043: */
044: public abstract class CustomPortalPageContainer implements
045: PortalPageContainer {
046:
047: private static Log log = LogFactory
048: .getLog(CustomPortalPageContainer.class);
049:
050: @ViewField(visible=AnnotationConstants.FALSE)
051: protected List<PortalPage> portlets;
052:
053: public List<PortalPage> getPortlets() {
054: return portlets;
055: }
056:
057: @ViewField(visible=AnnotationConstants.FALSE)
058: public String getContainerClassName() {
059: return this .getClass().getSimpleName();
060: }
061:
062: public void onDispose() {
063: }
064:
065: public void onShow() {
066: if (portlets == null)
067: portlets = new ArrayList<PortalPage>();
068: BaseAccount account = (BaseAccount) ObjectContext.getInstance()
069: .getComponent(SessionAspect.class)
070: .getActiveSessionInfo().getAccount();
071: if (account != null) {
072: PortalPreferences preferences = PortalPreferencesHelper
073: .getUserPreferences(account);
074: if (preferences != null) {
075: String this ClassName = getContainerClassName();
076: if (preferences.getPortletsInfos().containsKey(
077: this ClassName)) {
078: List<String> availablePortlets = preferences
079: .getPortletsInfos().get(this ClassName)
080: .getPortlets();
081: if (availablePortlets != null)
082: for (String portletName : availablePortlets) {
083: try {
084: SchemaClass cls = ObjectContext
085: .getInstance().getComponent(
086: SchemaManager.class)
087: .getClassInfo(portletName);
088: Class<?> entityClass = cls.getClazz();
089:
090: Object entityObject = EntityHelper
091: .createObject(null, entityClass);
092: if (entityObject instanceof PortalPage) {
093: ((PortalPage) entityObject)
094: .minimize();
095: ((PortalPage) entityObject)
096: .setContainerName(this ClassName);
097: portlets
098: .add((PortalPage) entityObject);
099: }
100: ObjectContext.getInstance().show(
101: entityObject,
102: "screen://" + portletName);
103: } catch (IllegalArgumentException iae) {
104: log.error(iae);
105: } catch (IllegalAccessException iae) {
106: log.error(iae);
107: } catch (InvocationTargetException ite) {
108: log.error(ite);
109: } catch (InstantiationException ie) {
110: log.error(ie);
111: } catch (NullPointerException npe) {
112: log.error(npe);
113: }
114: }
115: }
116: }
117: }
118: }
119:
120: }
|