KickJava   Java API By Example, From Geeks To Geeks.

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


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
22 import org.apache.pluto.driver.deploy.PortalRegistrarService;
23 import org.apache.pluto.descriptors.services.PortletAppDescriptorService;
24
25 /**
26  * Registrar service which adds the application context to the
27  * registry file.
28  *
29  * @author <a HREF="ddewolf@apache.org">David H. DeWolf</a>
30  * @version 1.0
31  * @since Mar 11, 2005
32  */

33 public class ContextRegistryRegistrarService implements PortalRegistrarService {
34
35     public static final String JavaDoc CONTEXT_FILE = "WEB-INF/data/portletcontexts.txt";
36
37     private File JavaDoc webAppDir;
38
39     public ContextRegistryRegistrarService(File JavaDoc webAppDir) {
40         this.webAppDir = webAppDir;
41     }
42
43     public void register(PortletAppDescriptorService service)
44         throws IOException JavaDoc {
45         System.out.println("<VERBOSE> Registering Applicaiton Context");
46         File JavaDoc file = new File JavaDoc(webAppDir, CONTEXT_FILE);
47         RandomAccessFile JavaDoc ras = new RandomAccessFile JavaDoc(file, "rw");
48
49         long length = ras.length();
50         byte[] contentByte = new byte[(int) length];
51         ras.read(contentByte);
52         String JavaDoc contents = new String JavaDoc(contentByte);
53         long pos = contents.lastIndexOf("/"+service.getContextPath());
54         if(pos > -1) {
55             System.out.println("<VERBOSE> Found previous context registration; Registration aborted.");
56             ras.close();
57             return;
58         }
59         ras.seek(length);
60         ras.writeBytes("/"+service.getContextPath());
61         ras.writeBytes("\n");
62         ras.close();
63     }
64 }
65
66
Popular Tags