first commit

This commit is contained in:
2025-07-28 13:56:49 +05:30
commit e9eb805edb
3438 changed files with 520990 additions and 0 deletions

View File

@@ -0,0 +1,60 @@
package org.apache.xerces.util;
import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import org.apache.xerces.xni.XMLResourceIdentifier;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLEntityResolver;
import org.apache.xerces.xni.parser.XMLInputSource;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
public class EntityResolverWrapper implements XMLEntityResolver {
protected EntityResolver fEntityResolver;
public EntityResolverWrapper() {}
public EntityResolverWrapper(EntityResolver entityResolver) {
setEntityResolver(entityResolver);
}
public void setEntityResolver(EntityResolver entityResolver) {
this.fEntityResolver = entityResolver;
}
public EntityResolver getEntityResolver() {
return this.fEntityResolver;
}
public XMLInputSource resolveEntity(XMLResourceIdentifier resourceIdentifier) throws XNIException, IOException {
String pubId = resourceIdentifier.getPublicId();
String sysId = resourceIdentifier.getExpandedSystemId();
if (pubId == null && sysId == null)
return null;
if (this.fEntityResolver != null && resourceIdentifier != null)
try {
InputSource inputSource = this.fEntityResolver.resolveEntity(pubId, sysId);
if (inputSource != null) {
String publicId = inputSource.getPublicId();
String systemId = inputSource.getSystemId();
String baseSystemId = resourceIdentifier.getBaseSystemId();
InputStream byteStream = inputSource.getByteStream();
Reader charStream = inputSource.getCharacterStream();
String encoding = inputSource.getEncoding();
XMLInputSource xmlInputSource = new XMLInputSource(publicId, systemId, baseSystemId);
xmlInputSource.setByteStream(byteStream);
xmlInputSource.setCharacterStream(charStream);
xmlInputSource.setEncoding(encoding);
return xmlInputSource;
}
} catch (SAXException e) {
Exception ex = e.getException();
if (ex == null)
ex = e;
throw new XNIException(ex);
}
return null;
}
}

View File

@@ -0,0 +1,121 @@
package org.apache.xerces.util;
import org.apache.xerces.xni.XMLLocator;
import org.apache.xerces.xni.XNIException;
import org.apache.xerces.xni.parser.XMLErrorHandler;
import org.apache.xerces.xni.parser.XMLParseException;
import org.xml.sax.ErrorHandler;
import org.xml.sax.SAXException;
import org.xml.sax.SAXParseException;
public class ErrorHandlerWrapper implements XMLErrorHandler {
protected ErrorHandler fErrorHandler;
public ErrorHandlerWrapper() {}
public ErrorHandlerWrapper(ErrorHandler errorHandler) {
setErrorHandler(errorHandler);
}
public void setErrorHandler(ErrorHandler errorHandler) {
this.fErrorHandler = errorHandler;
}
public ErrorHandler getErrorHandler() {
return this.fErrorHandler;
}
public void warning(String domain, String key, XMLParseException exception) throws XNIException {
SAXParseException saxException = createSAXParseException(exception);
try {
this.fErrorHandler.warning(saxException);
} catch (SAXParseException e) {
throw createXMLParseException(e);
} catch (SAXException e) {
throw createXNIException(e);
}
}
public void error(String domain, String key, XMLParseException exception) throws XNIException {
SAXParseException saxException = createSAXParseException(exception);
try {
this.fErrorHandler.error(saxException);
} catch (SAXParseException e) {
throw createXMLParseException(e);
} catch (SAXException e) {
throw createXNIException(e);
}
}
public void fatalError(String domain, String key, XMLParseException exception) throws XNIException {
SAXParseException saxException = createSAXParseException(exception);
try {
this.fErrorHandler.fatalError(saxException);
} catch (SAXParseException e) {
throw createXMLParseException(e);
} catch (SAXException e) {
throw createXNIException(e);
}
}
protected static SAXParseException createSAXParseException(XMLParseException exception) {
return new SAXParseException(exception.getMessage(), exception.getPublicId(), exception.getExpandedSystemId(), exception.getLineNumber(), exception.getColumnNumber(), exception.getException());
}
protected static XMLParseException createXMLParseException(SAXParseException exception) {
String fPublicId = exception.getPublicId();
String fExpandedSystemId = exception.getSystemId();
int fLineNumber = exception.getLineNumber();
int fColumnNumber = exception.getColumnNumber();
XMLLocator location = new XMLLocator(fPublicId, fExpandedSystemId, fColumnNumber, fLineNumber) {
private final String val$fPublicId;
private final String val$fExpandedSystemId;
private final int val$fColumnNumber;
private final int val$fLineNumber;
public void setPublicId(String id) {}
public String getPublicId() {
return this.val$fPublicId;
}
public void setExpandedSystemId(String id) {}
public String getExpandedSystemId() {
return this.val$fExpandedSystemId;
}
public void setBaseSystemId(String id) {}
public String getBaseSystemId() {
return null;
}
public void setLiteralSystemId(String id) {}
public String getLiteralSystemId() {
return null;
}
public int getColumnNumber() {
return this.val$fColumnNumber;
}
public void setColumnNumber(int col) {}
public int getLineNumber() {
return this.val$fLineNumber;
}
public void setLineNumber(int line) {}
};
return new XMLParseException(location, exception.getMessage(), exception.getException());
}
protected static XNIException createXNIException(SAXException exception) {
return new XNIException(exception.getMessage(), exception.getException());
}
}

View File

