Author: elvisisking
Date: 2012-03-30 18:16:19 -0400 (Fri, 30 Mar 2012)
New Revision: 39949
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
Log:
JBIDE-10702 Editor for JCR Compact Node Definition (CND) files. Work on path property
validation. Also did some preparatory work on node type definition business objects that
will allow keeping properties, child nodes, comments, and vendor blocks in the order they
were parsed.
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java 2012-03-30
18:35:02 UTC (rev 39948)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/NodeTypeDefinition.java 2012-03-30
22:16:19 UTC (rev 39949)
@@ -89,9 +89,14 @@
private final NodeTypeAttributes attributes;
/**
- * The collection of child node definitions (can be <code>null</code>).
+ * The collection of CND elements (can be <code>null</code>).
*/
- private List<ChildNodeDefinition> childNodesDefinitions;
+ private List<CndElement> cndElements;
+ //
+ // /**
+ // * The collection of child node definitions (can be
<code>null</code>).
+ // */
+ // private List<ChildNodeDefinition> childNodesDefinitions;
/**
* The collection of property change listeners (never
<code>null</code>).
@@ -102,13 +107,13 @@
* The node type name (never <code>null</code> but can have a
<code>null</code> or empty value).
*/
private final QualifiedName name;
+ //
+ // /**
+ // * The collection of property definitions (can be <code>null</code>).
+ // */
+ // private List<PropertyDefinition> propertyDefinitions;
/**
- * The collection of property definitions (can be <code>null</code>).
- */
- private List<PropertyDefinition> propertyDefinitions;
-
- /**
* The super types (never <code>null</code>).
*/
private final SuperTypes superTypes;
@@ -132,11 +137,11 @@
public boolean addChildNodeDefinition( final ChildNodeDefinition
childNodeDefinitionBeingAdded ) {
Utils.verifyIsNotNull(childNodeDefinitionBeingAdded,
"childNodeDefinitionBeingAdded"); //$NON-NLS-1$
- if (this.childNodesDefinitions == null) {
- this.childNodesDefinitions = new ArrayList<ChildNodeDefinition>();
+ if (this.cndElements == null) {
+ this.cndElements = new ArrayList<CndElement>();
}
- if (this.childNodesDefinitions.add(childNodeDefinitionBeingAdded)) {
+ if (this.cndElements.add(childNodeDefinitionBeingAdded)) {
notifyChangeListeners(PropertyName.CHILD_NODES, null,
childNodeDefinitionBeingAdded);
return true; // added
}
@@ -162,11 +167,11 @@
public boolean addPropertyDefinition( final PropertyDefinition
properyDefinitionBeingAdded ) {
Utils.verifyIsNotNull(properyDefinitionBeingAdded,
"properyDefinitionBeingAdded"); //$NON-NLS-1$
- if (this.propertyDefinitions == null) {
- this.propertyDefinitions = new ArrayList<PropertyDefinition>();
+ if (this.cndElements == null) {
+ this.cndElements = new ArrayList<CndElement>();
}
- if (this.propertyDefinitions.add(properyDefinitionBeingAdded)) {
+ if (this.cndElements.add(properyDefinitionBeingAdded)) {
notifyChangeListeners(PropertyName.PROPERTY_DEFINITIONS, null,
properyDefinitionBeingAdded);
return true; // added
}
@@ -237,64 +242,6 @@
}
/**
- * If cleared, a property change event is broadcast to all registered listeners.
- *
- * @return <code>true</code> if there was at least one child node before
clearing
- */
- public boolean clearChildNodeDefinitions() {
- if (this.childNodesDefinitions == null) {
- return false; // nothing to clear
- }
-
- final List<ChildNodeDefinition> childNodes = new
ArrayList<ChildNodeDefinition>(getChildNodeDefinitions());
- final boolean cleared = !this.childNodesDefinitions.isEmpty();
- this.childNodesDefinitions = null;
-
- if (cleared) {
- notifyChangeListeners(PropertyName.CHILD_NODES, childNodes, null);
- }
-
- return cleared;
- }
-
- /**
- * If cleared, a property change event is broadcast to all registered listeners.
- *
- * @return <code>true</code> if there was at least one property
definition before clearing
- */
- public boolean clearPropertyDefinitions() {
- if (this.propertyDefinitions == null) {
- return false; // nothing to clear
- }
-
- final List<PropertyDefinition> propDefns = new
ArrayList<PropertyDefinition>(getPropertyDefinitions());
- final boolean cleared = !this.propertyDefinitions.isEmpty();
- this.propertyDefinitions = null;
-
- if (cleared) {
- notifyChangeListeners(PropertyName.PROPERTY_DEFINITIONS, propDefns, null);
- }
-
- return cleared;
- }
-
- /**
- * If cleared, a property change event is broadcast to all registered listeners.
- *
- * @return <code>true</code> if there was at least one super type before
clearing
- */
- public boolean clearSuperTypes() {
- final List<QualifiedName> types = new
ArrayList<QualifiedName>(this.superTypes.getSupportedItems());
-
- if (this.superTypes.clear()) {
- notifyChangeListeners(PropertyName.SUPERTYPES, types, null);
- return true;
- }
-
- return false;
- }
-
- /**
* {@inheritDoc}
*
* @see java.lang.Comparable#compareTo(java.lang.Object)
@@ -379,19 +326,23 @@
return true;
}
- private String getChildNodeDefinitionDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.CHILD_NODE_DEFINITION_DELIMITER);
- }
-
/**
* @return the child node definitions (never <code>null</code>)
*/
public List<ChildNodeDefinition> getChildNodeDefinitions() {
- if (this.childNodesDefinitions == null) {
+ if (this.cndElements == null) {
return Collections.emptyList();
}
- return this.childNodesDefinitions;
+ final List<ChildNodeDefinition> childNodeDefinitions = new
ArrayList<ChildNodeDefinition>();
+
+ for (final CndElement element : this.cndElements) {
+ if (element instanceof ChildNodeDefinition) {
+ childNodeDefinitions.add((ChildNodeDefinition)element);
+ }
+ }
+
+ return childNodeDefinitions;
}
/**
@@ -426,35 +377,32 @@
return this.superTypes.toArray();
}
- private String getEndAttributesDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER);
- }
+ private List<CndElement> getElements() {
+ if (this.cndElements == null) {
+ return Collections.emptyList();
+ }
- private String getEndChildNodeDefinitionsDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.CHILD_NODE_DEFINITION_SECTION_END_DELIMITER);
+ return this.cndElements;
}
- private String getEndNameDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.NODE_TYPE_DEFINITION_NAME_END_DELIMITER);
- }
-
- private String getEndPropertyDefinitionsDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.PROPERTY_DEFINITION_SECTION_END_DELIMITER);
- }
-
- private String getEndSuperTypesDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.SUPER_TYPES_END_DELIMITER);
- }
-
/**
* @return the child node definitions and property definitions contained in this node
type definition (never <code>null</code>
* but can be empty)
*/
public List<ItemDefinition> getItemDefinitions() {
- // TODO this needs to be a field and getters for items need to filter this field
appropriately
- final List<ItemDefinition> currentItems = new
ArrayList<ItemDefinition>(getChildNodeDefinitions());
- currentItems.addAll(getPropertyDefinitions());
- return currentItems;
+ if (this.cndElements == null) {
+ return Collections.emptyList();
+ }
+
+ final List<ItemDefinition> itemDefinitions = new
ArrayList<ItemDefinition>();
+
+ for (final CndElement element : this.cndElements) {
+ if (element instanceof ItemDefinition) {
+ itemDefinitions.add((ItemDefinition)element);
+ }
+ }
+
+ return itemDefinitions;
}
/**
@@ -501,23 +449,23 @@
return primaryItem;
}
- private String getPropertyDefinitionDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.PROPERTY_DEFINITION_DELIMITER);
- }
-
/**
* @return the property definitions (never <code>null</code>)
*/
public List<PropertyDefinition> getPropertyDefinitions() {
- if (this.propertyDefinitions == null) {
+ if (this.cndElements == null) {
return Collections.emptyList();
}
- return this.propertyDefinitions;
- }
+ final List<PropertyDefinition> propertyDefinitions = new
ArrayList<PropertyDefinition>();
- private String getPropertyDefinitionStartDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.PROPERTY_DEFINITION_START_DELIMITER);
+ for (final CndElement element : this.cndElements) {
+ if (element instanceof PropertyDefinition) {
+ propertyDefinitions.add((PropertyDefinition)element);
+ }
+ }
+
+ return propertyDefinitions;
}
/**
@@ -537,10 +485,6 @@
return this.name;
}
- private String getStartChildNodeDefinitionDelimiter() {
- return
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.CHILD_NODE_DEFINITION_START_DELIMITER);
- }
-
/**
* Can be used to find the attribute state of the abstract, mixin, orderable, primary
item, queryable, and super types
* properties.
@@ -677,16 +621,17 @@
*/
public boolean removeChildNodeDefinition( final ChildNodeDefinition
childNodeDefinitionBeingRemoved ) {
Utils.verifyIsNotNull(childNodeDefinitionBeingRemoved,
"childNodeDefinitionBeingRemoved"); //$NON-NLS-1$
+ final List<ChildNodeDefinition> childNodeDefinitions =
getChildNodeDefinitions();
- if (this.childNodesDefinitions == null) {
+ if (childNodeDefinitions.isEmpty()) {
return false;
}
- if (this.childNodesDefinitions.remove(childNodeDefinitionBeingRemoved)) {
+ if (this.cndElements.remove(childNodeDefinitionBeingRemoved)) {
notifyChangeListeners(PropertyName.CHILD_NODES,
childNodeDefinitionBeingRemoved, null);
- if (this.childNodesDefinitions.isEmpty()) {
- this.childNodesDefinitions = null;
+ if (this.cndElements.isEmpty()) {
+ this.cndElements = null;
}
return true; // removed
@@ -712,16 +657,17 @@
*/
public boolean removePropertyDefinition( final PropertyDefinition
propertyDefinitionBeingRemoved ) {
Utils.verifyIsNotNull(propertyDefinitionBeingRemoved,
"propertyDefinitionBeingRemoved"); //$NON-NLS-1$
+ final List<PropertyDefinition> propertyDefinitions =
getPropertyDefinitions();
- if (this.propertyDefinitions == null) {
+ if (propertyDefinitions.isEmpty()) {
return false;
}
- if (this.propertyDefinitions.remove(propertyDefinitionBeingRemoved)) {
+ if (this.cndElements.remove(propertyDefinitionBeingRemoved)) {
notifyChangeListeners(PropertyName.PROPERTY_DEFINITIONS,
propertyDefinitionBeingRemoved, null);
- if (this.propertyDefinitions.isEmpty()) {
- this.propertyDefinitions = null;
+ if (this.cndElements.isEmpty()) {
+ this.cndElements = null;
}
return true; // removed
@@ -853,14 +799,15 @@
builder.append(NAME_NOTATION_PREFIX)
.append(this.name.toCndNotation(notationType))
.append(NAME_NOTATION_SUFFIX)
- .append(getEndNameDelimiter());
+
.append(CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.NODE_TYPE_DEFINITION_NAME_END_DELIMITER));
}
{ // super types
final String notation = this.superTypes.toCndNotation(notationType);
if (!Utils.isEmpty(notation)) {
- builder.append(notation).append(getEndSuperTypesDelimiter());
+ builder.append(notation)
+
.append(CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.SUPER_TYPES_END_DELIMITER));
}
}
@@ -871,30 +818,22 @@
builder.append(notation);
}
- builder.append(getEndAttributesDelimiter());
+
builder.append(CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER));
}
- { // property definitions
- if (!Utils.isEmpty(this.propertyDefinitions)) {
- for (final PropertyDefinition propDefn : this.propertyDefinitions) {
- builder.append(getPropertyDefinitionStartDelimiter());
- builder.append(propDefn.toCndNotation(notationType));
- builder.append(getPropertyDefinitionDelimiter());
- }
+ { // elements
+ final String elementStartDelimiter =
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.ELEMENTS_START_DELIMITER);
+ final String elementDelimiter =
CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.ELEMENT_DELIMITER);
+ final List<CndElement> elements = getElements();
- builder.append(getEndPropertyDefinitionsDelimiter());
- }
- }
-
- { // child node definitions
- if (!Utils.isEmpty(this.childNodesDefinitions)) {
- for (final ChildNodeDefinition childNodeDefn :
this.childNodesDefinitions) {
- builder.append(getStartChildNodeDefinitionDelimiter());
- builder.append(childNodeDefn.toCndNotation(notationType));
- builder.append(getChildNodeDefinitionDelimiter());
+ if (!Utils.isEmpty(elements)) {
+ for (final CndElement element : elements) {
+ builder.append(elementStartDelimiter);
+ builder.append(element.toCndNotation(notationType));
+ builder.append(elementDelimiter);
}
- builder.append(getEndChildNodeDefinitionsDelimiter());
+
builder.append(CndNotationPreferences.DEFAULT_PREFERENCES.get(Preference.ELEMENTS_END_DELIMITER));
}
}
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java 2012-03-30
18:35:02 UTC (rev 39948)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndNotationPreferences.java 2012-03-30
22:16:19 UTC (rev 39949)
@@ -70,16 +70,16 @@
map.put(Preference.ATTRIBUTE_LIST_ELEMENT_DELIMITER, ", ");
//$NON-NLS-1$
map.put(Preference.ATTRIBUTE_LIST_ITEM_QUOTE_CHAR, Utils.EMPTY_STRING);
- map.put(Preference.CHILD_NODE_DEFINITION_DELIMITER, "\n");
//$NON-NLS-1$
map.put(Preference.CHILD_NODE_DEFINITION_END_PREFIX_DELIMITER, " ");
//$NON-NLS-1$
map.put(Preference.CHILD_NODE_PROPERTY_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.DEFAULT_VALUES_END_PREFIX_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.DEFAULT_VALUES_QUOTE_CHARACTER, "'");
//$NON-NLS-1$
map.put(Preference.DEFAULT_TYPE_END_PREFIX_DELIMITER, Utils.SPACE_STRING);
- map.put(Preference.CHILD_NODE_DEFINITION_SECTION_END_DELIMITER,
Utils.EMPTY_STRING);
- map.put(Preference.CHILD_NODE_DEFINITION_START_DELIMITER, "\t");
//$NON-NLS-1$
map.put(Preference.ATTRIBUTE_LIST_PREFIX_END_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.ATTRIBUTE_LIST_QUOTE_CHAR, Utils.EMPTY_STRING);
+ map.put(Preference.ELEMENT_DELIMITER, "\n"); //$NON-NLS-1$
+ map.put(Preference.ELEMENTS_END_DELIMITER, Utils.EMPTY_STRING);
+ map.put(Preference.ELEMENTS_START_DELIMITER, "\t"); //$NON-NLS-1$
map.put(Preference.NAMESPACE_MAPPING_DELIMITER, "\n"); //$NON-NLS-1$
map.put(Preference.NAMESPACE_MAPPING_SECTION_END_DELIMITER, "\n");
//$NON-NLS-1$
map.put(Preference.CHILD_NODE_ATTRIBUTES_DELIMITER, Utils.SPACE_STRING);
@@ -89,10 +89,7 @@
map.put(Preference.NODE_TYPE_DEFINITION_NAME_END_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.NODE_TYPE_DEFINITION_SECTION_END_DELIMITER, "\n");
//$NON-NLS-1$
map.put(Preference.PROPERTY_DEFINITION_ATTRIBUTES_DELIMITER,
Utils.SPACE_STRING);
- map.put(Preference.PROPERTY_DEFINITION_DELIMITER, "\n"); //$NON-NLS-1$
map.put(Preference.PROPERTY_DEFINITION_END_PREFIX_DELIMITER,
Utils.SPACE_STRING);
- map.put(Preference.PROPERTY_DEFINITION_SECTION_END_DELIMITER,
Utils.EMPTY_STRING);
- map.put(Preference.PROPERTY_DEFINITION_START_DELIMITER, "\t");
//$NON-NLS-1$
map.put(Preference.REQUIRED_TYPES_END_PREFIX_DELIMITER, Utils.EMPTY_STRING);
map.put(Preference.SUPER_TYPES_END_DELIMITER, Utils.SPACE_STRING);
map.put(Preference.VALUE_CONSTRAINTS_ITEM_QUOTE_CHARACTER, "'");
//$NON-NLS-1$
@@ -130,26 +127,11 @@
CHILD_NODE_ATTRIBUTES_DELIMITER,
/**
- * The delimiter between child node definitions.
- */
- CHILD_NODE_DEFINITION_DELIMITER,
-
- /**
* The delimiter after the plus sign and before the child node definition name.
*/
CHILD_NODE_DEFINITION_END_PREFIX_DELIMITER,
/**
- * The delimiter after the last child node definition.
- */
- CHILD_NODE_DEFINITION_SECTION_END_DELIMITER,
-
- /**
- * The delimiter before a child node definition.
- */
- CHILD_NODE_DEFINITION_START_DELIMITER,
-
- /**
* The delimiter between child node properties.
*/
CHILD_NODE_PROPERTY_DELIMITER,
@@ -171,6 +153,21 @@
DEFAULT_VALUES_QUOTE_CHARACTER,
/**
+ * The delimiter between CND elements.
+ */
+ ELEMENT_DELIMITER,
+
+ /**
+ * The delimiter after the last CND element.
+ */
+ ELEMENTS_END_DELIMITER,
+
+ /**
+ * The delimiter before the first CND element.
+ */
+ ELEMENTS_START_DELIMITER,
+
+ /**
* The delimiter between namespace mappings.
*/
NAMESPACE_MAPPING_DELIMITER,
@@ -181,14 +178,14 @@
NAMESPACE_MAPPING_SECTION_END_DELIMITER,
/**
- * The delimiter after all the node type definition attributes.
+ * The delimiter between node type definition attributes.
*/
- NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER,
+ NODE_TYPE_DEFINITION_ATTRIBUTES_DELIMITER,
/**
- * The delimiter between node type definition attributes.
+ * The delimiter after all the node type definition attributes.
*/
- NODE_TYPE_DEFINITION_ATTRIBUTES_DELIMITER,
+ NODE_TYPE_DEFINITION_ATTRIBUTES_END_DELIMITER,
/**
* The delimiter between node type definitions.
@@ -211,26 +208,11 @@
PROPERTY_DEFINITION_ATTRIBUTES_DELIMITER,
/**
- * The delimiter between property definitions.
- */
- PROPERTY_DEFINITION_DELIMITER,
-
- /**
* The delimiter after the dash and before the property definition name.
*/
PROPERTY_DEFINITION_END_PREFIX_DELIMITER,
/**
- * The delimiter after the last property definition.
- */
- PROPERTY_DEFINITION_SECTION_END_DELIMITER,
-
- /**
- * The delimiter before a property definition.
- */
- PROPERTY_DEFINITION_START_DELIMITER,
-
- /**
* The delimiter after the open paren and before the required types.
*/
REQUIRED_TYPES_END_PREFIX_DELIMITER,
Modified:
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java
===================================================================
---
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-03-30
18:35:02 UTC (rev 39948)
+++
trunk/modeshape/plugins/org.jboss.tools.modeshape.jcr/src/org/jboss/tools/modeshape/jcr/cnd/CndValidator.java 2012-03-30
22:16:19 UTC (rev 39949)
@@ -12,6 +12,7 @@
import java.sql.Date;
import java.util.ArrayList;
import java.util.Collection;
+import java.util.StringTokenizer;
import org.eclipse.osgi.util.NLS;
import org.jboss.tools.modeshape.jcr.ChildNodeDefinition;
@@ -33,6 +34,9 @@
*/
public final class CndValidator {
+ private static final String PARENT_PATH_SEGMENT = ".."; //$NON-NLS-1$
+ private static final String SELF_PATH_SEGMENT = "."; //$NON-NLS-1$
+
/**
* @param value the value being checked (can be <code>null</code> or
empty)
* @param propertyType the property type of the property definition the value is for
(cannot be <code>null</code>)
@@ -95,7 +99,7 @@
} else if (PropertyType.NAME == propertyType) {
return validateLocalName(value, propertyName);
} else if (PropertyType.PATH == propertyType) {
- // TODO implement PATH validation
+ return validatePath(value, propertyName);
} else if (PropertyType.REFERENCE == propertyType) {
return ValidationStatus.OK_STATUS; // always valid
} else if (PropertyType.UNDEFINED == propertyType) {
@@ -432,7 +436,7 @@
}
// ERROR Local name cannot be self or parent
- if (localName.equals(".") || localName.equals("..")) {
//$NON-NLS-1$ //$NON-NLS-2$
+ if (localName.equals(SELF_PATH_SEGMENT) || localName.equals(PARENT_PATH_SEGMENT))
{
return
ValidationStatus.createErrorMessage(NLS.bind(Messages.localNameEqualToSelfOrParent,
messagePrefix));
}
@@ -920,6 +924,105 @@
}
/**
+ * @param path the path value being validated (can be <code>null</code>
or empty)
+ * @param propertyName the property name whose path value is being validated (cannot
be <code>null</code> or empty)
+ * @return the validation status (never <code>null</code>)
+ */
+ public static ValidationStatus validatePath( String path,
+ String propertyName ) {
+ Utils.verifyIsNotNull(propertyName, "propertyName"); //$NON-NLS-1$
+
+ if (Utils.isEmpty(propertyName)) {
+ propertyName = Messages.missingName;
+ }
+
+ if (Utils.isEmpty(path)) {
+ return ValidationStatus.createErrorMessage(NLS.bind(Messages.emptyValue,
propertyName));
+ }
+
+ StringTokenizer pathTokenizer = new StringTokenizer(path, "/");
//$NON-NLS-1$
+
+ if (pathTokenizer.hasMoreTokens()) {
+ while (pathTokenizer.hasMoreElements()) {
+ String segment = pathTokenizer.nextToken();
+
+ if (Utils.isEmpty(segment)) {
+ if (pathTokenizer.hasMoreTokens()) {
+ // found empty segment
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.invalidPropertyValueForType, path,
+
PropertyType.PATH));
+ }
+ } else {
+ StringTokenizer segmentTokenizer = new StringTokenizer(segment,
"[]"); //$NON-NLS-1$
+
+ if (segmentTokenizer.countTokens() == 2) {
+ // has SNS index
+ String qualifiedName = segmentTokenizer.nextToken();
+
+ if (Utils.isEmpty(qualifiedName)) {
+ // found SNS but now qualified name
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.invalidPropertyValueForType, path,
+
PropertyType.PATH));
+ }
+
+ // OK if segment is self or parent
+ if (PARENT_PATH_SEGMENT.equals(qualifiedName) ||
SELF_PATH_SEGMENT.equals(qualifiedName)) {
+ continue;
+ }
+
+ // validate qualified name
+ QualifiedName qname = QualifiedName.parse(qualifiedName);
+ MultiValidationStatus status = validateQualifiedName(qname,
propertyName, null, null);
+
+ // return if invalid qualified
+ if (status.isError()) {
+ return status;
+ }
+
+ // valid qualified name so check SNS index
+ if (segmentTokenizer.countTokens() == 1) {
+ String snsIndex = segmentTokenizer.nextToken();
+
+ // make sure SNS index is a number
+ for (char c : snsIndex.toCharArray()) {
+ if (!Character.isDigit(c)) {
+ // found invalid character
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.invalidPropertyValueForType, path,
+
PropertyType.PATH));
+ }
+ }
+ } else {
+ // no ending SNS bracket
+ return
ValidationStatus.createErrorMessage(NLS.bind(Messages.invalidPropertyValueForType, path,
+
PropertyType.PATH));
+ }
+ } else {
+ // OK if segment is self or parent
+ if (PARENT_PATH_SEGMENT.equals(segment) ||
SELF_PATH_SEGMENT.equals(segment)) {
+ continue;
+ }
+
+ // no SNS index
+ QualifiedName qname = QualifiedName.parse(segment);
+ MultiValidationStatus status = validateQualifiedName(qname,
propertyName, null, null);
+
+ // return if invalid segment
+ if (status.isError()) {
+ return status;
+ }
+ }
+ }
+ }
+ } else {
+ // only one segment
+ QualifiedName qname = QualifiedName.parse(path);
+ return validateQualifiedName(qname, propertyName, null, null);
+ }
+
+ return ValidationStatus.OK_STATUS;
+ }
+
+ /**
* @param propertyDefinition the property definition being validated (never
<code>null</code>)
* @param validNamespacePrefixes the valid namespace prefixes (can be
<code>null</code> or empty)
* @param existingPropertyNames the existing property names used to check for a
duplicate (can be <code>null</code> or empty)
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java 2012-03-30
18:35:02 UTC (rev 39948)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/CndValidatorTest.java 2012-03-30
22:16:19 UTC (rev 39949)
@@ -7,6 +7,7 @@
*/
package org.jboss.tools.modeshape.jcr.cnd;
+import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import org.jboss.tools.modeshape.jcr.ChildNodeDefinition;
@@ -393,4 +394,24 @@
this.nodeTypeDefinition.getState(NodeTypeDefinition.PropertyName.SUPERTYPES),
this.nodeTypeDefinition.getSupertypes()).isError());
}
+
+ @Test
+ public void shouldValidatePathsWithNoErrors() {
+ final String PROP_NAME = "testProperty"; //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A", PROP_NAME).isError());
//$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/B/C[1]/D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/B/C[1]/../../D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/B/C[1]/././D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/B/C[1]/../D[2]/./E/..",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/../../../B",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("../../B", PROP_NAME).isError());
//$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("A/./../../B/.",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/.", PROP_NAME).isError());
//$NON-NLS-1$
+ assertFalse(CndValidator.validatePath(".", PROP_NAME).isError());
//$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/A", PROP_NAME).isError());
//$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/A/B/C[1]/D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/A/B/C[1]/../../D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/A/B/C[1]/././D[2]",
PROP_NAME).isError()); //$NON-NLS-1$
+ assertFalse(CndValidator.validatePath("/A/B/C[1]/../D[2]/./E/..",
PROP_NAME).isError()); //$NON-NLS-1$
+ }
}
Modified:
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java
===================================================================
---
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java 2012-03-30
18:35:02 UTC (rev 39948)
+++
trunk/modeshape/tests/org.jboss.tools.modeshape.jcr.test/src/org/jboss/tools/modeshape/jcr/cnd/NodeTypeDefinitionTest.java 2012-03-30
22:16:19 UTC (rev 39949)
@@ -12,15 +12,11 @@
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
-import java.util.Collection;
-import java.util.Collections;
-
import org.jboss.tools.modeshape.jcr.ChildNodeDefinition;
import org.jboss.tools.modeshape.jcr.Listener;
import org.jboss.tools.modeshape.jcr.NodeTypeDefinition;
import org.jboss.tools.modeshape.jcr.NodeTypeDefinition.PropertyName;
import org.jboss.tools.modeshape.jcr.PropertyDefinition;
-import org.jboss.tools.modeshape.jcr.QualifiedName;
import org.jboss.tools.modeshape.jcr.Utils;
import org.jboss.tools.modeshape.jcr.attributes.AttributeState.Value;
import org.junit.Before;
@@ -183,29 +179,6 @@
}
@Test
- public void shouldClearChildNodeDefinitions() {
-
assertTrue(this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition));
- assertTrue(this.nodeTypeDefinition.clearChildNodeDefinitions());
- assertEquals(0, this.nodeTypeDefinition.getChildNodeDefinitions().size());
- assertEquals(0,
this.nodeTypeDefinition.getDeclaredChildNodeDefinitions().length);
- }
-
- @Test
- public void shouldClearPropertyDefinitions() {
-
assertTrue(this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition));
- assertTrue(this.nodeTypeDefinition.clearPropertyDefinitions());
- assertEquals(0, this.nodeTypeDefinition.getPropertyDefinitions().size());
- assertEquals(0,
this.nodeTypeDefinition.getDeclaredPropertyDefinitions().length);
- }
-
- @Test
- public void shouldClearSuperTypes() {
- assertTrue(this.nodeTypeDefinition.addSuperType("superType"));
//$NON-NLS-1$
- assertTrue(this.nodeTypeDefinition.clearSuperTypes());
- assertEquals(0, this.nodeTypeDefinition.getDeclaredSupertypeNames().length);
- }
-
- @Test
public void shouldNotAllowDuplicateSuperType() {
final String SUPER_TYPE = "superType"; //$NON-NLS-1$
assertTrue(this.nodeTypeDefinition.addSuperType(SUPER_TYPE));
@@ -228,21 +201,6 @@
}
@Test
- public void shouldNotClearChildNodeDefinitionsWhenEmpty() {
- assertFalse(this.nodeTypeDefinition.clearChildNodeDefinitions());
- }
-
- @Test
- public void shouldNotClearPropertyDefinitionsWhenEmpty() {
- assertFalse(this.nodeTypeDefinition.clearPropertyDefinitions());
- }
-
- @Test
- public void shouldNotClearSuperTypesWhenEmpty() {
- assertFalse(this.nodeTypeDefinition.clearSuperTypes());
- }
-
- @Test
public void shouldNotHaveChildNodeDefinitionsAfterConstruction() {
assertEquals(0, this.nodeTypeDefinition.getChildNodeDefinitions().size());
}
@@ -357,52 +315,6 @@
}
@Test
- public void shouldReceiveEventAfterClearingChildNodeDefinitions() {
-
assertTrue(this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition));
- final Collection<ChildNodeDefinition> oldValue =
Collections.singletonList(this.childNodeDefinition);
-
- final Listener l = new Listener();
- assertTrue(this.nodeTypeDefinition.addListener(l));
-
- assertTrue(this.nodeTypeDefinition.clearChildNodeDefinitions());
- assertEquals(1, l.getCount());
- assertEquals(PropertyName.CHILD_NODES.toString(), l.getPropertyName());
- assertNull(l.getNewValue());
- assertEquals(oldValue, l.getOldValue());
- }
-
- @Test
- public void shouldReceiveEventAfterClearingPropertyDefinitions() {
-
assertTrue(this.nodeTypeDefinition.addPropertyDefinition(this.propertyDefinition));
- final Collection<PropertyDefinition> oldValue =
Collections.singletonList(this.propertyDefinition);
-
- final Listener l = new Listener();
- assertTrue(this.nodeTypeDefinition.addListener(l));
-
- assertTrue(this.nodeTypeDefinition.clearPropertyDefinitions());
- assertEquals(1, l.getCount());
- assertEquals(PropertyName.PROPERTY_DEFINITIONS.toString(), l.getPropertyName());
- assertNull(l.getNewValue());
- assertEquals(oldValue, l.getOldValue());
- }
-
- @Test
- public void shouldReceiveEventAfterClearingSuperTypes() {
- final String SUPER_TYPE = "superType"; //$NON-NLS-1$
- assertTrue(this.nodeTypeDefinition.addSuperType(SUPER_TYPE));
- final Collection<QualifiedName> oldValue =
this.nodeTypeDefinition.getSupertypes();
-
- final Listener l = new Listener();
- assertTrue(this.nodeTypeDefinition.addListener(l));
-
- assertTrue(this.nodeTypeDefinition.clearSuperTypes());
- assertEquals(1, l.getCount());
- assertEquals(PropertyName.SUPERTYPES.toString(), l.getPropertyName());
- assertNull(l.getNewValue());
- assertEquals(oldValue, l.getOldValue());
- }
-
- @Test
public void shouldReceiveEventAfterRemovingChildNodeDefinition() {
assertTrue(this.nodeTypeDefinition.addChildNodeDefinition(this.childNodeDefinition));