Search in sources :

Example 1 with NameFactory

use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.

the class Spi2davRepositoryServiceFactory method createRepositoryService.

public RepositoryService createRepositoryService(Map<?, ?> parameters) throws RepositoryException {
    if (parameters == null) {
        throw new RepositoryException("Parameter " + PARAM_REPOSITORY_URI + " missing");
    }
    String uri;
    if (parameters.get(PARAM_REPOSITORY_URI) == null) {
        throw new RepositoryException("Parameter " + PARAM_REPOSITORY_URI + " missing");
    } else {
        uri = parameters.get(PARAM_REPOSITORY_URI).toString();
    }
    IdFactory idFactory;
    Object param = parameters.get(PARAM_ID_FACTORY);
    if (param != null && param instanceof IdFactory) {
        idFactory = (IdFactory) param;
    } else {
        idFactory = IdFactoryImpl.getInstance();
    }
    NameFactory nameFactory;
    param = parameters.get(PARAM_NAME_FACTORY);
    if (param != null && param instanceof NameFactory) {
        nameFactory = (NameFactory) param;
    } else {
        nameFactory = NameFactoryImpl.getInstance();
    }
    PathFactory pathFactory;
    param = parameters.get(PARAM_PATH_FACTORY);
    if (param != null && param instanceof PathFactory) {
        pathFactory = (PathFactory) param;
    } else {
        pathFactory = PathFactoryImpl.getInstance();
    }
    QValueFactory vFactory;
    param = parameters.get(PARAM_QVALUE_FACTORY);
    if (param != null && param instanceof QValueFactory) {
        vFactory = (QValueFactory) param;
    } else {
        vFactory = QValueFactoryImpl.getInstance();
    }
    int itemInfoCacheSize = ItemInfoCacheImpl.DEFAULT_CACHE_SIZE;
    param = parameters.get(PARAM_ITEMINFO_CACHE_SIZE);
    if (param != null) {
        try {
            itemInfoCacheSize = Integer.parseInt(param.toString());
        } catch (NumberFormatException e) {
        // ignore, use default
        }
    }
    // max connections config
    int maximumHttpConnections = 0;
    param = parameters.get(PARAM_MAX_CONNECTIONS);
    if (param != null) {
        try {
            maximumHttpConnections = Integer.parseInt(param.toString());
        } catch (NumberFormatException e) {
        // using default
        }
    }
    if (maximumHttpConnections > 0) {
        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory, itemInfoCacheSize, maximumHttpConnections);
    } else {
        return new RepositoryServiceImpl(uri, idFactory, nameFactory, pathFactory, vFactory, itemInfoCacheSize);
    }
}
Also used : IdFactory(org.apache.jackrabbit.spi.IdFactory) PathFactory(org.apache.jackrabbit.spi.PathFactory) RepositoryException(javax.jcr.RepositoryException) QValueFactory(org.apache.jackrabbit.spi.QValueFactory) NameFactory(org.apache.jackrabbit.spi.NameFactory)

Example 2 with NameFactory

use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.

the class CustomPrivilegeTest method testCustomEquivalentDefinitions.

public void testCustomEquivalentDefinitions() 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");
    Name test6 = nf.create(Name.NS_DEFAULT_URI, "test6");
    OutputStream out = resource.getOutputStream();
    try {
        List<PrivilegeDefinition> defs = new ArrayList<PrivilegeDefinition>();
        defs.add(new PrivilegeDefinitionImpl(test, false, createNameSet(test2, test3)));
        defs.add(new PrivilegeDefinitionImpl(test2, true, Collections.singleton(test4)));
        defs.add(new PrivilegeDefinitionImpl(test3, true, Collections.singleton(test5)));
        defs.add(new PrivilegeDefinitionImpl(test4, true, Collections.<Name>emptySet()));
        defs.add(new PrivilegeDefinitionImpl(test5, true, Collections.<Name>emptySet()));
        // the equivalent definition to 'test'
        defs.add(new PrivilegeDefinitionImpl(test6, false, createNameSet(test2, test5)));
        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("Equivalent 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 3 with NameFactory

use of org.apache.jackrabbit.spi.NameFactory in project jackrabbit by apache.

the class RepositoryChecker method removeVersionHistoryReferences.

// un-versions the node, and potentially moves the version history away
private void removeVersionHistoryReferences(NodeState node, NodeId vhid) {
    dirtyNodes += 1;
    brokenNodes += 1;
    NodeState modified = new NodeState(node, NodeState.STATUS_EXISTING_MODIFIED, true);
    Set<Name> mixins = new HashSet<Name>(node.getMixinTypeNames());
    if (mixins.remove(MIX_VERSIONABLE)) {
        // we are keeping jcr:uuid, so we need to make sure the type info stays valid
        mixins.add(MIX_REFERENCEABLE);
        modified.setMixinTypeNames(mixins);
    }
    removeProperty(modified, JCR_VERSIONHISTORY);
    removeProperty(modified, JCR_BASEVERSION);
    removeProperty(modified, JCR_PREDECESSORS);
    removeProperty(modified, JCR_ISCHECKEDOUT);
    workspaceChanges.modified(modified);
    if (vhid != null) {
        // attempt to rename the version history, so it doesn't interfere with
        // a future attempt to put the node under version control again 
        // (see JCR-3115)
        log.info("trying to rename version history of node " + node.getId());
        NameFactory nf = NameFactoryImpl.getInstance();
        // Name of VHR in parent folder is ID of versionable node
        Name vhrname = nf.create(Name.NS_DEFAULT_URI, node.getId().toString());
        try {
            NodeState vhrState = versionManager.getPersistenceManager().load(vhid);
            NodeState vhrParentState = versionManager.getPersistenceManager().load(vhrState.getParentId());
            if (vhrParentState.hasChildNodeEntry(vhrname)) {
                NodeState modifiedParent = (NodeState) vworkspaceChanges.get(vhrState.getParentId());
                if (modifiedParent == null) {
                    modifiedParent = new NodeState(vhrParentState, NodeState.STATUS_EXISTING_MODIFIED, true);
                }
                Calendar now = Calendar.getInstance(TimeZone.getTimeZone("UTC"));
                String appendme = String.format(" (disconnected by RepositoryChecker on %04d%02d%02dT%02d%02d%02dZ)", now.get(Calendar.YEAR), now.get(Calendar.MONTH) + 1, now.get(Calendar.DAY_OF_MONTH), now.get(Calendar.HOUR_OF_DAY), now.get(Calendar.MINUTE), now.get(Calendar.SECOND));
                modifiedParent.renameChildNodeEntry(vhid, nf.create(vhrname.getNamespaceURI(), vhrname.getLocalName() + appendme));
                vworkspaceChanges.modified(modifiedParent);
            } else {
                log.info("child node entry " + vhrname + " for version history not found inside parent folder.");
            }
        } catch (Exception ex) {
            log.error("while trying to rename the version history", ex);
        }
    }
}
Also used : NodeState(org.apache.jackrabbit.core.state.NodeState) Calendar(java.util.Calendar) RepositoryException(javax.jcr.RepositoryException) ItemStateException(org.apache.jackrabbit.core.state.ItemStateException) ItemNotFoundException(javax.jcr.ItemNotFoundException) HashSet(java.util.HashSet) Name(org.apache.jackrabbit.spi.Name) NameFactory(org.apache.jackrabbit.spi.NameFactory)

Example 4 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 5 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