@@ -0,0 +1,105 @@
package org.apache.xerces.util;
public class SymbolHash {
protected int fTableSize = 101;
protected Entry[] fBuckets;
protected int fNum = 0;
public SymbolHash() {
this.fBuckets = new Entry[this.fTableSize];
}
public SymbolHash(int size) {
this.fTableSize = size;
this.fBuckets = new Entry[this.fTableSize];
}
public void put(Object key, Object value) {
int bucket = (key.hashCode() & Integer.MAX_VALUE) % this.fTableSize;
Entry entry = search(key, bucket);
if (entry != null) {
entry.value = value;
} else {
entry = new Entry(key, value, this.fBuckets[bucket]);
this.fBuckets[bucket] = entry;
this.fNum++;
}
}
public Object get(Object key) {
int bucket = (key.hashCode() & Integer.MAX_VALUE) % this.fTableSize;
Entry entry = search(key, bucket);
if (entry != null)
return entry.value;
return null;
}
public int getLength() {
return this.fNum;
}
public int getValues(Object[] elements, int from) {
for (int i = 0, j = 0; i < this.fTableSize && j < this.fNum; i++) {
for (Entry entry = this.fBuckets[i]; entry != null; entry = entry.next) {
elements[from + j] = entry.value;
j++;
}
}
return this.fNum;
}
public SymbolHash makeClone() {
SymbolHash newTable = new SymbolHash(this.fTableSize);
newTable.fNum = this.fNum;
for (int i = 0; i < this.fTableSize; i++) {
if (this.fBuckets[i] != null)
newTable.fBuckets[i] = this.fBuckets[i].makeClone();
}
return newTable;
}
public void clear() {
for (int i = 0; i < this.fTableSize; i++)
this.fBuckets[i] = null;
this.fNum = 0;
}
protected Entry search(Object key, int bucket) {
for (Entry entry = this.fBuckets[bucket]; entry != null; entry = entry.next) {
if (key.equals(entry.key))
return entry;
}
return null;
}
protected static final class Entry {
public Object key;
public Object value;
public Entry next;
public Entry() {
this.key = null;
this.value = null;
this.next = null;
}
public Entry(Object key, Object value, Entry next) {
this.key = key;
this.value = value;
this.next = next;
}
public Entry makeClone() {
Entry entry = new Entry();
entry.key = this.key;
entry.value = this.value;
if (this.next != null)
entry.next = this.next.makeClone();
return entry;
}
}
}

View File

@@ -0,0 +1,139 @@
package org.apache.xerces.util;
public class SymbolTable {
protected static final int TABLE_SIZE = 101;
protected Entry[] fBuckets = null;
protected int fTableSize;
public SymbolTable() {
this(101);
}
public SymbolTable(int tableSize) {
this.fTableSize = tableSize;
this.fBuckets = new Entry[this.fTableSize];
}
public String addSymbol(String symbol) {
int bucket = hash(symbol) % this.fTableSize;
int length = symbol.length();
Entry entry;
for (entry = this.fBuckets[bucket]; entry != null; entry = entry.next) {
if (length == entry.characters.length) {
int i = 0;
while (true) {
if (i < length) {
if (symbol.charAt(i) != entry.characters[i])
break;
i++;
continue;
}
return entry.symbol;
}
}
}
entry = new Entry(symbol, this.fBuckets[bucket]);
this.fBuckets[bucket] = entry;
return entry.symbol;
}
public String addSymbol(char[] buffer, int offset, int length) {
int bucket = hash(buffer, offset, length) % this.fTableSize;
Entry entry;
for (entry = this.fBuckets[bucket]; entry != null; entry = entry.next) {
if (length == entry.characters.length) {
int i = 0;
while (true) {
if (i < length) {
if (buffer[offset + i] != entry.characters[i])
break;
i++;
continue;
}
return entry.symbol;
}
}
}
entry = new Entry(buffer, offset, length, this.fBuckets[bucket]);
this.fBuckets[bucket] = entry;
return entry.symbol;
}
public int hash(String symbol) {
int code = 0;
int length = symbol.length();
for (int i = 0; i < length; i++)
code = code * 37 + symbol.charAt(i);
return code & 0x7FFFFFF;
}
public int hash(char[] buffer, int offset, int length) {
int code = 0;
for (int i = 0; i < length; i++)
code = code * 37 + buffer[offset + i];
return code & 0x7FFFFFF;
}
public boolean containsSymbol(String symbol) {
int bucket = hash(symbol) % this.fTableSize;
int length = symbol.length();
for (Entry entry = this.fBuckets[bucket]; entry != null; entry = entry.next) {
if (length == entry.characters.length) {
int i = 0;
while (true) {
if (i < length) {
if (symbol.charAt(i) != entry.characters[i])
break;
i++;
continue;
}
return true;
}
}
}
return false;
}
public boolean containsSymbol(char[] buffer, int offset, int length) {
int bucket = hash(buffer, offset, length) % this.fTableSize;
for (Entry entry = this.fBuckets[bucket]; entry != null; entry = entry.next) {
if (length == entry.characters.length) {
int i = 0;
while (true) {
if (i < length) {
if (buffer[offset + i] != entry.characters[i])
break;
i++;
continue;
}
return true;
}
}
}
return false;
}
protected static final class Entry {
public String symbol;
public char[] characters;
public Entry next;
public Entry(String symbol, Entry next) {
this.symbol = symbol.intern();
this.characters = new char[symbol.length()];
symbol.getChars(0, this.characters.length, this.characters, 0);
this.next = next;
}
public Entry(char[] ch, int offset, int length, Entry next) {
this.characters = new char[length];
System.arraycopy(ch, offset, this.characters, 0, length);
this.symbol = (new String(this.characters)).intern();
this.next = next;
}
}
}