Search in sources :

Example 6 with NameFactory

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;
}
Also used : IdFactory(org.apache.jackrabbit.spi.IdFactory) PathFactory(org.apache.jackrabbit.spi.PathFactory) QValueFactory(org.apache.jackrabbit.spi.QValueFactory) NameFactory(org.apache.jackrabbit.spi.NameFactory)

Example 7 with NameFactory

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");
    }
}
Also used : PrivilegeDefinitionImpl(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl) FileSystem(org.apache.jackrabbit.core.fs.FileSystem) OutputStream(java.io.OutputStream) ArrayList(java.util.ArrayList) PrivilegeDefinition(org.apache.jackrabbit.spi.PrivilegeDefinition) RepositoryException(javax.jcr.RepositoryException) FileSystemResource(org.apache.jackrabbit.core.fs.FileSystemResource) PrivilegeDefinitionWriter(org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter) NameFactory(org.apache.jackrabbit.spi.NameFactory) Name(org.apache.jackrabbit.spi.Name)

Example 8 with NameFactory

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() + ")");
    }
}
Also used : NameFactory(org.apache.jackrabbit.spi.NameFactory) Name(org.apache.jackrabbit.spi.Name)

Aggregations

NameFactory (org.apache.jackrabbit.spi.NameFactory)8 Name (org.apache.jackrabbit.spi.Name)5 RepositoryException (javax.jcr.RepositoryException)4 IdFactory (org.apache.jackrabbit.spi.IdFactory)3 PathFactory (org.apache.jackrabbit.spi.PathFactory)3 QValueFactory (org.apache.jackrabbit.spi.QValueFactory)3 OutputStream (java.io.OutputStream)2 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 FileSystem (org.apache.jackrabbit.core.fs.FileSystem)2 FileSystemResource (org.apache.jackrabbit.core.fs.FileSystemResource)2 PrivilegeDefinition (org.apache.jackrabbit.spi.PrivilegeDefinition)2 PrivilegeDefinitionImpl (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionImpl)2 PrivilegeDefinitionWriter (org.apache.jackrabbit.spi.commons.privilege.PrivilegeDefinitionWriter)2 Calendar (java.util.Calendar)1 ItemNotFoundException (javax.jcr.ItemNotFoundException)1 ItemStateException (org.apache.jackrabbit.core.state.ItemStateException)1 NodeState (org.apache.jackrabbit.core.state.NodeState)1 QNodeDefinition (org.apache.jackrabbit.spi.QNodeDefinition)1 QPropertyDefinition (org.apache.jackrabbit.spi.QPropertyDefinition)1