KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > pluto > driver > deploy > impl > PortletEntityRegistryRegistrarService


1 /*
2  * Copyright 2004 The Apache Software Foundation
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.pluto.driver.deploy.impl;
17
18 import java.io.File JavaDoc;
19 import java.io.IOException JavaDoc;
20 import java.io.RandomAccessFile JavaDoc;
21 import java.util.Iterator JavaDoc;
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 JavaDoc REGISTRY_FILE =
40         "WEB-INF/data/portletentityregistry.xml";
41
42     private File JavaDoc portalRoot;
43
44     /**
45      * Default Constructor wich provides the root of
46      * the portal application.
47      *
48      * @param portalRoot
49      */

50     public PortletEntityRegistryRegistrarService(File JavaDoc 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 JavaDoc {
61         System.out.println("<VERBOSE> Registering application '"+service.getContextPath()+"'");
62
63         File JavaDoc file = new File JavaDoc(portalRoot, REGISTRY_FILE);
64         RandomAccessFile JavaDoc ras = new RandomAccessFile JavaDoc(file, "rw");
65         long length = ras.length();
66         byte[] contentByte = new byte[(int) length];
67         ras.read(contentByte);
68         String JavaDoc contentString = new String JavaDoc(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 JavaDoc 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