+public class NestElement extends DataType {\r
+ //\r
+ // The name list. All the name strings got from setXXX methods will be put\r
+ // in here.\r
+ //\r
+ private List<String> nameList = new ArrayList<String>();\r
+\r
+ /**\r
+ Handle "name" attribute. No delimiter and special treatment are assumed.\r
+\r
+ @param name A single string value of "name" attribute \r
+ **/\r
+ public void setName(String name) {\r
+ if (name.length() > 0) {\r
+ nameList.add(name);\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "list" attribute. The value of "list" is assumed as string \r
+ separated by space, tab, comma or semmicolon.\r
+\r
+ @param nameList The value of "list" separated by " \t,;"\r
+ **/\r
+ public void setList(String nameList) {\r
+ if (nameList.length() == 0) {\r
+ return;\r
+ }\r
+\r
+ StringTokenizer tokens = new StringTokenizer(nameList, " \t,;", false);\r
+ while (tokens.hasMoreTokens()) {\r
+ String name = tokens.nextToken().trim();\r
+ if (name.length() > 0) {\r
+ this.nameList.add(name);\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "ListFile" attribute. The value of "ListFile" should be the path of\r
+ a file which contains name strings, one name per line.\r
+\r
+ @param listFileName The file path\r
+ **/\r
+ public void setListFile(String listFileName) {\r
+ FileReader fileReader = null;\r
+ BufferedReader in = null;\r
+ String str;\r
+\r
+ //\r
+ // Check if the file exists or not\r
+ // \r
+ File file = new File(listFileName);\r
+ if (!file.exists()) {\r
+ throw new BuildException("The file, " + file + " does not exist!"); \r
+ } \r
+\r
+ try {\r
+ fileReader = new FileReader(file);\r
+ in = new BufferedReader(fileReader);\r
+\r
+ //\r
+ // Read line by line\r
+ // \r
+ while((str = in.readLine()) != null){\r
+ str = str.trim();\r
+ if (str.length() == 0){\r
+ continue;\r
+ }\r
+\r
+ //getProject().replaceProperties(str);\r
+ nameList.add(str);\r
+ }\r
+ } catch (Exception e){\r
+ throw new BuildException(e.getMessage()); \r
+ } finally {\r
+ try {\r
+ //\r
+ // close the file\r
+ // \r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fileReader != null) {\r
+ fileReader.close();\r
+ }\r
+ } catch (Exception e) {\r
+ throw new BuildException(e.getMessage()); \r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "file" attribute. The value of "file" should be a path.\r
+\r
+ @param file The path name of a file\r
+ **/\r
+ public void setFile(String file) {\r
+ setPath(file);\r
+ }\r
+\r
+ /**\r
+ Handle "path" attribute. The value of "path" may contain compound path\r
+ separator (/ or \) which should be cleaned up. Because the "path" string\r
+ will always be passed to external native program which may not handle \r
+ non-native path separator, the clean-up action is a must. And the value\r
+ of "path" may contains several path separated by space, tab, comma or\r
+ semmicolon. We need to split it and put each part in nameList.\r
+\r
+ @param path String value of a file system path\r
+ **/\r
+ public void setPath(String path) {\r
+ if (path.length() == 0) {\r
+ return;\r
+ }\r
+\r
+ //\r
+ // split the value of "path" into separated single path\r
+ // \r
+ StringTokenizer tokens = new StringTokenizer(path, " \t,;", false);\r
+ while (tokens.hasMoreTokens()) {\r
+ String pathName = tokens.nextToken().trim();\r
+ if (pathName.length() > 0) {\r
+ //\r
+ // Make clean the path string before storing it\r
+ // \r
+ this.nameList.add(cleanupPath(pathName));\r
+ }\r
+ }\r
+ }\r
+\r
+ /**\r
+ Handle "FileName" attribute. The value of "FileName" should be the path\r
+ of a file which contains path strings, one path per line.\r
+\r
+ @param pathFileName\r
+ **/\r
+ public void setPathFile(String pathFileName) {\r
+ FileReader fileReader = null;\r
+ BufferedReader in = null;\r
+ String path;\r
+\r
+ //\r
+ // Check if the file exists or not\r
+ // \r
+ File file = new File(pathFileName);\r
+ if (!file.exists()) {\r
+ throw new BuildException("The file, " + file + " does not exist!"); \r
+ } \r
+\r
+ try {\r
+ fileReader = new FileReader(file);\r
+ in = new BufferedReader(fileReader);\r
+\r
+ //\r
+ // Read the file line by line, skipping empty ones\r
+ // \r
+ while((path = in.readLine()) != null){\r
+ path = path.trim();\r
+ if (path.length() == 0){\r
+ continue;\r
+ }\r
+ //getProject().replaceProperties(path);\r
+\r
+ //\r
+ // Make clean the path string before storing it.\r
+ // \r
+ nameList.add(cleanupPath(path));\r
+ }\r
+ } catch (Exception e){\r
+ throw new BuildException(e.getMessage()); \r
+ } finally {\r
+ try {\r
+ //\r
+ // close the file\r
+ // \r
+ if (in != null) {\r
+ in.close();\r
+ }\r
+ if (fileReader != null) {\r
+ fileReader.close();\r
+ }\r
+ } catch (Exception e) {\r
+ throw new BuildException(e.getMessage()); \r
+ }\r
+ }\r
+ }\r
+\r