|
What this is
Other links
The source code/* * Sun Public License Notice * * The contents of this file are subject to the Sun Public License * Version 1.0 (the "License"). You may not use this file except in * compliance with the License. A copy of the License is available at * http://www.sun.com/ * * The Original Code is NetBeans. The Initial Developer of the Original * Code is Sun Microsystems, Inc. Portions Copyright 1997-2002 Sun * Microsystems, Inc. All Rights Reserved. */ package org.netbeans.test.web.editor.completion; import java.io.File; import java.io.FileInputStream; import java.io.IOException; import java.util.Enumeration; import java.util.HashMap; import java.util.Hashtable; import java.util.Iterator; import java.util.Properties; import java.util.StringTokenizer; import java.util.Vector; /** * * @author Marek Fukala */ public class ProjectInfo { private File projectPath; private TestFileInfo[] tfis; /** Creates a new instance of ProjectInfo */ public ProjectInfo(File projectPath) throws IOException { this.projectPath = projectPath; parseTestConfig(); } private void parseTestConfig() throws IOException { //where to place created TFIS Vector tfisv = new Vector(); //load config file File testConfigFile = new File(getProjectPath(), TEST_CONFIG_NAME); Properties props = new Properties(); props.load(new FileInputStream(testConfigFile)); //parse the config file //example of the parsed line: afolder/test.jsp=test.jsp.golden:10,15 Enumeration keys = props.propertyNames(); while(keys.hasMoreElements()) { String testFileName = (String)keys.nextElement(); String value = props.getProperty(testFileName); //System.out.println(key + " = " + value); //parse the config file StringTokenizer prim = new StringTokenizer(value, ":"); String goldenFileName = null; String elements = null; while(prim.hasMoreTokens()) { goldenFileName = prim.nextToken(); elements = prim.nextToken(); } //parse the test elements StringTokenizer sec = new StringTokenizer(elements, ";"); int[][]indexes = null; Vector idx = new Vector(); while(sec.hasMoreTokens()) { String item = sec.nextToken(); //parse the pair StringTokenizer pair = new StringTokenizer(item, ","); while(pair.hasMoreTokens()) { String row = pair.nextToken(); String lineOffset = pair.nextToken(); idx.addElement(new Pair(row, lineOffset)); } } //create a two-dimensional array for the indexes indexes = new int[idx.size()][2]; Enumeration kenum = idx.elements(); int count = 0; while(kenum.hasMoreElements()) { Pair pair = (Pair)kenum.nextElement(); try { indexes[count][0] = Integer.parseInt(pair.getA()); indexes[count++][1] = Integer.parseInt(pair.getB()); }catch(NumberFormatException e) { throw new IOException("cannot parse number: " + e.getMessage()); } } //create a TestFileInfo instance for this test file TestFileInfo tfi = new TestFileInfo(testFileName, goldenFileName, indexes); tfisv.addElement(tfi); } this.tfis = (TestFileInfo[])tfisv.toArray(new TestFileInfo[]{}); } public File getProjectPath() { return this.projectPath; } public TestFileInfo[] getTestFileInfos() { return this.tfis; } public static final String TEST_CONFIG_NAME = "testconfig.properties"; private static class Pair { private String a,b; public Pair(String a, String b) { this.a = a; this.b = b; } public String getA() {return a;} public String getB() {return b;} } public static class TestFileInfo { private String testFileName; private String goldenFileName; private int[][] indexes; public TestFileInfo(String testFileName, String goldenFileName, int[][] indexes) { this.testFileName = testFileName; this.goldenFileName = goldenFileName; this.indexes = indexes; } public String getTestFileName() { return this.testFileName; } public String getGoldenFileName() { return this.goldenFileName; } public int[][] getIndexes() { return this.indexes; } public String toString() { String pairsInfo = new String(); for(int i = 0; i < indexes.length; i++) { pairsInfo += "(" + indexes[i][0] + "," + indexes[i][1] + ")"; if(i < indexes.length - 1) pairsInfo += ", "; } return "TestFileInfo[testFile=" + testFileName +", goldenFile=" + goldenFileName + ", pairs=" + pairsInfo; } } } |
... this post is sponsored by my books ... | |
#1 New Release! |
FP Best Seller |
Copyright 1998-2021 Alvin Alexander, alvinalexander.com
All Rights Reserved.
A percentage of advertising revenue from
pages under the /java/jwarehouse
URI on this website is
paid back to open source projects.