View Javadoc

1   package net.sf.tomp.xml.include;
2   
3   import net.sf.tomp.xml.type.Type;
4   import net.sf.tomp.xml.type.VariantImpl;
5   
6   import org.apache.commons.logging.Log;
7   import org.apache.commons.logging.LogFactory;
8   import org.xml.sax.SAXException;
9   import org.xml.sax.XMLReader;
10  
11  /***
12   * DOCUMENT ME!
13   * 
14   * @author $author$
15   * @version $Revision$
16   */
17  public class AdaptiveXIncludeFilter extends AdaptiveFilterImpl {
18      private Log log = LogFactory.getLog(AdaptiveXIncludeFilter.class);
19  
20      /*** DOCUMENT ME! */
21      protected XIncludeFilter xif;
22  
23      private final String XINCLUDE_NAMESPACE = "http://tomp.sf.net/ns/axi/1.0";
24  
25      /***
26       * Creates a new AdaptiveXIncludeFilter object.
27       */
28      public AdaptiveXIncludeFilter() {
29          super();
30          xif = getXIncludeFilter();
31          xif.setParent(parent);
32          parent = xif;
33          log.debug("\n&&&& " + this + "<init>: xif=" + xif);
34      }
35  
36      /***
37       * Construct an XML filter with the specified parent.
38       * 
39       * @param p DOCUMENT ME!
40       * @see #setParent
41       * @see #getParent
42       */
43      public AdaptiveXIncludeFilter(XMLReader p) {
44          super(p);
45          xif = getXIncludeFilter();
46          xif.setParent(parent);
47          parent = xif;
48          log.debug("\n&&&& " + this + "<init>: xif=" + xif);
49  
50          //System.out.println("\n&&&& AdaptiveXIncludeFilter<init>:
51          // parent="+getParent());
52      }
53  
54      /***
55       * DOCUMENT ME!
56       * 
57       * @param p DOCUMENT ME!
58       */
59      public void setParent(XMLReader p) {
60          xif.setParent(typeDetectorFilter);
61          this.parent = xif;
62  
63          //System.out.println(" $$$ "+this+" setParent to
64          // "+typeDetectorFilter+"... ");
65          if (typeDetectorFilter != null) {
66              typeDetectorFilter.setParent(p);
67          }
68      }
69  
70      /*
71       * public void setDocumentLocator(Locator locator) { if(locator == null ||
72       * locator.getSystemId() == null) { //System.out.println("########
73       * "+this+".(trying to)setDocumentLocator=null"); return; }
74       * //super.setDocumentLocator(locator); xif.setDocumentLocator(locator); }
75       */
76      public XIncludeFilter getXIncludeFilter() {
77          final AdaptiveXIncludeFilter axi = this;
78  
79          XIncludeFilter xif = new XIncludeFilter() {
80              public String getXIncludeNamespace() {
81                  return XINCLUDE_NAMESPACE;
82              }
83  
84              public XMLReader getXMLReader(String variant) throws SAXException {
85                  //System.out.println("GETTING getXMLReader with
86                  // locator="+axi.locator);
87                  XMLReader parser = super.getXMLReader(variant);
88  
89                  // adaptive filter reading from standard parser
90                  AdaptiveFilterImpl adaptive = new AdaptiveXIncludeFilter(parser); //new
91  
92                  // AdaptiveFilterImpl(parser);
93                  log.debug("+++++ returning " + adaptive
94                          + " from getXMLReader() in " + this);
95  
96                  // adaptive type database
97                  adaptive.setVariant(new VariantImpl(variant));
98                  adaptive.setTypeDatabase(getTypeDatabase());
99  
100                 Type s = getSourceType();
101                 Type t = getSourceTypeForCurrentContext();
102 
103                 //System.out.println("--- sourcetype "+s+" st for context "+t);
104                 adaptive.setTargetType(t);
105 
106                 //adaptive.setDocumentLocator(axi.locator);
107                 return adaptive;
108             }
109         };
110 
111         log.debug("--- returning " + xif + " from getXIncludeFilter() in "
112                 + this);
113 
114         return xif;
115     }
116 
117     /***
118      * @return Returns the xINCLUDE_NAMESPACE.
119      */
120     public String getXIncludeNamespace() {
121         return XINCLUDE_NAMESPACE;
122     }
123 }
124 
125 /*
126  * The contents of this file are subject to the Mozilla Public License Version
127  * 1.1 (the "License"); you may not use this file except in compliance with the
128  * License. You may obtain a copy of the License at http://www.mozilla.org/MPL/
129  * Software distributed under the License is distributed on an "AS IS" basis,
130  * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License for
131  * the specific language governing rights and limitations under the License. The
132  * Original Code is: all this file. The Initial Developer of the Original Code
133  * is: Tomas Pitner, Masaryk University in Brno, Czech Republic. Contributor(s):
134  */