1 29 30 package com.caucho.quercus.lib.xml; 31 32 import com.caucho.quercus.QuercusModuleException; 33 import com.caucho.quercus.annotation.NotNull; 34 import com.caucho.quercus.annotation.Optional; 35 import com.caucho.quercus.annotation.Reference; 36 import com.caucho.quercus.env.BooleanValue; 37 import com.caucho.quercus.env.Env; 38 import com.caucho.quercus.env.LongValue; 39 import com.caucho.quercus.env.StringValue; 40 import com.caucho.quercus.env.StringValueImpl; 41 import com.caucho.quercus.env.Value; 42 import com.caucho.quercus.module.AbstractQuercusModule; 43 import com.caucho.util.L10N; 44 45 48 public class XmlModule extends AbstractQuercusModule { 49 private static final L10N L = new L10N(XmlModule.class); 50 51 52 public static final int XML_OPTION_CASE_FOLDING = 0x0; 53 public static final int XML_OPTION_SKIP_TAGSTART = 0x1; 54 public static final int XML_OPTION_SKIP_WHITE = 0x2; 55 public static final int XML_OPTION_TARGET_ENCODING = 0x3; 56 57 public static final int XML_ERROR_NONE = 0; 58 public static final int XML_ERROR_NO_MEMORY = 1; 59 public static final int XML_ERROR_SYNTAX = 2; 60 public static final int XML_ERROR_NO_ELEMENTS = 3; 61 public static final int XML_ERROR_INVALID_TOKEN = 4; 62 public static final int XML_ERROR_UNCLOSED_TOKEN = 5; 63 public static final int XML_ERROR_PARTIAL_CHAR = 6; 64 public static final int XML_ERROR_TAG_MISMATCH = 7; 65 public static final int XML_ERROR_DUPLICATE_ATTRIBUTE = 8; 66 public static final int XML_ERROR_JUNK_AFTER_DOC_ELEMENT = 9; 67 public static final int XML_ERROR_PARAM_ENTITY_REF = 10; 68 public static final int XML_ERROR_UNDEFINED_ENTITY = 11; 69 public static final int XML_ERROR_RECURSIVE_ENTITY_REF = 12; 70 public static final int XML_ERROR_ASYNC_ENTITY = 13; 71 public static final int XML_ERROR_BAD_CHAR_REF = 14; 72 public static final int XML_ERROR_BINARY_ENTITY_REF = 15; 73 public static final int XML_ERROR_ATTRIBUTE_EXTERNAL_ENTITY_REF = 16; 74 public static final int XML_ERROR_MISPLACED_XML_PI = 17; 75 public static final int XML_ERROR_UNKNOWN_ENCODING = 18; 76 public static final int XML_ERROR_INCORRECT_ENCODING = 19; 77 public static final int XML_ERROR_UNCLOSED_CDATA_SECTION = 20; 78 public static final int XML_ERROR_EXTERNAL_ENTITY_HANDLING = 21; 79 public static final int XML_ERROR_NOT_STANDALONE = 22; 80 public static final int XML_ERROR_UNEXPECTED_STATE = 23; 81 public static final int XML_ERROR_ENTITY_DECLARED_IN_PE = 24; 82 public static final int XML_ERROR_FEATURE_REQUIRES_XML_DTD = 25; 83 public static final int XML_ERROR_CANT_CHANGE_FEATURE_ONCE_PARSING = 26; 84 public static final int XML_ERROR_UNBOUND_PREFIX = 27; 85 public static final int XML_ERROR_UNDECLARING_PREFIX = 28; 86 public static final int XML_ERROR_INCOMPLETE_PE = 29; 87 public static final int XML_ERROR_XML_DECL = 30; 88 public static final int XML_ERROR_TEXT_DECL = 31; 89 public static final int XML_ERROR_PUBLICID = 32; 90 public static final int XML_ERROR_SUSPENDED = 33; 91 public static final int XML_ERROR_NOT_SUSPENDED = 34; 92 public static final int XML_ERROR_ABORTED = 35; 93 public static final int XML_ERROR_FINISHED = 36; 94 public static final int XML_ERROR_SUSPEND_PE = 37; 95 96 public String []getLoadedExtensions() 97 { 98 return new String [] { "xml" }; 99 } 100 101 104 public static Value utf8_encode(String str) 105 { 106 108 return new StringValueImpl(str); 109 } 110 111 114 public static Value utf8_decode(String str) 115 { 116 118 return new StringValueImpl(str); 119 } 120 121 124 public Value xml_get_error_code(Xml parser) 125 { 126 if (parser == null) 127 return BooleanValue.FALSE; 128 129 return LongValue.create(parser.getErrorCode()); 130 } 131 132 135 public Value xml_error_string(int code) 136 { 137 switch (code) { 138 case XML_ERROR_NONE: 139 return StringValue.create(""); 140 141 case XML_ERROR_SYNTAX: 142 return StringValue.create("syntax error"); 143 144 default: 145 return BooleanValue.FALSE; 146 } 147 } 148 149 158 public boolean xml_parse(Env env, 159 @NotNull Xml parser, 160 String data, 161 @Optional("true") boolean isFinal) 162 { 163 if (parser == null) 164 return false; 165 166 try { 167 return parser.xml_parse(env, data, isFinal); 168 } catch (Exception e) { 169 throw QuercusModuleException.create(e); 170 } 171 } 172 173 176 public Xml xml_parser_create(Env env, 177 @Optional String outputEncoding) 178 { 179 return new Xml(env,outputEncoding,null); 180 } 181 182 191 public Xml xml_parser_create_ns(Env env, 192 @Optional String outputEncoding, 193 @Optional("':'") String separator) 194 { 195 return new Xml(env,outputEncoding,separator); 196 } 197 198 207 public boolean xml_parser_set_option(@NotNull Xml parser, 208 @NotNull int option, 209 @NotNull Value value) 210 { 211 if (parser == null) 212 return false; 213 214 return parser.xml_parser_set_option(option, value); 215 } 216 217 224 public Value xml_parser_get_option(@NotNull Xml parser, 225 @NotNull int option) 226 { 227 if (parser == null) 228 return BooleanValue.FALSE; 229 230 return parser.xml_parser_get_option(option); 231 } 232 233 241 public boolean xml_set_element_handler(@NotNull Xml parser, 242 @NotNull Value startElementHandler, 243 @NotNull Value endElementHandler) 244 { 245 if (parser == null) 246 return false; 247 248 return parser.xml_set_element_handler(startElementHandler, endElementHandler); 249 } 250 251 258 public boolean xml_set_character_data_handler(@NotNull Xml parser, 259 @NotNull Value handler) 260 { 261 if (parser == null) 262 return false; 263 264 return parser.xml_set_character_data_handler(handler); 265 } 266 267 268 275 public boolean xml_set_start_namespace_decl_handler(@NotNull Xml parser, 276 @NotNull Value startNamespaceDeclHandler) 277 { 278 if (parser == null) 279 return false; 280 281 return parser.xml_set_start_namespace_decl_handler(startNamespaceDeclHandler); 282 } 283 284 290 public boolean xml_set_object(@NotNull Xml parser, 291 @NotNull Value obj) 292 { 293 if (parser == null) 294 return false; 295 296 return parser.xml_set_object(obj); 297 } 298 299 305 public boolean xml_set_processing_instruction_handler(@NotNull Xml parser, 306 @NotNull Value handler) 307 { 308 if (parser == null) 309 return false; 310 311 return parser.xml_set_processing_instruction_handler(handler); 312 } 313 314 320 public boolean xml_set_default_handler(@NotNull Xml parser, 321 @NotNull Value handler) 322 { 323 if (parser == null) 324 return false; 325 326 return parser.xml_set_default_handler(handler); 327 } 328 329 336 public boolean xml_set_notation_decl_handler(@NotNull Xml parser, 337 @NotNull Value handler) 338 { 339 if (parser == null) 340 return false; 341 342 return parser.xml_set_notation_decl_handler(handler); 343 } 344 345 351 public boolean xml_set_end_namespace_decl_handler(@NotNull Xml parser, 352 @NotNull Value handler) 353 { 354 if (parser == null) 355 return false; 356 357 return parser.xml_set_end_namespace_decl_handler(handler); 358 } 359 360 369 public int xml_parse_into_struct(@NotNull Xml parser, 370 @NotNull String data, 371 @Reference Value valueArray, 372 @Optional @Reference Value indexArray) 373 { 374 try { 375 if (parser == null) 376 return 0; 377 378 return parser.xml_parse_into_struct(data, valueArray, indexArray); 379 } catch (Exception e) { 380 throw QuercusModuleException.create(e); 381 } 382 } 383 384 390 public boolean xml_parser_free(@NotNull Xml parser) 391 { 392 if (parser == null) 393 return false; 394 else 395 return true; 396 } 397 398 405 public boolean xml_set_unparsed_entity_decl_handler(@NotNull Xml parser, 406 @NotNull Value handler) 407 { 408 if (parser == null) 409 return false; 410 411 return parser.xml_set_unparsed_entity_decl_handler(handler); 412 } 413 414 } 421 422 | Popular Tags |