Package org.apache.jackrabbit.core.fs

Examples of org.apache.jackrabbit.core.fs.FileSystemResource


     * Stores the properties to a persistent resource in the meta filesytem.
     *
     * @throws RepositoryException
     */
    protected void storeRepProps(Properties props) throws RepositoryException {
        FileSystemResource propFile = new FileSystemResource(metaDataStore, PROPERTIES_RESOURCE);
        try {
            propFile.makeParentDirs();
            OutputStream os = propFile.getOutputStream();
            try {
                props.store(os, null);
            } finally {
                // make sure stream is closed
                os.close();
View Full Code Here


     * @param fs
     * @return
     * @throws RepositoryException
     */
    protected NodeId loadRootNodeId(FileSystem fs) throws RepositoryException {
        FileSystemResource uuidFile = new FileSystemResource(fs, "rootUUID");
        try {
            if (uuidFile.exists()) {
                try {
                    // load uuid of the repository's root node
                    InputStream in = uuidFile.getInputStream();
/*
                   // uuid is stored in binary format (16 bytes)
                   byte[] bytes = new byte[16];
                   try {
                       in.read(bytes);
                   } finally {
                       try {
                           in.close();
                       } catch (IOException ioe) {
                           // ignore
                       }
                   }
                   rootNodeUUID = new UUID(bytes).toString();            // uuid is stored in binary format (16 bytes)
*/
                    // uuid is stored in text format (36 characters) for better readability

                    char[] chars;
                    try {
                        chars = IOUtils.toCharArray(in);
                    } finally {
                        IOUtils.closeQuietly(in);
                    }
                    return NodeId.valueOf(new String(chars));
                } catch (Exception e) {
                    String msg = "failed to load persisted repository state";
                    log.debug(msg);
                    throw new RepositoryException(msg, e);
                }
            } else {
                // create new uuid
/*
                UUID rootUUID = UUID.randomUUID();     // version 4 uuid
                rootNodeUUID = rootUUID.toString();
*/
                /**
                 * use hard-coded uuid for root node rather than generating
                 * a different uuid per repository instance; using a
                 * hard-coded uuid makes it easier to copy/move entire
                 * workspaces from one repository instance to another.
                 */
                try {
                    // persist uuid of the repository's root node
                    OutputStream out = uuidFile.getOutputStream();
/*
                    // store uuid in binary format
                    try {
                        out.write(rootUUID.getBytes());
                    } finally {
View Full Code Here

    public LockManagerImpl(
            SessionImpl session, FileSystem fs,
            ScheduledExecutorService executor) throws RepositoryException {

        this.sysSession = session;
        this.locksFile = new FileSystemResource(fs, FileSystem.SEPARATOR + LOCKS_FILE);

        session.getWorkspace().getObservationManager().
                addEventListener(this, Event.NODE_ADDED | Event.NODE_REMOVED,
                        "/", true, null, null, true);
View Full Code Here

     * @throws IOException         if another exception occurs.
     */
    protected FileSystemResource createSynonymProviderConfigResource()
            throws FileSystemException, IOException {
        if (synonymProviderConfigPath != null) {
            FileSystemResource fsr;
            // simple sanity check
            if (synonymProviderConfigPath.endsWith(FileSystem.SEPARATOR)) {
                throw new FileSystemException(
                        "Invalid synonymProviderConfigPath: "
                        + synonymProviderConfigPath);
            }
            if (fs == null) {
                fs = new LocalFileSystem();
                int lastSeparator = synonymProviderConfigPath.lastIndexOf(
                        FileSystem.SEPARATOR_CHAR);
                if (lastSeparator != -1) {
                    File root = new File(path,
                            synonymProviderConfigPath.substring(0, lastSeparator));
                    ((LocalFileSystem) fs).setRoot(root.getCanonicalFile());
                    fs.init();
                    fsr = new FileSystemResource(fs,
                            synonymProviderConfigPath.substring(lastSeparator + 1));
                } else {
                    ((LocalFileSystem) fs).setPath(path);
                    fs.init();
                    fsr = new FileSystemResource(fs, synonymProviderConfigPath);
                }
                synonymProviderConfigFs = fs;
            } else {
                fsr = new FileSystemResource(fs, synonymProviderConfigPath);
            }
            return fsr;
        } else {
            // path not configured
            return null;
View Full Code Here

    @SuppressWarnings("unchecked")
    protected NodeTypeRegistry(NamespaceRegistry nsReg, FileSystem ntStore)
            throws RepositoryException {
        this.nsReg = nsReg;
        customNodeTypesResource =
                new FileSystemResource(ntStore, CUSTOM_NODETYPES_RESOURCE_NAME);
        try {
            // make sure path to resource exists
            if (!customNodeTypesResource.exists()) {
                customNodeTypesResource.makeParentDirs();
            }
View Full Code Here

            uriToIndex.put(uri, idx);
        }
    }

    private void load() throws RepositoryException {
        FileSystemResource propFile =
                new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
        FileSystemResource idxFile =
                new FileSystemResource(nsRegStore, NS_IDX_RESOURCE);
        try {
            if (!propFile.exists()) {
                // clear existing mappings
                clear();

                // default namespace (if no prefix is specified)
                map(Name.NS_EMPTY_PREFIX, Name.NS_DEFAULT_URI);

                // declare the predefined mappings
                // rep:
                map(Name.NS_REP_PREFIX, Name.NS_REP_URI);
                // jcr:
                map(Name.NS_JCR_PREFIX, Name.NS_JCR_URI);
                // nt:
                map(Name.NS_NT_PREFIX, Name.NS_NT_URI);
                // mix:
                map(Name.NS_MIX_PREFIX, Name.NS_MIX_URI);
                // sv:
                map(Name.NS_SV_PREFIX, Name.NS_SV_URI);
                // xml:
                map(Name.NS_XML_PREFIX, Name.NS_XML_URI);

                // persist mappings
                store();
                return;
            }

            // check if index file exists
            Properties indexes = new Properties();
            if (idxFile.exists()) {
                InputStream in = idxFile.getInputStream();
                try {
                    indexes.load(in);
                } finally {
                    in.close();
                }
            }

            InputStream in = propFile.getInputStream();
            try {
                Properties props = new Properties();
                props.load(in);

                // clear existing mappings
                clear();

                // read mappings from properties
                for (Object p : props.keySet()) {
                    String prefix = (String) p;
                    String uri = props.getProperty(prefix);
                    String idx = indexes.getProperty(escapePropertyKey(uri));
                    // JCR-888: Backwards compatibility check
                    if (idx == null && uri.equals("")) {
                        idx = indexes.getProperty(uri);
                    }
                    if (idx != null) {
                        map(unescapePropertyKey(prefix), uri, Integer.decode(idx));
                    } else {
                        map(unescapePropertyKey(prefix), uri);
                    }
                }
            } finally {
                in.close();
            }
            if (!idxFile.exists()) {
                store();
            }
        } catch (Exception e) {
            String msg = "failed to load namespace registry";
            log.debug(msg);
View Full Code Here

            throw new RepositoryException(msg, e);
        }
    }

    private void store() throws RepositoryException {
        FileSystemResource propFile =
                new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
        try {
            propFile.makeParentDirs();
            OutputStream os = propFile.getOutputStream();
            Properties props = new Properties();

            // store mappings in properties
            for (String prefix : prefixToURI.keySet()) {
                String uri = prefixToURI.get(prefix);
                props.setProperty(escapePropertyKey(prefix), uri);
            }

            try {
                props.store(os, null);
            } finally {
                // make sure stream is closed
                os.close();
            }
        } catch (Exception e) {
            String msg = "failed to persist namespace registry";
            log.debug(msg);
            throw new RepositoryException(msg, e);
        }

        FileSystemResource indexFile =
                new FileSystemResource(nsRegStore, NS_IDX_RESOURCE);
        try {
            indexFile.makeParentDirs();
            OutputStream os = indexFile.getOutputStream();
            Properties props = new Properties();

            // store mappings in properties
            for (String uri : uriToIndex.keySet()) {
                String index = uriToIndex.get(uri).toString();
View Full Code Here

     * @throws IOException         if another exception occurs.
     */
    protected FileSystemResource createSynonymProviderConfigResource()
            throws FileSystemException, IOException {
        if (synonymProviderConfigPath != null) {
            FileSystemResource fsr;
            // simple sanity check
            if (synonymProviderConfigPath.endsWith(FileSystem.SEPARATOR)) {
                throw new FileSystemException(
                        "Invalid synonymProviderConfigPath: "
                        + synonymProviderConfigPath);
            }
            if (fs == null) {
                fs = new LocalFileSystem();
                int lastSeparator = synonymProviderConfigPath.lastIndexOf(
                        FileSystem.SEPARATOR_CHAR);
                if (lastSeparator != -1) {
                    File root = new File(path,
                            synonymProviderConfigPath.substring(0, lastSeparator));
                    ((LocalFileSystem) fs).setRoot(root.getCanonicalFile());
                    fs.init();
                    fsr = new FileSystemResource(fs,
                            synonymProviderConfigPath.substring(lastSeparator + 1));
                } else {
                    ((LocalFileSystem) fs).setPath(path);
                    fs.init();
                    fsr = new FileSystemResource(fs, synonymProviderConfigPath);
                }
                synonymProviderConfigFs = fs;
            } else {
                fsr = new FileSystemResource(fs, synonymProviderConfigPath);
            }
            return fsr;
        } else {
            // path not configured
            return null;
View Full Code Here

        resolver = new CachingNamespaceResolver(this, 1000);
        load();
    }

    private void load() throws RepositoryException {
        FileSystemResource propFile =
                new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
        try {
            if (!propFile.exists()) {
                // clear existing mappings
                prefixToURI.clear();
                uriToPrefix.clear();

                // default namespace (if no prefix is specified)
                prefixToURI.put(QName.NS_EMPTY_PREFIX, QName.NS_DEFAULT_URI);
                uriToPrefix.put(QName.NS_DEFAULT_URI, QName.NS_EMPTY_PREFIX);
                // declare the predefined mappings
                // rep:
                prefixToURI.put(QName.NS_REP_PREFIX, QName.NS_REP_URI);
                uriToPrefix.put(QName.NS_REP_URI, QName.NS_REP_PREFIX);
                // jcr:
                prefixToURI.put(QName.NS_JCR_PREFIX, QName.NS_JCR_URI);
                uriToPrefix.put(QName.NS_JCR_URI, QName.NS_JCR_PREFIX);
                // nt:
                prefixToURI.put(QName.NS_NT_PREFIX, QName.NS_NT_URI);
                uriToPrefix.put(QName.NS_NT_URI, QName.NS_NT_PREFIX);
                // mix:
                prefixToURI.put(QName.NS_MIX_PREFIX, QName.NS_MIX_URI);
                uriToPrefix.put(QName.NS_MIX_URI, QName.NS_MIX_PREFIX);
                // sv:
                prefixToURI.put(QName.NS_SV_PREFIX, QName.NS_SV_URI);
                uriToPrefix.put(QName.NS_SV_URI, QName.NS_SV_PREFIX);
                // xml:
                prefixToURI.put(QName.NS_XML_PREFIX, QName.NS_XML_URI);
                uriToPrefix.put(QName.NS_XML_URI, QName.NS_XML_PREFIX);

                // persist mappings
                store();
                return;
            }

            InputStream in = propFile.getInputStream();
            try {
                Properties props = new Properties();
                props.load(in);

                // clear existing mappings
View Full Code Here

            throw new RepositoryException(msg, e);
        }
    }

    private void store() throws RepositoryException {
        FileSystemResource propFile =
                new FileSystemResource(nsRegStore, NS_REG_RESOURCE);
        try {
            propFile.makeParentDirs();
            OutputStream os = propFile.getOutputStream();
            Properties props = new Properties();

            // store mappings in properties
            Iterator iter = prefixToURI.keySet().iterator();
            while (iter.hasNext()) {
View Full Code Here

TOP

Related Classes of org.apache.jackrabbit.core.fs.FileSystemResource

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.