KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > openbravo > xmlEngine > TagValue


1 /*
2  ************************************************************************************
3  * Copyright (C) 2001-2006 Openbravo S.L.
4  * Licensed under the Apache Software License version 2.0
5  * You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0
6  * Unless required by applicable law or agreed to in writing, software distributed
7  * under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
8  * CONDITIONS OF ANY KIND, either express or implied. See the License for the
9  * specific language governing permissions and limitations under the License.
10  ************************************************************************************
11 */

12 package org.openbravo.xmlEngine;
13
14 import java.util.Vector JavaDoc;
15 import java.util.Enumeration JavaDoc;
16
17 import org.apache.log4j.Logger ;
18
19 class TagValue implements XmlComponentValue {
20   protected TagTemplate tagTemplate;
21   protected Vector JavaDoc<AttributeItemValue> attributeVectorValue; // vector of AttributeItemValues
22

23   static Logger log4jTagValue = Logger.getLogger(TagValue.class);
24
25   public TagValue(TagTemplate tagTemplate, XmlDocument xmlDocument) {
26     this.tagTemplate = tagTemplate;
27     attributeVectorValue = new Vector JavaDoc<AttributeItemValue>();
28     for (Enumeration JavaDoc<AttributeItemTemplate> e1 = tagTemplate.attributeVectorTemplate.elements() ; e1.hasMoreElements();) {
29       AttributeItemTemplate attributeItemTemplate = e1.nextElement();
30       AttributeItemValue attributeItemValue = attributeItemTemplate.createAttributeItemValue(xmlDocument);
31       attributeVectorValue.addElement(attributeItemValue);
32       log4jTagValue.debug("TagValue: " + attributeItemValue.attributeItemTemplate.name);
33     }
34
35   }
36
37   public String JavaDoc print() {
38     String JavaDoc character = "";
39     if (tagTemplate.tag().equals("DIVFO") || tagTemplate.tag().endsWith("_TMP")) return "";
40     character = "<" + tagTemplate.tag();
41     for (Enumeration JavaDoc<AttributeItemValue> e = attributeVectorValue.elements() ; e.hasMoreElements() ;) {
42       AttributeItemValue attribute = e.nextElement();
43       if (attribute.attributeItemTemplate.attributeBoolean) {
44         String JavaDoc myValue = "";
45         try {
46           myValue = attribute.valueToCompare.print();
47         } catch (Exception JavaDoc ex) {
48           myValue = "";
49         }
50         if (attribute.value.print().equals(myValue)) {
51           character += " " + attribute.attributeItemTemplate.name;
52         }
53       } else {
54         character += attribute.print();
55       }
56     }
57     character += ">";
58     return character;
59   }
60
61   public String JavaDoc printPrevious() {
62     if (tagTemplate.tag().equals("DIVFO")) return "";
63     String JavaDoc character = "<" + tagTemplate.tag();
64     for (Enumeration JavaDoc<AttributeItemValue> e = attributeVectorValue.elements() ; e.hasMoreElements() ;) {
65       AttributeItemValue attribute = e.nextElement();
66       character = character + attribute.printPrevious();
67     }
68     character = character + ">";
69     return character;
70   }
71
72   // in this class donĀ“t have sense the prints Simple
73
public String JavaDoc printSimple() {
74     return print();
75   }
76
77   public String JavaDoc printPreviousSimple() {
78     return printPrevious();
79   }}
80
Popular Tags