use of org.exist.dom.QName in project exist by eXist-db.
the class DocumentImpl method createAttributeNS.
/**
* The method <code>createAttributeNS</code>
*
* @param namespaceURI a <code>String</code> value
* @param qualifiedName a <code>String</code> value
* @return an <code>Attr</code> value
* @throws DOMException if an error occurs
*/
@Override
public Attr createAttributeNS(final String namespaceURI, final String qualifiedName) throws DOMException {
final QName qname;
try {
qname = QName.parse(namespaceURI, qualifiedName);
} catch (final IllegalQNameException e) {
final short errCode;
if (e.getValidity() == ILLEGAL_FORMAT.val || (e.getValidity() & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
errCode = DOMException.NAMESPACE_ERR;
} else {
errCode = DOMException.INVALID_CHARACTER_ERR;
}
throw new DOMException(errCode, "qualified name is invalid");
}
// check the QName is valid for use
final byte validity = qname.isValid(false);
if ((validity & QName.Validity.INVALID_LOCAL_PART.val) == QName.Validity.INVALID_LOCAL_PART.val) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "qualified name is invalid");
} else if ((validity & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
throw new DOMException(DOMException.NAMESPACE_ERR, "qualified name is invalid");
}
final AttrImpl attr = new AttrImpl(qname, getBrokerPool().getSymbols());
attr.setOwnerDocument(this);
return attr;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class DocumentImpl method createElement.
/**
* The method <code>createElement</code>
*
* @param tagName a <code>String</code> value
* @return an <code>Element</code> value
* @throws DOMException if an error occurs
*/
@Override
public Element createElement(final String tagName) throws DOMException {
final QName qname;
try {
qname = new QName(tagName);
} catch (final IllegalQNameException e) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "name is invalid");
}
// check the QName is valid for use
if (qname.isValid(false) != QName.Validity.VALID.val) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "name is invalid");
}
final ElementImpl element = new ElementImpl(qname, getBrokerPool().getSymbols());
element.setOwnerDocument(this);
return element;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class DocumentImpl method createElementNS.
/**
* The method <code>createElementNS</code>
*
* @param namespaceURI a <code>String</code> value
* @param qualifiedName a <code>String</code> value
* @return an <code>Element</code> value
* @throws DOMException if an error occurs
*/
@Override
public Element createElementNS(final String namespaceURI, final String qualifiedName) throws DOMException {
final QName qname;
try {
qname = QName.parse(namespaceURI, qualifiedName);
} catch (final IllegalQNameException e) {
final short errCode;
if (e.getValidity() == ILLEGAL_FORMAT.val || (e.getValidity() & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
errCode = DOMException.NAMESPACE_ERR;
} else {
errCode = DOMException.INVALID_CHARACTER_ERR;
}
throw new DOMException(errCode, "qualified name is invalid");
}
// check the QName is valid for use
final byte validity = qname.isValid(false);
if ((validity & QName.Validity.INVALID_LOCAL_PART.val) == QName.Validity.INVALID_LOCAL_PART.val) {
throw new DOMException(DOMException.INVALID_CHARACTER_ERR, "qualified name is invalid");
} else if ((validity & QName.Validity.INVALID_NAMESPACE.val) == QName.Validity.INVALID_NAMESPACE.val) {
throw new DOMException(DOMException.NAMESPACE_ERR, "qualified name is invalid");
}
final ElementImpl element = new ElementImpl(qname, getBrokerPool().getSymbols());
element.setOwnerDocument(this);
return element;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class SymbolTable method getQName.
/**
* Retrieve a shared QName instance from the temporary pool.
*
* TODO: make the namePool thread-local to avoid synchronization.
* @param type qname type
* @param namespaceURI qname namespace uri
* @param localName qname localname
* @param prefix qname prefix
* @return qname from pool
*/
public synchronized QName getQName(final short type, final String namespaceURI, final String localName, final String prefix) {
final byte itype = type == Node.ATTRIBUTE_NODE ? ElementValue.ATTRIBUTE : ElementValue.ELEMENT;
QName qn = namePool.get(itype, namespaceURI, localName, prefix);
if (qn == null) {
qn = namePool.add(itype, namespaceURI, localName, prefix);
}
return qn;
}
use of org.exist.dom.QName in project exist by eXist-db.
the class AdaptiveWriter method write.
/**
* Serialize the given sequence using adaptive output mode.
*
* @param sequence input sequence
* @param itemSep separator string to output between items in the sequence
* @param enclose if set to true: enclose sequences of items into parentheses
* @throws SAXException if an error occurs during serialization
* @throws XPathException if an XPath error occurs
* @throws TransformerException if an error occurs whilst transforming
*/
public void write(final Sequence sequence, final String itemSep, final boolean enclose) throws SAXException, XPathException, TransformerException {
try {
if (enclose && sequence.getItemCount() != 1) {
writer.write('(');
}
for (final SequenceIterator si = sequence.iterate(); si.hasNext(); ) {
final Item item = si.nextItem();
switch(item.getType()) {
case Type.DOCUMENT:
case Type.ELEMENT:
case Type.TEXT:
case Type.COMMENT:
case Type.CDATA_SECTION:
case Type.PROCESSING_INSTRUCTION:
writeXML(item);
break;
case Type.ATTRIBUTE:
final Attr node = (Attr) ((NodeValue) item).getNode();
writeText(node.getName() + "=\"" + node.getValue() + '"');
break;
case Type.NAMESPACE:
final NamespaceNode ns = (NamespaceNode) item;
writeText(ns.getName() + "=\"" + ns.getValue() + '"');
break;
case Type.STRING:
case Type.NORMALIZED_STRING:
case Type.TOKEN:
case Type.LANGUAGE:
case Type.NMTOKEN:
case Type.NAME:
case Type.NCNAME:
case Type.ID:
case Type.IDREF:
case Type.ENTITY:
case Type.UNTYPED_ATOMIC:
case Type.ANY_URI:
final String v = item.getStringValue();
writeText('"' + escapeQuotes(v) + '"');
break;
case Type.INTEGER:
case Type.DECIMAL:
case Type.INT:
case Type.LONG:
case Type.SHORT:
case Type.BYTE:
case Type.UNSIGNED_LONG:
case Type.UNSIGNED_INT:
case Type.UNSIGNED_SHORT:
case Type.UNSIGNED_BYTE:
case Type.NON_NEGATIVE_INTEGER:
case Type.NON_POSITIVE_INTEGER:
case Type.POSITIVE_INTEGER:
case Type.NEGATIVE_INTEGER:
writeText(item.getStringValue());
break;
case Type.DOUBLE:
writeDouble((DoubleValue) item);
break;
case Type.BOOLEAN:
writeText(item.getStringValue() + "()");
break;
case Type.QNAME:
case Type.NOTATION:
final QName qn = ((QNameValue) item).getQName();
writeText("Q{" + qn.getNamespaceURI() + '}' + qn.getLocalPart());
break;
case Type.ARRAY:
writeArray((ArrayType) item);
break;
case Type.MAP:
writeMap((AbstractMapType) item);
break;
case Type.FUNCTION_REFERENCE:
writeFunctionItem((FunctionReference) item);
break;
default:
writeAtomic(item.atomize());
break;
}
if (si.hasNext()) {
try {
writer.write(itemSep);
} catch (IOException e) {
throw new SAXException(e.getMessage());
}
}
}
if (enclose && sequence.getItemCount() != 1) {
writer.write(')');
}
} catch (IOException e) {
throw new SAXException(e.getMessage(), e);
}
}
Aggregations