📄 valuehelper.java
字号:
/* * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed with * this work for additional information regarding copyright ownership. * The ASF licenses this file to You 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 org.apache.jackrabbit.value;import org.apache.jackrabbit.util.Base64;import org.apache.jackrabbit.util.Text;import org.apache.jackrabbit.util.TransientFileFactory;import javax.jcr.PropertyType;import javax.jcr.RepositoryException;import javax.jcr.Value;import javax.jcr.ValueFormatException;import javax.jcr.ValueFactory;import java.io.ByteArrayOutputStream;import java.io.InputStream;import java.io.Reader;import java.io.StringWriter;import java.io.Writer;import java.io.File;import java.io.FileOutputStream;import java.io.FileInputStream;import java.io.IOException;import java.io.FilterInputStream;/** * The <code>ValueHelper</code> class provides several <code>Value</code> * related utility methods. */public class ValueHelper { /** * empty private constructor */ private ValueHelper() { } /** * Same as {@link #convert(String, int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * * @param srcValue * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @deprecated Use {@link #convert(String, int, ValueFactory)} instead. * @see #convert(Value, int, ValueFactory) */ public static Value convert(String srcValue, int targetType) throws ValueFormatException, IllegalArgumentException { return convert(srcValue, targetType, ValueFactoryImpl.getInstance()); } /** * @param srcValue * @param targetType * @param factory * @throws ValueFormatException * @throws IllegalArgumentException * @see #convert(Value, int, ValueFactory) */ public static Value convert(String srcValue, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException { if (srcValue == null) { return null; } else { return factory.createValue(srcValue, targetType); } } /** * Same as {@link #convert(InputStream, int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * * @param srcValue * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @deprecated Use {@link #convert(InputStream, int, ValueFactory)} instead. */ public static Value convert(InputStream srcValue, int targetType) throws ValueFormatException, IllegalArgumentException { return convert(srcValue, targetType, ValueFactoryImpl.getInstance()); } /** * @param srcValue * @param targetType * @param factory * @throws ValueFormatException * @throws IllegalArgumentException */ public static Value convert(InputStream srcValue, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException { if (srcValue == null) { return null; } else { return convert(factory.createValue(srcValue), targetType, factory); } } /** * Same as {@link #convert(String[], int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * * @param srcValues * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @deprecated Use {@link #convert(String[], int, ValueFactory)} instead. * @see #convert(Value, int, ValueFactory) */ public static Value[] convert(String[] srcValues, int targetType) throws ValueFormatException, IllegalArgumentException { return convert(srcValues, targetType, ValueFactoryImpl.getInstance()); } /** * Same as {@link #convert(String[], int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * * @param srcValues * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @see #convert(Value, int, ValueFactory) */ public static Value[] convert(String[] srcValues, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException { if (srcValues == null) { return null; } Value[] newValues = new Value[srcValues.length]; for (int i = 0; i < srcValues.length; i++) { newValues[i] = convert(srcValues[i], targetType, factory); } return newValues; } /** * @param srcValues * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @see #convert(Value, int, ValueFactory) */ public static Value[] convert(InputStream[] srcValues, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException { if (srcValues == null) { return null; } Value[] newValues = new Value[srcValues.length]; for (int i = 0; i < srcValues.length; i++) { newValues[i] = convert(srcValues[i], targetType, factory); } return newValues; } /** * Same as {@link #convert(Value[], int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * * @param srcValues * @param targetType * @throws ValueFormatException * @throws IllegalArgumentException * @deprecated Use {@link #convert(Value[], int, ValueFactory)} instead. * @see #convert(Value, int, ValueFactory) */ public static Value[] convert(Value[] srcValues, int targetType) throws ValueFormatException, IllegalArgumentException { return convert(srcValues, targetType, ValueFactoryImpl.getInstance()); } /** * @param srcValues * @param targetType * @param factory * @throws ValueFormatException * @throws IllegalArgumentException * @see #convert(Value, int, ValueFactory) */ public static Value[] convert(Value[] srcValues, int targetType, ValueFactory factory) throws ValueFormatException, IllegalArgumentException { if (srcValues == null) { return null; } Value[] newValues = new Value[srcValues.length]; int srcValueType = PropertyType.UNDEFINED; for (int i = 0; i < srcValues.length; i++) { if (srcValues[i] == null) { newValues[i] = null; continue; } // check type of values if (srcValueType == PropertyType.UNDEFINED) { srcValueType = srcValues[i].getType(); } else if (srcValueType != srcValues[i].getType()) { // inhomogeneous types String msg = "inhomogeneous type of values"; throw new ValueFormatException(msg); } newValues[i] = convert(srcValues[i], targetType, factory); } return newValues; } /** * Same as {@link #convert(Value, int, ValueFactory)} using * <code>ValueFactoryImpl</code>. * @param srcValue * @param targetType * @throws ValueFormatException * @throws IllegalStateException * @throws IllegalArgumentException * @deprecated Use {@link #convert(Value, int, ValueFactory)} instead. * @see #convert(Value, int, ValueFactory) */ public static Value convert(Value srcValue, int targetType) throws ValueFormatException, IllegalStateException, IllegalArgumentException { return convert(srcValue, targetType, ValueFactoryImpl.getInstance()); } /** * Converts the given value to a value of the specified target type. * The conversion is performed according to the rules described in * "6.2.6 Property Type Conversion" in the JSR 170 specification. * * @param srcValue * @param targetType * @param factory * @throws ValueFormatException * @throws IllegalStateException * @throws IllegalArgumentException */ public static Value convert(Value srcValue, int targetType, ValueFactory factory) throws ValueFormatException, IllegalStateException, IllegalArgumentException { if (srcValue == null) { return null; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -