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. import java.util.Stack;
  59. import com.sun.org.apache.xerces.internal.xinclude.XPointerSchema;
  60. public class XPointerFramework{
  61. /*
  62. Todo's by next integration.
  63. While constructing schema names and uris use a dynamic datastructure.
  64. */
  65. XPointerSchema [] fXPointerSchema;
  66. String [] fSchemaPointerName;
  67. String [] fSchemaPointerURI;
  68. String fSchemaPointer;
  69. String fCurrentSchemaPointer;
  70. Stack fSchemaNotAvailable;
  71. int fCountSchemaName = 0;
  72. int schemaLength = 0;
  73. XPointerSchema fDefaultXPointerSchema;
  74. public XPointerFramework(){
  75. this(null);
  76. }
  77. public XPointerFramework(XPointerSchema [] xpointerschema){
  78. fXPointerSchema = xpointerschema;
  79. fSchemaNotAvailable = new Stack();
  80. }
  81. public void reset(){
  82. fXPointerSchema = null;
  83. fXPointerSchema = null;
  84. fCountSchemaName = 0;
  85. schemaLength = 0;
  86. fSchemaPointerName = null;
  87. fSchemaPointerURI = null;
  88. fDefaultXPointerSchema = null;
  89. fCurrentSchemaPointer = null;
  90. }
  91. public void setXPointerSchema(XPointerSchema [] xpointerschema){
  92. fXPointerSchema = xpointerschema;
  93. }
  94. public void setSchemaPointer(String schemaPointer){
  95. fSchemaPointer = schemaPointer;
  96. }
  97. public XPointerSchema getNextXPointerSchema(){
  98. int i=fCountSchemaName;
  99. if(fSchemaPointerName == null){
  100. getSchemaNames();
  101. }
  102. if(fDefaultXPointerSchema == null){
  103. getDefaultSchema();
  104. }
  105. if(fDefaultXPointerSchema.getXpointerSchemaName().equalsIgnoreCase(fSchemaPointerName[i])){
  106. fDefaultXPointerSchema.reset();
  107. fDefaultXPointerSchema.setXPointerSchemaPointer(fSchemaPointerURI[i]);
  108. fCountSchemaName = ++i;
  109. return getDefaultSchema();
  110. }
  111. if(fXPointerSchema == null){
  112. fCountSchemaName = ++i;
  113. return null;
  114. }
  115. int fschemalength = fXPointerSchema.length;
  116. for(;fSchemaPointerName[i] != null; i++){
  117. for(int j=0; j<fschemalength; j++ ){
  118. if(fSchemaPointerName[i].equalsIgnoreCase(fXPointerSchema[j].getXpointerSchemaName())){
  119. fXPointerSchema[j].setXPointerSchemaPointer(fSchemaPointerURI[i]);
  120. fCountSchemaName = ++i;
  121. return fXPointerSchema[j];
  122. }
  123. }
  124. if(fSchemaNotAvailable == null);
  125. fSchemaNotAvailable = new Stack();
  126. fSchemaNotAvailable.push(fSchemaPointerName[i]);
  127. }
  128. return null;
  129. }
  130. public XPointerSchema getDefaultSchema(){
  131. if(fDefaultXPointerSchema == null)
  132. fDefaultXPointerSchema = new XPointerElementHandler();
  133. return fDefaultXPointerSchema;
  134. }
  135. public void getSchemaNames(){
  136. int count =0;
  137. int index =0, lastindex =0;
  138. int schemapointerindex =0, schemapointerURIindex=0;
  139. char c;
  140. int length = fSchemaPointer.length();
  141. fSchemaPointerName = new String [5];
  142. fSchemaPointerURI = new String [5];
  143. index = fSchemaPointer.indexOf('(');
  144. if( index <= 0)
  145. return;
  146. fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(0, index++).trim();
  147. lastindex = index;
  148. String tempURI = null;
  149. count++;
  150. while(index < length){
  151. c = fSchemaPointer.charAt(index);
  152. if(c == '(')
  153. count++;
  154. if(c == ')')
  155. count--;
  156. if(count==0 ){
  157. tempURI = fSchemaPointer.substring(lastindex, index).trim();
  158. fSchemaPointerURI[schemapointerURIindex++] = getEscapedURI(tempURI);
  159. lastindex = index;
  160. if((index = fSchemaPointer.indexOf('(', lastindex)) != -1){
  161. fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(lastindex+1, index).trim();
  162. count++;
  163. lastindex = index+1;
  164. }
  165. else{
  166. index = lastindex;
  167. }
  168. }
  169. index++;
  170. }
  171. schemaLength = schemapointerURIindex -1;
  172. }
  173. public String getEscapedURI(String URI){
  174. return URI;
  175. }
  176. public int getSchemaCount(){
  177. return schemaLength;
  178. }
  179. public int getCurrentPointer(){
  180. return fCountSchemaName;
  181. }
  182. }//XPointerFramwork