📄 abstractnode.java
字号:
return true; } } } /** * Checks if this node is locked. * <p> * The default implementation calls {@link Node#getLock()} and returns * <code>true</code> iff a {@link LockException} is not thrown. * * @return <code>true</code> if this node is locked, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isLocked() throws RepositoryException { try { getLock(); return true; } catch (LockException e) { return false; } } /** * Checks whether this node is of the given type. * <p> * The default implementation iterates through the primary and mixin * types and all the supertypes of this node, returning <code>true</code> * if a type with the given name is encountered. Returns <code>false</code> * if none of the types matches. * * @param name type name * @return <code>true</code> if this node is of the given type, * <code>false</code> otherwise * @throws RepositoryException if an error occurs */ public boolean isNodeType(String name) throws RepositoryException { NodeType type = getPrimaryNodeType(); if (name.equals(type.getName())) { return true; } NodeType[] supertypes = type.getSupertypes(); for (int i = 0; i < supertypes.length; i++) { if (name.equals(supertypes[i].getName())) { return true; } } NodeType[] mixins = getMixinNodeTypes(); for (int i = 0; i < mixins.length; i++) { if (name.equals(mixins[i].getName())) { return true; } supertypes = mixins[i].getSupertypes(); for (int j = 0; j < supertypes.length; j++) { if (name.equals(supertypes[j].getName())) { return true; } } } return false; } /** * Restores this node to the version with the given name. * <p> * The default implement retrieves the named {@link Version} from the * associated {@link VersionHistory} and forwards the call to the * {@link Node#restore(Version, boolean)} method. * * @param versionName version name * @param removeExisting passed through * @throws RepositoryException if an error occurs */ public void restore(String versionName, boolean removeExisting) throws RepositoryException { restore(getVersionHistory().getVersion(versionName), removeExisting); } /** * Restores this node to the given version. * <p> * The default implementation forwards the call to the * {@link Node#restore(Version, String, boolean)} method using the * relative path ".". * * @param version passed through * @param removeExisting passed through * @throws RepositoryException if an error occurs */ public void restore(Version version, boolean removeExisting) throws RepositoryException { restore(version, ".", removeExisting); } /** * Restores this node to the version with the given label. * <p> * The default implement retrieves the labeled {@link Version} from the * associated {@link VersionHistory} and forwards the call to the * {@link Node#restore(Version, boolean)} method. * * @param versionLabel version label * @param removeExisting passed through * @throws RepositoryException if an error occurs */ public void restoreByLabel(String versionLabel, boolean removeExisting) throws RepositoryException { restore(getVersionHistory().getVersionByLabel(versionLabel), removeExisting); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instances from * the given string values and forwards the call to the * {@link Node#setProperty(String, Value[])} method. * * @param name property name * @param strings string values * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, String[] strings) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); Value[] values = new Value[strings.length]; for (int i = 0; i < strings.length; i++) { values[i] = factory.createValue(strings[i]); } return setProperty(name, values); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given string value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value string value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, String value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given binary value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value binary value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, InputStream value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given boolean value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value boolean value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, boolean value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given double value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value double value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, double value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given long value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value long value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, long value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given date value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value date value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, Calendar value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance from * the given reference value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value reference value * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, Node value) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value)); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to convert the given value to the given * type and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value property value * @param type property type * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, Value value, int type) throws RepositoryException { if (value.getType() != type) { ValueFactory factory = getSession().getValueFactory(); value = factory.createValue(value.getString(), type); } return setProperty(name, value); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to convert the given values to the given * type and forwards the call to the * {@link Node#setProperty(String, Value[])} method. * * @param name property name * @param values property values * @param type property type * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, Value[] values, int type) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); Value[] converted = new Value[values.length]; for (int i = 0; i < values.length; i++) { if (values[i].getType() != type) { converted[i] = factory.createValue(values[i].getString(), type); } else { converted[i] = values[i]; } } return setProperty(name, converted); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create {@link Value} instances of the * given type from the given string values and forwards the call to the * {@link Node#setProperty(String, Value[])} method. * * @param name property name * @param strings string values * @param type property type * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, String[] strings, int type) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); Value[] values = new Value[strings.length]; for (int i = 0; i < strings.length; i++) { values[i] = factory.createValue(strings[i], type); } return setProperty(name, values); } /** * Sets the value of the named property. * <p> * The default implementation uses the {@link ValueFactory} of the * current {@link Session} to create a {@link Value} instance of the * given type from the given string value and forwards the call to the * {@link Node#setProperty(String, Value)} method. * * @param name property name * @param value string value * @param type property type * @return modified property * @throws RepositoryException if an error occurs */ public Property setProperty(String name, String value, int type) throws RepositoryException { ValueFactory factory = getSession().getValueFactory(); return setProperty(name, factory.createValue(value, type)); } //-------------------------------------------------------------< private > /** * Returns the prefixed JCR name for the given {@link QName} using the * current namespace mappings. The given name is assumed <em>not</em> * to be in the default namespace, i.e. there will always be a non-empty * prefix for the name. * * @param name namespaced name * @return prefixed JCR name * @throws RepositoryException if an error occurs */ private String getName(QName name) throws RepositoryException { assert name.getNamespaceURI().length() > 0; String prefix = getSession().getNamespacePrefix(name.getNamespaceURI()); return prefix + ":" + name.getLocalName(); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -