use of javax.jcr.InvalidSerializedDataException 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.InvalidSerializedDataException 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.InvalidSerializedDataException in project jackrabbit-oak by apache.
the class SessionImpl method importXML.
@Override
public void importXML(String parentAbsPath, InputStream in, int uuidBehavior) throws IOException, RepositoryException {
try {
ContentHandler handler = getImportContentHandler(checkNotNull(parentAbsPath), uuidBehavior);
new ParsingContentHandler(handler).parse(in);
} catch (SAXException e) {
Throwable exception = e.getException();
if (exception instanceof RepositoryException) {
throw (RepositoryException) exception;
} else if (exception instanceof IOException) {
throw (IOException) exception;
} else {
throw new InvalidSerializedDataException("XML parse error", e);
}
} finally {
// JCR-2903
if (in != null) {
try {
in.close();
} catch (IOException ignore) {
}
}
}
}
use of javax.jcr.InvalidSerializedDataException in project jackrabbit by apache.
the class SerializationTest method doTestNodeTypeConstraintViolation.
// ------------------< Node type constraint violation tests >--------------------------------
/**
* Create a node named ntBase with node type nt:base
* and creates a tree in the repository which will be exported
* and reimported below the node ntBase.
*
* @param useWorkspace
* @param useHandler
* @throws RepositoryException
* @throws FileNotFoundException
* @throws IOException
*/
public void doTestNodeTypeConstraintViolation(boolean useWorkspace, boolean useHandler) throws Exception {
treeComparator.createExampleTree();
String nodetype = testNodeTypeNoChildren == null ? ntBase : testNodeTypeNoChildren;
Node node = testRootNode.addNode("ntBase", nodetype);
session.save();
FileInputStream in = new FileInputStream(file);
try {
if (useHandler) {
try {
doImport(node.getPath(), in, useWorkspace, useHandler);
fail("Node type constraint violation should throw a SAXException " + "during xml import using a Contenthandler.");
} catch (SAXException se) {
// ok
}
} else {
try {
doImport(node.getPath(), in, useWorkspace, useHandler);
fail("Node type constraint violation should throw a " + " InvalidSerializedDataException during xml import " + "using a Contenthandler.");
} catch (InvalidSerializedDataException isde) {
// ok
}
}
} finally {
try {
in.close();
} catch (IOException ignore) {
}
}
}
Aggregations