View Javadoc

1   /*
2    * EDI-Knight Integration and Transformation Platform
3    * Copyright (C) 2006-2007 Holger Joest <hjoest@users.sourceforge.net>
4    *
5    * This program is free software; you can redistribute it and/or modify
6    * it under the terms of the GNU General Public License as published by
7    * the Free Software Foundation; either version 2 of the License, or
8    * (at your option) any later version.
9    *
10   * This program 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 General Public License for more details.
14   *
15   * You should have received a copy of the GNU General Public License
16   * along with this program; if not, write to the Free Software
17   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18   */
19  
20  package net.sf.ediknight.edifact.setup;
21  
22  import java.io.File;
23  import java.util.HashMap;
24  import java.util.Map;
25  
26  
27  /***
28   * @author Holger Joest
29   */
30  public final class AnalyzerContext {
31  
32      private File targetDirectory;
33  
34      private Map<String, String> parameterValues =
35          new HashMap<String, String>();
36  
37  
38      /***
39       * Returns a parameter value.
40       *
41       * @param parameter the parameter name
42       * @return the value of the specified parameter
43       */
44      public String getValue(String parameter) {
45          return parameterValues.get(parameter);
46      }
47  
48  
49      /***
50       * Sets a parameter value.
51       *
52       * @param parameter the parameter name
53       * @param value the value to set
54       */
55      public void setValue(String parameter, String value) {
56          parameterValues.put(parameter, value);
57      }
58  
59  
60      /***
61       * Expands parameter values in a given string.
62       *
63       * @param string the value to expand
64       * @return the expanded value
65       */
66      public String expandValues(String string) {
67          int p1 = string.indexOf("${");
68          while (p1 > -1) {
69              int p2 = string.indexOf("}", p1);
70              if (p2 < 0) {
71                  return string;
72              }
73              String parameter = string.substring(p1 + 2, p2);
74              string = string.substring(0, p1)
75                  + getValue(parameter)
76                  + string.substring(p2 + 1);
77              p1 = string.indexOf("${");
78          }
79          return string;
80      }
81  
82  
83      /***
84       * Returns the target directory.
85       *
86       * @return the target directory
87       */
88      public File getTargetDirectory() {
89          return targetDirectory;
90      }
91  
92  
93      /***
94       * Sets the target directory.
95       *
96       * @param targetDirectory the directory to set
97       */
98      public void setTargetDirectory(File targetDirectory) {
99          this.targetDirectory = targetDirectory;
100     }
101 
102 }
103