@Override public boolean equals(Object object) { if (this == object) { return true; } else if (object instanceof PropertyTemplate) { PropertyTemplate that = (PropertyTemplate) object; return name.equals(that.name) && type.equals(that.type); } else { return false; } }
static Map<String, String> collectNamespaces(Iterable<? extends PropertyState> properties) { Map<String, String> map = newHashMap(); for (PropertyState property : properties) { String prefix = property.getName(); if (STRING.equals(property.getType()) && isValidPrefix(prefix)) { map.put(prefix, property.getValue(STRING)); } } return map; }
protected void checkValidValue(PropertyState property) throws CommitFailedException { if (Type.NAME.equals(property.getType()) || Type.NAMES.equals(property.getType())) { for (String value : property.getValue(Type.NAMES)) { checkValidValue(value); } } else if (Type.PATH.equals(property.getType()) || Type.PATHS.equals(property.getType())) { for (String value : property.getValue(Type.PATHS)) { for (String name: PathUtils.elements(value)) { checkValidValue(name); } } } }
protected void checkValidValue(PropertyState property) throws CommitFailedException { if (Type.NAME.equals(property.getType()) || Type.NAMES.equals(property.getType())) { for (String value : property.getValue(Type.NAMES)) { checkValidValue(value); } } else if (Type.PATH.equals(property.getType()) || Type.PATHS.equals(property.getType())) { for (String value : property.getValue(Type.PATHS)) { for (String name: PathUtils.elements(value)) { checkValidValue(name); } } } }
protected void checkValidValue(PropertyState property) throws CommitFailedException { if (Type.NAME.equals(property.getType()) || Type.NAMES.equals(property.getType())) { for (String value : property.getValue(Type.NAMES)) { checkValidValue(value); } } else if (Type.PATH.equals(property.getType()) || Type.PATHS.equals(property.getType())) { for (String value : property.getValue(Type.PATHS)) { for (String name: PathUtils.elements(value)) { checkValidValue(name); } } } }
static Map<String, String> collectNamespaces(Iterable<? extends PropertyState> properties) { Map<String, String> map = newHashMap(); for (PropertyState property : properties) { String prefix = property.getName(); if (STRING.equals(property.getType()) && isValidPrefix(prefix)) { map.put(prefix, property.getValue(STRING)); } } return map; }
private void checkAddModifyProperties(@NotNull NodeState parent, @NotNull String name, @NotNull PropertyState propertyState, boolean isModify) throws CommitFailedException { if (RESERVED_PROPERTY_NAMES.contains(name)) { Type<?> type = propertyState.getType(); if (REP_EXTERNAL_PRINCIPAL_NAMES.equals(name)) { if (!isSystem) { throw new CommitFailedException(CommitFailedException.CONSTRAINT, 70, ERROR_MSGS.get(70)); } if (!Type.STRINGS.equals(type) || !propertyState.isArray()) { throw new CommitFailedException(CommitFailedException.CONSTRAINT, 71, ERROR_MSGS.get(71)); } if (!parent.hasProperty(REP_EXTERNAL_ID)) { throw new CommitFailedException(CommitFailedException.CONSTRAINT, 72, ERROR_MSGS.get(72)); } } if (REP_EXTERNAL_ID.equals(name) && protectedExternalIds) { if (isModify && !isSystem) { throw new CommitFailedException(CommitFailedException.CONSTRAINT, 74, ERROR_MSGS.get(74)); } if (!Type.STRING.equals(type) || propertyState.isArray()) { throw new CommitFailedException(CommitFailedException.CONSTRAINT, 75, ERROR_MSGS.get(75)); } } } }
private static boolean shallWeProcessProperty(final PropertyState property, final String path, final NodeBuilder builder) { boolean process = false; PropertyState mixin = checkNotNull(builder).getProperty(JCR_MIXINTYPES); if (mixin != null && PROP_INCREMENT.equals(property.getName()) && Iterators.contains(mixin.getValue(NAMES).iterator(), MIX_ATOMIC_COUNTER)) { if (LONG.equals(property.getType())) { process = true; } else { LOG.warn( "although the {} property is set is not of the right value: LONG. Not processing node: {}.", PROP_INCREMENT, path); } } return process; }
public static Map<String, String> getNamespaceMap(Tree root) { Map<String, String> map = newHashMap(); map.put("", ""); // default namespace, not included in tree Tree namespaces = getNamespaceTree(root); for (PropertyState property : namespaces.getProperties()) { String prefix = property.getName(); if (STRING.equals(property.getType()) && isValidPrefix(prefix)) { map.put(prefix, property.getValue(STRING)); } } return map; }
private static boolean shallWeProcessProperty(final PropertyState property, final String path, final NodeBuilder builder) { boolean process = false; PropertyState mixin = checkNotNull(builder).getProperty(JCR_MIXINTYPES); if (mixin != null && PROP_INCREMENT.equals(property.getName()) && Iterators.contains(mixin.getValue(NAMES).iterator(), MIX_ATOMIC_COUNTER)) { if (LONG.equals(property.getType())) { process = true; } else { LOG.warn( "although the {} property is set is not of the right value: LONG. Not processing node: {}.", PROP_INCREMENT, path); } } return process; }
private static boolean shallWeProcessProperty(final PropertyState property, final String path, final NodeBuilder builder) { boolean process = false; PropertyState mixin = checkNotNull(builder).getProperty(JCR_MIXINTYPES); if (mixin != null && PROP_INCREMENT.equals(property.getName()) && Iterators.contains(mixin.getValue(NAMES).iterator(), MIX_ATOMIC_COUNTER)) { if (LONG.equals(property.getType())) { process = true; } else { LOG.warn( "although the {} property is set is not of the right value: LONG. Not processing node: {}.", PROP_INCREMENT, path); } } return process; }
@Override public boolean equals(Object object) { // optimize for common cases if (this == object) { // don't use fastEquals here due to value sharing return true; } if (object instanceof SegmentPropertyState) { SegmentPropertyState that = (SegmentPropertyState) object; if (!type.equals(that.type) || !name.equals(that.name)) { return false; } else if (getRecordId().equals(that.getRecordId())) { return true; } } // fall back to default equality check in AbstractPropertyState return object instanceof PropertyState && AbstractPropertyState.equal(this, (PropertyState) object); }
public static void buildIndexNode(NodeBuilder namespaces) { // initialize prefix and URI sets with the defaults namespace // that's not stored along with the other mappings Set<String> prefixes = newHashSet(""); Set<String> uris = newHashSet(""); Map<String, String> reverse = new HashMap<String, String>(); for (PropertyState property : namespaces.getProperties()) { String prefix = property.getName(); if (STRING.equals(property.getType()) && isValidPrefix(prefix)) { prefixes.add(prefix); String uri = property.getValue(STRING); uris.add(uri); reverse.put(uri, prefix); } } NodeBuilder data = namespaces.setChildNode(REP_NSDATA); data.setProperty(JCR_PRIMARYTYPE, NodeTypeConstants.NT_REP_UNSTRUCTURED, Type.NAME); data.setProperty(REP_PREFIXES, prefixes, Type.STRINGS); data.setProperty(REP_URIS, uris, Type.STRINGS); for (Entry<String, String> e : reverse.entrySet()) { data.setProperty(encodeUri(e.getKey()), e.getValue()); } }
@Override public long size(int index) { ListRecord values = getValueList(getSegment()); checkElementIndex(index, values.size()); RecordId entry = values.getEntry(index); if (getType().equals(BINARY) || getType().equals(BINARIES)) { return reader.readBlob(entry).length(); } return Segment.readLength(entry); }
@Override public void propertyAdded(PropertyState after) throws CommitFailedException { String prefix = after.getName(); // ignore jcr:primaryType if (JCR_PRIMARYTYPE.equals(prefix)) { return; } if (namespaces.hasProperty(prefix)) { throw new CommitFailedException(CommitFailedException.NAMESPACE, 1, "Namespace mapping already registered: " + prefix); } else if (isValidPrefix(prefix)) { if (after.isArray() || !STRING.equals(after.getType())) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 2, "Invalid namespace mapping: " + prefix); } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml")) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 3, "XML prefixes are reserved: " + prefix); } else if (containsValue(namespaces, after.getValue(STRING))) { throw modificationNotAllowed(prefix); } } else { throw new CommitFailedException(CommitFailedException.NAMESPACE, 4, "Not a valid namespace prefix: " + prefix); } modified = true; }
@Override public void propertyAdded(PropertyState after) throws CommitFailedException { String prefix = after.getName(); // ignore jcr:primaryType if (JCR_PRIMARYTYPE.equals(prefix)) { return; } if (namespaces.hasProperty(prefix)) { throw new CommitFailedException(CommitFailedException.NAMESPACE, 1, "Namespace mapping already registered: " + prefix); } else if (isValidPrefix(prefix)) { if (after.isArray() || !STRING.equals(after.getType())) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 2, "Invalid namespace mapping: " + prefix); } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml") && namespaces.hasProperty("xml")) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 3, "XML prefixes are reserved: " + prefix); } else if (containsValue(namespaces, after.getValue(STRING))) { throw modificationNotAllowed(prefix); } } else { throw new CommitFailedException(CommitFailedException.NAMESPACE, 4, "Not a valid namespace prefix: " + prefix); } modified = true; }
@Override public void propertyAdded(PropertyState after) throws CommitFailedException { String prefix = after.getName(); // ignore jcr:primaryType if (JCR_PRIMARYTYPE.equals(prefix)) { return; } if (namespaces.hasProperty(prefix)) { throw new CommitFailedException(CommitFailedException.NAMESPACE, 1, "Namespace mapping already registered: " + prefix); } else if (isValidPrefix(prefix)) { if (after.isArray() || !STRING.equals(after.getType())) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 2, "Invalid namespace mapping: " + prefix); } else if (prefix.toLowerCase(Locale.ENGLISH).startsWith("xml") && namespaces.hasProperty("xml")) { throw new CommitFailedException( CommitFailedException.NAMESPACE, 3, "XML prefixes are reserved: " + prefix); } else if (containsValue(namespaces, after.getValue(STRING))) { throw modificationNotAllowed(prefix); } } else { throw new CommitFailedException(CommitFailedException.NAMESPACE, 4, "Not a valid namespace prefix: " + prefix); } modified = true; }