KickJava   Java API By Example, From Geeks To Geeks.

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


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 org.openbravo.utils.Replace;
15
16 import java.util.Enumeration JavaDoc;
17
18 class ParameterValue implements XmlComponentValue {
19   String JavaDoc strValue = null;
20   ParameterTemplate parameterTemplate;
21   XmlComponentValue xmlComponentValue = null;
22
23
24   public ParameterValue(ParameterTemplate ParameterTemplate, XmlDocument xmlDocument) {
25     this.parameterTemplate = ParameterTemplate;
26   }
27
28   public void setXmlComponentValue(XmlDocument xmlDocument) {
29     if (parameterTemplate.xmlComponentTemplate != null) {
30       xmlComponentValue = parameterTemplate.xmlComponentTemplate.createXmlComponentValue(xmlDocument.parentXmlDocument);
31     }
32   }
33
34   private String JavaDoc replace(String JavaDoc strIni) {
35     if (parameterTemplate.vecReplace != null) {
36       String JavaDoc strFin = strIni;
37       for (Enumeration JavaDoc<ReplaceElement> e = parameterTemplate.vecReplace.elements() ; e.hasMoreElements();) {
38         ReplaceElement replaceElement = e.nextElement();
39         strFin = Replace.replace(strFin, replaceElement.replaceWhat, replaceElement.replaceWith);
40       }
41       return strFin;
42     } else {
43       return strIni;
44     }
45   }
46
47
48   public void setValue(String JavaDoc strValue) {
49     this.strValue = replace(strValue);
50   }
51
52   public String JavaDoc print() {
53     if (xmlComponentValue != null) {
54       return xmlComponentValue.print();
55     } else {
56       return strValue;
57     }
58   }
59
60   public String JavaDoc printPrevious() {
61     if (xmlComponentValue != null) {
62       return xmlComponentValue.printPrevious();
63     } else {
64       return strValue;
65     }
66   }
67
68   public String JavaDoc printSimple() {
69     if (xmlComponentValue != null) {
70       return xmlComponentValue.printSimple();
71     } else {
72       return strValue;
73     }
74   }
75
76   public String JavaDoc printPreviousSimple() {
77     if (xmlComponentValue != null) {
78       return xmlComponentValue.printPreviousSimple();
79     } else {
80       return strValue;
81     }
82   }
83 }
84
Popular Tags