001/* 002 * Licensed to DuraSpace under one or more contributor license agreements. 003 * See the NOTICE file distributed with this work for additional information 004 * regarding copyright ownership. 005 * 006 * DuraSpace licenses this file to you under the Apache License, 007 * Version 2.0 (the "License"); you may not use this file except in 008 * compliance with the License. You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018package org.fcrepo.kernel.modeshape.services.functions; 019 020import javax.jcr.Node; 021import javax.jcr.Property; 022import javax.jcr.Value; 023 024import org.fcrepo.kernel.modeshape.utils.UncheckedFunction; 025 026import java.util.function.Function; 027import java.util.function.Predicate; 028import java.util.stream.Stream; 029 030import static java.util.stream.Stream.of; 031import static javax.jcr.PropertyType.BINARY; 032import static org.fcrepo.kernel.modeshape.FedoraJcrConstants.FROZEN_NODE; 033import static org.modeshape.jcr.api.JcrConstants.JCR_DATA; 034import static org.fcrepo.kernel.modeshape.utils.UncheckedPredicate.uncheck; 035 036/** 037 * @author cabeer 038 * @since 9/25/14 039 */ 040public final class JcrPropertyFunctions { 041 042 private JcrPropertyFunctions() { 043 } 044 045 /** 046 * Constructs an {@link java.util.stream.Stream} of {@link javax.jcr.Value}s from any {@link javax.jcr.Property}, 047 * multi- or single-valued. 048 */ 049 public static final Function<Property, Stream<Value>> property2values = 050 UncheckedFunction.uncheck((final Property p) -> p.isMultiple() ? of(p.getValues()) : of(p.getValue())); 051 052 /** 053 * Check if a JCR property is a binary jcr:data property 054 */ 055 public static final Predicate<Property> isBinaryContentProperty = uncheck(p -> p.getType() == BINARY && 056 p.getName().equals(JCR_DATA)); 057 058 /** 059 * Predicate for determining whether this {@link javax.jcr.Node} is a frozen node 060 * (a part of the system version history). 061 */ 062 public static final Predicate<Node> isFrozen = uncheck(n -> n.isNodeType(FROZEN_NODE)); 063 064}