use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class SysViewImportHandler method endElement.
/**
* {@inheritDoc}
*/
@Override
public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
// check element name
ImportState state = stack.peek();
if (NODE.equals(localName)) {
// sv:node element
if (!state.started) {
// need to start & end current node
processNode(state, true, true);
state.started = true;
} else {
// need to end current node
processNode(state, false, true);
}
// pop current state from stack
stack.pop();
} else if (PROPERTY.equals(localName)) {
// have been collected and create node as necessary
if (currentPropName.equals(NameConstants.JCR_PRIMARYTYPE)) {
AppendableValue val = (AppendableValue) currentPropValues.get(0);
String s = null;
try {
s = val.retrieve();
state.nodeTypeName = resolver.getQName(s);
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node type name: " + s, e));
}
} else if (currentPropName.equals(NameConstants.JCR_MIXINTYPES)) {
if (state.mixinNames == null) {
state.mixinNames = new ArrayList<Name>(currentPropValues.size());
}
for (int i = 0; i < currentPropValues.size(); i++) {
AppendableValue val = (AppendableValue) currentPropValues.get(i);
String s = null;
try {
s = val.retrieve();
Name mixin = resolver.getQName(s);
state.mixinNames.add(mixin);
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal mixin type name: " + s, e));
}
}
} else if (currentPropName.equals(NameConstants.JCR_UUID)) {
AppendableValue val = (AppendableValue) currentPropValues.get(0);
try {
state.uuid = val.retrieve();
} catch (IOException ioe) {
throw new SAXException("error while retrieving value", ioe);
}
} else {
Importer.TextValue[] values = currentPropValues.toArray(new Importer.TextValue[currentPropValues.size()]);
Importer.PropInfo prop = new Importer.PropInfo(currentPropName, currentPropType, values);
state.props.add(prop);
}
// reset temp fields
currentPropValues.clear();
} else if (VALUE.equals(localName)) {
// sv:value element
currentPropValues.add(currentPropValue);
// reset temp fields
currentPropValue = null;
} else {
throw new SAXException(new InvalidSerializedDataException("invalid element in system view xml document: " + localName));
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class LogUtil method saveGetIdString.
/**
* Failsafe conversion of an <code>ItemId</code> to a human readable string
* resolving the path part of the specified id using the given path resolver.
*
* @param itemId
* @param pathResolver
* @return a String representation of the given <code>ItemId</code>.
*/
public static String saveGetIdString(ItemId itemId, PathResolver pathResolver) {
Path p = itemId.getPath();
if (p == null || pathResolver == null) {
return itemId.toString();
} else {
StringBuffer bf = new StringBuffer();
String uniqueID = itemId.getUniqueID();
if (uniqueID != null) {
bf.append(uniqueID).append(" - ");
}
String jcrPath;
try {
jcrPath = pathResolver.getJCRPath(p);
} catch (NamespaceException e) {
jcrPath = p.toString();
}
bf.append(jcrPath);
return bf.toString();
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class SysViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
// check namespace
if (!Name.NS_SV_URI.equals(namespaceURI)) {
throw new SAXException(new InvalidSerializedDataException("invalid namespace for element in system view xml document: " + namespaceURI));
}
// check element name
if (NODE.equals(localName)) {
// sv:node element
// node name (value of sv:name attribute)
String name = atts.getValue(Name.NS_SV_URI, NAME);
if (name == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:node"));
}
if (!stack.isEmpty()) {
// process current node first
ImportState current = stack.peek();
// need to start current node
if (!current.started) {
processNode(current, true, false);
current.started = true;
}
}
// push new ImportState instance onto the stack
ImportState state = new ImportState();
try {
state.nodeName = resolver.getQName(name);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal node name: " + name, e));
}
stack.push(state);
} else if (PROPERTY.equals(localName)) {
// sv:property element
// reset temp fields
currentPropValues.clear();
// property name (value of sv:name attribute)
String name = atts.getValue(Name.NS_SV_URI, NAME);
if (name == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:property"));
}
try {
currentPropName = resolver.getQName(name);
} catch (NameException e) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
} catch (NamespaceException e) {
throw new SAXException(new InvalidSerializedDataException("illegal property name: " + name, e));
}
// property type (sv:type attribute)
String type = atts.getValue(Name.NS_SV_URI, TYPE);
if (type == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:type attribute of element sv:property"));
}
currentPropType = PropertyType.valueFromName(type);
} else if (VALUE.equals(localName)) {
// sv:value element
// reset temp fields
currentPropValue = new BufferedStringValue();
} else {
throw new SAXException(new InvalidSerializedDataException("unexpected element found in system view xml document: " + localName));
}
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class DocViewImportHandler method parseNames.
/**
* Parses the given string as a list of JCR names. Any whitespace sequence
* is supported as a names separator instead of just a single space to
* be more liberal in what we accept. The current namespace context is
* used to convert the prefixed name strings to Names.
*
* @param value string value
* @return the parsed names
* @throws SAXException if an invalid name was encountered
*/
private Name[] parseNames(String value) throws SAXException {
String[] names = value.split("\\p{Space}+");
Name[] qnames = new Name[names.length];
for (int i = 0; i < names.length; i++) {
try {
qnames[i] = resolver.getQName(names[i]);
} catch (NameException ne) {
throw new SAXException("Invalid name: " + names[i], ne);
} catch (NamespaceException e) {
throw new SAXException("Invalid name: " + names[i], e);
}
}
return qnames;
}
use of javax.jcr.NamespaceException in project jackrabbit by apache.
the class ValueFactoryQImpl method createValue.
/**
* {@inheritDoc}
*/
public Value createValue(String value, int type) throws ValueFormatException {
try {
QValue qvalue;
if (type == PropertyType.NAME) {
Name name = resolver.getQName(value);
qvalue = qfactory.create(name);
} else if (type == PropertyType.PATH) {
Path path = resolver.getQPath(value, false);
qvalue = qfactory.create(path);
} else {
qvalue = qfactory.create(value, type);
}
return new QValueValue(qvalue, resolver);
} catch (IllegalNameException ex) {
throw new ValueFormatException(ex);
} catch (MalformedPathException ex) {
throw new ValueFormatException(ex);
} catch (NamespaceException ex) {
throw new ValueFormatException(ex);
} catch (ValueFormatException ex) {
throw ex;
} catch (RepositoryException ex) {
throw new ValueFormatException(ex);
}
}
Aggregations