KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > xerces > xinclude > XIncludeNamespaceSupport


1 /*
2  * Copyright 2003-2005 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16 package org.apache.xerces.xinclude;
17
18 import org.apache.xerces.xni.NamespaceContext;
19
20 /**
21  * This is an implementation of NamespaceContext which is intended to be used for
22  * XInclude processing. It enables each context to be marked as invalid, if necessary,
23  * to indicate that the namespaces recorded on those contexts won't be apparent in the
24  * resulting infoset.
25  *
26  * @author Peter McCracken, IBM
27  *
28  * @version $Id: XIncludeNamespaceSupport.java,v 1.7 2005/01/11 13:40:29 mrglavas Exp $
29  */

30 public class XIncludeNamespaceSupport extends MultipleScopeNamespaceSupport {
31
32     /**
33      * This stores whether or not the context at the matching depth was valid.
34      */

35     private boolean[] fValidContext = new boolean[8];
36
37     /**
38      *
39      */

40     public XIncludeNamespaceSupport() {
41         super();
42     }
43
44     /**
45      * @param context
46      */

47     public XIncludeNamespaceSupport(NamespaceContext context) {
48         super(context);
49     }
50
51     /**
52      * Pushes a new context onto the stack.
53      */

54     public void pushContext() {
55         super.pushContext();
56         if (fCurrentContext + 1 == fValidContext.length) {
57             boolean[] contextarray = new boolean[fValidContext.length * 2];
58             System.arraycopy(fValidContext, 0, contextarray, 0, fValidContext.length);
59             fValidContext = contextarray;
60         }
61
62         fValidContext[fCurrentContext] = true;
63     }
64
65     /**
66      * This method is used to set a context invalid for XInclude namespace processing.
67      * Any context defined by an <include> or <fallback> element is not
68      * valid for processing the include parent's [in-scope namespaces]. Thus, contexts
69      * defined by these elements are set to invalid by the XInclude processor using
70      * this method.
71      */

72     public void setContextInvalid() {
73         fValidContext[fCurrentContext] = false;
74     }
75     
76     /**
77      * This returns the namespace URI which was associated with the given pretext, in
78      * the context that existed at the include parent of the current element. The
79      * include parent is the last element, before the current one, which was not set
80      * to an invalid context using setContextInvalid()
81      *
82      * @param prefix the prefix of the desired URI
83      * @return the URI corresponding to the prefix in the context of the include parent
84      */

85     public String JavaDoc getURIFromIncludeParent(String JavaDoc prefix) {
86         int lastValidContext = fCurrentContext - 1;
87         while (lastValidContext > 0 && !fValidContext[lastValidContext]) {
88             lastValidContext--;
89         }
90         return getURI(prefix, lastValidContext);
91     }
92 }
Popular Tags