1 package JSci.mathml; 2 3 import org.w3c.dom.*; 4 import org.w3c.dom.mathml.*; 5 6 11 public class MathMLContentTokenImpl extends MathMLElementImpl implements MathMLContentToken { 12 15 public MathMLContentTokenImpl(MathMLDocumentImpl owner, String qualifiedName) { 16 super (owner, qualifiedName); 17 } 18 19 public String getDefinitionURL() { 20 return getAttribute("definitionURL"); 21 } 22 public void setDefinitionURL(String definitionURL) { 23 setAttribute("definitionURL", definitionURL); 24 } 25 26 public String getEncoding() { 27 return getAttribute("encoding"); 28 } 29 public void setEncoding(String encoding) { 30 setAttribute("encoding", encoding); 31 } 32 33 public MathMLNodeList getArguments() { 34 return new MathMLNodeList() { 35 public int getLength() { 36 return getArgumentsGetLength(); 37 } 38 public Node item(int index) { 39 return getArgumentsItem(index); 40 } 41 }; 42 } 43 public Node getArgument(int index) { 44 Node arg = getArgumentsItem(index-1); 45 46 return arg; 47 } 48 public Node setArgument(Node newArgument, int index) { 49 final int argsLength = getArgumentsGetLength(); 50 51 return replaceChild(newArgument, getArgumentsItem(index-1)); 52 } 53 public Node insertArgument(Node newArgument, int index) { 54 final int argsLength = getArgumentsGetLength(); 55 56 return insertBefore(newArgument, getArgumentsItem(index-1)); 57 } 58 public Node removeArgument(int index) { 59 Node arg = getArgumentsItem(index-1); 60 61 return removeChild(arg); 62 } 63 public void deleteArgument(int index) { 64 removeArgument(index); 65 } 66 67 private int getArgumentsGetLength() { 68 final int length = getLength(); 69 int numArgs = 0; 70 71 for (int i = 0; i < length; i++) { 72 String localName = item(i).getLocalName(); 73 if (!(localName != null && localName.equals("sep"))) { 74 numArgs++; 75 } 76 } 77 return numArgs; 78 } 79 private Node getArgumentsItem(int index) { 80 final int argsLength = getArgumentsGetLength(); 81 82 if ((index < 0) || (index >= argsLength)) 83 return null; 84 85 Node node = null; 86 int n = -1; 87 for (int i = 0; n < index; i++) { 88 node = item(i); 89 String localName = item(i).getLocalName(); 90 if (!(localName != null && localName.equals("sep"))) { 91 n++; 92 } 93 } 94 return node; 95 } 96 } 97 98 | Popular Tags |