2 Copyright (C) 2004 Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
40 #include "xmlj_util.h"
44 xmlExternalEntityLoader defaultLoader
= NULL
;
47 xmljDispatchError (xmlParserCtxtPtr ctx
,
55 /* -- GnomeLocator -- */
57 JNIEXPORT jstring JNICALL
58 Java_gnu_xml_libxmlj_sax_GnomeLocator_publicId (JNIEnv
* env
,
60 __attribute__((__unused__
)),
68 ctx
= (xmlParserCtxtPtr
) xmljAsPointer (env
, j_ctx
);
69 loc
= (xmlSAXLocatorPtr
) xmljAsPointer (env
, j_loc
);
70 sax
= (SAXParseContext
*) ctx
->_private
;
75 JNIEXPORT jstring JNICALL
76 Java_gnu_xml_libxmlj_sax_GnomeLocator_systemId (JNIEnv
* env
,
78 __attribute__((__unused__
)),
86 ctx
= (xmlParserCtxtPtr
) xmljAsPointer (env
, j_ctx
);
87 loc
= (xmlSAXLocatorPtr
) xmljAsPointer (env
, j_loc
);
88 sax
= (SAXParseContext
*) ctx
->_private
;
93 JNIEXPORT jint JNICALL
94 Java_gnu_xml_libxmlj_sax_GnomeLocator_lineNumber (JNIEnv
* env
,
96 __attribute__((__unused__
)),
100 xmlParserCtxtPtr ctx
;
101 xmlSAXLocatorPtr loc
;
103 ctx
= (xmlParserCtxtPtr
) xmljAsPointer (env
, j_ctx
);
104 loc
= (xmlSAXLocatorPtr
) xmljAsPointer (env
, j_loc
);
105 if (ctx
== NULL
|| ctx
->input
== NULL
)
109 return ctx
->input
->line
;
112 JNIEXPORT jint JNICALL
113 Java_gnu_xml_libxmlj_sax_GnomeLocator_columnNumber (JNIEnv
* env
,
115 __attribute__((__unused__
)),
119 xmlParserCtxtPtr ctx
;
120 xmlSAXLocatorPtr loc
;
122 ctx
= (xmlParserCtxtPtr
) xmljAsPointer (env
, j_ctx
);
123 loc
= (xmlSAXLocatorPtr
) xmljAsPointer (env
, j_loc
);
124 if (ctx
== NULL
|| ctx
->input
== NULL
)
128 return ctx
->input
->col
;
131 /* -- GnomeXMLReader -- */
134 * Entry point for SAX parsing.
136 JNIEXPORT
void JNICALL
137 Java_gnu_xml_libxmlj_sax_GnomeXMLReader_parseStream (JNIEnv
* env
,
140 jbyteArray detectBuffer
,
145 jboolean contentHandler
,
147 jboolean entityResolver
,
148 jboolean errorHandler
,
151 jboolean lexicalHandler
)
153 xmljParseDocument (env
,
173 xmljExternalEntityLoader (const char *url
, const char *id
,
174 xmlParserCtxtPtr ctx
)
176 const xmlChar
*systemId
;
177 const xmlChar
*publicId
;
178 xmlParserInputPtr ret
;
180 systemId
= xmlCharStrdup (url
);
181 publicId
= xmlCharStrdup (id
);
182 /* TODO convert systemId to absolute URI */
183 ret
= xmljSAXResolveEntity (ctx
, publicId
, systemId
);
186 ret
= defaultLoader (url
, id
, ctx
);
192 * Allocates and configures a SAX handler that can report the various
193 * classes of callback.
196 xmljNewSAXHandler (jboolean contentHandler
,
198 jboolean entityResolver
,
199 jboolean errorHandler
,
200 jboolean declarationHandler
,
201 jboolean lexicalHandler
)
203 xmlSAXHandlerPtr sax
;
205 sax
= (xmlSAXHandlerPtr
) malloc (sizeof (xmlSAXHandler
));
210 memset (sax
, 0, sizeof (xmlSAXHandler
));
211 xmlSAXVersion (sax
, 1); /* TODO SAX2 */
215 sax
->internalSubset
= &xmljSAXInternalSubset
;
217 if (defaultLoader
== NULL
)
219 defaultLoader
= xmlGetExternalEntityLoader ();
220 xmlSetExternalEntityLoader (xmljExternalEntityLoader
);
224 sax
->resolveEntity
= &xmljSAXResolveEntity
;
227 if (declarationHandler
)
229 sax
->entityDecl
= &xmljSAXEntityDecl
;
230 sax
->notationDecl
= &xmljSAXNotationDecl
;
231 sax
->attributeDecl
= &xmljSAXAttributeDecl
;
232 sax
->elementDecl
= &xmljSAXElementDecl
;
233 sax
->unparsedEntityDecl
= &xmljSAXUnparsedEntityDecl
;
236 /* We always listen for the locator callback */
237 sax
->setDocumentLocator
= &xmljSAXSetDocumentLocator
;
240 sax
->startDocument
= &xmljSAXStartDocument
;
241 sax
->endDocument
= &xmljSAXEndDocument
;
242 sax
->startElement
= &xmljSAXStartElement
;
243 sax
->endElement
= &xmljSAXEndElement
;
244 sax
->characters
= &xmljSAXCharacters
;
245 sax
->ignorableWhitespace
= &xmljSAXIgnorableWhitespace
;
246 sax
->processingInstruction
= &xmljSAXProcessingInstruction
;
249 /* We always intercept getEntity */
250 /* TODO this should only be if lexicalHandler */
251 sax
->getEntity
= &xmljSAXGetEntity
;
254 sax
->getEntity
= &xmljSAXGetEntity
;
255 sax
->reference
= &xmljSAXReference
;
256 sax
->comment
= &xmljSAXComment
;
257 sax
->cdataBlock
= &xmljSAXCDataBlock
;
259 else if (contentHandler
)
261 sax
->cdataBlock
= &xmljSAXCharacters
;
266 sax
->warning
= &xmljSAXWarning
;
267 sax
->error
= &xmljSAXError
;
268 sax
->fatalError
= &xmljSAXFatalError
;
274 /* -- Callback functions -- */
277 xmljSAXInternalSubset (void *vctx
,
278 const xmlChar
* name
,
279 const xmlChar
* publicId
, const xmlChar
* systemId
)
281 xmlParserCtxtPtr ctx
;
282 SAXParseContext
*sax
;
289 xmlSAX2InternalSubset (vctx
, name
, publicId
, systemId
);
291 ctx
= (xmlParserCtxtPtr
) vctx
;
292 sax
= (SAXParseContext
*) ctx
->_private
;
296 xmljCheckWellFormed (ctx
);
297 if ((*env
)->ExceptionOccurred (env
))
302 if (sax
->startDTD
== NULL
)
305 xmljGetMethodID (env
,
308 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
309 if (sax
->startDTD
== NULL
)
315 j_name
= xmljNewString (env
, name
);
316 j_publicId
= xmljNewString (env
, publicId
);
317 j_systemId
= xmljNewString (env
, systemId
);
319 (*env
)->CallVoidMethod (env
,
328 xmljSAXResolveEntity (void *vctx
,
329 const xmlChar
* publicId
, const xmlChar
* systemId
)
331 xmlParserCtxtPtr ctx
;
332 SAXParseContext
*sax
;
339 /* xmlSAX2ResolveEntity (vctx, publicId, systemId); */
341 ctx
= (xmlParserCtxtPtr
) vctx
;
342 if (ctx
->_private
== NULL
)
347 sax
= (SAXParseContext
*) ctx
->_private
;
351 if ((*env
)->ExceptionOccurred (env
))
356 if (sax
->resolveEntity
== NULL
)
359 xmljGetMethodID (env
,
362 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)Ljava/io/InputStream;");
363 if (sax
->resolveEntity
== NULL
)
369 j_publicId
= xmljNewString (env
, publicId
);
370 j_systemId
= xmljNewString (env
, systemId
);
372 inputStream
= (*env
)->CallObjectMethod (env
,
379 /* Return an xmlParserInputPtr corresponding to the input stream */
380 if (inputStream
!= NULL
)
382 jbyteArray detectBuffer
;
383 jmethodID getDetectBuffer
;
385 /* Get the detect buffer from the NamedInputStream */
386 getDetectBuffer
= xmljGetMethodID (env
, inputStream
, "getDetectBuffer",
388 if (getDetectBuffer
== NULL
)
392 detectBuffer
= (*env
)->CallObjectMethod (env
, inputStream
,
395 return xmljNewParserInput (env
, inputStream
, detectBuffer
, ctx
);
404 xmljSAXGetEntity (void *vctx
__attribute__((__unused__
)), const xmlChar
* name
)
409 /* ret = xmlSAX2GetEntity (vctx, name); */
415 xmljSAXEntityDecl (void *vctx
,
416 const xmlChar
* name
,
418 const xmlChar
* publicId
,
419 const xmlChar
* systemId
,
422 xmlParserCtxtPtr ctx
;
423 SAXParseContext
*sax
;
431 xmlSAX2EntityDecl (vctx
, name
, type
, publicId
, systemId
, content
);
433 ctx
= (xmlParserCtxtPtr
) vctx
;
434 sax
= (SAXParseContext
*) ctx
->_private
;
438 xmljCheckWellFormed (ctx
);
439 if ((*env
)->ExceptionOccurred (env
))
444 j_name
= xmljNewString (env
, name
);
447 case XML_INTERNAL_GENERAL_ENTITY
:
448 case XML_INTERNAL_PARAMETER_ENTITY
:
449 case XML_INTERNAL_PREDEFINED_ENTITY
:
450 if (sax
->internalEntityDecl
== NULL
)
452 sax
->internalEntityDecl
=
453 xmljGetMethodID (env
,
455 "internalEntityDecl",
456 "(Ljava/lang/String;Ljava/lang/String;)V");
457 if (sax
->internalEntityDecl
== NULL
)
462 j_value
= xmljNewString (env
, content
);
463 (*env
)->CallVoidMethod (env
,
465 sax
->internalEntityDecl
,
470 if (sax
->externalEntityDecl
== NULL
)
472 sax
->externalEntityDecl
=
473 xmljGetMethodID (env
,
475 "externalEntityDecl",
476 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
477 if (sax
->externalEntityDecl
== NULL
)
482 j_publicId
= xmljNewString (env
, publicId
);
483 j_systemId
= xmljNewString (env
, systemId
);
484 (*env
)->CallVoidMethod (env
,
486 sax
->externalEntityDecl
,
494 xmljSAXNotationDecl (void *vctx
,
495 const xmlChar
* name
,
496 const xmlChar
* publicId
,
497 const xmlChar
* systemId
)
499 xmlParserCtxtPtr ctx
;
500 SAXParseContext
*sax
;
507 xmlSAX2NotationDecl (vctx
, name
, publicId
, systemId
);
509 ctx
= (xmlParserCtxtPtr
) vctx
;
510 sax
= (SAXParseContext
*) ctx
->_private
;
514 xmljCheckWellFormed (ctx
);
515 if ((*env
)->ExceptionOccurred (env
))
520 if (sax
->notationDecl
== NULL
)
523 xmljGetMethodID (env
,
526 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
527 if (sax
->notationDecl
== NULL
)
533 j_name
= xmljNewString (env
, name
);
534 j_publicId
= xmljNewString (env
, publicId
);
535 j_systemId
= xmljNewString (env
, systemId
);
537 /* Invoke the method */
538 (*env
)->CallVoidMethod (env
,
547 xmljSAXAttributeDecl (void *vctx
,
548 const xmlChar
* elem
,
549 const xmlChar
* fullName
,
552 const xmlChar
* defaultValue
,
553 xmlEnumerationPtr tree
)
555 xmlParserCtxtPtr ctx
;
556 SAXParseContext
*sax
;
565 xmlSAX2AttributeDecl (vctx
, elem
, fullName
, type
, def
, defaultValue
, tree
);
567 ctx
= (xmlParserCtxtPtr
) vctx
;
568 sax
= (SAXParseContext
*) ctx
->_private
;
572 xmljCheckWellFormed (ctx
);
573 if ((*env
)->ExceptionOccurred (env
))
578 if (sax
->attributeDecl
== NULL
)
581 xmljGetMethodID (env
,
584 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
585 if (sax
->attributeDecl
== NULL
)
591 j_eName
= xmljNewString (env
, elem
);
592 j_aName
= xmljNewString (env
, fullName
);
593 j_type
= xmljAttributeTypeName (env
, type
);
594 j_mode
= xmljAttributeModeName (env
, def
);
595 j_value
= xmljNewString (env
, defaultValue
);
597 (*env
)->CallVoidMethod (env
,
608 xmljSAXElementDecl (void *vctx
,
609 const xmlChar
* name
,
611 xmlElementContentPtr content
)
613 xmlParserCtxtPtr ctx
;
614 SAXParseContext
*sax
;
620 xmlSAX2ElementDecl (vctx
, name
, type
, content
);
622 ctx
= (xmlParserCtxtPtr
) vctx
;
623 sax
= (SAXParseContext
*) ctx
->_private
;
627 xmljCheckWellFormed (ctx
);
628 if ((*env
)->ExceptionOccurred (env
))
633 if (sax
->elementDecl
== NULL
)
636 xmljGetMethodID (env
,
639 "(Ljava/lang/String;Ljava/lang/String;)V");
640 if (sax
->elementDecl
== NULL
)
646 j_name
= xmljNewString (env
, name
);
647 j_model
= NULL
; /* TODO */
649 (*env
)->CallVoidMethod (env
,
657 xmljSAXUnparsedEntityDecl (void *vctx
,
658 const xmlChar
* name
,
659 const xmlChar
* publicId
,
660 const xmlChar
* systemId
,
661 const xmlChar
* notationName
)
663 xmlParserCtxtPtr ctx
;
664 SAXParseContext
*sax
;
670 jstring j_notationName
;
672 xmlSAX2UnparsedEntityDecl (vctx
, name
, publicId
, systemId
, notationName
);
674 ctx
= (xmlParserCtxtPtr
) vctx
;
675 sax
= (SAXParseContext
*) ctx
->_private
;
679 xmljCheckWellFormed (ctx
);
680 if ((*env
)->ExceptionOccurred (env
))
685 if (sax
->unparsedEntityDecl
== NULL
)
687 sax
->unparsedEntityDecl
=
688 xmljGetMethodID (env
,
690 "unparsedEntityDecl",
691 "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;Ljava/lang/String;)V");
692 if (sax
->unparsedEntityDecl
== NULL
)
698 j_name
= xmljNewString (env
, name
);
699 j_publicId
= xmljNewString (env
, publicId
);
700 j_systemId
= xmljNewString (env
, systemId
);
701 j_notationName
= xmljNewString (env
, notationName
);
703 (*env
)->CallVoidMethod (env
,
705 sax
->unparsedEntityDecl
,
713 xmljSAXSetDocumentLocator (void *vctx
, xmlSAXLocatorPtr loc
)
715 xmlParserCtxtPtr ctx
;
716 SAXParseContext
*sax
;
720 xmlSAX2SetDocumentLocator (vctx
, loc
);
722 ctx
= (xmlParserCtxtPtr
) vctx
;
723 sax
= (SAXParseContext
*) ctx
->_private
;
729 /* No Java parse context */
733 /* Update locator on sax context */
735 if ((*env
)->ExceptionOccurred (env
))
740 if (sax
->setDocumentLocator
== NULL
)
742 sax
->setDocumentLocator
= xmljGetMethodID (env
,
744 "setDocumentLocator",
745 "(Ljava/lang/Object;Ljava/lang/Object;)V");
746 if (sax
->setDocumentLocator
== NULL
)
752 (*env
)->CallVoidMethod (env
,
754 sax
->setDocumentLocator
,
755 xmljAsField (env
, ctx
),
756 xmljAsField (env
, loc
));
760 xmljSAXStartDocument (void *vctx
)
762 xmlParserCtxtPtr ctx
;
763 SAXParseContext
*sax
;
767 xmlSAX2StartDocument (vctx
);
769 ctx
= (xmlParserCtxtPtr
) vctx
;
770 sax
= (SAXParseContext
*) ctx
->_private
;
774 xmljCheckWellFormed (ctx
);
775 if ((*env
)->ExceptionOccurred (env
))
780 if (sax
->startDocument
== NULL
)
782 sax
->startDocument
= xmljGetMethodID (env
,
786 if (sax
->startDocument
== NULL
)
792 (*env
)->CallVoidMethod (env
,
799 xmljSAXEndDocument (void *vctx
)
801 xmlParserCtxtPtr ctx
;
802 SAXParseContext
*sax
;
806 xmlSAX2EndDocument (vctx
);
808 ctx
= (xmlParserCtxtPtr
) vctx
;
809 sax
= (SAXParseContext
*) ctx
->_private
;
813 xmljCheckWellFormed (ctx
);
814 if ((*env
)->ExceptionOccurred (env
))
819 if (sax
->endDocument
== NULL
)
821 sax
->endDocument
= xmljGetMethodID (env
,
825 if (sax
->endDocument
== NULL
)
831 (*env
)->CallVoidMethod (env
,
837 xmljSAXStartElement (void *vctx
,
838 const xmlChar
* name
,
839 const xmlChar
** attrs
)
841 xmlParserCtxtPtr ctx
;
842 SAXParseContext
*sax
;
846 jobjectArray j_attrs
;
850 xmlSAX2StartElement (vctx
, name
, attrs
);
852 ctx
= (xmlParserCtxtPtr
) vctx
;
853 sax
= (SAXParseContext
*) ctx
->_private
;
857 xmljCheckWellFormed (ctx
);
858 if ((*env
)->ExceptionOccurred (env
))
863 if (sax
->startElement
== NULL
)
866 xmljGetMethodID (env
,
869 "(Ljava/lang/String;[Ljava/lang/String;)V");
870 if (sax
->startElement
== NULL
)
876 j_name
= xmljNewString (env
, name
);
877 /* build attributes array */
879 for (len
= 0; attrs
&& attrs
[len
]; len
++)
884 if (sax
->stringClass
== NULL
)
886 sax
->stringClass
= (*env
)->FindClass (env
, "java/lang/String");
887 if (sax
->stringClass
== NULL
)
889 fprintf (stderr
, "Can't find java.lang.String class!\n");
893 j_attrs
= (*env
)->NewObjectArray (env
, len
, sax
->stringClass
, NULL
);
896 fprintf (stderr
, "Can't allocate attributes array!\n");
900 for (len
= 0; attrs
&& attrs
[len
]; len
++)
902 j_attr
= xmljNewString (env
, attrs
[len
]);
903 (*env
)->SetObjectArrayElement (env
, j_attrs
, len
, j_attr
);
906 (*env
)->CallVoidMethod (env
,
911 (*env
)->DeleteLocalRef (env
, j_attrs
);
915 (*env
)->CallVoidMethod (env
,
925 xmljSAXEndElement (void *vctx
,
926 const xmlChar
* name
)
928 xmlParserCtxtPtr ctx
;
929 SAXParseContext
*sax
;
934 xmlSAX2EndElement (vctx
, name
);
936 ctx
= (xmlParserCtxtPtr
) vctx
;
937 sax
= (SAXParseContext
*) ctx
->_private
;
941 xmljCheckWellFormed (ctx
);
942 if ((*env
)->ExceptionOccurred (env
))
947 if (sax
->endElement
== NULL
)
949 sax
->endElement
= xmljGetMethodID (env
,
952 "(Ljava/lang/String;)V");
953 if (sax
->endElement
== NULL
)
959 j_name
= xmljNewString (env
, name
);
961 (*env
)->CallVoidMethod (env
,
968 xmljSAXReference (void *vctx
,
969 const xmlChar
* name
)
971 xmlSAX2Reference (vctx
, name
);
975 xmljSAXCharacters (void *vctx
,
979 xmlParserCtxtPtr ctx
;
980 SAXParseContext
*sax
;
986 xmlSAX2Characters (vctx
, ch
, len
);
988 ctx
= (xmlParserCtxtPtr
) vctx
;
989 sax
= (SAXParseContext
*) ctx
->_private
;
993 xmljCheckWellFormed (ctx
);
994 if ((*env
)->ExceptionOccurred (env
))
999 if (sax
->characters
== NULL
)
1001 sax
->characters
= xmljGetMethodID (env
,
1004 "(Ljava/lang/String;)V");
1005 if (sax
->characters
== NULL
)
1011 dup
= xmlStrndup (ch
, len
);
1012 j_ch
= xmljNewString (env
, dup
);
1014 (*env
)->CallVoidMethod (env
,
1022 xmljSAXIgnorableWhitespace (void *vctx
,
1026 xmlParserCtxtPtr ctx
;
1027 SAXParseContext
*sax
;
1033 xmlSAX2IgnorableWhitespace (vctx
, ch
, len
);
1035 ctx
= (xmlParserCtxtPtr
) vctx
;
1036 sax
= (SAXParseContext
*) ctx
->_private
;
1040 xmljCheckWellFormed (ctx
);
1041 if ((*env
)->ExceptionOccurred (env
))
1046 if (sax
->ignorableWhitespace
== NULL
)
1048 sax
->ignorableWhitespace
= xmljGetMethodID (env
,
1050 "ignorableWhitespace",
1051 "(Ljava/lang/String;)V");
1052 if (sax
->ignorableWhitespace
== NULL
)
1058 dup
= xmlStrndup (ch
, len
);
1059 j_ch
= xmljNewString (env
, dup
);
1061 (*env
)->CallVoidMethod (env
,
1063 sax
->ignorableWhitespace
,
1069 xmljSAXProcessingInstruction (void *vctx
,
1070 const xmlChar
* targ
,
1071 const xmlChar
* data
)
1073 xmlParserCtxtPtr ctx
;
1074 SAXParseContext
*sax
;
1080 xmlSAX2ProcessingInstruction (vctx
, targ
, data
);
1082 ctx
= (xmlParserCtxtPtr
) vctx
;
1083 sax
= (SAXParseContext
*) ctx
->_private
;
1087 xmljCheckWellFormed (ctx
);
1088 if ((*env
)->ExceptionOccurred (env
))
1093 if (sax
->processingInstruction
== NULL
)
1095 sax
->processingInstruction
=
1096 xmljGetMethodID (env
,
1098 "processingInstruction",
1099 "(Ljava/lang/String;Ljava/lang/String;)V");
1100 if (sax
->processingInstruction
== NULL
)
1106 j_targ
= xmljNewString (env
, targ
);
1107 j_data
= xmljNewString (env
, data
);
1109 (*env
)->CallVoidMethod (env
,
1111 sax
->processingInstruction
,
1117 xmljSAXComment (void *vctx
,
1118 const xmlChar
* value
)
1120 xmlParserCtxtPtr ctx
;
1121 SAXParseContext
*sax
;
1126 xmlSAX2Comment (vctx
, value
);
1128 ctx
= (xmlParserCtxtPtr
) vctx
;
1129 sax
= (SAXParseContext
*) ctx
->_private
;
1133 xmljCheckWellFormed (ctx
);
1134 if ((*env
)->ExceptionOccurred (env
))
1139 if (sax
->comment
== NULL
)
1142 xmljGetMethodID (env
,
1145 "(Ljava/lang/String;)V");
1146 if (sax
->comment
== NULL
)
1152 j_text
= xmljNewString (env
, value
);
1154 (*env
)->CallVoidMethod (env
,
1161 xmljSAXCDataBlock (void *vctx
,
1165 xmlParserCtxtPtr ctx
;
1166 SAXParseContext
*sax
;
1172 xmlSAX2CDataBlock (vctx
, ch
, len
);
1174 ctx
= (xmlParserCtxtPtr
) vctx
;
1175 sax
= (SAXParseContext
*) ctx
->_private
;
1179 xmljCheckWellFormed (ctx
);
1180 if ((*env
)->ExceptionOccurred (env
))
1185 if (sax
->cdataBlock
== NULL
)
1188 xmljGetMethodID (env
,
1191 "(Ljava/lang/String;)V");
1192 if (sax
->cdataBlock
== NULL
)
1198 dup
= xmlStrndup (ch
, len
);
1199 j_ch
= xmljNewString (env
, dup
);
1201 (*env
)->CallVoidMethod (env
,
1209 xmljDispatchError (xmlParserCtxtPtr ctx
,
1210 xmlSAXLocatorPtr loc
,
1221 char buffer
[2048] = "";
1225 vsnprintf (buffer
, sizeof buffer
, msg
, args
);
1227 lineNumber
= loc
->getLineNumber (ctx
);
1228 columnNumber
= loc
->getColumnNumber (ctx
);
1229 publicId
= xmljNewString (env
, loc
->getPublicId (ctx
));
1230 systemId
= xmljNewString (env
, loc
->getSystemId (ctx
));
1231 (*env
)->CallVoidMethod (env
,
1234 (*env
)->NewStringUTF (env
, buffer
),
1242 xmljSAXWarning (void *vctx
,
1248 xmlParserCtxtPtr ctx
;
1249 SAXParseContext
*sax
;
1250 xmlSAXLocatorPtr loc
;
1254 ctx
= (xmlParserCtxtPtr
) vctx
;
1255 sax
= (SAXParseContext
*) ctx
->_private
;
1256 loc
= (xmlSAXLocatorPtr
) sax
->loc
;
1260 if ((*env
)->ExceptionOccurred (env
))
1264 if (sax
->warning
== NULL
)
1267 xmljGetMethodID (env
,
1270 "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V");
1271 if (sax
->warning
== NULL
)
1277 va_start (args
, msg
);
1278 /* xmlParserWarning (vctx, msg, args); */
1279 xmljDispatchError (ctx
, loc
, env
, target
, sax
->warning
, msg
, args
);
1284 xmljSAXError (void *vctx
,
1290 xmlParserCtxtPtr ctx
;
1291 SAXParseContext
*sax
;
1292 xmlSAXLocatorPtr loc
;
1296 ctx
= (xmlParserCtxtPtr
) vctx
;
1297 sax
= (SAXParseContext
*) ctx
->_private
;
1298 loc
= (xmlSAXLocatorPtr
) sax
->loc
;
1302 if ((*env
)->ExceptionOccurred (env
))
1306 if (sax
->error
== NULL
)
1309 xmljGetMethodID (env
,
1312 "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V");
1313 if (sax
->error
== NULL
)
1319 va_start (args
, msg
);
1320 /* xmlParserError (vctx, msg, args); */
1321 xmljDispatchError (ctx
, loc
, env
, target
, sax
->error
, msg
, args
);
1326 xmljSAXFatalError (void *vctx
,
1332 xmlParserCtxtPtr ctx
;
1333 SAXParseContext
*sax
;
1334 xmlSAXLocatorPtr loc
;
1338 ctx
= (xmlParserCtxtPtr
) vctx
;
1339 sax
= (SAXParseContext
*) ctx
->_private
;
1340 loc
= (xmlSAXLocatorPtr
) sax
->loc
;
1344 if ((*env
)->ExceptionOccurred (env
))
1348 if (sax
->fatalError
== NULL
)
1351 xmljGetMethodID (env
,
1354 "(Ljava/lang/String;IILjava/lang/String;Ljava/lang/String;)V");
1355 if (sax
->fatalError
== NULL
)
1361 va_start (args
, msg
);
1362 /* xmlParserError (vctx, msg, args); */
1363 xmljDispatchError (ctx
, loc
, env
, target
, sax
->fatalError
, msg
, args
);
1368 xmljCheckWellFormed (xmlParserCtxtPtr ctx
)
1370 if (!ctx
->wellFormed
)
1372 xmljSAXFatalError (ctx
, "document is not well-formed");
1374 if (ctx
->validate
&& !ctx
->valid
)
1376 xmljSAXFatalError (ctx
, "document is not valid");
1381 * Convert a libxml2 attribute type to a string.
1384 xmljAttributeTypeName (JNIEnv
* env
, int type
)
1390 case XML_ATTRIBUTE_CDATA
:
1393 case XML_ATTRIBUTE_ID
:
1396 case XML_ATTRIBUTE_IDREF
:
1399 case XML_ATTRIBUTE_IDREFS
:
1402 case XML_ATTRIBUTE_NMTOKEN
:
1405 case XML_ATTRIBUTE_NMTOKENS
:
1408 case XML_ATTRIBUTE_ENTITY
:
1411 case XML_ATTRIBUTE_ENTITIES
:
1418 return (*env
)->NewStringUTF (env
, text
);
1422 * Convert a libxml2 attribute default value type to a string.
1425 xmljAttributeModeName (JNIEnv
* env
, int type
)
1431 case XML_ATTRIBUTE_IMPLIED
:
1434 case XML_ATTRIBUTE_REQUIRED
:
1437 case XML_ATTRIBUTE_FIXED
:
1444 return (*env
)->NewStringUTF (env
, text
);