All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.squeakysand.jcr.NodeUtils Maven / Gradle / Ivy

The newest version!
/*
 * Copyright 2010-2011 Craig S. Dickson (http://craigsdickson.com)
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.squeakysand.jcr;

import java.util.ArrayList;
import java.util.List;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class NodeUtils {

    private static final Logger LOG = LoggerFactory.getLogger(SimpleNode.class);

    public static List asList(NodeIterator nodeIterator) {
        List result = new ArrayList();
        if (nodeIterator != null) {
            while (nodeIterator.hasNext()) {
                Node node = nodeIterator.nextNode();
                result.add(new SimpleNode(node));
            }
        }
        return result;
    }

    public static SimpleNode getNodeByPath(String nodePath, Session session) {
        SimpleNode result = null;
        if (nodePath != null) {
            Node node = null;
            try {
                node = session.getNode(nodePath);
            } catch (PathNotFoundException e) {
                LOG.trace(e.getMessage(), e);
            } catch (RepositoryException e) {
                LOG.error(e.getMessage(), e);
            }
            if (node != null) {
                result = new SimpleNode(node);
            }
        }
        if (LOG.isDebugEnabled()) {
            LOG.debug("found node {} at path {}", result, nodePath);
        }
        return result;
    }

}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy