01: /*
02: * Licensed to the Apache Software Foundation (ASF) under one
03: * or more contributor license agreements. See the NOTICE file
04: * distributed with this work for additional information
05: * regarding copyright ownership. The ASF licenses this file
06: * to you under the Apache License, Version 2.0 (the
07: * "License"); you may not use this file except in compliance
08: * with the License. You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing,
13: * software distributed under the License is distributed on an
14: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
15: * KIND, either express or implied. See the License for the
16: * specific language governing permissions and limitations
17: * under the License.
18: */
19:
20: package org.apache.axis2.java.security.action;
21:
22: import org.apache.axis2.java.security.driver.Java2SecTest;
23: import org.apache.axis2.java.security.interf.Actor;
24: import org.apache.axis2.AbstractTestCase;
25:
26: import java.io.CharArrayWriter;
27: import java.io.FileReader;
28: import java.io.IOException;
29:
30: /**
31: * Action reads the data from an input file
32: * and then saves the file input to Java2SecTest class
33: */
34:
35: public class Action implements Actor {
36:
37: private String fileName;
38: private FileReader fileReader;
39:
40: // Constructor
41: public Action(String fileName) {
42: this .fileName = fileName;
43: }
44:
45: // Implementing Actor's takeAction method
46: public void takeAction() {
47: try {
48: // Print out maven's base,build, and test direcotories
49: String baseDir = AbstractTestCase.basedir;
50: System.out.println("basedir => " + baseDir);
51:
52: String buildDir = System.getProperty("maven_build_dir");
53: System.out.println("buildDir => " + buildDir);
54:
55: String testDir = System.getProperty("maven_test_dest");
56: System.out.println("testDir => " + testDir);
57:
58: // Convert the \ (back slash) to / (forward slash)
59: String baseDirM = baseDir.replace('\\', '/');
60: System.out.println("baseDirM => " + baseDirM);
61:
62: String fs = "/";
63:
64: // Build the file URL
65: String fileURL = baseDirM + fs + "test-resources" + fs
66: + "java2javaec" + fs + fileName;
67: System.out.println("File URL => " + fileURL);
68:
69: if (fileName != null)
70: fileReader = new FileReader(fileURL);
71: else
72: fileReader = new FileReader("public.txt");
73:
74: try {
75: CharArrayWriter caw = new CharArrayWriter();
76: int c;
77: while ((c = fileReader.read()) != -1) {
78: caw.write(c);
79: }
80: // Set/save the file input as test result onto Java2SecTest
81: Java2SecTest.testResult = caw.toString();
82: } catch (IOException e) {
83: e.printStackTrace(System.out);
84: } finally {
85: try {
86: fileReader.close();
87: } catch (IOException e) {
88: e.printStackTrace(System.out);
89: }
90: }
91: } catch (IOException e) {
92: e.printStackTrace(System.out);
93: }
94: }
95: }
|