1 57 58 package org.enhydra.apache.xerces.readers; 59 60 import java.util.Stack ; 61 62 import org.enhydra.apache.xerces.framework.XMLErrorReporter; 63 import org.enhydra.apache.xerces.utils.ChunkyByteArray; 64 import org.enhydra.apache.xerces.utils.StringPool; 65 66 80 public abstract class XMLDeclRecognizer { 81 82 87 public static void registerDefaultRecognizers(Stack recognizerStack) { 88 recognizerStack.push(new EBCDICRecognizer()); 89 recognizerStack.push(new UCSRecognizer()); 90 recognizerStack.push(new UTF8Recognizer()); 91 } 92 93 107 public abstract XMLEntityHandler.EntityReader recognize(XMLEntityReaderFactory readerFactory, 108 XMLEntityHandler entityHandler, 109 XMLErrorReporter errorReporter, 110 boolean sendCharDataAsCharArray, 111 StringPool stringPool, 112 ChunkyByteArray data, 113 boolean xmlDecl, 114 boolean allowJavaEncodingName) throws Exception ; 115 116 136 protected int prescanXMLDeclOrTextDecl(XMLEntityHandler.EntityReader entityReader, boolean xmlDecl) throws Exception 137 { 138 if (!entityReader.lookingAtChar('<', true)) { 139 return -1; 140 } 141 if (!entityReader.lookingAtChar('?', true)) { 142 return -1; 143 } 144 if (!entityReader.skippedString(xml_string)) { 145 return -1; 146 } 147 entityReader.skipPastSpaces(); 148 boolean single; 149 char qchar; 150 if (entityReader.skippedString(version_string)) { 151 entityReader.skipPastSpaces(); 152 if (!entityReader.lookingAtChar('=', true)) { 153 return -1; 154 } 155 entityReader.skipPastSpaces(); 156 int versionIndex = entityReader.scanStringLiteral(); 157 if (versionIndex < 0) { 158 return -1; 159 } 160 if (!entityReader.lookingAtSpace(true)) { 161 return -1; 162 } 163 entityReader.skipPastSpaces(); 164 } 165 else if (xmlDecl) { 166 return -1; 167 } 168 if (!entityReader.skippedString(encoding_string)) { 169 return -1; 170 } 171 entityReader.skipPastSpaces(); 172 if (!entityReader.lookingAtChar('=', true)) { 173 return -1; 174 } 175 entityReader.skipPastSpaces(); 176 int encodingIndex = entityReader.scanStringLiteral(); 177 return encodingIndex; 178 } 179 private static final char[] xml_string = { 'x','m','l' }; 184 private static final char[] version_string = { 'v','e','r','s','i','o','n' }; 188 private static final char[] encoding_string = { 'e','n','c','o','d','i','n','g' }; 192 } 193 | Popular Tags |