use of org.apache.jackrabbit.spi.Name 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 {
Name name = NameFactoryImpl.getInstance().create(namespaceURI, localName);
// check element name
if (name.equals(NameConstants.SV_NODE)) {
// sv:node element
// node name (value of sv:name attribute)
String svName = getAttribute(atts, NameConstants.SV_NAME);
if (svName == 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(svName);
} 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 (name.equals(NameConstants.SV_PROPERTY)) {
// sv:property element
// reset temp fields
currentPropValues.clear();
// property name (value of sv:name attribute)
String svName = getAttribute(atts, NameConstants.SV_NAME);
if (svName == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:name attribute of element sv:property"));
}
try {
currentPropName = resolver.getQName(svName);
} 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 = getAttribute(atts, NameConstants.SV_TYPE);
if (type == null) {
throw new SAXException(new InvalidSerializedDataException("missing mandatory sv:type attribute of element sv:property"));
}
try {
currentPropType = PropertyType.valueFromName(type);
} catch (IllegalArgumentException e) {
throw new SAXException(new InvalidSerializedDataException("Unknown property type: " + type, e));
}
// 'multi-value' hint (sv:multiple attribute)
String multiple = getAttribute(atts, NameConstants.SV_MULTIPLE);
if (multiple != null) {
currentPropMultipleStatus = MultipleStatus.MULTIPLE;
} else {
currentPropMultipleStatus = MultipleStatus.UNKNOWN;
}
} else if (name.equals(NameConstants.SV_VALUE)) {
// sv:value element
currentPropValue = new BufferedStringValue(resolver, valueFactory);
String xsiType = atts.getValue("xsi:type");
currentPropValue.setBase64("xs:base64Binary".equals(xsiType));
} else {
throw new SAXException(new InvalidSerializedDataException("Unexpected element in system view xml document: " + name));
}
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class AccessControlImporter method checkIdMixins.
private static void checkIdMixins(NodeInfo nInfo) throws ConstraintViolationException {
// neither explicit id NOR mixin types may be present.
Name[] mixins = nInfo.getMixinNames();
NodeId id = nInfo.getId();
if (id != null || mixins != null) {
throw new ConstraintViolationException("The node represented by NodeInfo " + nInfo + " may neither be referenceable nor have mixin types.");
}
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class DocViewImportHandler method startElement.
//-------------------------------------------------------< ContentHandler >
/**
* {@inheritDoc}
* <p>
* See also {@link org.apache.jackrabbit.commons.xml.Exporter#exportProperties(Node)}
* regarding special handling of multi-valued properties on export.
*/
@Override
public void startElement(String namespaceURI, String localName, String qName, Attributes atts) throws SAXException {
// process buffered character data
processCharacters();
try {
Name nodeName = NameFactoryImpl.getInstance().create(namespaceURI, localName);
// process node name
nodeName = processName(nodeName);
// properties
NodeId id = null;
Name nodeTypeName = null;
Name[] mixinTypes = null;
List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getURI(i).equals(Name.NS_XMLNS_URI)) {
// see http://issues.apache.org/jira/browse/JCR-620#action_12448164
continue;
}
Name propName = NameFactoryImpl.getInstance().create(atts.getURI(i), atts.getLocalName(i));
// process property name
propName = processName(propName);
// value(s)
String attrValue = atts.getValue(i);
TextValue[] propValues;
// always assume single-valued property for the time being
// until a way of properly serializing/detecting multi-valued
// properties on re-import is found (see JCR-325);
// see also DocViewSAXEventGenerator#leavingProperties(Node, int)
// todo proper multi-value serialization support
propValues = new TextValue[1];
propValues[0] = new StringValue(attrValue, resolver, valueFactory);
if (propName.equals(NameConstants.JCR_PRIMARYTYPE)) {
// jcr:primaryType
if (attrValue.length() > 0) {
try {
nodeTypeName = resolver.getQName(attrValue);
} catch (NameException ne) {
throw new SAXException("illegal jcr:primaryType value: " + attrValue, ne);
}
}
} else if (propName.equals(NameConstants.JCR_MIXINTYPES)) {
// jcr:mixinTypes
mixinTypes = parseNames(attrValue);
} else if (propName.equals(NameConstants.JCR_UUID)) {
// jcr:uuid
if (attrValue.length() > 0) {
id = NodeId.valueOf(attrValue);
}
} else {
props.add(new PropInfo(propName, PropertyType.UNDEFINED, propValues));
}
}
NodeInfo node = new NodeInfo(nodeName, nodeTypeName, mixinTypes, id);
// all information has been collected, now delegate to importer
importer.startNode(node, props);
// push current node data onto stack
stack.push(node);
} catch (RepositoryException re) {
throw new SAXException(re);
}
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class DefinitionValidator method checkForCircularInheritance.
/**
*
* @param supertypes
* @param inheritanceChain
* @param ntdMap
* @throws InvalidNodeTypeDefinitionException
* @throws RepositoryException
*/
private void checkForCircularInheritance(Name[] supertypes, Stack<Name> inheritanceChain, Map<Name, QNodeTypeDefinition> ntdMap) throws InvalidNodeTypeDefinitionException, RepositoryException {
for (int i = 0; i < supertypes.length; i++) {
Name stName = supertypes[i];
int pos = inheritanceChain.lastIndexOf(stName);
if (pos >= 0) {
StringBuffer buf = new StringBuffer();
for (int j = 0; j < inheritanceChain.size(); j++) {
if (j == pos) {
buf.append("--> ");
}
buf.append(inheritanceChain.get(j));
buf.append(" extends ");
}
buf.append("--> ");
buf.append(stName);
throw new InvalidNodeTypeDefinitionException("circular inheritance detected: " + buf.toString());
}
if (ntdMap.containsKey(stName)) {
Name[] sta = ntdMap.get(stName).getSupertypes();
if (sta.length > 0) {
// check recursively
inheritanceChain.push(stName);
checkForCircularInheritance(sta, inheritanceChain, ntdMap);
inheritanceChain.pop();
}
} else {
throw new InvalidNodeTypeDefinitionException("Unknown supertype: " + stName);
}
}
}
use of org.apache.jackrabbit.spi.Name in project jackrabbit by apache.
the class NodeEntryImpl method buildPath.
/**
* Adds the path element of an item id to the path currently being built.
* On exit, <code>builder</code> contains the path of this entry.
*
* @param builder
* @param nEntry NodeEntryImpl of the state the path should be built for.
* @param wspPath true if the workspace path should be built
*/
private static void buildPath(PathBuilder builder, NodeEntryImpl nEntry, boolean wspPath) throws RepositoryException {
NodeEntryImpl parentEntry = (wspPath && nEntry.revertInfo != null) ? nEntry.revertInfo.oldParent : nEntry.parent;
// shortcut for root state
if (parentEntry == null) {
builder.addRoot();
return;
}
// recursively build path of parent
buildPath(builder, parentEntry, wspPath);
int index = nEntry.getIndex(wspPath);
Name name = nEntry.getName(wspPath);
builder.addLast(name, index);
}
Aggregations