52 |
import org.w3c.dom.NodeList; |
import org.w3c.dom.NodeList; |
53 |
import org.w3c.dom.TypeInfo; |
import org.w3c.dom.TypeInfo; |
54 |
import org.w3c.dom.UserDataHandler; |
import org.w3c.dom.UserDataHandler; |
55 |
|
import javax.imageio.metadata.IIOMetadataFormatImpl.IIOMetadataNodeAttr; |
56 |
|
|
57 |
public class IIOMetadataNode |
public class IIOMetadataNode |
58 |
implements Element, NodeList |
implements Element, NodeList |
62 |
private List children = new ArrayList(); |
private List children = new ArrayList(); |
63 |
private IIOMetadataNode parent; |
private IIOMetadataNode parent; |
64 |
private Object obj; |
private Object obj; |
65 |
|
|
66 |
|
/** |
67 |
|
* Simple NamedNodeMap class for IIOMetadataNode. |
68 |
|
* |
69 |
|
* @author jlquinn |
70 |
|
*/ |
71 |
|
private class IIONamedNodeMap implements NamedNodeMap |
72 |
|
{ |
73 |
|
HashMap attrs; |
74 |
|
|
75 |
|
/** |
76 |
|
* @param attrs |
77 |
|
* @param node |
78 |
|
*/ |
79 |
|
public IIONamedNodeMap(HashMap attrs) |
80 |
|
{ |
81 |
|
this.attrs = attrs; |
82 |
|
} |
83 |
|
|
84 |
|
/* (non-Javadoc) |
85 |
|
* @see org.w3c.dom.NamedNodeMap#getNamedItem(java.lang.String) |
86 |
|
*/ |
87 |
|
public Node getNamedItem(String name) |
88 |
|
{ |
89 |
|
return (Node)attrs.get(name); |
90 |
|
} |
91 |
|
|
92 |
|
/* (non-Javadoc) |
93 |
|
* @see org.w3c.dom.NamedNodeMap#setNamedItem(org.w3c.dom.Node) |
94 |
|
*/ |
95 |
|
public Node setNamedItem(Node arg) throws DOMException |
96 |
|
{ |
97 |
|
if (arg instanceof IIOMetadataNodeAttr) |
98 |
|
{ |
99 |
|
IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr) arg; |
100 |
|
// The only code that can successfully do this is in this package. |
101 |
|
if (attr.owner != null) |
102 |
|
throw new DOMException(DOMException.INUSE_ATTRIBUTE_ERR, ""); |
103 |
|
return (Node)attrs.put(attr.name, attr); |
104 |
|
} |
105 |
|
// Anything else gets treated as an invalid op. |
106 |
|
throw new DOMException(DOMException.HIERARCHY_REQUEST_ERR, ""); |
107 |
|
} |
108 |
|
|
109 |
|
/* (non-Javadoc) |
110 |
|
* @see org.w3c.dom.NamedNodeMap#removeNamedItem(java.lang.String) |
111 |
|
*/ |
112 |
|
public Node removeNamedItem(String name) throws DOMException |
113 |
|
{ |
114 |
|
return (Node)attrs.remove(name); |
115 |
|
} |
116 |
|
|
117 |
|
/* (non-Javadoc) |
118 |
|
* @see org.w3c.dom.NamedNodeMap#item(int) |
119 |
|
*/ |
120 |
|
public Node item(int index) |
121 |
|
{ |
122 |
|
return (Node)attrs.values().toArray()[index]; |
123 |
|
} |
124 |
|
|
125 |
|
/* (non-Javadoc) |
126 |
|
* @see org.w3c.dom.NamedNodeMap#getLength() |
127 |
|
*/ |
128 |
|
public int getLength() |
129 |
|
{ |
130 |
|
return attrs.size(); |
131 |
|
} |
132 |
|
|
133 |
|
/* (non-Javadoc) |
134 |
|
* @see org.w3c.dom.NamedNodeMap#getNamedItemNS(java.lang.String, java.lang.String) |
135 |
|
*/ |
136 |
|
public Node getNamedItemNS(String namespaceURI, String localName) |
137 |
|
{ |
138 |
|
return getNamedItem(localName); |
139 |
|
} |
140 |
|
|
141 |
|
/* (non-Javadoc) |
142 |
|
* @see org.w3c.dom.NamedNodeMap#setNamedItemNS(org.w3c.dom.Node) |
143 |
|
*/ |
144 |
|
public Node setNamedItemNS(Node arg) throws DOMException |
145 |
|
{ |
146 |
|
return setNamedItem(arg); |
147 |
|
} |
148 |
|
|
149 |
|
/* (non-Javadoc) |
150 |
|
* @see org.w3c.dom.NamedNodeMap#removeNamedItemNS(java.lang.String, java.lang.String) |
151 |
|
*/ |
152 |
|
public Node removeNamedItemNS(String namespaceURI, String localName) |
153 |
|
throws DOMException |
154 |
|
{ |
155 |
|
return removeNamedItem(localName); |
156 |
|
} |
157 |
|
} |
158 |
|
|
159 |
|
/** |
160 |
|
* Simple NodeList implementation for IIOMetadataNode. |
161 |
|
* |
162 |
|
* @author jlquinn |
163 |
|
* |
164 |
|
*/ |
165 |
|
private class IIONodeList implements NodeList |
166 |
|
{ |
167 |
|
List children = new ArrayList(); |
168 |
|
|
169 |
|
/* (non-Javadoc) |
170 |
|
* @see org.w3c.dom.NodeList#item(int) |
171 |
|
*/ |
172 |
|
public Node item(int index) |
173 |
|
{ |
174 |
|
return (index < children.size()) ? (Node)children.get(index) : null; |
175 |
|
} |
176 |
|
|
177 |
|
/* (non-Javadoc) |
178 |
|
* @see org.w3c.dom.NodeList#getLength() |
179 |
|
*/ |
180 |
|
public int getLength() |
181 |
|
{ |
182 |
|
return children.size(); |
183 |
|
} |
184 |
|
} |
185 |
|
|
186 |
public IIOMetadataNode() |
public IIOMetadataNode() |
187 |
{ |
{ |
188 |
// Do nothing here. |
// Do nothing here. |
192 |
{ |
{ |
193 |
name = nodename; |
name = nodename; |
194 |
} |
} |
195 |
|
|
196 |
public Object getUserObject() |
public Object getUserObject() |
197 |
{ |
{ |
198 |
return obj; |
return obj; |
199 |
} |
} |
200 |
|
|
201 |
public void setUserObject(Object o) |
public void setUserObject(Object o) |
202 |
{ |
{ |
203 |
obj = o; |
obj = o; |
206 |
public short compareDocumentPosition(Node other) |
public short compareDocumentPosition(Node other) |
207 |
throws DOMException |
throws DOMException |
208 |
{ |
{ |
209 |
throw new Error("not implemented"); |
return Element.DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC; |
210 |
} |
} |
211 |
|
|
212 |
/* (non-Javadoc) |
/* (non-Javadoc) |
225 |
{ |
{ |
226 |
String val = getAttribute(name); |
String val = getAttribute(name); |
227 |
if (val != null) |
if (val != null) |
228 |
return new IIOAttr(name, val, this); |
return new IIOMetadataNodeAttr(this, name, val); |
229 |
return null; |
return null; |
230 |
} |
} |
231 |
|
|
247 |
|
|
248 |
public String getBaseURI() |
public String getBaseURI() |
249 |
{ |
{ |
250 |
throw new Error("not implemented"); |
return null; |
251 |
} |
} |
252 |
|
|
253 |
// Recursive function for assembling a node list. |
// Recursive function for assembling a node list. |
338 |
if (attr != null) |
if (attr != null) |
339 |
attr.setValue(value); |
attr.setValue(value); |
340 |
else |
else |
341 |
attrs.put(name, new IIOAttr(name, value, this)); |
attrs.put(name, new IIOMetadataNodeAttr(this, name, value)); |
342 |
} |
} |
343 |
|
|
344 |
/* (non-Javadoc) |
/* (non-Javadoc) |
416 |
// clone attrs |
// clone attrs |
417 |
for (Iterator it = attrs.values().iterator(); it.hasNext();) |
for (Iterator it = attrs.values().iterator(); it.hasNext();) |
418 |
{ |
{ |
419 |
IIOAttr attr = (IIOAttr)it.next(); |
IIOMetadataNodeAttr attr = (IIOMetadataNodeAttr)it.next(); |
420 |
newnode.attrs.put(attr.name, attr.cloneNode(deep)); |
newnode.attrs.put(attr.name, attr.cloneNode(deep)); |
421 |
attr.owner = newnode; |
attr.owner = newnode; |
422 |
} |
} |
442 |
|
|
443 |
public Object getFeature(String feature, String version) |
public Object getFeature(String feature, String version) |
444 |
{ |
{ |
445 |
throw new Error("not implemented"); |
return null; |
446 |
} |
} |
447 |
|
|
448 |
/* (non-Javadoc) |
/* (non-Javadoc) |
553 |
|
|
554 |
public TypeInfo getSchemaTypeInfo() |
public TypeInfo getSchemaTypeInfo() |
555 |
{ |
{ |
556 |
throw new Error("not implemented"); |
return null; |
557 |
} |
} |
558 |
|
|
559 |
public String getTextContent() |
public String getTextContent() |
560 |
throws DOMException |
throws DOMException |
561 |
{ |
{ |
562 |
throw new Error("not implemented"); |
return null; |
563 |
} |
} |
564 |
|
|
565 |
public Object getUserData(String key) |
public Object getUserData(String key) |
566 |
{ |
{ |
567 |
throw new Error("not implemented"); |
return null; |
568 |
} |
} |
569 |
|
|
570 |
/* (non-Javadoc) |
/* (non-Javadoc) |
603 |
|
|
604 |
public boolean isDefaultNamespace(String namespaceURI) |
public boolean isDefaultNamespace(String namespaceURI) |
605 |
{ |
{ |
606 |
throw new Error("not implemented"); |
return true; |
607 |
} |
} |
608 |
|
|
609 |
public boolean isEqualNode(Node arg) |
public boolean isEqualNode(Node arg) |
610 |
{ |
{ |
611 |
throw new Error("not implemented"); |
return true; |
612 |
} |
} |
613 |
|
|
614 |
public boolean isSameNode(Node other) |
public boolean isSameNode(Node other) |
627 |
|
|
628 |
public String lookupNamespaceURI(String prefix) |
public String lookupNamespaceURI(String prefix) |
629 |
{ |
{ |
630 |
throw new Error("not implemented"); |
return null; |
631 |
} |
} |
632 |
|
|
633 |
public String lookupPrefix(String namespaceURI) |
public String lookupPrefix(String namespaceURI) |
634 |
{ |
{ |
635 |
throw new Error("not implemented"); |
return null; |
636 |
} |
} |
637 |
|
|
638 |
/* (non-Javadoc) |
/* (non-Javadoc) |
671 |
public void setIdAttribute(String name, boolean isId) |
public void setIdAttribute(String name, boolean isId) |
672 |
throws DOMException |
throws DOMException |
673 |
{ |
{ |
|
throw new Error("not implemented"); |
|
674 |
} |
} |
675 |
|
|
676 |
public void setIdAttributeNode(Attr idAttr, boolean isId) |
public void setIdAttributeNode(Attr idAttr, boolean isId) |
677 |
throws DOMException |
throws DOMException |
678 |
{ |
{ |
|
throw new Error("not implemented"); |
|
679 |
} |
} |
680 |
|
|
681 |
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) |
public void setIdAttributeNS(String namespaceURI, String localName, boolean isId) |
682 |
throws DOMException |
throws DOMException |
683 |
{ |
{ |
|
throw new Error("not implemented"); |
|
684 |
} |
} |
685 |
|
|
686 |
/* (non-Javadoc) |
/* (non-Javadoc) |
700 |
public void setTextContent(String textContent) |
public void setTextContent(String textContent) |
701 |
throws DOMException |
throws DOMException |
702 |
{ |
{ |
|
throw new Error("not implemented"); |
|
703 |
} |
} |
704 |
|
|
705 |
public Object setUserData(String key, Object data, UserDataHandler handler) |
public Object setUserData(String key, Object data, UserDataHandler handler) |
706 |
{ |
{ |
707 |
throw new Error("not implemented"); |
return null; |
708 |
} |
} |
709 |
} |
} |