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

Quick Search    Search Deep

Source code: openfuture/editxml/servlet/DomainFromFileProviderServlet.java


1   package openfuture.editxml.servlet;
2   /*
3    * This library is free software; you can redistribute it and/or
4    * modify it under the terms of the GNU Lesser General Public
5    * License as published by the Free Software Foundation; either
6    * version 2 of the License, or (at your option) any later version.<p>
7    *
8    * This library is distributed in the hope that it will be useful,
9    * but WITHOUT ANY WARRANTY; without even the implied warranty of
10   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11   * Lesser General Public License for more details.<p>
12   *
13   * You should have received a copy of the GNU Lesser General Public
14   * License along with this library; if not, write to the Free Software
15   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307  USA<br>
16   * http://www.gnu.org/copyleft/lesser.html
17   */
18  
19  import java.io.BufferedReader;
20  import java.io.FileNotFoundException;
21  import java.io.FileReader;
22  import java.io.IOException;
23  import java.util.LinkedList;
24  import java.util.LinkedList;
25  import java.util.StringTokenizer;
26  import javax.servlet.ServletConfig;
27  import javax.servlet.ServletException;
28  import openfuture.editxml.model.JspConstants;
29  import openfuture.editxml.model.XmlDomain;
30  import openfuture.util.servlet.HttpActionServlet;
31  
32  // Configuration Management Information: 
33  // -------------------------------------
34  // $Id: DomainFromFileProviderServlet.java,v 1.1.1.1 2001/07/08 18:29:31 wreissen Exp $
35  //
36  // Version History:
37  // ----------------
38  // $Log: DomainFromFileProviderServlet.java,v $
39  // Revision 1.1.1.1  2001/07/08 18:29:31  wreissen
40  // initial version registered ad SourceForge
41  //
42  // Revision 1.1  2001/05/09 20:07:27  wreissen
43  // initial version.
44  //
45  //
46  // ***********************************************************************************
47  /**
48   * This servlet initializes the list of XML domains from an initialization
49   * file. The file is set as init parameter.<p>
50   *
51   *
52   * Created: Tue Apr 10 18:46:52 2001
53   *
54   * @author <a href="mailto:wolfgang@openfuture.de">Wolfgang Reissenberger</a>
55   * @version $Revision: 1.1.1.1 $
56   */
57  
58  public class DomainFromFileProviderServlet extends HttpActionServlet
59      implements JspConstants {
60      
61  
62      /**
63       * Initializes the servlet. The following initialization
64       * parameters are recognized:
65       * <ul>
66       *   <li> <strong>initfile</strong>: File holding the XML domains
67       *        as a semicolon separated list: &lt;name&gt;; &lt;DTD URL&gt;;
68       *        &lt;editor URL&gt;; &lt;upload directory&gt;;
69       *        &lt;file name filter&gt;; 
70       *        &lt;URL prefix of the XML files&gt;.<br>
71       *        [<em>Default: xmldomains.txt</em>]
72       * </ul><p>
73       * 
74       * The following context parameters are set:
75       * <ul>
76       *   <li> <strong>openfuture.editxml.domains</strong>: a
77       *        {@link java.util.LinkedList list} of 
78       *        {@link openfuture.editxml.model.XmlDomain XmlDomain}.
79       * </ul>
80       *
81       * @param config a <code>ServletConfig</code> value
82       * @exception ServletException if an error occurs
83       */
84      public void init (ServletConfig config) throws ServletException  {
85  
86    super.init(config);
87  
88    // initialize the locales
89    String value = getInitParameter("initfile");
90    if (value == null) value = "xmldomains.txt";
91  
92    // open the file
93  
94    try {
95        BufferedReader in = new BufferedReader(new FileReader(value));
96  
97        String line;
98        int nr = 0;
99  
100       LinkedList domains = new LinkedList();
101 
102       while((line = in.readLine()) != null) {
103     nr++;
104     StringTokenizer st = new StringTokenizer(line.trim(), ";");
105 
106     if (st.countTokens() == 7) {
107         String name = st.nextToken().trim();
108         String dtd = st.nextToken().trim();
109         String editor = st.nextToken().trim();
110         String directory = st.nextToken().trim();
111         String filter = st.nextToken().trim();
112         String urlprefix = st.nextToken().trim();
113         String xmlPathList = st.nextToken().trim();      
114 
115         // separate the namespace        
116         LinkedList xmlPath = new LinkedList();
117         StringTokenizer nst = new StringTokenizer(xmlPathList,
118                     ",");
119 
120         while (nst.hasMoreElements()) {
121       String path = ((String) nst.nextElement()).trim();
122       xmlPath.add(path);
123       log("XML domain: adding path " + path);
124         }
125 
126         domains.add(new XmlDomain(name, dtd, editor, directory,
127                 filter, urlprefix, xmlPath));
128 
129         log("new XML domain: " + name);
130     } else {
131         log("WRONG number of tokens. " + st.countTokens() +
132       " instead of expected 7: " + line);
133     }
134       }
135       getServletContext().setAttribute(XML_DOMAINS, domains);
136 
137       log("XML domains initialized successfully.");
138   } catch (FileNotFoundException e) {
139       log (e.getMessage());
140       log("XML domains initialization FAILED!");
141   } catch (IOException e) {
142       log (e.getMessage());
143       log("XML domains initialization FAILED!");
144   }
145     }
146     
147 } // DomainFromFileProviderServlet