1 16 17 package org.apache.jetspeed.services.persistence; 18 19 import java.util.ArrayList ; 20 import java.util.Iterator ; 21 import java.util.List ; 22 23 import org.apache.jetspeed.om.profile.Entry; 25 import org.apache.jetspeed.om.profile.PSMLDocument; 26 import org.apache.jetspeed.om.profile.Portlets; 27 import org.apache.jetspeed.om.profile.Profile; 28 import org.apache.jetspeed.portal.JetspeedPortletInstance; 29 import org.apache.jetspeed.portal.Portlet; 30 import org.apache.jetspeed.portal.PortletException; 31 import org.apache.jetspeed.portal.PortletInstance; 32 import org.apache.jetspeed.services.PortletFactory; 33 import org.apache.jetspeed.services.PsmlManager; 34 import org.apache.jetspeed.services.logging.JetspeedLogFactoryService; 35 import org.apache.jetspeed.services.logging.JetspeedLogger; 36 import org.apache.jetspeed.services.rundata.JetspeedRunData; 37 38 import org.apache.turbine.services.InitializationException; 40 import org.apache.turbine.services.TurbineBaseService; 41 import org.apache.turbine.util.RunData; 42 43 50 public class JetspeedPortalPersistenceService 51 extends TurbineBaseService 52 implements PortalPersistenceService 53 { 54 57 private static final JetspeedLogger logger = JetspeedLogFactoryService.getLogger(JetspeedPortalPersistenceService.class.getName()); 58 59 65 public void init(RunData data) throws InitializationException 66 { 67 if (!(data instanceof JetspeedRunData)) 68 { 69 logger.error( 70 "[PortalPersistenceService] The current RunData implenetation does not implement the JetspeedRunData interface."); 71 setInit(false); 72 throw new InitializationException("The current RunData implenetation does not implement the JetspeedRunData interface."); 73 } 74 75 super.init(data); 76 } 77 78 81 public PortletInstance getInstance(Portlet portlet, Profile profile) 82 { 83 return new JetspeedPortletInstance(portlet, profile); 84 } 85 86 89 public PortletInstance getInstance(Portlet portlet, RunData data) 90 { 91 String attrKey = "portlet_instance:"+portlet.getID(); 92 PortletInstance instance = (PortletInstance) data.getRequest().getAttribute(attrKey); 96 if(instance != null) 97 { 98 return instance; 99 } 100 else 101 { 102 instance= new JetspeedPortletInstance(portlet, data); 103 data.getRequest().setAttribute(attrKey, instance); 104 return instance; 105 } 106 107 } 108 109 112 public void store(PortletInstance pPortlet) throws PortalPersistenceException 113 { 114 Profile profile = pPortlet.getProfile(); 115 profile.setDocument(pPortlet.getDocument()); 116 117 if(!PsmlManager.store(profile)) 118 { 119 throw new PortalPersistenceException("Unable to write portlet information."); 120 } 121 } 122 123 126 public List getInstances( Profile profile) throws PortletException 127 { 128 PSMLDocument doc = profile.getDocument(); 129 Portlets portlets = doc.getPortlets(); 130 ArrayList pList = new ArrayList (); 131 132 buildAllEntries(portlets, pList, profile); 133 134 return pList; 135 } 136 137 140 public List getInstances( RunData data) throws PortletException 141 { 142 JetspeedRunData jData = (JetspeedRunData) data; 143 return getInstances(jData.getProfile()); 144 } 145 146 protected void buildAllEntries(Portlets portlets, ArrayList entries, Profile profile) throws PortletException 147 { 148 Iterator eItr = portlets.getEntriesIterator(); 150 while(eItr.hasNext()) 151 { 152 Object obj = eItr.next(); 153 Entry entry = (Entry)obj; 154 Portlet portlet = PortletFactory.getPortlet(entry); 155 entries.add(new JetspeedPortletInstance(portlet, profile)); 156 } 157 158 if(portlets.getPortletsCount() > 0) 160 { 161 Iterator pItr = portlets.getPortletsIterator(); 162 while(pItr.hasNext()) 163 { 164 Portlets childPortlets = (Portlets)pItr.next(); 165 buildAllEntries(childPortlets, entries, profile); 166 } 167 168 return; 169 } 170 else 171 { 173 return; 174 } 175 176 177 } 178 179 } | Popular Tags |