1 /**********************************************
2 * Copyright (C) 2010 Lukas Laag
3 * This file is part of lib-gwt-svg.
4 *
5 * libgwtsvg is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU Lesser General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * libgwtsvg is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU Lesser General Public License for more details.
14 *
15 * You should have received a copy of the GNU Lesser General Public License
16 * along with libgwtsvg. If not, see http://www.gnu.org/licenses/
17 **********************************************/
18 /*
19 * Copyright (c) 2004 World Wide Web Consortium,
20 *
21 * (Massachusetts Institute of Technology, European Research Consortium for
22 * Informatics and Mathematics, Keio University). All Rights Reserved. This
23 * work is distributed under the W3C(r) Software License [1] in the hope that
24 * it will be useful, but WITHOUT ANY WARRANTY; without even the implied
25 * warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
26 *
27 * [1] http://www.w3.org/Consortium/Legal/2002/copyright-software-20021231
28 */
29 package org.vectomatic.dom.svg;
30
31 import org.vectomatic.dom.svg.impl.Attr;
32 import org.w3c.dom.DOMException;
33
34 /**
35 * Wrapper class for DOM Attr
36 * @author laaglu
37 */
38 public class OMAttr extends OMNode {
39 /**
40 * Constructor
41 * @param ot the {@link org.vectomatic.dom.svg.impl.Attr} to wrap.
42 */
43 protected OMAttr(Attr ot) {
44 super(ot);
45 }
46 /**
47 * Returns the wrapped {@link org.vectomatic.dom.svg.impl.Attr}
48 * @return the wrapped {@link org.vectomatic.dom.svg.impl.Attr}
49 */
50 public Attr getAttr() {
51 return ot.cast();
52 }
53
54 /**
55 * Returns the name of this attribute. If <code>OMNode.localName</code> is
56 * different from <code>null</code>, this attribute is a qualified name.
57 * @return the attribute name
58 */
59 public final String getName() {
60 return ((Attr)ot).getName();
61 }
62
63 /**
64 * On retrieval, the value of the attribute is returned as a string.
65 * Character and general entity references are replaced with their
66 * values. See also the method <code>getAttribute</code> on the
67 * <code>OMElement</code> interface.
68 * <br>On setting, this creates a <code>OMText</code> node with the unparsed
69 * contents of the string, i.e. any characters that an XML processor
70 * would recognize as markup are instead treated as literal text. See
71 * also the method <code>OMElement.setAttribute()</code>.
72 * <br> Some specialized implementations, such as some [<a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/'>SVG 1.1</a>]
73 * implementations, may do normalization automatically, even after
74 * mutation; in such case, the value on retrieval may differ from the
75 * value on setting.
76 * @return the attribute value
77 */
78 public final String getValue() {
79 return ((Attr)ot).getValue();
80 }
81
82 /**
83 * On retrieval, the value of the attribute is returned as a string.
84 * Character and general entity references are replaced with their
85 * values. See also the method <code>getAttribute</code> on the
86 * <code>OMElement</code> interface.
87 * <br>On setting, this creates a <code>OMText</code> node with the unparsed
88 * contents of the string, i.e. any characters that an XML processor
89 * would recognize as markup are instead treated as literal text. See
90 * also the method <code>OMElement.setAttribute()</code>.
91 * <br> Some specialized implementations, such as some [<a href='http://www.w3.org/TR/2003/REC-SVG11-20030114/'>SVG 1.1</a>]
92 * implementations, may do normalization automatically, even after
93 * mutation; in such case, the value on retrieval may differ from the
94 * value on setting.
95 * @param value the attribute value
96 * @exception DOMException
97 * NO_MODIFICATION_ALLOWED_ERR: Raised when the node is readonly.
98 */
99 public final void setValue(String value) {
100 ((Attr)ot).setValue(value);
101 }
102
103 /**
104 * Returns whether this attribute is known to be of type ID (i.e. to
105 * contain an identifier for its owner element) or not. When it is and
106 * its value is unique, the <code>ownerElement</code> of this attribute
107 * can be retrieved using the method <code>OMDocument.getElementById</code>
108 * . The implementation could use several ways to determine if an
109 * attribute node is known to contain an identifier:
110 * <ul>
111 * <li> If validation
112 * occurred using an XML Schema [<a href='http://www.w3.org/TR/2001/REC-xmlschema-1-20010502/'>XML Schema Part 1</a>]
113 * while loading the document or while invoking
114 * <code>OMDocument.normalizeDocument()</code>, the post-schema-validation
115 * infoset contributions (PSVI contributions) values are used to
116 * determine if this attribute is a schema-determined ID attribute using
117 * the <a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/#term-sdi'>
118 * schema-determined ID</a> definition in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
119 * .
120 * </li>
121 * <li> If validation occurred using a DTD while loading the document or
122 * while invoking <code>OMDocument.normalizeDocument()</code>, the infoset <b>[type definition]</b> value is used to determine if this attribute is a DTD-determined ID
123 * attribute using the <a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/#term-ddi'>
124 * DTD-determined ID</a> definition in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
125 * .
126 * </li>
127 * <li> from the use of the methods <code>OMElement.setIdAttribute()</code>,
128 * <code>OMElement.setIdAttributeNS()</code>, or
129 * <code>OMElement.setIdAttributeNode()</code>, i.e. it is an
130 * user-determined ID attribute;
131 * <p ><b>Note:</b> XPointer framework (see section 3.2 in [<a href='http://www.w3.org/TR/2003/REC-xptr-framework-20030325/'>XPointer</a>]
132 * ) consider the DOM user-determined ID attribute as being part of the
133 * XPointer externally-determined ID definition.
134 * </li>
135 * <li> using mechanisms that
136 * are outside the scope of this specification, it is then an
137 * externally-determined ID attribute. This includes using schema
138 * languages different from XML schema and DTD.
139 * </li>
140 * </ul>
141 * <br> If validation occurred while invoking
142 * <code>OMDocument.normalizeDocument()</code>, all user-determined ID
143 * attributes are reset and all attribute nodes ID information are then
144 * reevaluated in accordance to the schema used. As a consequence, if
145 * the <code>OMAttr.schemaTypeInfo</code> attribute contains an ID type,
146 * <code>isId</code> will always return true.
147 * @since DOM Level 3
148 */
149 public final boolean isId() {
150 return ((Attr)ot).isId();
151 }
152 }