use of org.apache.jackrabbit.oak.spi.xml.TextValue in project jackrabbit-oak by apache.
the class UserImporter method startChildInfo.
@Override
public void startChildInfo(@Nonnull NodeInfo childInfo, @Nonnull List<PropInfo> propInfos) throws RepositoryException {
checkState(currentMembership != null);
String ntName = childInfo.getPrimaryTypeName();
// noinspection deprecation
if (NT_REP_MEMBERS.equals(ntName)) {
for (PropInfo prop : propInfos) {
for (TextValue tv : prop.getTextValues()) {
currentMembership.addMember(tv.getString());
}
}
} else if (NT_REP_MEMBER_REFERENCES.equals(ntName)) {
for (PropInfo prop : propInfos) {
if (REP_MEMBERS.equals(prop.getName())) {
currentMembership.addMembers(prop.getTextValues());
}
}
} else {
// noinspection deprecation
log.warn("{} is not of type " + NT_REP_MEMBERS + " or " + NT_REP_MEMBER_REFERENCES, childInfo.getName());
}
}
use of org.apache.jackrabbit.oak.spi.xml.TextValue in project jackrabbit-oak by apache.
the class CugImporterTest method testInvalidPropInfo.
@Test
public void testInvalidPropInfo() throws Exception {
createCug(root, SUPPORTED_PATH, "principalName");
Tree parent = root.getTree(SUPPORTED_PATH);
PropInfo propInfo = new PropInfo(JcrConstants.JCR_PRIMARYTYPE, PropertyType.STRING, ImmutableList.of(new TextValue() {
@Override
public String getString() {
return "principalName";
}
@Override
public Value getValue(int targetType) throws RepositoryException {
return getValueFactory(root).createValue("principalName", PropertyType.STRING);
}
@Override
public void dispose() {
}
}));
PropertyDefinition propDef = Mockito.mock(PropertyDefinition.class);
assertFalse(importer.handlePropInfo(parent, propInfo, propDef));
}
use of org.apache.jackrabbit.oak.spi.xml.TextValue in project jackrabbit-oak by apache.
the class CugImporter method handlePropInfo.
// ------------------------------------------< ProtectedPropertyImporter >---
@Override
public boolean handlePropInfo(@Nonnull Tree parent, @Nonnull PropInfo protectedPropInfo, @Nonnull PropertyDefinition def) throws RepositoryException {
if (CugUtil.definesCug(parent) && isValid(protectedPropInfo, def) && CugUtil.isSupportedPath(parent.getPath(), supportedPaths)) {
Set<String> principalNames = new HashSet<>();
for (TextValue txtValue : protectedPropInfo.getTextValues()) {
String principalName = txtValue.getString();
Principal principal = principalManager.getPrincipal(principalName);
if (principal == null) {
switch(importBehavior) {
case ImportBehavior.IGNORE:
log.debug("Ignoring unknown principal with name '" + principalName + "'.");
break;
case ImportBehavior.ABORT:
throw new AccessControlException("Unknown principal '" + principalName + "'.");
case ImportBehavior.BESTEFFORT:
log.debug("Importing unknown principal '" + principalName + '\'');
principalNames.add(principalName);
break;
default:
throw new IllegalArgumentException("Invalid import behavior " + importBehavior);
}
} else {
principalNames.add(principalName);
}
}
parent.setProperty(REP_PRINCIPAL_NAMES, principalNames, Type.STRINGS);
return true;
} else {
return false;
}
}
use of org.apache.jackrabbit.oak.spi.xml.TextValue in project jackrabbit-oak 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 {
NameInfo nameInfo = new NameInfo(qName);
nameInfo = processName(nameInfo);
// properties
String id = null;
String nodeTypeName = null;
Iterable<String> mixinTypes = null;
List<PropInfo> props = new ArrayList<PropInfo>(atts.getLength());
for (int i = 0; i < atts.getLength(); i++) {
if (atts.getURI(i).equals(NamespaceConstants.NAMESPACE_XMLNS)) {
// see http://issues.apache.org/jira/browse/JCR-620#action_12448164
continue;
}
NameInfo propNameInfo = processName(new NameInfo(atts.getQName(i)));
String attrValue = atts.getValue(i);
if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "primaryType".equals(propNameInfo.getLocalName())) {
// jcr:primaryType
if (!attrValue.isEmpty()) {
// TODO
nodeTypeName = attrValue;
}
} else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "mixinTypes".equals(propNameInfo.getLocalName())) {
// jcr:mixinTypes
mixinTypes = parseNames(attrValue);
} else if (NamespaceRegistry.NAMESPACE_JCR.equals(propNameInfo.getNamespaceUri()) && "uuid".equals(propNameInfo.getLocalName())) {
// jcr:uuid
if (!attrValue.isEmpty()) {
id = attrValue;
}
} else {
// 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
TextValue tv = new StringValue(attrValue, sessionContext.getValueFactory(), currentNamePathMapper());
props.add(new PropInfo(propNameInfo.getRepoQualifiedName(), PropertyType.UNDEFINED, tv));
}
}
NodeInfo node = new NodeInfo(nameInfo.getRepoQualifiedName(), 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);
}
}
Aggregations