1 /* 2 * reserved comment block 3 * DO NOT REMOVE OR ALTER! 4 */ 5 /* 6 * Licensed to the Apache Software Foundation (ASF) under one or more 7 * contributor license agreements. See the NOTICE file distributed with 8 * this work for additional information regarding copyright ownership. 9 * The ASF licenses this file to You under the Apache License, Version 2.0 10 * (the "License"); you may not use this file except in compliance with 11 * the License. You may obtain a copy of the License at 12 * 13 * http://www.apache.org/licenses/LICENSE-2.0 14 * 15 * Unless required by applicable law or agreed to in writing, software 16 * distributed under the License is distributed on an "AS IS" BASIS, 17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 18 * See the License for the specific language governing permissions and 19 * limitations under the License. 20 */ 21 22 package com.sun.org.apache.xerces.internal.xinclude; 23 24 import java.util.Stack; 25 import com.sun.org.apache.xerces.internal.xinclude.XPointerSchema; 26 27 public class XPointerFramework{ 28 29 /* 30 Todo's by next integration. 31 While constructing schema names and uris use a dynamic datastructure. 32 */ 33 34 XPointerSchema [] fXPointerSchema; 35 String [] fSchemaPointerName; 36 String [] fSchemaPointerURI; 37 String fSchemaPointer; 38 String fCurrentSchemaPointer; 39 Stack fSchemaNotAvailable; 40 int fCountSchemaName = 0; 41 int schemaLength = 0; 42 XPointerSchema fDefaultXPointerSchema; 43 44 public XPointerFramework(){ 45 this(null); 46 } 47 48 public XPointerFramework(XPointerSchema [] xpointerschema){ 49 fXPointerSchema = xpointerschema; 50 fSchemaNotAvailable = new Stack(); 51 } 52 53 public void reset(){ 54 fXPointerSchema = null; 55 fXPointerSchema = null; 56 fCountSchemaName = 0; 57 schemaLength = 0; 58 fSchemaPointerName = null; 59 fSchemaPointerURI = null; 60 fDefaultXPointerSchema = null; 61 fCurrentSchemaPointer = null; 62 } 63 64 public void setXPointerSchema(XPointerSchema [] xpointerschema){ 65 fXPointerSchema = xpointerschema; 66 } 67 68 public void setSchemaPointer(String schemaPointer){ 69 fSchemaPointer = schemaPointer; 70 } 71 72 public XPointerSchema getNextXPointerSchema(){ 73 int i=fCountSchemaName; 74 if(fSchemaPointerName == null){ 75 getSchemaNames(); 76 } 77 if(fDefaultXPointerSchema == null){ 78 getDefaultSchema(); 79 } 80 if(fDefaultXPointerSchema.getXpointerSchemaName().equalsIgnoreCase(fSchemaPointerName[i])){ 81 fDefaultXPointerSchema.reset(); 82 fDefaultXPointerSchema.setXPointerSchemaPointer(fSchemaPointerURI[i]); 83 fCountSchemaName = ++i; 84 return getDefaultSchema(); 85 } 86 if(fXPointerSchema == null){ 87 fCountSchemaName = ++i; 88 return null; 89 } 90 91 int fschemalength = fXPointerSchema.length; 92 93 for(;fSchemaPointerName[i] != null; i++){ 94 for(int j=0; j<fschemalength; j++ ){ 95 if(fSchemaPointerName[i].equalsIgnoreCase(fXPointerSchema[j].getXpointerSchemaName())){ 96 fXPointerSchema[j].setXPointerSchemaPointer(fSchemaPointerURI[i]); 97 fCountSchemaName = ++i; 98 return fXPointerSchema[j]; 99 } 100 } 101 102 if(fSchemaNotAvailable == null) 103 fSchemaNotAvailable = new Stack(); 104 105 fSchemaNotAvailable.push(fSchemaPointerName[i]); 106 } 107 return null; 108 } 109 110 public XPointerSchema getDefaultSchema(){ 111 if(fDefaultXPointerSchema == null) 112 fDefaultXPointerSchema = new XPointerElementHandler(); 113 return fDefaultXPointerSchema; 114 } 115 116 public void getSchemaNames(){ 117 int count =0; 118 int index =0, lastindex =0; 119 int schemapointerindex =0, schemapointerURIindex=0; 120 char c; 121 int length = fSchemaPointer.length(); 122 fSchemaPointerName = new String [5]; 123 fSchemaPointerURI = new String [5]; 124 125 index = fSchemaPointer.indexOf('('); 126 if( index <= 0) 127 return; 128 129 fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(0, index++).trim(); 130 lastindex = index; 131 String tempURI = null; 132 count++; 133 134 while(index < length){ 135 c = fSchemaPointer.charAt(index); 136 if(c == '(') 137 count++; 138 if(c == ')') 139 count--; 140 if(count==0 ){ 141 tempURI = fSchemaPointer.substring(lastindex, index).trim(); 142 fSchemaPointerURI[schemapointerURIindex++] = getEscapedURI(tempURI); 143 lastindex = index; 144 if((index = fSchemaPointer.indexOf('(', lastindex)) != -1){ 145 fSchemaPointerName[schemapointerindex++] = fSchemaPointer.substring(lastindex+1, index).trim(); 146 count++; 147 lastindex = index+1; 148 } 149 else{ 150 index = lastindex; 151 } 152 } 153 index++; 154 } 155 schemaLength = schemapointerURIindex -1; 156 } 157 158 public String getEscapedURI(String URI){ 159 return URI; 160 } 161 162 public int getSchemaCount(){ 163 return schemaLength; 164 } 165 166 public int getCurrentPointer(){ 167 return fCountSchemaName; 168 } 169 170 }//XPointerFramwork