📄 predefinednodetypetest.java
字号:
" not supported by this repository implementation."); } } catch (RepositoryException e) { fail(e.getMessage()); } } /** * Creates and returns a spec string for the given node type definition. * The returned spec string follows the node type definition format * used in the JSR 170 specification. * * @param type node type definition * @return spec string * @throws RepositoryException on repository errors */ private static String getNodeTypeSpec(NodeType type) throws RepositoryException { String typeName = type.getName(); StringWriter buffer = new StringWriter(); PrintWriter writer = new PrintWriter(buffer); writer.println("NodeTypeName"); writer.println(" " + typeName); writer.println("Supertypes"); NodeType[] supertypes = type.getDeclaredSupertypes(); Arrays.sort(supertypes, NODE_TYPE_COMPARATOR); boolean hasPrinted = false; for (int i = 0; i < supertypes.length; i++) { String name = supertypes[i].getName(); if (name.startsWith("nt:") || (name.equals("mix:referenceable") && (typeName.equals("mix:versionable") || typeName.equals("nt:resource") || typeName.equals("nt:versionHistory") || typeName.equals("nt:version") || typeName.equals("nt:frozenNode")))) { writer.println(" " + supertypes[i].getName()); hasPrinted = true; } } if (!hasPrinted) { writer.println(" []"); } writer.println("IsMixin"); writer.println(" " + type.isMixin()); writer.println("HasOrderableChildNodes"); writer.println(" " + type.hasOrderableChildNodes()); writer.println("PrimaryItemName"); writer.println(" " + type.getPrimaryItemName()); NodeDefinition[] nodes = type.getDeclaredChildNodeDefinitions(); Arrays.sort(nodes, NODE_DEF_COMPARATOR); for (int i = 0; i < nodes.length; i++) { writer.print(getChildNodeDefSpec(nodes[i])); } PropertyDefinition[] properties = type.getDeclaredPropertyDefinitions(); Arrays.sort(properties, PROPERTY_DEF_COMPARATOR); for (int i = 0; i < properties.length; i++) { writer.print(getPropertyDefSpec(properties[i])); } return buffer.toString(); } /** * Creates and returns a spec string for the given node definition. * The returned spec string follows the child node definition format * used in the JSR 170 specification. * * @param node child node definition * @return spec string */ private static String getChildNodeDefSpec(NodeDefinition node) { StringWriter buffer = new StringWriter(); PrintWriter writer = new PrintWriter(buffer); writer.println("ChildNodeDefinition"); if (node.getName().equals("*")) { writer.println(" Name \"*\""); } else { writer.println(" Name " + node.getName()); } writer.print(" RequiredPrimaryTypes ["); NodeType[] types = node.getRequiredPrimaryTypes(); Arrays.sort(types, NODE_TYPE_COMPARATOR); for (int j = 0; j < types.length; j++) { if (j > 0) { writer.print(','); } writer.print(types[j].getName()); } writer.println("]"); if (node.getDefaultPrimaryType() != null) { writer.println(" DefaultPrimaryType " + node.getDefaultPrimaryType().getName()); } else { writer.println(" DefaultPrimaryType null"); } writer.println(" AutoCreated " + node.isAutoCreated()); writer.println(" Mandatory " + node.isMandatory()); writer.println(" OnParentVersion " + OnParentVersionAction.nameFromValue(node.getOnParentVersion())); writer.println(" Protected " + node.isProtected()); writer.println(" SameNameSiblings " + node.allowsSameNameSiblings()); return buffer.toString(); } /** * Creates and returns a spec string for the given property definition. * The returned spec string follows the property definition format * used in the JSR 170 specification. * * @param property property definition * @return spec string * @throws RepositoryException on repository errors */ private static String getPropertyDefSpec(PropertyDefinition property) throws RepositoryException { StringWriter buffer = new StringWriter(); PrintWriter writer = new PrintWriter(buffer); writer.println("PropertyDefinition"); if (property.getName().equals("*")) { writer.println(" Name \"*\""); } else { writer.println(" Name " + property.getName()); } String type = PropertyType.nameFromValue(property.getRequiredType()); writer.println(" RequiredType " + type.toUpperCase()); Value[] values = property.getDefaultValues(); if (values != null && values.length > 0) { writer.print(" DefaultValues ["); for (int j = 0; j < values.length; j++) { if (j > 0) { writer.print(','); } writer.print(values[j].getString()); } writer.println("]"); } else { writer.println(" DefaultValues null"); } writer.println(" AutoCreated " + property.isAutoCreated()); writer.println(" Mandatory " + property.isMandatory()); String action = OnParentVersionAction.nameFromValue( property.getOnParentVersion()); writer.println(" OnParentVersion " + action); writer.println(" Protected " + property.isProtected()); writer.println(" Multiple " + property.isMultiple()); return buffer.toString(); } /** * Replaces platform-dependant line-separators in <code>stringValue</code> * with "\n". * * @param stringValue string to normalize * @return the normalized string */ private String normalizeLineSeparators(String stringValue) { // Replace "\r\n" (Windows format) with "\n" (Unix format) stringValue = stringValue.replaceAll("\r\n", "\n"); // Replace "\r" (Mac format) with "\n" (Unix format) stringValue = stringValue.replaceAll("\r", "\n"); return stringValue; } /** * Comparator for ordering node definition arrays. Node definitions are * ordered by name, with the wildcard item definition ("*") ordered last. */ private static final Comparator NODE_DEF_COMPARATOR = new Comparator() { public int compare(Object a, Object b) { NodeDefinition nda = (NodeDefinition) a; NodeDefinition ndb = (NodeDefinition) b; if (nda.getName().equals("*") && !ndb.getName().equals("*")) { return 1; } else if (!nda.getName().equals("*") && ndb.getName().equals("*")) { return -1; } else { return nda.getName().compareTo(ndb.getName()); } } }; /** * Comparator for ordering property definition arrays. Property definitions * are ordered by name, with the wildcard item definition ("*") ordered * last, and isMultiple flag, with <code>isMultiple==true</code> ordered last. */ private static final Comparator PROPERTY_DEF_COMPARATOR = new Comparator() { public int compare(Object a, Object b) { PropertyDefinition pda = (PropertyDefinition) a; PropertyDefinition pdb = (PropertyDefinition) b; if (pda.getName().equals("*") && !pdb.getName().equals("*")) { return 1; } else if (!pda.getName().equals("*") && pdb.getName().equals("*")) { return -1; } int result = pda.getName().compareTo(pdb.getName()); if (result != 0) { return result; } if (pda.isMultiple() && !pdb.isMultiple()) { return 1; } else if (!pda.isMultiple() && pdb.isMultiple()) { return -1; } else { return 0; } } }; /** * Comparator for ordering node type arrays. Node types are ordered by * name, with all primary node types ordered before mixin node types. */ private static final Comparator NODE_TYPE_COMPARATOR = new Comparator() { public int compare(Object a, Object b) { NodeType nta = (NodeType) a; NodeType ntb = (NodeType) b; if (nta.isMixin() && !ntb.isMixin()) { return 1; } else if (!nta.isMixin() && ntb.isMixin()) { return -1; } else { return nta.getName().compareTo(ntb.getName()); } } };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -