1 16 package org.apache.cocoon.portal.components.modules.input; 17 18 import java.util.Iterator ; 19 import java.util.Map ; 20 21 import org.apache.avalon.framework.activity.Disposable; 22 import org.apache.avalon.framework.configuration.Configuration; 23 import org.apache.avalon.framework.configuration.ConfigurationException; 24 import org.apache.avalon.framework.service.ServiceException; 25 import org.apache.avalon.framework.service.ServiceSelector; 26 import org.apache.cocoon.components.modules.input.InputModule; 27 import org.apache.cocoon.portal.PortalService; 28 import org.apache.cocoon.portal.layout.Layout; 29 import org.apache.cocoon.portal.layout.SkinDescription; 30 31 36 public class SkinModule 37 extends AbstractModule 38 implements Disposable { 39 40 protected InputModule globalModule; 41 protected ServiceSelector moduleSelector; 42 43 46 public void dispose() { 47 if ( this.manager != null ) { 48 if ( this.moduleSelector != null ) { 49 this.moduleSelector.release(this.globalModule); 50 this.manager.release(this.moduleSelector); 51 this.moduleSelector = null; 52 this.globalModule = null; 53 } 54 } 55 } 56 57 60 public Object getAttribute(String name, Configuration modeConf, Map objectModel) 61 throws ConfigurationException { 62 if ( this.moduleSelector == null ) { 64 synchronized ( this ) { 65 try { 66 if ( this.moduleSelector == null ) { 67 this.moduleSelector = (ServiceSelector)this.manager.lookup(InputModule.ROLE+"Selector"); 68 this.globalModule = (InputModule)this.moduleSelector.select("global"); 69 } 70 } catch (ServiceException e) { 71 throw new ConfigurationException("Unable to lookup input module.", e); 72 } 73 } 74 } 75 76 PortalService portalService = null; 77 try { 78 79 portalService = (PortalService)this.manager.lookup(PortalService.ROLE); 80 81 String skinName = null; 82 final Layout rootLayout = portalService.getComponentManager().getProfileManager().getPortalLayout(null, null); 87 if ( rootLayout != null ) { 88 skinName = (String )rootLayout.getParameters().get("skin"); 89 } 90 if ( skinName == null ) { 92 skinName = (String )this.globalModule.getAttribute("skin", modeConf, objectModel); 93 if ( skinName == null ) { 94 skinName = "common"; 95 } 96 } 97 98 SkinDescription desc = null; 100 final Iterator i = portalService.getSkinDescriptions().iterator(); 101 while ( i.hasNext() && desc == null ) { 102 final SkinDescription current = (SkinDescription)i.next(); 103 if ( current.getName().equals(skinName) ) { 104 desc = current; 105 } 106 } 107 if ( desc != null ) { 108 if ( "skin".equals(name) ) { 109 return skinName; 110 } else if ( "skin.basepath".equals(name) ) { 111 return desc.getBasePath(); 112 } else if ( "skin.thumbnailpath".equals(name) ) { 113 return desc.getThumbnailPath(); 114 } else if ( name.startsWith("skin.thumbnailuri.") ) { 115 String selectedSkinName = name.substring(name.lastIndexOf(".")+ 1, name.length()); 116 for(Iterator it = portalService.getSkinDescriptions().iterator(); it.hasNext();) { 117 SkinDescription selected = (SkinDescription) it.next(); 118 if(selected.getName().equals(selectedSkinName)) { 119 return selected.getBasePath() + "/" + selected.getThumbnailPath(); 120 } 121 } 122 } 123 } 124 return null; 125 } catch (ServiceException e) { 126 throw new ConfigurationException("Unable to lookup portal service.", e); 127 } finally { 128 this.manager.release(portalService); 129 } 130 } 131 132 } 133 | Popular Tags |