Docjar: A Java Source and Docuemnt Enginecom.*    java.*    javax.*    org.*    all    new    plug-in

Quick Search    Search Deep

Source code: com/obinary/cms/beans/ListenerInfo.java


1   /**
2    *
3    * Magnolia and its source-code is licensed under the LGPL.
4    * You may copy, adapt, and redistribute this file for commercial or non-commercial use.
5    * When copying, adapting, or redistributing this document in keeping with the guidelines above,
6    * you are required to provide proper attribution to obinary.
7    * If you reproduce or distribute the document without making any substantive modifications to its content,
8    * please use the following attribution line:
9    *
10   * Copyright 1993-2003 obinary Ltd. (http://www.obinary.com) All rights reserved.
11   *
12   * */
13  
14  
15  
16  package com.obinary.cms.beans;
17  
18  
19  import com.obinary.cms.core.HierarchyManager;
20  import com.obinary.cms.core.Content;
21  
22  import javax.jcr.ElementNotFoundException;
23  import javax.jcr.RepositoryException;
24  import java.util.Iterator;
25  import java.util.Hashtable;
26  
27  
28  /**
29   * User: sameercharles
30   * Date: Apr 28, 2003
31   * Time: 11:20:59 AM
32   * @author Sameer Charles
33   * @version 1.0
34   */
35  
36  
37  
38  public class ListenerInfo {
39  
40  
41      private static final String START_PAGE = "/listener";
42  
43      private static Iterator ipList;
44      private static Hashtable cachedContent;
45  
46  
47      /**
48       * constructor
49       */
50      public ListenerInfo() {
51  
52      }
53  
54  
55  
56      /**
57       * constructor Initializes and cache content
58       *
59       * @param init
60       * @throws ElementNotFoundException
61       * @throws RepositoryException
62       */
63      public ListenerInfo(boolean init) throws ElementNotFoundException, RepositoryException {
64          ListenerInfo.init();
65      }
66  
67  
68  
69      /**
70       * <p>reads listener config from the config repository and caches its content
71       * in to the hash table</p>
72       * FIXME : in version 2 there will be a seperate conf for
73       * URI - isProtected mapping , which will allow to have sub URI to be
74       * free or protected
75       *
76       * @throws ElementNotFoundException
77       * @throws RepositoryException
78       */
79      public static void init() throws ElementNotFoundException, RepositoryException {
80          HierarchyManager hm = new HierarchyManager();
81          hm.setStartPage(ConfigLoader.configRoot);
82          Content startPage = hm.getPage(START_PAGE);
83          ListenerInfo.ipList = startPage.getContainerList("IPConfig").getChildren().iterator();
84          ListenerInfo.cacheContent();
85      }
86  
87  
88  
89      /**
90       * <p>Cache listener content from the config repository</p>
91       *
92       */
93      private static void cacheContent() {
94          ListenerInfo.cachedContent = new Hashtable();
95          while (ListenerInfo.ipList.hasNext()) {
96              Content c = (Content) ListenerInfo.ipList.next();
97              try {
98                  Hashtable types = new Hashtable();
99                  ListenerInfo.cachedContent.put(c.getName(),types);
100                 Iterator it = c.getContainerList("Access").getChildren().iterator();
101                 while (it.hasNext()) {
102                     Content type = (Content) it.next();
103                     types.put(type.getName(),"");
104                 }
105 
106             } catch (RepositoryException re) { re.printStackTrace(); }
107         }
108         ListenerInfo.ipList = null;
109     }
110 
111 
112 
113     /**
114      * <p>get access info of the requested IP
115      * </p>
116      * @param key IP tp be checked
117      * @return Hashtable containing Access info
118      * @throws Exception
119      */
120     public static Hashtable getInfo(String key) throws Exception {
121         return (Hashtable) ListenerInfo.cachedContent.get(key);
122     }
123 
124 
125 
126 
127 }