Author: fanningpj
Date: Wed Sep 24 08:35:05 2025
New Revision: 1928724
Log:
[XMLBEANS-660] Add Locale enter and exit to XML Cursor attribute handling.
Thanks to waa-ben. This closes #24
Modified:
xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
xmlbeans/trunk/src/test/java/xmlcursor/checkin/StoreTests.java
Modified: xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
==============================================================================
--- xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
Wed Sep 24 08:21:53 2025 (r1928723)
+++ xmlbeans/trunk/src/main/java/org/apache/xmlbeans/impl/store/Cur.java
Wed Sep 24 08:35:05 2025 (r1928724)
@@ -2923,10 +2923,12 @@ public final class Cur {
text(value, 0, value.length());
end();
if (isId) {
+ _locale.enter();
Cur c1 = x.tempCur();
c1.toRoot();
Xobj doc = c1._xobj;
c1.release();
+ _locale.exit();
if (doc instanceof DocumentXobj) {
((DocumentXobj) doc).addIdElement(value,
x._parent.getDom());
@@ -3425,4 +3427,4 @@ public final class Cur {
public Locale getLocale() {
return _locale;
}
-}
\ No newline at end of file
+}
Modified: xmlbeans/trunk/src/test/java/xmlcursor/checkin/StoreTests.java
==============================================================================
--- xmlbeans/trunk/src/test/java/xmlcursor/checkin/StoreTests.java Wed Sep
24 08:21:53 2025 (r1928723)
+++ xmlbeans/trunk/src/test/java/xmlcursor/checkin/StoreTests.java Wed Sep
24 08:35:05 2025 (r1928724)
@@ -18,6 +18,7 @@ package xmlcursor.checkin;
import org.apache.xmlbeans.*;
import org.apache.xmlbeans.XmlCursor.TokenType;
import org.apache.xmlbeans.XmlCursor.XmlBookmark;
+import org.apache.xmlbeans.impl.store.Locale;
import org.apache.xmlbeans.impl.xb.xsdschema.SchemaDocument;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Disabled;
@@ -26,6 +27,7 @@ import org.junit.jupiter.params.Paramete
import org.junit.jupiter.params.provider.ValueSource;
import org.xml.sax.*;
import org.xml.sax.ext.LexicalHandler;
+import org.xml.sax.helpers.AttributesImpl;
import xmlcursor.common.Common;
import javax.xml.namespace.QName;
@@ -1951,6 +1953,38 @@ public class StoreTests {
}
@Test
+ void testSaxHandlerIdDetection() throws SAXException{
+ final XmlOptions emptyXmlOptions = new XmlOptions();
+ final String schemaUri = "http://example.com/schema";
+
+ final Locale loc = Locale.getLocale(null, null);
+ final AttributesImpl attrs = new AttributesImpl();
+
+ // The QName must be "id" as that's now enough for an attribute to be
treated as an ID
+ attrs.addAttribute(
+ schemaUri,
+ "localIgnored",
+ "id",
+ "CDATA",
+ "anId"
+ );
+
+ loc.getSchemaTypeLoader().newXmlSaxHandler(null, emptyXmlOptions);
+ ContentHandler xmlSaxHandler = Locale.newSaxHandler(
+ loc.getSchemaTypeLoader(),
+ null,
+ emptyXmlOptions
+ ).getContentHandler();
+
+ xmlSaxHandler.startElement(
+ schemaUri,
+ "localIgnored",
+ "sa:someName",
+ attrs
+ );
+ }
+
+ @Test
void testAdditionalNamespaces() throws Exception {
String xml = "<a xmlns:a='aNS'><a:b/></a>";
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]