01: /*
02: * Copyright 2007 Outerthought bvba and Schaubroeck nv
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: */
16: package org.outerj.daisy.diff.tag;
17:
18: /**
19: * An atom that represents a closing or opening tag.
20: */
21: public class TagAtom implements Atom {
22:
23: private String identifier;
24:
25: private String internalIdentifiers = "";
26:
27: public TagAtom(String s) {
28: if (!isValidAtom(s))
29: throw new IllegalArgumentException(
30: "The given string is not a valid tag");
31: s = s.substring(1, s.length() - 1);
32:
33: if (s.indexOf(' ') > 0) {
34: identifier = s.substring(0, s.indexOf(' '));
35: // TODO check if the +1 is ok!
36: internalIdentifiers = s.substring(s.indexOf(' ') + 1);
37: } else {
38: identifier = s;
39: }
40: }
41:
42: public String getIdentifier() {
43: return identifier;
44: }
45:
46: public String getInternalIdentifiers() {
47: return internalIdentifiers;
48: }
49:
50: public boolean hasInternalIdentifiers() {
51: return internalIdentifiers.length() > 0;
52: }
53:
54: public static boolean isValidTag(String s) {
55: return s.lastIndexOf('<') == 0
56: && s.indexOf('>') == s.length() - 1 && s.length() >= 3;
57: }
58:
59: public String getFullText() {
60: String s = "<" + identifier;
61: if (hasInternalIdentifiers())
62: s += " " + internalIdentifiers;
63: return s += ">";
64: }
65:
66: public boolean isValidAtom(String s) {
67: return isValidTag(s);
68: }
69:
70: @Override
71: public String toString() {
72: return "TagAtom: " + getFullText();
73: }
74:
75: public boolean equalsIdentifier(Atom other) {
76: return other.getIdentifier().equals(getIdentifier());
77: }
78:
79: }
|