List of usage examples for java.io File isHidden
public boolean isHidden()
From source file:com.egt.ejb.toolkit.ToolKitSessionBean.java
private void copydirs(File sourceProj, File targetProj, File sourceFile, File targetFile, Map replacements) { if (!sourceFile.exists() || sourceFile.isHidden() || !sourceFile.isDirectory()) { return;/* w w w. jav a 2s . c om*/ } if (!targetFile.exists() || targetFile.isHidden() || !targetFile.isDirectory()) { return; } Bitacora.trace(this.getClass(), "copydirs-source", sourceFile.getAbsolutePath(), sourceFile.getName()); Bitacora.trace(this.getClass(), "copydirs-target", targetFile.getAbsolutePath(), targetFile.getName()); String sep = System.getProperties().getProperty("file.separator"); String[] filenames = sourceFile.list(); for (String filename : filenames) { if (!isExcludedFile(filename)) { File source = new File(sourceFile.getAbsolutePath() + sep + filename); File target; String pathname = targetFile.getAbsolutePath() + sep + filename; if (source.exists()) { if (source.isHidden()) { } else if (source.isDirectory()) { if (filename.equals("resources")) { try { String command = "xcopy.exe *.* \"" + pathname + "\" /Y"; Bitacora.trace(command); Runtime.getRuntime().exec(command, null, source); } catch (IOException ex) { Bitacora.logFatal(ThrowableUtils.getString(ex)); } } else { String suffix = ToolKitUtils.getWebPackageName(sourceProj.getName()).replace(".", sep); if (source.getAbsolutePath().endsWith(suffix)) { pathname = ToolKitUtils.getWebSrcDir(targetProj.getParent(), targetProj.getName()); } target = new File(pathname); copydirs(sourceProj, targetProj, source, target, replacements); } } else if (source.isFile()) { target = new File(pathname); copyfile(source, target, replacements); } } } } }
From source file:com.aliyun.odps.local.common.WareHouse.java
public List<String> getProjectNames() { File warehouseDir = getWarehouseDir(); if (!warehouseDir.exists()) { return null; }//from w ww .ja va 2s. c o m List<String> result = new ArrayList<String>(); File[] projects = warehouseDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !pathname.isHidden(); } }); for (File p : projects) { if (p.isDirectory()) { result.add(p.getName()); } } return result; }
From source file:com.aliyun.odps.local.common.WareHouse.java
public List<TableMeta> getTableMetas(String projName) throws IOException { File projectDir = getProjectDir(projName); if (!projectDir.exists()) { return null; }//from ww w .j a va2s .co m List<TableMeta> result = new ArrayList<TableMeta>(); File[] tables = projectDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !pathname.isHidden() && !pathname.getName().equals(Constants.RESOURCES_DIR); } }); // old version for (File t : tables) { if (!existsTable(projName, t.getName())) { continue; } TableMeta tableMeta = getTableMeta(projName, t.getName()); if (tableMeta != null) { result.add(tableMeta); } } // new version >=0.14 File tableBaseDir = new File(projectDir, Constants.TABLES_DIR); if (!tableBaseDir.exists()) { return result; } tables = tableBaseDir.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { return pathname.isDirectory() && !pathname.isHidden(); } }); for (File t : tables) { if (!existsTable(projName, t.getName())) { continue; } TableMeta tableMeta = getTableMeta(projName, t.getName()); if (tableMeta != null) { result.add(tableMeta); } } return result; }
From source file:de.uzk.hki.da.sb.SIPFactory.java
/** * Creates a list of source folders//ww w. j av a 2 s . c om * * @param folderPath * The main source folder path * @throws Exception */ HashMap<File, String> createFolderList(String folderPath) throws Exception { HashMap<File, String> folderListWithFolderNames = new HashMap<File, String>(); File sourceFolder = new File(folderPath); switch (kindofSIPBuilding) { case MULTIPLE_FOLDERS: List<File> folderContent = Arrays.asList(sourceFolder.listFiles()); for (File file : folderContent) { if (!file.isHidden() && file.isDirectory()) folderListWithFolderNames.put(file, null); } break; case SINGLE_FOLDER: folderListWithFolderNames.put(sourceFolder, null); break; case NESTED_FOLDERS: NestedContentStructure ncs; try { TreeMap<File, String> metadataFileWithType = new FormatDetectionService(sourceFolder) .getMetadataFileWithType(); if (!metadataFileWithType.isEmpty() && (!metadataFileWithType.get(metadataFileWithType.firstKey()) .equals(C.CB_PACKAGETYPE_METS))) { messageWriter.showMessage("Es wurde eine Metadatendatei des Typs " + metadataFileWithType.get(metadataFileWithType.firstKey()) + " auf der obersten Ebene gefunden. " + "\nBitte whlen Sie diese Option ausschlielich fr die Erstellung von SIPs des Typs METS."); } else { ncs = new NestedContentStructure(sourceFolder); folderListWithFolderNames = ncs.getSipCandidates(); if (folderListWithFolderNames.isEmpty()) { messageWriter.showMessage( "Es wurde kein Unterverzeichnis mit einer METS-Metadatendatei gefunden."); } break; } } catch (IOException e) { throw new Exception(e); } default: break; } return folderListWithFolderNames; }
From source file:org.geotools.gce.imagemosaic.Utils.java
static URL checkSource(Object source, Hints hints) { URL sourceURL = null;/*www . j av a 2 s .c o m*/ File sourceFile = null; // // Check source // // if it is a URL or a String let's try to see if we can get a file to // check if we have to build the index if (source instanceof File) { sourceFile = (File) source; sourceURL = DataUtilities.fileToURL(sourceFile); } else if (source instanceof URL) { sourceURL = (URL) source; if (sourceURL.getProtocol().equals("file")) { sourceFile = DataUtilities.urlToFile(sourceURL); } } else if (source instanceof String) { // is it a File? final String tempSource = (String) source; File tempFile = new File(tempSource); if (!tempFile.exists()) { // is it a URL try { sourceURL = new URL(tempSource); source = DataUtilities.urlToFile(sourceURL); } catch (MalformedURLException e) { sourceURL = null; source = null; } } else { sourceURL = DataUtilities.fileToURL(tempFile); // so that we can do our magic here below sourceFile = tempFile; } } // // // // at this point we have tried to convert the thing to a File as hard as // we could, let's see what we can do // // // if (sourceFile != null) { if (!sourceFile.isDirectory()) // real file, can only be a shapefile at this stage or a // datastore.properties file sourceURL = DataUtilities.fileToURL((File) sourceFile); else { // it's a DIRECTORY, let's look for a possible properties files // that we want to load final String locationPath = sourceFile.getAbsolutePath(); final String defaultIndexName = FilenameUtils.getName(locationPath); boolean datastoreFound = false; boolean buildMosaic = false; // // do we have a datastore properties file? It will preempt on // the shapefile // File dataStoreProperties = new File(locationPath, "datastore.properties"); // this can be used to look for properties files that do NOT // define a datastore final File[] properties = sourceFile.listFiles((FilenameFilter) FileFilterUtils.and( FileFilterUtils.notFileFilter(FileFilterUtils.nameFileFilter("datastore.properties")), FileFilterUtils.makeFileOnly(FileFilterUtils.suffixFileFilter(".properties")))); // do we have a valid datastore + mosaic properties pair? if (Utils.checkFileReadable(dataStoreProperties)) { // we have a datastore.properties file datastoreFound = true; // check the first valid mosaic properties boolean found = false; for (File propFile : properties) if (Utils.checkFileReadable(propFile)) { // load it if (null != Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), "location")) { found = true; break; } } // we did not find any good candidate for mosaic.properties // file, this will signal it if (!found) buildMosaic = true; } else { // we did not find any good candidate for mosaic.properties // file, this will signal it buildMosaic = true; datastoreFound = false; } // // now let's try with shapefile and properties couple // File shapeFile = null; if (!datastoreFound) { for (File propFile : properties) { // load properties if (null == Utils.loadMosaicProperties(DataUtilities.fileToURL(propFile), Utils.DEFAULT_LOCATION_ATTRIBUTE)) continue; // look for a couple shapefile, mosaic properties file shapeFile = new File(locationPath, FilenameUtils.getBaseName(propFile.getName()) + ".shp"); if (!Utils.checkFileReadable(shapeFile) && Utils.checkFileReadable(propFile)) buildMosaic = true; else { buildMosaic = false; break; } } } // did we find anything? If no, we try to build a new mosaic if (buildMosaic) { //// // // Creating a new mosaic // //// // try to build a mosaic inside this directory and see what // happens // preliminar checks final File mosaicDirectory = new File(locationPath); if (!mosaicDirectory.exists() || mosaicDirectory.isFile() || !mosaicDirectory.canWrite()) { if (LOGGER.isLoggable(Level.SEVERE)) { LOGGER.log(Level.SEVERE, "Unable to create the mosaic, check the location:\n" + "location is:" + locationPath + "\n" + "location exists:" + mosaicDirectory.exists() + "\n" + "location is a directory:" + mosaicDirectory.isDirectory() + "\n" + "location is writable:" + mosaicDirectory.canWrite() + "\n" + "location is readable:" + mosaicDirectory.canRead() + "\n" + "location is hidden:" + mosaicDirectory.isHidden() + "\n"); } return null; } // actual creation createMosaic(locationPath, defaultIndexName, DEFAULT_WILCARD, DEFAULT_PATH_BEHAVIOR, hints); // check that the mosaic properties file was created final File propertiesFile = new File(locationPath, defaultIndexName + ".properties"); if (!Utils.checkFileReadable(propertiesFile)) { // retrieve a null so that we shows that a problem occurred sourceURL = null; return sourceURL; } // check that the shapefile was correctly created in case it // was needed if (!datastoreFound) { shapeFile = new File(locationPath, defaultIndexName + ".shp"); if (!Utils.checkFileReadable(shapeFile)) sourceURL = null; else // now set the new source and proceed sourceURL = DataUtilities.fileToURL(shapeFile); } else { dataStoreProperties = new File(locationPath, "datastore.properties"); // datastore.properties as the source if (!Utils.checkFileReadable(dataStoreProperties)) { sourceURL = null; } else { sourceURL = DataUtilities.fileToURL(dataStoreProperties); } } } else // now set the new source and proceed sourceURL = datastoreFound ? DataUtilities.fileToURL(dataStoreProperties) : DataUtilities.fileToURL(shapeFile); } } else { // SK: We don't set SourceURL to null now, just because it doesn't // point to a file // sourceURL=null; } return sourceURL; }
From source file:net.massbank.validator.RecordValidator.java
/** * ??//from w w w. j av a 2 s.c om * * @param db * DB * @param op * PrintWriter? * @param dataPath * ? * @param registPath * * @param ver * ? * @return ??Map<??, ?> * @throws IOException * */ private static TreeMap<String, String> validationRecordOnline(DatabaseAccess db, PrintStream op, String dataPath, String registPath, int ver) throws IOException { op.println(msgInfo("validation archive is [" + UPLOAD_RECDATA_ZIP + "] or [" + UPLOAD_RECDATA_MSBK + "].")); if (ver == 1) { op.println(msgInfo("check record format version is [version 1].")); } final String[] dataList = (new File(dataPath)).list(); TreeMap<String, String> validationMap = new TreeMap<String, String>(); if (dataList.length == 0) { op.println(msgWarn("no file for validation.")); return validationMap; } // ---------------------------------------------------- // ??? // ---------------------------------------------------- String[] requiredList = new String[] { // Ver.2 "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "LICENSE: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$MASS_SPECTROMETRY: MS_TYPE ", "AC$MASS_SPECTROMETRY: ION_MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; if (ver == 1) { // Ver.1 requiredList = new String[] { "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "COPYRIGHT: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$ANALYTICAL_CONDITION: MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; } for (int i = 0; i < dataList.length; i++) { String name = dataList[i]; String status = ""; StringBuilder detailsErr = new StringBuilder(); StringBuilder detailsWarn = new StringBuilder(); // ???? File file = new File(dataPath + name); if (file.isDirectory()) { // ?? status = STATUS_ERR; detailsErr.append("[" + name + "] is directory."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (file.isHidden()) { // ??? status = STATUS_ERR; detailsErr.append("[" + name + "] is hidden."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (name.lastIndexOf(REC_EXTENSION) == -1) { // ???? status = STATUS_ERR; detailsErr.append("file extension of [" + name + "] is not [" + REC_EXTENSION + "]."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } // ?? boolean isEndTagRead = false; boolean isInvalidInfo = false; boolean isDoubleByte = false; ArrayList<String> fileContents = new ArrayList<String>(); boolean existLicense = false; // LICENSE?Ver.1 ArrayList<String> workChName = new ArrayList<String>(); // RECORD_TITLE??CH$NAME??Ver.1? String workAcInstrumentType = ""; // RECORD_TITLE??AC$INSTRUMENT_TYPE??Ver.1? String workAcMsType = ""; // RECORD_TITLE??AC$MASS_SPECTROMETRY: // MS_TYPE??Ver.2 String line = ""; BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); while ((line = br.readLine()) != null) { if (isEndTagRead) { if (!line.equals("")) { isInvalidInfo = true; } } // if (line.startsWith("//")) { isEndTagRead = true; } fileContents.add(line); // LICENSE?Ver.1 if (line.startsWith("LICENSE: ")) { existLicense = true; } // CH$NAME?Ver.1? else if (line.startsWith("CH$NAME: ")) { workChName.add(line.trim().replaceAll("CH\\$NAME: ", "")); } // AC$INSTRUMENT_TYPE?Ver.1? else if (line.startsWith("AC$INSTRUMENT_TYPE: ")) { workAcInstrumentType = line.trim().replaceAll("AC\\$INSTRUMENT_TYPE: ", ""); } // AC$MASS_SPECTROMETRY: MS_TYPE?Ver.2 else if (ver != 1 && line.startsWith("AC$MASS_SPECTROMETRY: MS_TYPE ")) { workAcMsType = line.trim().replaceAll("AC\\$MASS_SPECTROMETRY: MS_TYPE ", ""); } // ? if (!isDoubleByte) { byte[] bytes = line.getBytes("MS932"); if (bytes.length != line.length()) { isDoubleByte = true; } } } } catch (IOException e) { Logger.getLogger("global").severe("file read failed." + NEW_LINE + " " + file.getPath()); e.printStackTrace(); op.println(msgErr("server error.")); validationMap.clear(); return validationMap; } finally { try { if (br != null) { br.close(); } } catch (IOException e) { } } if (isInvalidInfo) { // ????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append("invalid after the end tag [//]."); } if (isDoubleByte) { // ????? if (status.equals("")) status = STATUS_ERR; detailsErr.append("double-byte character included."); } if (ver == 1 && existLicense) { // LICENSE???Ver.1 if (status.equals("")) status = STATUS_ERR; detailsErr.append("[LICENSE: ] tag can not be used in record format [version 1]."); } // ---------------------------------------------------- // ???? // ---------------------------------------------------- boolean isNameCheck = false; int peakNum = -1; for (int j = 0; j < requiredList.length; j++) { String requiredStr = requiredList[j]; ArrayList<String> valStrs = new ArrayList<String>(); // boolean findRequired = false; // boolean findValue = false; // boolean isPeakMode = false; // for (int k = 0; k < fileContents.size(); k++) { String lineStr = fileContents.get(k); // ????RELATED_RECORD?????? if (lineStr.startsWith("//")) { // Ver.1? break; } else if (ver == 1 && lineStr.startsWith("RELATED_RECORD:")) { // Ver.1 break; } // ????? else if (isPeakMode) { findRequired = true; if (!lineStr.trim().equals("")) { valStrs.add(lineStr); } } // ?????? else if (lineStr.indexOf(requiredStr) != -1) { // findRequired = true; if (requiredStr.equals("PK$PEAK: ")) { isPeakMode = true; findValue = true; valStrs.add(lineStr.replace(requiredStr, "")); } else { // String tmpVal = lineStr.replace(requiredStr, ""); if (!tmpVal.trim().equals("")) { findValue = true; valStrs.add(tmpVal); } break; } } } if (!findRequired) { // ?????? status = STATUS_ERR; detailsErr.append("no required item [" + requiredStr + "]."); } else { if (!findValue) { // ????? status = STATUS_ERR; detailsErr.append("no value of required item [" + requiredStr + "]."); } else { // ??? // ---------------------------------------------------- // ?? // ---------------------------------------------------- String val = (valStrs.size() > 0) ? valStrs.get(0) : ""; // ACESSIONVer.1? if (requiredStr.equals("ACCESSION: ")) { if (!val.equals(name.replace(REC_EXTENSION, ""))) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] not correspond to file name."); } if (val.length() != 8) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is 8 digits necessary."); } } // RECORD_TITLEVer.1? else if (requiredStr.equals("RECORD_TITLE: ")) { if (!val.equals(DEFAULT_VALUE)) { if (val.indexOf(";") != -1) { String[] recTitle = val.split(";"); if (!workChName.contains(recTitle[0].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(recTitle[1].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(recTitle[2].trim())) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } else { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not record title format."); if (!workChName.contains(val)) { detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } else { if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } // DATEVer.1? else if (requiredStr.equals("DATE: ") && !val.equals(DEFAULT_VALUE)) { val = val.replace(".", "/"); val = val.replace("-", "/"); try { DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN).parse(val); } catch (ParseException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is not date format."); } } // CH$COMPOUND_CLASSVer.1? else if (requiredStr.equals("CH$COMPOUND_CLASS: ") && !val.equals(DEFAULT_VALUE)) { if (!val.startsWith("Natural Product") && !val.startsWith("Non-Natural Product")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not compound class format."); } } // CH$EXACT_MASSVer.1? else if (requiredStr.equals("CH$EXACT_MASS: ") && !val.equals(DEFAULT_VALUE)) { try { Double.parseDouble(val); } catch (NumberFormatException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not numeric."); } } // AC$INSTRUMENT_TYPEVer.1? else if (requiredStr.equals("AC$INSTRUMENT_TYPE: ") && !val.equals(DEFAULT_VALUE)) { if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } } // AC$MASS_SPECTROMETRY: MS_TYPEVer.2 else if (ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: MS_TYPE ") && !val.equals(DEFAULT_VALUE)) { boolean isMsType = true; if (val.startsWith("MS")) { val = val.replace("MS", ""); if (!val.equals("")) { try { Integer.parseInt(val); } catch (NumberFormatException e) { isMsType = false; } } } else { isMsType = false; } if (!isMsType) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"MSn\"."); } } // AC$MASS_SPECTROMETRY: // ION_MODEVer.2?AC$ANALYTICAL_CONDITION: MODEVer.1 else if ((ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: ION_MODE ") && !val.equals(DEFAULT_VALUE)) || (ver == 1 && requiredStr.equals("AC$ANALYTICAL_CONDITION: MODE ") && !val.equals(DEFAULT_VALUE))) { if (!val.equals("POSITIVE") && !val.equals("NEGATIVE")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"POSITIVE\" or \"NEGATIVE\"."); } } // PK$NUM_PEAKVer.1? else if (requiredStr.equals("PK$NUM_PEAK: ") && !val.equals(DEFAULT_VALUE)) { try { peakNum = Integer.parseInt(val); } catch (NumberFormatException e) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] is not numeric."); } } // PK$PEAK:Ver.1? else if (requiredStr.equals("PK$PEAK: ")) { if (valStrs.size() == 0 || !valStrs.get(0).startsWith("m/z int. rel.int.")) { status = STATUS_ERR; detailsErr.append( "value of required item [PK$PEAK: ] , the first line is not \"PK$PEAK: m/z int. rel.int.\"."); } else { boolean isNa = false; String peak = ""; String mz = ""; String intensity = ""; boolean mzDuplication = false; boolean mzNotNumeric = false; boolean intensityNotNumeric = false; boolean invalidFormat = false; HashSet<String> mzSet = new HashSet<String>(); for (int l = 0; l < valStrs.size(); l++) { peak = valStrs.get(l).trim(); // N/A if (peak.indexOf(DEFAULT_VALUE) != -1) { isNa = true; break; } if (l == 0) { continue; } // m/z int. rel.int.?????????? if (peak.indexOf(" ") != -1) { mz = peak.split(" ")[0]; if (!mzSet.add(mz)) { mzDuplication = true; } try { Double.parseDouble(mz); } catch (NumberFormatException e) { mzNotNumeric = true; } intensity = peak.split(" ")[1]; try { Double.parseDouble(intensity); } catch (NumberFormatException e) { intensityNotNumeric = true; } } else { invalidFormat = true; } if (mzDuplication && mzNotNumeric && intensityNotNumeric && invalidFormat) { break; } } if (isNa) {// PK$PEAK:?N/A?? if (peakNum != -1) { // PK$NUM_PEAK:N/A?? if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } if (valStrs.size() - 1 > 0) { // PK$PEAK:???????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$NUM_PEAK: ] is invalid peak information exists."); } } else { if (mzDuplication) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is duplication."); } if (mzNotNumeric) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is not numeric."); } if (intensityNotNumeric) { status = STATUS_ERR; detailsErr.append("intensity value of required item [" + requiredStr + "] is not numeric."); } if (invalidFormat) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is not peak format."); } if (peakNum != 0 && valStrs.size() - 1 == 0) { // ?????N/A????PK$NUM_PEAK:?0??????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$PEAK: ] is no value. at that time, please add \"" + DEFAULT_VALUE + "\". "); } if (peakNum != valStrs.size() - 1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } } } } } } } String details = detailsErr.toString() + detailsWarn.toString(); if (status.equals("")) { status = STATUS_OK; details = " "; } validationMap.put(name, status + "\t" + details); } // ---------------------------------------------------- // ???? // ---------------------------------------------------- // ?ID?DB HashSet<String> regIdList = new HashSet<String>(); String[] sqls = { "SELECT ID FROM SPECTRUM ORDER BY ID", "SELECT ID FROM RECORD ORDER BY ID", "SELECT ID FROM PEAK GROUP BY ID ORDER BY ID", "SELECT ID FROM CH_NAME ID ORDER BY ID", "SELECT ID FROM CH_LINK ID ORDER BY ID", "SELECT ID FROM TREE WHERE ID IS NOT NULL AND ID<>'' ORDER BY ID" }; for (int i = 0; i < sqls.length; i++) { String execSql = sqls[i]; ResultSet rs = null; try { rs = db.executeQuery(execSql); while (rs.next()) { String idStr = rs.getString("ID"); regIdList.add(idStr); } } catch (SQLException e) { Logger.getLogger("global").severe(" sql : " + execSql); e.printStackTrace(); op.println(msgErr("database access error.")); return new TreeMap<String, String>(); } finally { try { if (rs != null) { rs.close(); } } catch (SQLException e) { } } } // ?ID? final String[] recFileList = (new File(registPath)).list(); for (int i = 0; i < recFileList.length; i++) { String name = recFileList[i]; File file = new File(registPath + File.separator + name); if (!file.isFile() || file.isHidden() || name.lastIndexOf(REC_EXTENSION) == -1) { continue; } String idStr = name.replace(REC_EXTENSION, ""); regIdList.add(idStr); } // ?? for (Map.Entry<String, String> e : validationMap.entrySet()) { String statusStr = e.getValue().split("\t")[0]; if (statusStr.equals(STATUS_ERR)) { continue; } String nameStr = e.getKey(); String idStr = e.getKey().replace(REC_EXTENSION, ""); String detailsStr = e.getValue().split("\t")[1]; if (regIdList.contains(idStr)) { statusStr = STATUS_WARN; detailsStr += "id [" + idStr + "] of file name [" + nameStr + "] already registered."; validationMap.put(nameStr, statusStr + "\t" + detailsStr); } } return validationMap; }
From source file:net.massbank.validator.RecordValidator.java
/** * ??//w w w . j av a 2 s . c o m * * @param db * DB * @param op * PrintWriter? * @param dataPath * ? * @param registPath * * @param ver * ? * @return ??Map<??, ?> * @throws IOException * */ private static TreeMap<String, String> validationRecord(DatabaseAccess dbx, PrintStream op, String dataPath, String registPath, int ver) throws IOException { if (ver == 1) { op.println(msgInfo("check record format version is [version 1].")); } final String[] dataList = (new File(dataPath)).list(); TreeMap<String, String> validationMap = new TreeMap<String, String>(); if (dataList.length == 0) { op.println(msgWarn("no file for validation.")); return validationMap; } // ---------------------------------------------------- // ??? // ---------------------------------------------------- String[] requiredList = new String[] { // Ver.2 "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "LICENSE: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$MASS_SPECTROMETRY: MS_TYPE ", "AC$MASS_SPECTROMETRY: ION_MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; if (ver == 1) { // Ver.1 requiredList = new String[] { "ACCESSION: ", "RECORD_TITLE: ", "DATE: ", "AUTHORS: ", "COPYRIGHT: ", "CH$NAME: ", "CH$COMPOUND_CLASS: ", "CH$FORMULA: ", "CH$EXACT_MASS: ", "CH$SMILES: ", "CH$IUPAC: ", "AC$INSTRUMENT: ", "AC$INSTRUMENT_TYPE: ", "AC$ANALYTICAL_CONDITION: MODE ", "PK$NUM_PEAK: ", "PK$PEAK: " }; } for (int i = 0; i < dataList.length; i++) { String name = dataList[i]; String status = ""; StringBuilder detailsErr = new StringBuilder(); StringBuilder detailsWarn = new StringBuilder(); // ???? File file = new File(dataPath + name); if (file.isDirectory()) { // ?? status = STATUS_ERR; detailsErr.append("[" + name + "] is directory."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (file.isHidden()) { // ??? status = STATUS_ERR; detailsErr.append("[" + name + "] is hidden."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } else if (name.lastIndexOf(REC_EXTENSION) == -1) { // ???? status = STATUS_ERR; detailsErr.append("file extension of [" + name + "] is not [" + REC_EXTENSION + "]."); validationMap.put(name, status + "\t" + detailsErr.toString()); continue; } // ?? boolean isEndTagRead = false; boolean isInvalidInfo = false; boolean isDoubleByte = false; ArrayList<String> fileContents = new ArrayList<String>(); boolean existLicense = false; // LICENSE?Ver.1 ArrayList<String> workChName = new ArrayList<String>(); // RECORD_TITLE??CH$NAME??Ver.1? String workAcInstrumentType = ""; // RECORD_TITLE??AC$INSTRUMENT_TYPE??Ver.1? String workAcMsType = ""; // RECORD_TITLE??AC$MASS_SPECTROMETRY: // MS_TYPE??Ver.2 String line = ""; BufferedReader br = null; try { br = new BufferedReader(new FileReader(file)); while ((line = br.readLine()) != null) { if (isEndTagRead) { if (!line.equals("")) { isInvalidInfo = true; } } // if (line.startsWith("//")) { isEndTagRead = true; } fileContents.add(line); // LICENSE?Ver.1 if (line.startsWith("LICENSE: ")) { existLicense = true; } // CH$NAME?Ver.1? else if (line.startsWith("CH$NAME: ")) { workChName.add(line.trim().replaceAll("CH\\$NAME: ", "")); } // AC$INSTRUMENT_TYPE?Ver.1? else if (line.startsWith("AC$INSTRUMENT_TYPE: ")) { workAcInstrumentType = line.trim().replaceAll("AC\\$INSTRUMENT_TYPE: ", ""); } // AC$MASS_SPECTROMETRY: MS_TYPE?Ver.2 else if (ver != 1 && line.startsWith("AC$MASS_SPECTROMETRY: MS_TYPE ")) { workAcMsType = line.trim().replaceAll("AC\\$MASS_SPECTROMETRY: MS_TYPE ", ""); } // ? if (!isDoubleByte) { byte[] bytes = line.getBytes("MS932"); if (bytes.length != line.length()) { isDoubleByte = true; } } } } catch (IOException e) { Logger.getLogger("global").severe("file read failed." + NEW_LINE + " " + file.getPath()); e.printStackTrace(); op.println(msgErr("server error.")); validationMap.clear(); return validationMap; } finally { try { if (br != null) { br.close(); } } catch (IOException e) { } } if (isInvalidInfo) { // ????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append("invalid after the end tag [//]."); } if (isDoubleByte) { // ????? if (status.equals("")) status = STATUS_ERR; detailsErr.append("double-byte character included."); } if (ver == 1 && existLicense) { // LICENSE???Ver.1 if (status.equals("")) status = STATUS_ERR; detailsErr.append("[LICENSE: ] tag can not be used in record format [version 1]."); } // ---------------------------------------------------- // ???? // ---------------------------------------------------- boolean isNameCheck = false; int peakNum = -1; for (int j = 0; j < requiredList.length; j++) { String requiredStr = requiredList[j]; ArrayList<String> valStrs = new ArrayList<String>(); // boolean findRequired = false; // boolean findValue = false; // boolean isPeakMode = false; // for (int k = 0; k < fileContents.size(); k++) { String lineStr = fileContents.get(k); // ????RELATED_RECORD?????? if (lineStr.startsWith("//")) { // Ver.1? break; } else if (ver == 1 && lineStr.startsWith("RELATED_RECORD:")) { // Ver.1 break; } // ????? else if (isPeakMode) { findRequired = true; if (!lineStr.trim().equals("")) { valStrs.add(lineStr); } } // ?????? else if (lineStr.indexOf(requiredStr) != -1) { // findRequired = true; if (requiredStr.equals("PK$PEAK: ")) { isPeakMode = true; findValue = true; valStrs.add(lineStr.replace(requiredStr, "")); } else { // String tmpVal = lineStr.replace(requiredStr, ""); if (!tmpVal.trim().equals("")) { findValue = true; valStrs.add(tmpVal); } break; } } } if (!findRequired) { // ?????? status = STATUS_ERR; detailsErr.append("no required item [" + requiredStr + "]."); } else { if (!findValue) { // ????? status = STATUS_ERR; detailsErr.append("no value of required item [" + requiredStr + "]."); } else { // ??? // ---------------------------------------------------- // ?? // ---------------------------------------------------- String val = (valStrs.size() > 0) ? valStrs.get(0) : ""; // ACESSIONVer.1? if (requiredStr.equals("ACCESSION: ")) { if (!val.equals(name.replace(REC_EXTENSION, ""))) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] not correspond to file name."); } if (val.length() != 8) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is 8 digits necessary."); } } // RECORD_TITLEVer.1? else if (requiredStr.equals("RECORD_TITLE: ")) { if (!val.equals(DEFAULT_VALUE)) { if (val.indexOf(";") != -1) { String[] recTitle = val.split(";"); if (!workChName.contains(recTitle[0].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(recTitle[1].trim())) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(recTitle[2].trim())) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } else { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not record title format."); if (!workChName.contains(val)) { detailsWarn.append("value of required item [" + requiredStr + "], compound name is not included in the [CH$NAME]."); } if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } else { if (!workAcInstrumentType.equals(DEFAULT_VALUE)) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], instrument type is different from [AC$INSTRUMENT_TYPE]."); } if (ver != 1 && !workAcMsType.equals(DEFAULT_VALUE)) { // Ver.2 if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "], ms type is different from [AC$MASS_SPECTROMETRY: MS_TYPE]."); } } } // DATEVer.1? else if (requiredStr.equals("DATE: ") && !val.equals(DEFAULT_VALUE)) { val = val.replace(".", "/"); val = val.replace("-", "/"); try { DateFormat.getDateInstance(DateFormat.SHORT, Locale.JAPAN).parse(val); } catch (ParseException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is not date format."); } } // CH$COMPOUND_CLASSVer.1? else if (requiredStr.equals("CH$COMPOUND_CLASS: ") && !val.equals(DEFAULT_VALUE)) { if (!val.startsWith("Natural Product") && !val.startsWith("Non-Natural Product")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not compound class format."); } } // CH$EXACT_MASSVer.1? else if (requiredStr.equals("CH$EXACT_MASS: ") && !val.equals(DEFAULT_VALUE)) { try { Double.parseDouble(val); } catch (NumberFormatException e) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not numeric."); } } // AC$INSTRUMENT_TYPEVer.1? else if (requiredStr.equals("AC$INSTRUMENT_TYPE: ") && !val.equals(DEFAULT_VALUE)) { if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } if (val.trim().indexOf(" ") != -1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [" + requiredStr + "] is space included."); } } // AC$MASS_SPECTROMETRY: MS_TYPEVer.2 else if (ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: MS_TYPE ") && !val.equals(DEFAULT_VALUE)) { boolean isMsType = true; if (val.startsWith("MS")) { val = val.replace("MS", ""); if (!val.equals("")) { try { Integer.parseInt(val); } catch (NumberFormatException e) { isMsType = false; } } } else { isMsType = false; } if (!isMsType) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"MSn\"."); } } // AC$MASS_SPECTROMETRY: // ION_MODEVer.2?AC$ANALYTICAL_CONDITION: MODEVer.1 else if ((ver != 1 && requiredStr.equals("AC$MASS_SPECTROMETRY: ION_MODE ") && !val.equals(DEFAULT_VALUE)) || (ver == 1 && requiredStr.equals("AC$ANALYTICAL_CONDITION: MODE ") && !val.equals(DEFAULT_VALUE))) { if (!val.equals("POSITIVE") && !val.equals("NEGATIVE")) { if (status.equals("")) status = STATUS_WARN; detailsWarn.append("value of required item [" + requiredStr + "] is not \"POSITIVE\" or \"NEGATIVE\"."); } } // PK$NUM_PEAKVer.1? else if (requiredStr.equals("PK$NUM_PEAK: ") && !val.equals(DEFAULT_VALUE)) { try { peakNum = Integer.parseInt(val); } catch (NumberFormatException e) { status = STATUS_ERR; detailsErr.append("value of required item [" + requiredStr + "] is not numeric."); } } // PK$PEAK:Ver.1? else if (requiredStr.equals("PK$PEAK: ")) { if (valStrs.size() == 0 || !valStrs.get(0).startsWith("m/z int. rel.int.")) { status = STATUS_ERR; detailsErr.append( "value of required item [PK$PEAK: ] , the first line is not \"PK$PEAK: m/z int. rel.int.\"."); } else { boolean isNa = false; String peak = ""; String mz = ""; String intensity = ""; boolean mzDuplication = false; boolean mzNotNumeric = false; boolean intensityNotNumeric = false; boolean invalidFormat = false; HashSet<String> mzSet = new HashSet<String>(); for (int l = 0; l < valStrs.size(); l++) { peak = valStrs.get(l).trim(); // N/A if (peak.indexOf(DEFAULT_VALUE) != -1) { isNa = true; break; } if (l == 0) { continue; } // m/z int. rel.int.?????????? if (peak.indexOf(" ") != -1) { mz = peak.split(" ")[0]; if (!mzSet.add(mz)) { mzDuplication = true; } try { Double.parseDouble(mz); } catch (NumberFormatException e) { mzNotNumeric = true; } intensity = peak.split(" ")[1]; try { Double.parseDouble(intensity); } catch (NumberFormatException e) { intensityNotNumeric = true; } } else { invalidFormat = true; } if (mzDuplication && mzNotNumeric && intensityNotNumeric && invalidFormat) { break; } } if (isNa) {// PK$PEAK:?N/A?? if (peakNum != -1) { // PK$NUM_PEAK:N/A?? if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } if (valStrs.size() - 1 > 0) { // PK$PEAK:???????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$NUM_PEAK: ] is invalid peak information exists."); } } else { if (mzDuplication) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is duplication."); } if (mzNotNumeric) { status = STATUS_ERR; detailsErr.append( "mz value of required item [" + requiredStr + "] is not numeric."); } if (intensityNotNumeric) { status = STATUS_ERR; detailsErr.append("intensity value of required item [" + requiredStr + "] is not numeric."); } if (invalidFormat) { status = STATUS_ERR; detailsErr.append( "value of required item [" + requiredStr + "] is not peak format."); } if (peakNum != 0 && valStrs.size() - 1 == 0) { // ?????N/A????PK$NUM_PEAK:?0??????? if (status.equals("")) status = STATUS_WARN; detailsWarn.append( "value of required item [PK$PEAK: ] is no value. at that time, please add \"" + DEFAULT_VALUE + "\". "); } if (peakNum != valStrs.size() - 1) { if (status.equals("")) status = STATUS_WARN; detailsWarn .append("value of required item [PK$NUM_PEAK: ] is mismatch or \"" + DEFAULT_VALUE + "\"."); } } } } } } } String details = detailsErr.toString() + detailsWarn.toString(); if (status.equals("")) { status = STATUS_OK; details = " "; } validationMap.put(name, status + "\t" + details); } // // ---------------------------------------------------- // // ???? // // ---------------------------------------------------- // // ?ID?DB // HashSet<String> regIdList = new HashSet<String>(); // String[] sqls = { "SELECT ID FROM SPECTRUM ORDER BY ID", // "SELECT ID FROM RECORD ORDER BY ID", // "SELECT ID FROM PEAK GROUP BY ID ORDER BY ID", // "SELECT ID FROM CH_NAME ID ORDER BY ID", // "SELECT ID FROM CH_LINK ID ORDER BY ID", // "SELECT ID FROM TREE WHERE ID IS NOT NULL AND ID<>'' ORDER BY ID" }; // for (int i = 0; i < sqls.length; i++) { // String execSql = sqls[i]; // ResultSet rs = null; // try { // rs = db.executeQuery(execSql); // while (rs.next()) { // String idStr = rs.getString("ID"); // regIdList.add(idStr); // } // } catch (SQLException e) { // Logger.getLogger("global").severe(" sql : " + execSql); // e.printStackTrace(); // op.println(msgErr("database access error.")); // return new TreeMap<String, String>(); // } finally { // try { // if (rs != null) { // rs.close(); // } // } catch (SQLException e) { // } // } // } // // ?ID? // final String[] recFileList = (new File(registPath)).list(); // for (int i = 0; i < recFileList.length; i++) { // String name = recFileList[i]; // File file = new File(registPath + File.separator + name); // if (!file.isFile() || file.isHidden() // || name.lastIndexOf(REC_EXTENSION) == -1) { // continue; // } // String idStr = name.replace(REC_EXTENSION, ""); // regIdList.add(idStr); // } // // ?? // for (Map.Entry<String, String> e : validationMap.entrySet()) { // String statusStr = e.getValue().split("\t")[0]; // if (statusStr.equals(STATUS_ERR)) { // continue; // } // String nameStr = e.getKey(); // String idStr = e.getKey().replace(REC_EXTENSION, ""); // String detailsStr = e.getValue().split("\t")[1]; // if (regIdList.contains(idStr)) { // statusStr = STATUS_WARN; // detailsStr += "id [" // + idStr + "] of file name [" // + nameStr // + "] already registered."; // validationMap.put(nameStr, statusStr + "\t" + detailsStr); // } // } return validationMap; }
From source file:org.jini.commands.files.FindFiles.java
/** * Search for files with specific extensions * * @param dirName/* w w w.java 2 s . c om*/ * @param extensions * @param recursive */ void findFileWithExtension(String dirName, String[] extensions, boolean recursive) { PrintChar printChar = new PrintChar(); printChar.setOutPutChar(">"); if ((this.getJcError() == false) && (this.isDir(dirName) == false)) { this.setJcError(true); this.addErrorMessages("Error : Directory [" + dirName + "] does not exsist."); } if (this.getJcError() == false) { printChar.start(); File root = new File(dirName); try { Collection files = FileUtils.listFiles(root, extensions, recursive); TablePrinter tableF = new TablePrinter("Name", "Type", "Readable", "Writable", "Executable", "Size KB", "Size MB", "Last Modified"); for (Iterator iterator = files.iterator(); iterator.hasNext();) { File file = (File) iterator.next(); if (this.withDetails == false) { System.out.println(file.getAbsolutePath()); } else { java.util.Date lastModified = new java.util.Date(file.lastModified()); long filesizeInKB = file.length() / 1024; double bytes = file.length(); double kilobytes = (bytes / 1024); double megabytes = (kilobytes / 1024); String type = ""; DecimalFormat df = new DecimalFormat("####.####"); if (file.isDirectory()) { type = "Dir"; } if (file.isFile()) { type = "File"; } if (file.isFile() && file.isHidden()) { type = "File (Hidden)"; } if (file.isDirectory() && (file.isHidden())) { type = "Dir (Hidden)"; } String canExec = "" + file.canExecute(); String canRead = "" + file.canRead(); String canWrite = "" + file.canWrite(); String filesizeInKBStr = Long.toString(filesizeInKB); String filesizeInMBStr = df.format(megabytes); tableF.addRow(file.getAbsolutePath(), type, canRead, canWrite, canExec, filesizeInKBStr, filesizeInMBStr, lastModified.toString()); } } if (this.withDetails == true) { if (files.isEmpty() == false) { tableF.print(); } } printChar.setStopPrinting(true); } catch (Exception e) { this.setJcError(true); this.addErrorMessages("Error : " + e.toString()); } } this.done = true; }
From source file:org.ow2.mind.unit.Launcher.java
/** * Recursively find ADL files from the root directory. * Inspired by Mindoc's DocumentationIndexGenerator. * FileFilterUtils comes from Apache commons-io. * @throws IOException/*from w w w .j av a 2 s . c o m*/ */ private void exploreDirectory(final File directory, String currentPackage) { if (directory.isHidden()) return; String subPackage = ""; for (final File file : directory.listFiles((FileFilter) FileFilterUtils.suffixFileFilter(".adl"))) { String compName = file.getName(); // remove ".adl" extension compName = compName.substring(0, compName.length() - 4); // add package compName = currentPackage + "." + compName; // save component info testFolderADLList.add(compName); } for (final File subDirectory : directory.listFiles(new FileFilter() { public boolean accept(final File pathname) { return pathname.isDirectory(); } })) { // base folder if (currentPackage == null) subPackage = subDirectory.getName(); else // already in sub-folder subPackage = currentPackage + "." + subDirectory.getName(); // recursion exploreDirectory(subDirectory, subPackage); } }
From source file:com.topsec.tsm.sim.sysconfig.web.SystemConfigController.java
/** * ??/*w w w. ja v a2 s.c om*/ * @param parentDirPath * @return */ private List getDirectoryLists(String parentDirPath) { List lists = new ArrayList(); if (parentDirPath != null) { File file = new File(parentDirPath); File[] childDir = file.listFiles(new FileFilter() { @Override public boolean accept(File pathname) { if (pathname.isDirectory() && !StringUtil.matchPattern(pathname.getName(), CommonUtils.REGEX_ZH) && !pathname.isHidden()) return true; return false; } }); for (File dir : childDir) { TreeData treedata = new TreeData(dir.getName()); Map attr = new HashMap(); attr.put("path", dir.getPath()); treedata.setId(dir.getPath()); treedata.setAttributes(attr); lists.add(treedata); } } return lists; }