Building Controls Virtual Test Bed
VersionUpdater.java
Go to the documentation of this file.
1 package BCVTB;
2 import java.io.File;
3 import java.io.BufferedReader;
4 import java.io.PrintWriter;
5 import java.io.FileReader;
6 import java.io.FileWriter;
7 import java.util.Collection;
8 import java.util.HashMap;
9 import java.util.Map;
10 import java.util.Iterator;
11 
12 public class VersionUpdater{
13 
19  public static void main(String[] args)
20  throws Exception
21  {
22  final String toVersion = args[0];
23  final String fileName = args[1];
24  File temp = File.createTempFile("temp", ".xml");
25  temp.deleteOnExit();
26 
27  Map<String, String> rep = new HashMap<String, String>();
28  if (toVersion.equalsIgnoreCase("1.1")) {
29  rep.put("startTime", "beginTime");
30  rep.put("finalTime", "endTime");
31  rep.put("ptolemy.actor.lib.MonitorValue", "ptolemy.actor.lib.gui.MonitorValue");
32  }
33  else
34  throw new Exception("Version number '" + toVersion + "' is not valid.");
35 
36  FileReader fr = new FileReader(fileName);
37  BufferedReader reader = new BufferedReader(fr);
38  FileWriter fw = new FileWriter(temp);
39  PrintWriter writer = new PrintWriter(fw);
40  String line = null;
41  Collection c = rep.values();
42  while ((line = reader.readLine()) != null){
43  for (Map.Entry<String, String> entry : rep.entrySet()){
44  line = new String(line.replaceAll((String)(entry.getKey()), (String)(entry.getValue())));
45  }
46  writer.println(line);
47  }
48  reader.close();
49  fr.close();
50  writer.close();
51  fw.close();
52  temp.renameTo(new File(fileName));
53  }
54 }
55 /********************************************************************
56 Copyright Notice
57 ----------------
58 
59 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
60 Regents of the University of California, through Lawrence Berkeley
61 National Laboratory (subject to receipt of any required approvals from
62 the U.S. Dept. of Energy). All rights reserved.
63 
64 If you have questions about your rights to use or distribute this
65 software, please contact Berkeley Lab's Technology Transfer Department
66 at TTD@lbl.gov
67 
68 NOTICE. This software was developed under partial funding from the U.S.
69 Department of Energy. As such, the U.S. Government has been granted for
70 itself and others acting on its behalf a paid-up, nonexclusive,
71 irrevocable, worldwide license in the Software to reproduce, prepare
72 derivative works, and perform publicly and display publicly. Beginning
73 five (5) years after the date permission to assert copyright is obtained
74 from the U.S. Department of Energy, and subject to any subsequent five
75 (5) year renewals, the U.S. Government is granted for itself and others
76 acting on its behalf a paid-up, nonexclusive, irrevocable, worldwide
77 license in the Software to reproduce, prepare derivative works,
78 distribute copies to the public, perform publicly and display publicly,
79 and to permit others to do so.
80 
81 
82 Modified BSD License agreement
83 ------------------------------
84 
85 Building Controls Virtual Test Bed (BCVTB) Copyright (c) 2008-2009, The
86 Regents of the University of California, through Lawrence Berkeley
87 National Laboratory (subject to receipt of any required approvals from
88 the U.S. Dept. of Energy). All rights reserved.
89 
90 Redistribution and use in source and binary forms, with or without
91 modification, are permitted provided that the following conditions are met:
92 
93  1. Redistributions of source code must retain the above copyright
94  notice, this list of conditions and the following disclaimer.
95  2. Redistributions in binary form must reproduce the above copyright
96  notice, this list of conditions and the following disclaimer in
97  the documentation and/or other materials provided with the
98  distribution.
99  3. Neither the name of the University of California, Lawrence
100  Berkeley National Laboratory, U.S. Dept. of Energy nor the names
101  of its contributors may be used to endorse or promote products
102  derived from this software without specific prior written permission.
103 
104 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS
105 IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
106 TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A
107 PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER
108 OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
109 EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
110 PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
111 PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
112 LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
113 NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
114 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
115 
116 You are under no obligation whatsoever to provide any bug fixes,
117 patches, or upgrades to the features, functionality or performance of
118 the source code ("Enhancements") to anyone; however, if you choose to
119 make your Enhancements available either publicly, or directly to
120 Lawrence Berkeley National Laboratory, without imposing a separate
121 written license agreement for such Enhancements, then you hereby grant
122 the following license: a non-exclusive, royalty-free perpetual license
123 to install, use, modify, prepare derivative works, incorporate into
124 other computer software, distribute, and sublicense such enhancements or
125 derivative works thereof, in binary and source code form.
126 
127 ********************************************************************
128 */
129 
static void main(String[] args)
Replace string in files.
FSCHANGE is a Mathworks internal function that is used for troubleshooting purposes It takes the name of a directory as an input and forces the MATLAB path manager to recheck the contents of the directory to check for windows have Windows c
Definition: compile.m:89