1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
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 /***
29 * Service Implementation used by the command line deployer
30 * to register portlet applications with the Portal.
31 *
32 * @author <a href="ddewolf@apache.org">David H. DeWolf</a>
33 * @version 1.0
34 * @since Mar 6, 2005
35 */
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 /***
45 * Default Constructor wich provides the root of
46 * the portal application.
47 *
48 * @param portalRoot
49 */
50 public PortletEntityRegistryRegistrarService(File portalRoot) {
51 this.portalRoot = portalRoot;
52 }
53
54 /***
55 * Register the portlet application represented by the
56 * descriptor service provided.
57 * @param service service used to obtain desc info.
58 */
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