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

Quick Search    Search Deep

Source code: com/obinary/cms/beans/ParagraphInfo.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  
17  
18  package com.obinary.cms.beans;
19  
20  
21  import com.obinary.cms.core.*;
22  import com.obinary.cms.util.ChildrenCollector;
23  
24  import javax.jcr.ElementNotFoundException;
25  import javax.jcr.RepositoryException;
26  import java.util.Iterator;
27  import java.util.Hashtable;
28  
29  import org.w3c.util.UUID;
30  
31  
32  
33  /**
34   * User: sameercharles
35   * Date: Apr 28, 2003
36   * Time: 11:20:59 AM
37   * @author Sameer Charles
38   * @version 1.0
39   */
40  
41  
42  public class ParagraphInfo {
43  
44  
45  
46      private static final String START_PAGE = "/paragraphInfo";
47      private static final String DIALOGS_START_PAGE = "/dialogs";
48  
49  
50      private static Hashtable cachedContent;
51      private static HierarchyManager hm;
52  
53  
54      private String name;
55      private String title;
56      private String template;
57      private String type;
58      private String description;
59      private String path;
60      private ContainerList atoms;
61  
62  
63  
64  
65      /**
66       * constructor
67       *
68       */
69      public ParagraphInfo() {
70      }
71  
72  
73  
74      /**
75       * constructor
76       *
77       * @throws ElementNotFoundException
78       * @throws RepositoryException
79       */
80      public ParagraphInfo(boolean initialize) throws ElementNotFoundException, RepositoryException {
81          ParagraphInfo.init();
82      }
83  
84  
85  
86      /**
87       * <p>load all paragraph definitions available as a collection of Content objects</p>
88       *
89       * @throws ElementNotFoundException
90       * @throws RepositoryException
91       */
92      public static void init() throws ElementNotFoundException, RepositoryException {
93          hm = new HierarchyManager();
94          hm.setStartPage(ConfigLoader.configRoot);
95          Content startPage = hm.getPage(START_PAGE);
96          ParagraphInfo.cachedContent = new Hashtable();
97          ParagraphInfo.cacheContent(startPage);
98      }
99  
100 
101 
102     /**
103      * <p>load content of this paragraph info page in a hash table
104      * caching at the system load, this will save lot of time on every request
105      * while matching paragraph info
106      * </p>
107      *
108      */
109     private static void cacheContent(Content startPage) {
110         Iterator paragraphs = startPage.getChildren(ChildrenCollector.SIMPLE_NODE).iterator();
111         while (paragraphs.hasNext()) {
112             Container c = (Container)paragraphs.next();
113             String dialog = c.getAtom("dialog").getString();
114             ParagraphInfo pi = new ParagraphInfo();
115             try {
116                 int lastIndexOfDot = dialog.lastIndexOf(".");
117                 if (lastIndexOfDot > -1)
118                     dialog = dialog.substring(0,lastIndexOfDot);
119                 Content dialogPage = hm.getPage(DIALOGS_START_PAGE+dialog);
120                 pi.name = c.getName();
121                 pi.template = c.getAtom("template").getString();
122                 pi.type = c.getAtom("type").getString();
123                 pi.path = c.getHandle();
124                 pi.title = c.getAtom("title").getString();
125                 pi.description = c.getAtom("description").getString();
126                 /* get remaining fro dialog definition */
127                 pi.atoms = dialogPage.getContainerList("AtomDefinitions");
128       } catch (RepositoryException re ) {}
129             ParagraphInfo.updateContainer(c,pi);
130 
131         }
132         if (startPage.hasChildren()) {
133             Iterator children = startPage.getChildren(ChildrenCollector.HIERARCHY_NODE).iterator();
134             while (children.hasNext()) {
135                 cacheContent((Content)children.next());
136             }
137         }
138     }
139 
140 
141 
142     /**
143      * @return String, name
144      */
145     public String getName() {
146         return this.name;
147     }
148 
149 
150 
151     /**
152      * @return String, title
153      */
154     public String getTitle() {
155         return this.title;
156     }
157 
158 
159 
160     /**
161      * @return String, template
162      */
163     public String getTemplate() {
164         return this.template;
165     }
166 
167 
168 
169     /**
170      * @return String, template type  (jsp / servlet)
171      */
172     public String getTemplateType() {
173         return this.type;
174     }
175 
176 
177 
178     /**
179      * @return String, description
180      */
181     public String getDescription() {
182         return this.description;
183     }
184 
185 
186 
187     /**
188      * @return String path
189      * */
190     public String getPath() {
191         return this.path;
192     }
193 
194 
195 
196     /**
197      * @return ContainerList, containers holding atom information for the paragraph
198      */
199     public ContainerList getAtomDefinitions() {
200         return this.atoms;
201     }
202 
203 
204 
205     /**
206      * <p>returns the cached content of the requested template<br>
207      * TemplateInfo properties :<br>
208      * 1. title - title describing template<br>
209      * 2. type - jsp / servlet<br>
210      * 3. path - jsp / servlet path<br>
211      * 4. description - description of a template
212      * </p>
213      *
214      * @return TemplateInfo
215      */
216     public static ParagraphInfo getInfo(String key) throws Exception {
217         return (ParagraphInfo) ParagraphInfo.cachedContent.get(key);
218     }
219 
220 
221 
222     /**
223      * <p>add uuid in paragraph container</p>
224      * @param container
225      * @param pi , paragraph info
226      */
227     private static void updateContainer(Container container, ParagraphInfo pi) {
228         Atom uuid = container.getAtom("UUID");
229         if (uuid.isExist()) {
230             ParagraphInfo.cachedContent.put(uuid.getString(),pi);
231         } else {
232             try {
233                 String id = ParagraphInfo.getUUID();
234                 container.createAtom("UUID").setValue(id);
235                 ParagraphInfo.cachedContent.put(id,pi);
236             } catch (RepositoryException re) {
237                 re.printStackTrace();
238             }
239         }
240     }
241 
242 
243 
244     /**
245      * @return UUID
246      */
247     private static String getUUID() {
248         return (new UUID()).toString();
249     }
250 
251 
252 
253 }