1 16 package org.apache.pluto.driver.deploy; 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 27 35 class PortalRegistrarServiceImpl { 36 37 private static final String REGISTRY_FILE = 38 "WEB-INF/data/portletentityregistry.xml"; 39 40 private File portalRoot; 41 42 48 public PortalRegistrarServiceImpl(File portalRoot) { 49 this.portalRoot = portalRoot; 50 } 51 52 57 public void register(PortletAppDescriptorService portletAppDescriptorService) 58 throws IOException { 59 File file = new File (portalRoot, REGISTRY_FILE); 60 RandomAccessFile ras = new RandomAccessFile (file, "rw"); 61 62 long length = ras.length(); 63 byte[] contentByte = new byte[(int) length]; 64 ras.read(contentByte); 65 String contentString = new String (contentByte); 66 long pos = contentString.lastIndexOf("</portlet-entity-registry>"); 67 ras.seek(pos); 68 ras.writeBytes(" <application id=\"" + portletAppDescriptorService.getContextPath() + "\">\r\n"); 69 ras.writeBytes(" <definition-id>" + portletAppDescriptorService.getContextPath() + "</definition-id>\r\n"); 70 71 PortletAppDD app = portletAppDescriptorService.read(); 72 PortletDD p; 73 Iterator i = app.getPortlets().iterator(); 74 while(i.hasNext()) { 75 p = (PortletDD)i.next(); 76 ras.writeBytes(" <portlet id=\"" + p.getPortletName() + "\">\r\n"); 77 ras.writeBytes(" <definition-id>" + portletAppDescriptorService.getContextPath() 78 + "." + p.getPortletName() + "</definition-id>\r\n"); 79 ras.writeBytes(" </portlet>\r\n"); 80 } 81 ras.writeBytes(" </application>\r\n"); 82 ras.writeBytes("</portlet-entity-registry>\r\n"); 83 ras.close(); 84 } 85 } 86 87 | Popular Tags |