1 57 package com.sun.org.apache.xerces.internal.xinclude; 58 59 import java.util.Stack ; 60 import com.sun.org.apache.xerces.internal.xinclude.XPointerSchema; 61 62 public class XPointerFramework{ 63 64 68 69 XPointerSchema [] fXPointerSchema; 70 String [] fSchemaPointerName; 71 String [] fSchemaPointerURI; 72 String fSchemaPointer; 73 String fCurrentSchemaPointer; 74 Stack 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 (); 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 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 (); 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 [5]; 158 fSchemaPointerURI = new String [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 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 getEscapedURI(String 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 } | Popular Tags |