1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
28 * Service Implementation used by the command line deployer
29 * to register portlet applications with the Portal.
30 *
31 * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
32 * @version 1.0
33 * @since Mar 6, 2005
34 */
35 class PortalRegistrarServiceImpl {
36
37 private static final String REGISTRY_FILE =
38 "WEB-INF/data/portletentityregistry.xml";
39
40 private File portalRoot;
41
42 /***
43 * Default Constructor wich provides the root of
44 * the portal application.
45 *
46 * @param portalRoot
47 */
48 public PortalRegistrarServiceImpl(File portalRoot) {
49 this.portalRoot = portalRoot;
50 }
51
52 /***
53 * Register the portlet application represented by the
54 * descriptor service provided.
55 * @param portletAppDescriptorService service used to obtain desc info.
56 */
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