1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: TestDataLoader.java,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 package mod
._scripting
;
34 import java
.io
.FileReader
;
35 import java
.io
.BufferedReader
;
36 import java
.io
.IOException
;
38 import java
.util
.ArrayList
;
39 import java
.util
.HashMap
;
40 import java
.util
.StringTokenizer
;
42 import lib
.TestEnvironment
;
43 import lib
.Parameters
;
45 public class TestDataLoader
{
47 private TestDataLoader() {
50 public static void setupData(TestEnvironment tEnv
, String name
) {
52 util
.utils
.getFullTestDocName("testdata");
53 File testdatadir
= new File(filename
);
54 File f
= new File(testdatadir
, name
+ ".csv");
62 in
= new BufferedReader(new FileReader(f
));
64 String s
, previous
, current
;
65 ArrayList list
= new ArrayList(11);
67 if ((s
= in
.readLine()) != null) {
68 StringTokenizer st
= new StringTokenizer(s
, ";");
70 current
= previous
= st
.nextToken();
71 list
.add(getParameters(st
));
77 while ((s
= in
.readLine()) != null) {
78 StringTokenizer st
= new StringTokenizer(s
, ";");
80 current
= st
.nextToken();
82 if (!current
.equals(previous
)) {
83 tEnv
.addObjRelation(previous
, list
);
85 list
= new ArrayList(11);
88 list
.add(getParameters(st
));
91 tEnv
.addObjRelation(previous
, list
);
93 catch (IOException ioe
) {
97 private static Parameters
getParameters(StringTokenizer st
) {
98 String separator
= "=";
99 HashMap map
= new HashMap(5);
101 while (st
.hasMoreTokens()) {
102 String pair
= st
.nextToken();
103 StringTokenizer tokens
= new StringTokenizer(pair
, separator
);
108 if (tokens
.countTokens() < 2)
111 name
= tokens
.nextToken();
112 if (tokens
.countTokens() == 1)
113 value
= tokens
.nextToken();
115 StringBuffer buf
= new StringBuffer(tokens
.nextToken());
116 while (tokens
.hasMoreTokens())
117 buf
.append(separator
).append(tokens
.nextToken());
118 value
= buf
.toString();
121 map
.put(name
, value
);
124 return new Parameters(map
);