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