use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.
the class NamespaceContextPreservationFilterHandler method attributesCompleted.
@Override
public void attributesCompleted() throws StreamException {
if (!done) {
try {
CoreElement current = contextElement;
while (true) {
CoreAttribute attr = current.coreGetFirstAttribute();
while (attr != null) {
if (attr instanceof CoreNamespaceDeclaration) {
CoreNamespaceDeclaration decl = (CoreNamespaceDeclaration) attr;
String prefix = decl.coreGetDeclaredPrefix();
if (prefixesAlreadyBound.add(prefix)) {
super.processNamespaceDeclaration(prefix, decl.coreGetCharacterData().toString());
}
}
attr = attr.coreGetNextAttribute();
}
CoreParentNode parent = current.coreGetParent();
if (!(parent instanceof CoreElement)) {
break;
}
current = (CoreElement) parent;
}
prefixesAlreadyBound = null;
done = true;
} catch (CoreModelException ex) {
throw new StreamException(ex);
}
}
super.attributesCompleted();
}
use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.
the class XMLStreamWriterNamespaceContextProvider method isBound.
/**
* @param prefix
* @param namespace
* @return true if the prefix is associated with the namespace in the current context
*/
public boolean isBound(String prefix, String namespace) throws StreamException {
try {
// of this issue.
if ("xml".equals(prefix)) {
return true;
}
// NOTE: Calling getNamespaceContext() on many XMLStreamWriter implementations is expensive.
// Please use other writer methods first.
// For consistency, convert null arguments.
// This helps get around the parser implementation differences.
// In addition, the getPrefix/getNamespace methods cannot be called with null parameters.
prefix = (prefix == null) ? "" : prefix;
namespace = (namespace == null) ? "" : namespace;
if (namespace.length() > 0) {
// QUALIFIED NAMESPACE
// Get the namespace associated with the prefix
String writerPrefix = writer.getPrefix(namespace);
if (prefix.equals(writerPrefix)) {
return true;
}
// So try getting the namespace as a second step.
if (writerPrefix != null) {
NamespaceContext nsContext = writer.getNamespaceContext();
if (nsContext != null) {
String writerNS = nsContext.getNamespaceURI(prefix);
return namespace.equals(writerNS);
}
}
return false;
} else {
// Neither XML 1.0 nor XML 1.1 allow to associate a prefix with an unqualified name (see also AXIOM-372).
if (prefix.length() > 0) {
throw new StreamException("Invalid namespace declaration: Prefixed namespace bindings may not be empty.");
}
// protected
try {
String writerPrefix = writer.getPrefix("");
if (writerPrefix != null && writerPrefix.length() == 0) {
return true;
}
} catch (Throwable t) {
if (log.isDebugEnabled()) {
log.debug("Caught exception from getPrefix(\"\"). Processing continues: " + t);
}
}
// Fallback to using the namespace context
NamespaceContext nsContext = writer.getNamespaceContext();
if (nsContext != null) {
String writerNS = nsContext.getNamespaceURI("");
if (writerNS != null && writerNS.length() > 0) {
return false;
}
}
return true;
}
} catch (XMLStreamException ex) {
throw new StreamException(ex);
}
}
use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.
the class ContentHandlerXmlHandler method processNamespaceDeclaration.
public void processNamespaceDeclaration(String prefix, String namespaceURI) throws StreamException {
if (bindings == prefixStack.length) {
String[] newPrefixStack = new String[prefixStack.length * 2];
System.arraycopy(prefixStack, 0, newPrefixStack, 0, prefixStack.length);
prefixStack = newPrefixStack;
}
prefixStack[bindings++] = prefix;
try {
contentHandler.startPrefixMapping(prefix, namespaceURI);
} catch (SAXException ex) {
throw new StreamException(ex);
}
// TODO: depending on the http://xml.org/sax/features/xmlns-uris feature, we also need to add an attribute
}
use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.
the class ContentHandlerXmlHandler method processCharacterData.
public void processCharacterData(Object data, boolean ignorable) throws StreamException {
try {
switch(characterDataMode) {
case PASS_THROUGH:
if (ignorable) {
writeToBuffer(data.toString());
contentHandler.ignorableWhitespace(buffer, 0, bufferPos);
bufferPos = 0;
} else if (data instanceof CharacterData) {
try {
((CharacterData) data).writeTo(this);
} catch (IOException ex) {
Throwable cause = ex.getCause();
SAXException saxException;
if (cause instanceof SAXException) {
saxException = (SAXException) cause;
} else {
saxException = new SAXException(ex);
}
throw new StreamException(saxException);
}
} else {
writeToBuffer(data.toString());
contentHandler.characters(buffer, 0, bufferPos);
bufferPos = 0;
}
break;
case BUFFER:
writeToBuffer(data.toString());
break;
case ACCUMULATE:
accumulator.append(data);
break;
case SKIP:
}
} catch (SAXException ex) {
throw new StreamException(ex);
}
}
use of org.apache.axiom.core.stream.StreamException in project webservices-axiom by apache.
the class ContentHandlerXmlHandler method attributesCompleted.
public void attributesCompleted() throws StreamException {
try {
contentHandler.startElement(elementURI, elementLocalName, elementQName, attributes);
elementNameStack.push(elementURI);
elementNameStack.push(elementLocalName);
elementNameStack.push(elementQName);
elementURI = null;
elementLocalName = null;
elementQName = null;
attributes.clear();
} catch (SAXException ex) {
throw new StreamException(ex);
}
}
Aggregations