📄 xmpnode.java
字号:
} } catch (XMPException e) { // cannot happen (duplicate childs/quals do not exist in this node) assert false; } } /** * Renders this node and the tree unter this node in a human readable form. * @param recursive Flag is qualifier and child nodes shall be rendered too * @return Returns a multiline string containing the dump. */ public String dumpNode(boolean recursive) { StringBuffer result = new StringBuffer(512); this.dumpNode(result, recursive, 0, 0); return result.toString(); } /** * @see Comparable#compareTo(Object) */ public int compareTo(Object xmpNode) { if (getOptions().isSchemaNode()) { return this.value.compareTo(((XMPNode) xmpNode).getValue()); } else { return this.name.compareTo(((XMPNode) xmpNode).getName()); } } /** * @return Returns the name. */ public String getName() { return name; } /** * @param name The name to set. */ public void setName(String name) { this.name = name; } /** * @return Returns the value. */ public String getValue() { return value; } /** * @param value The value to set. */ public void setValue(String value) { this.value = value; } /** * @return Returns the options. */ public PropertyOptions getOptions() { if (options == null) { options = new PropertyOptions(); } return options; } /** * Updates the options of the node. * @param options the options to set. */ public void setOptions(PropertyOptions options) { this.options = options; } /** * @return Returns the implicit flag */ public boolean isImplicit() { return implicit; } /** * @param implicit Sets the implicit node flag */ public void setImplicit(boolean implicit) { this.implicit = implicit; } /** * @return Returns if the node contains aliases (applies only to schema nodes) */ public boolean getHasAliases() { return hasAliases; } /** * @param hasAliases sets the flag that the node contains aliases */ public void setHasAliases(boolean hasAliases) { this.hasAliases = hasAliases; } /** * @return Returns if the node contains aliases (applies only to schema nodes) */ public boolean isAlias() { return alias; } /** * @param alias sets the flag that the node is an alias */ public void setAlias(boolean alias) { this.alias = alias; } /** * @return the hasValueChild */ public boolean getHasValueChild() { return hasValueChild; } /** * @param hasValueChild the hasValueChild to set */ public void setHasValueChild(boolean hasValueChild) { this.hasValueChild = hasValueChild; } /** * Sorts the complete datamodel according to the following rules: * <ul> * <li>Nodes at one level are sorted by name, that is prefix + local name * <li>Starting at the root node the children and qualifier are sorted recursively, * which the following exceptions. * <li>Sorting will not be used for arrays. * <li>Within qualifier "xml:lang" and/or "rdf:type" stay at the top in that order, * all others are sorted. * </ul> */ public void sort() { // sort qualifier if (hasQualifier()) { XMPNode[] quals = (XMPNode[]) getQualifier() .toArray(new XMPNode[getQualifierLength()]); int sortFrom = 0; while ( quals.length > sortFrom && (XMPConst.XML_LANG.equals(quals[sortFrom].getName()) || "rdf:type".equals(quals[sortFrom].getName())) ) { quals[sortFrom].sort(); sortFrom++; } Arrays.sort(quals, sortFrom, quals.length); ListIterator it = qualifier.listIterator(); for (int j = 0; j < quals.length; j++) { it.next(); it.set(quals[j]); quals[j].sort(); } } // sort children if (hasChildren()) { if (!getOptions().isArray()) { Collections.sort(children); } for (Iterator it = iterateChildren(); it.hasNext();) { ((XMPNode) it.next()).sort(); } } } //------------------------------------------------------------------------------ private methods /** * Dumps this node and its qualifier and children recursively. * <em>Note:</em> It creats empty options on every node. * * @param result the buffer to append the dump. * @param recursive Flag is qualifier and child nodes shall be rendered too * @param indent the current indent level. * @param index the index within the parent node (important for arrays) */ private void dumpNode(StringBuffer result, boolean recursive, int indent, int index) { // write indent for (int i = 0; i < indent; i++) { result.append('\t'); } // render Node if (parent != null) { if (getOptions().isQualifier()) { result.append('?'); result.append(name); } else if (getParent().getOptions().isArray()) { result.append('['); result.append(index); result.append(']'); } else { result.append(name); } } else { // applies only to the root node result.append("ROOT NODE"); if (name != null && name.length() > 0) { // the "about" attribute result.append(" ("); result.append(name); result.append(')'); } } if (value != null && value.length() > 0) { result.append(" = \""); result.append(value); result.append('"'); } // render options if at least one is set if (getOptions().containsOneOf(0xffffffff)) { result.append("\t("); result.append(getOptions().toString()); result.append(" : "); result.append(getOptions().getOptionsString()); result.append(')'); } result.append('\n'); // render qualifier if (recursive && hasQualifier()) { XMPNode[] quals = (XMPNode[]) getQualifier() .toArray(new XMPNode[getQualifierLength()]); int i = 0; while (quals.length > i && (XMPConst.XML_LANG.equals(quals[i].getName()) || "rdf:type".equals(quals[i].getName())) ) { i++; } Arrays.sort(quals, i, quals.length); for (i = 0; i < quals.length; i++) { XMPNode qualifier = quals[i]; qualifier.dumpNode(result, recursive, indent + 2, i + 1); } } // render children if (recursive && hasChildren()) { XMPNode[] children = (XMPNode[]) getChildren() .toArray(new XMPNode[getChildrenLength()]); if (!getOptions().isArray()) { Arrays.sort(children); } for (int i = 0; i < children.length; i++) { XMPNode child = children[i]; child.dumpNode(result, recursive, indent + 1, i + 1); } } } /** * @return Returns whether this node is a language qualifier. */ private boolean isLanguageNode() { return XMPConst.XML_LANG.equals(name); } /** * @return Returns whether this node is a type qualifier. */ private boolean isTypeNode() { return "rdf:type".equals(name); } /** * <em>Note:</em> This method should always be called when accessing 'children' to be sure * that its initialized. * @return Returns list of children that is lazy initialized. */ private List getChildren() { if (children == null) { children = new ArrayList(0); } return children; } /** * @return Returns a read-only copy of child nodes list. */ public List getUnmodifiableChildren() { return Collections.unmodifiableList(new ArrayList(getChildren())); } /** * @return Returns list of qualifier that is lazy initialized. */ private List getQualifier() { if (qualifier == null) { qualifier = new ArrayList(0); } return qualifier; } /** * Sets the parent node, this is solely done by <code>addChild(...)</code> * and <code>addQualifier()</code>. * * @param parent * Sets the parent node. */ protected void setParent(XMPNode parent) { this.parent = parent; } /** * Internal find. * @param list the list to search in * @param expr the search expression * @return Returns the found node or <code>nulls</code>. */ private XMPNode find(List list, String expr) { if (list != null) { for (Iterator it = list.iterator(); it.hasNext();) { XMPNode child = (XMPNode) it.next(); if (child.getName().equals(expr)) { return child; } } } return null; } /** * Checks that a node name is not existing on the same level, except for array items. * @param childName the node name to check * @throws XMPException Thrown if a node with the same name is existing. */ private void assertChildNotExisting(String childName) throws XMPException { if (!XMPConst.ARRAY_ITEM_NAME.equals(childName) && findChildByName(childName) != null) { throw new XMPException("Duplicate property or field node '" + childName + "'", XMPError.BADXMP); } } /** * Checks that a qualifier name is not existing on the same level. * @param qualifierName the new qualifier name * @throws XMPException Thrown if a node with the same name is existing. */ private void assertQualifierNotExisting(String qualifierName) throws XMPException { if (!XMPConst.ARRAY_ITEM_NAME.equals(qualifierName) && findQualifierByName(qualifierName) != null) { throw new XMPException("Duplicate '" + qualifierName + "' qualifier", XMPError.BADXMP); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -