View Javadoc

1   // ========================================================================
2   // Copyright (c) 2010 Mort Bay Consulting Pty. Ltd.
3   // ------------------------------------------------------------------------
4   // All rights reserved. This program and the accompanying materials
5   // are made available under the terms of the Eclipse Public License v1.0
6   // and Apache License v2.0 which accompanies this distribution.
7   // The Eclipse Public License is available at 
8   // http://www.eclipse.org/legal/epl-v10.html
9   // The Apache License v2.0 is available at
10  // http://www.opensource.org/licenses/apache2.0.php
11  // You may elect to redistribute this code under either of these licenses. 
12  // ========================================================================
13  
14  package org.eclipse.jetty.webapp;
15  
16  import java.net.URL;
17  
18  import org.eclipse.jetty.util.resource.Resource;
19  import org.eclipse.jetty.xml.XmlParser;
20  
21  public abstract class Descriptor
22  {
23      protected Resource _xml;
24      protected XmlParser.Node _root;
25      protected XmlParser _parser;
26      protected boolean _validating;
27      
28      public Descriptor (Resource xml)
29      {
30          _xml = xml;
31      }
32      
33      public abstract XmlParser newParser()
34      throws ClassNotFoundException;
35      
36      public abstract void ensureParser()
37      throws ClassNotFoundException;
38      
39      protected void redirect(XmlParser parser, String resource, URL source)
40      {
41          if (source != null) parser.redirectEntity(resource, source);
42      }
43      
44      
45      public void setValidating (boolean validating)
46      {
47         _validating = validating;
48      }
49      
50      public void parse ()
51      throws Exception
52      {
53          if (_parser == null)
54             ensureParser();
55          
56          if (_root == null)
57          {
58              //boolean oldValidating = _processor.getParser().getValidating();
59              //_processor.getParser().setValidating(_validating);
60              _root = _parser.parse(_xml.getURL().toString());
61              //_processor.getParser().setValidating(oldValidating);
62          }
63      }
64      
65      public Resource getResource ()
66      {
67          return _xml;
68      }
69      
70      public XmlParser.Node getRoot ()
71      {
72          return _root;
73      }
74  }