use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.
the class ServiceStubImpl method getRepositoryService.
@Override
public RepositoryService getRepositoryService() throws RepositoryException {
if (service == null) {
String uri = getProperty(PROP_REPOSITORY_URI);
IdFactory idFactory = IdFactoryImpl.getInstance();
NameFactory nFactory = NameFactoryImpl.getInstance();
PathFactory pFactory = PathFactoryImpl.getInstance();
QValueFactory vFactory = QValueFactoryImpl.getInstance();
service = new RepositoryServiceImpl(uri, idFactory, nFactory, pFactory, vFactory);
}
return service;
}
use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.
the class CustomPrivilegeTest method testCustomDefinitionsWithCyclicReferences.
public void testCustomDefinitionsWithCyclicReferences() throws RepositoryException, FileSystemException, IOException {
// setup the custom privilege file with cyclic references
FileSystem fs = ((RepositoryImpl) superuser.getRepository()).getConfig().getFileSystem();
FileSystemResource resource = new FileSystemResource(fs, "/privileges/custom_privileges.xml");
if (!resource.exists()) {
resource.makeParentDirs();
}
NameFactory nf = NameFactoryImpl.getInstance();
Name test = nf.create(Name.NS_DEFAULT_URI, "test");
Name test2 = nf.create(Name.NS_DEFAULT_URI, "test2");
Name test3 = nf.create(Name.NS_DEFAULT_URI, "test3");
Name test4 = nf.create(Name.NS_DEFAULT_URI, "test4");
Name test5 = nf.create(Name.NS_DEFAULT_URI, "test5");
OutputStream out = resource.getOutputStream();
try {
List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
defs.add(new PrivilegeDefinitionImpl(test, false, Collections.singleton(test2)));
defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.singleton(test5)));
defs.add(new PrivilegeDefinitionImpl(test5, false, Collections.singleton(test3)));
defs.add(new PrivilegeDefinitionImpl(test3, false, Collections.singleton(test)));
defs.add(new PrivilegeDefinitionImpl(test2, false, Collections.singleton(test4)));
PrivilegeDefinitionWriter pdw = new PrivilegeDefinitionWriter("text/xml");
pdw.writeDefinitions(out, defs.toArray(new PrivilegeDefinition[defs.size()]), Collections.<String, String>emptyMap());
new PrivilegeRegistry(superuser.getWorkspace().getNamespaceRegistry(), fs);
fail("Cyclic definitions must be detected upon registry startup.");
} catch (RepositoryException e) {
// success
} finally {
out.close();
fs.deleteFolder("/privileges");
}
}
use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.
the class PathFactoryImpl method createElementFromString.
/**
* Create an element from the element string
*/
private Path.Element createElementFromString(String elementString) {
if (elementString == null) {
throw new IllegalArgumentException("null PathElement literal");
}
if (elementString.equals(RootPath.NAME.toString())) {
return RootPath.ROOT_PATH;
} else if (elementString.equals(CurrentPath.CURRENT_PATH.getString())) {
return CurrentPath.CURRENT_PATH;
} else if (elementString.equals(ParentPath.PARENT_PATH.getString())) {
return ParentPath.PARENT_PATH;
} else if (elementString.startsWith("[") && elementString.endsWith("]") && elementString.length() > 2) {
return new IdentifierPath(elementString.substring(1, elementString.length() - 1));
}
NameFactory factory = NameFactoryImpl.getInstance();
int pos = elementString.indexOf('[');
if (pos == -1) {
Name name = factory.create(elementString);
return new NamePath(null, name, Path.INDEX_UNDEFINED);
}
Name name = factory.create(elementString.substring(0, pos));
int pos1 = elementString.indexOf(']');
if (pos1 == -1) {
throw new IllegalArgumentException("invalid PathElement literal: " + elementString + " (missing ']')");
}
try {
int index = Integer.valueOf(elementString.substring(pos + 1, pos1));
if (index < 1) {
throw new IllegalArgumentException("invalid PathElement literal: " + elementString + " (index is 1-based)");
}
return new NamePath(null, name, index);
} catch (NumberFormatException e) {
throw new IllegalArgumentException("invalid PathElement literal: " + elementString + " (" + e.getMessage() + ")");
}
}
Aggregations