KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > sun > org > apache > xerces > internal > xinclude > XPointerFramework


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Xerces" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation and was
52  * originally based on software copyright (c) 1999, International
53  * Business Machines, Inc., http://www.apache.org. For more
54  * information on the Apache Software Foundation, please see
55  * <http://www.apache.org/>.
56  */

57 package com.sun.org.apache.xerces.internal.xinclude;
58
59 import java.util.Stack JavaDoc;
60 import com.sun.org.apache.xerces.internal.xinclude.XPointerSchema;
61
62 public class XPointerFramework{
63     
64         /*
65                 Todo's by next integration.
66                 While constructing schema names and uris use a dynamic datastructure.
67          */

68     
69     XPointerSchema [] fXPointerSchema;
70     String JavaDoc [] fSchemaPointerName;
71     String JavaDoc [] fSchemaPointerURI;
72     String JavaDoc fSchemaPointer;
73     String JavaDoc fCurrentSchemaPointer;
74     Stack JavaDoc fSchemaNotAvailable;
75     int fCountSchemaName = 0;
76     int schemaLength = 0;
77     XPointerSchema fDefaultXPointerSchema;
78     
79     public XPointerFramework(){
80         this(null);
81     }
82     
83     public XPointerFramework(XPointerSchema [] xpointerschema){
84         fXPointerSchema = xpointerschema;
85         fSchemaNotAvailable = new Stack JavaDoc();
86     }
87     
88     public void reset(){
89         fXPointerSchema = null;
90         fXPointerSchema = null;
91         fCountSchemaName = 0;
92         schemaLength = 0;
93         fSchemaPointerName = null;
94         fSchemaPointerURI = null;
95         fDefaultXPointerSchema = null;
96         fCurrentSchemaPointer = null;
97     }
98     
99     public void setXPointerSchema(XPointerSchema [] xpointerschema){
100         fXPointerSchema = xpointerschema;
101     }
102     
103     public void setSchemaPointer(String JavaDoc schemaPointer){
104         fSchemaPointer = schemaPointer;
105     }
106     
107     public XPointerSchema getNextXPointerSchema(){
108         int i=fCountSchemaName;
109         if(fSchemaPointerName == null){
110             getSchemaNames();
111         }
112         if(fDefaultXPointerSchema == null){
113             getDefaultSchema();
114         }
115         if(fDefaultXPointerSchema.getXpointerSchemaName().equalsIgnoreCase(fSchemaPointerName[i])){
116             fDefaultXPointerSchema.reset();
117             fDefaultXPointerSchema.setXPointerSchemaPointer(fSchemaPointerURI[i]);
118             fCountSchemaName = ++i;
119             return getDefaultSchema();
120         }
121         if(fXPointerSchema == null){
122             fCountSchemaName = ++i;
123             return null;
124         }
125         
126         int fschemalength = fXPointerSchema.length;
127         
128         for(;fSchemaPointerName[i] != null; i++){
129             for(int j=0; j<fschemalength; j++ ){
130                 if(fSchemaPointerName[i].equalsIgnoreCase(fXPointerSchema[j].getXpointerSchemaName())){
131                     fXPointerSchema[j].setXPointerSchemaPointer(fSchemaPointerURI[i]);
132                     fCountSchemaName = ++i;
133                     return fXPointerSchema[j];
134                 }
135             }
136             
137             if(fSchemaNotAvailable == null);
138             fSchemaNotAvailable = new Stack JavaDoc();
139             
140             fSchemaNotAvailable.push(fSchemaPointerName[i]);
141         }
142         return null;
143     }
144     
145     public XPointerSchema getDefaultSchema(){
146         if(fDefaultXPointerSchema == null)
147             fDefaultXPointerSchema = new XPointerElementHandler();
148         return fDefaultXPointerSchema;
149     }
150     
151     public void getSchemaNames(){
152         int count =0;
153         int index =0, lastindex =0;
154         int schemapointerindex =0, schemapointerURIindex=0;
155         char c;
156         int length = fSchemaPointer.length();
157         fSchemaPointerName = new String JavaDoc [5];
158         fSchemaPointerURI = new String JavaDoc [5];
159         
160         index = fSchemaPointer.indexOf('(');
161         if( index <= 0)
162             return;
163         
164         fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(0, index++).trim();
165         lastindex = index;
166         String JavaDoc tempURI = null;
167         count++;
168         
169         while(index < length){
170             c = fSchemaPointer.charAt(index);
171             if(c == '(')
172                 count++;
173             if(c == ')')
174                 count--;
175             if(count==0 ){
176                 tempURI = fSchemaPointer.substring(lastindex, index).trim();
177                 fSchemaPointerURI[schemapointerURIindex++] = getEscapedURI(tempURI);
178                 lastindex = index;
179                 if((index = fSchemaPointer.indexOf('(', lastindex)) != -1){
180                     fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(lastindex+1, index).trim();
181                     count++;
182                     lastindex = index+1;
183                 }
184                 else{
185                     index = lastindex;
186                 }
187             }
188             index++;
189         }
190         schemaLength = schemapointerURIindex -1;
191     }
192     
193     public String JavaDoc getEscapedURI(String JavaDoc URI){
194         return URI;
195     }
196     
197     public int getSchemaCount(){
198         return schemaLength;
199     }
200     
201     public int getCurrentPointer(){
202         return fCountSchemaName;
203     }
204     
205 }//XPointerFramwork
206
Popular Tags