1 16 package org.apache.pluto.driver.deploy.impl; 17 18 import java.io.File ; 19 import java.io.IOException ; 20 import java.io.RandomAccessFile ; 21 import java.util.Iterator ; 22 23 import org.apache.pluto.descriptors.portlet.PortletAppDD; 24 import org.apache.pluto.descriptors.portlet.PortletDD; 25 import org.apache.pluto.descriptors.services.PortletAppDescriptorService; 26 import org.apache.pluto.driver.deploy.PortalRegistrarService; 27 28 36 public class PortletEntityRegistryRegistrarService 37 implements PortalRegistrarService { 38 39 private static final String REGISTRY_FILE = 40 "WEB-INF/data/portletentityregistry.xml"; 41 42 private File portalRoot; 43 44 50 public PortletEntityRegistryRegistrarService(File portalRoot) { 51 this.portalRoot = portalRoot; 52 } 53 54 59 public void register(PortletAppDescriptorService service) 60 throws IOException { 61 System.out.println("<VERBOSE> Registering application '"+service.getContextPath()+"'"); 62 63 File file = new File (portalRoot, REGISTRY_FILE); 64 RandomAccessFile ras = new RandomAccessFile (file, "rw"); 65 long length = ras.length(); 66 byte[] contentByte = new byte[(int) length]; 67 ras.read(contentByte); 68 String contentString = new String (contentByte); 69 long pos = contentString.indexOf("<definition-id>"+service.getContextPath()+"</definition-id>"); 70 if(pos > 0) { 71 System.out.println("<VERBOSE> Found previous entity registery; Registration Aborted."); 72 ras.close(); 73 return; 74 } 75 pos = contentString.lastIndexOf("</portlet-entity-registry>"); 76 ras.seek(pos); 77 ras.writeBytes(" <application id=\"" + service.getContextPath() + "\">\n"); 78 ras.writeBytes(" <definition-id>" + service.getContextPath() + "</definition-id>\n"); 79 80 PortletAppDD app = service.read(); 81 PortletDD p; 82 Iterator i = app.getPortlets().iterator(); 83 while(i.hasNext()) { 84 p = (PortletDD)i.next(); 85 ras.writeBytes(" <portlet id=\"" + p.getPortletName() + "\">\n"); 86 ras.writeBytes(" <definition-id>" + service.getContextPath() 87 + "." + p.getPortletName() + "</definition-id>\n"); 88 ras.writeBytes(" </portlet>\n"); 89 } 90 ras.writeBytes(" </application>\n"); 91 ras.writeBytes("</portlet-entity-registry>\n"); 92 ras.close(); 93 } 94 } 95 96 | Popular Tags |