List of usage examples for java.util Vector elementAt
public synchronized E elementAt(int index)
From source file:fr.sanofi.fcl4transmart.controllers.listeners.clinicalData.SetLabelsOntologyListener.java
@Override public void handleEvent(Event event) { // TODO Auto-generated method stub Vector<String> headers = this.setLabelsOntologyUI.getHeaders(); Vector<String> newLabels = this.setLabelsOntologyUI.getNewLabels(); Vector<String> codes = this.setLabelsOntologyUI.getCodes(); if (((ClinicalData) this.dataType).getCMF() == null) { this.setLabelsOntologyUI.displayMessage("Error: no column mapping file"); return;// ww w . j a v a 2 s.c o m } File file = new File(this.dataType.getPath().toString() + File.separator + this.dataType.getStudy().toString() + ".columns.tmp"); try { FileWriter fw = new FileWriter(file); BufferedWriter out = new BufferedWriter(fw); out.write( "Filename\tCategory Code\tColumn Number\tData Label\tData Label Source\tControlled Vocab Code\n"); try { BufferedReader br = new BufferedReader(new FileReader(((ClinicalData) this.dataType).getCMF())); String line = br.readLine(); while ((line = br.readLine()) != null) { if (line.split("\t", -1)[3].compareTo("SUBJ_ID") == 0 || line.split("\t", -1)[3].compareTo("VISIT_NAME") == 0 || line.split("\t", -1)[3].compareTo("SITE_ID") == 0 || line.split("\t", -1)[3].compareTo("\\") == 0 || line.split("\t", -1)[3].compareTo("DATA_LABEL") == 0 || line.split("\t", -1)[3].compareTo("OMIT") == 0) { out.write(line + "\n"); } else { File rawFile = new File(this.dataType.getPath() + File.separator + line.split("\t", -1)[0]); String header = FileHandler.getColumnByNumber(rawFile, Integer.parseInt(line.split("\t", -1)[2])); String newLabel = newLabels.elementAt(headers.indexOf(rawFile.getName() + " - " + header)); if (newLabel.compareTo("") == 0) { newLabel = header; } out.write(line.split("\t", -1)[0] + "\t" + line.split("\t", -1)[1] + "\t" + line.split("\t", -1)[2] + "\t" + newLabel + "\t\t" + codes.elementAt(headers.indexOf(rawFile.getName() + " - " + header)) + "\n"); } } br.close(); } catch (Exception e) { this.setLabelsOntologyUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); out.close(); } out.close(); String fileName = ((ClinicalData) this.dataType).getCMF().getName(); FileUtils.deleteQuietly(((ClinicalData) this.dataType).getCMF()); try { File fileDest = new File(this.dataType.getPath() + File.separator + fileName); FileUtils.moveFile(file, fileDest); ((ClinicalData) this.dataType).setCMF(fileDest); } catch (Exception ioe) { this.setLabelsOntologyUI.displayMessage("File error: " + ioe.getLocalizedMessage()); return; } } catch (Exception e) { this.setLabelsOntologyUI.displayMessage("Error: " + e.getLocalizedMessage()); e.printStackTrace(); } this.setLabelsOntologyUI.displayMessage("Column mapping file updated"); WorkPart.updateSteps(); WorkPart.updateFiles(); }
From source file:org.jboss.dashboard.commons.text.StringUtil.java
/** * It returns an array of subchains of maximum length in pixels. * * @param text original string// w w w .ja v a 2s .c om * @param fontMetrics scrren font of text. * @param maxWidth maximum width of subchains in pixels. * @return array of subchains of maximum length in pixels. */ public static String[] cutString(String text, FontMetrics fontMetrics, int maxWidth) { Vector strings = new Vector(0, 10); text = text.trim(); while (!text.trim().equals("")) { // Search for the position where I must cut the chain. int cutPos = text.length(); while (fontMetrics.stringWidth(text.substring(0, cutPos)) > maxWidth) cutPos--; // Search for a space or a separator. int sepPos = cutPos - 1; boolean foundSep = false; if (cutPos != text.length()) while (sepPos > 0 && !foundSep) switch (text.charAt(sepPos)) { case ' ': case '.': case ',': case ';': case ':': case '?': foundSep = true; break; default: sepPos--; } // If I did not find then the separator, cut the string in cutPos. if (!foundSep) sepPos = cutPos; else sepPos++; strings.addElement(text.substring(0, sepPos).trim()); text = text.substring(sepPos, text.length()).trim(); } String[] result = new String[strings.size()]; for (int i = 0; i < result.length; i++) result[i] = (String) strings.elementAt(i); return result; }
From source file:gov.nih.nci.evs.browser.utils.MappingSearchUtils.java
public ResolvedConceptReferencesIteratorWrapper searchByName(Vector schemes, Vector versions, String matchText, String matchAlgorithm, int maxToReturn) { if (matchText == null || matchText.trim().length() == 0) return null; matchText = matchText.trim();/*from ww w . j av a 2 s. co m*/ _logger.debug("searchByName ... " + matchText); if (matchAlgorithm.compareToIgnoreCase("contains") == 0) { matchAlgorithm = new SearchUtils().findBestContainsAlgorithm(matchText); } LexBIGService lbSvc = RemoteServerUtil.createLexBIGService(); MappingExtension mappingExtension = null; try { mappingExtension = (MappingExtension) lbSvc.getGenericExtension("MappingExtension"); } catch (Exception ex) { ex.printStackTrace(); return null; } ResolvedConceptReferencesIterator itr = null; int lcv = 0; String scheme = null; String version = null; int numberRemaining = -1; while (itr == null && numberRemaining == -1 && lcv < schemes.size()) { scheme = (String) schemes.elementAt(lcv); version = (String) versions.elementAt(lcv); String containerName = getMappingRelationsContainerName(scheme, version); if (containerName != null) { try { CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag(); if (version != null) { versionOrTag.setVersion(version); } Mapping mapping = mappingExtension.getMapping(scheme, versionOrTag, containerName); if (mapping != null) { mapping = mapping.restrictToMatchingDesignations(matchText, SearchDesignationOption.ALL, matchAlgorithm, null, SearchContext.SOURCE_OR_TARGET_CODES); //Finally, resolve the Mapping. itr = mapping.resolveMapping(); try { numberRemaining = itr.numberRemaining(); //System.out.println("Number of matches: " + numberRemaining); } catch (Exception ex) { ex.printStackTrace(); } } } catch (Exception e) { e.printStackTrace(); } } lcv++; } if (itr != null) { ResolvedConceptReferencesIteratorWrapper wrapper = new ResolvedConceptReferencesIteratorWrapper(itr); wrapper.setCodingSchemeName(scheme); wrapper.setCodingSchemeVersion(version); return wrapper; } return null; }
From source file:org.apache.jasper.compiler.JspConfig.java
private void processWebDotXml(ServletContext ctxt) throws JasperException { InputStream is = ctxt.getResourceAsStream(WEB_XML); if (is == null) { // no web.xml return;//from www . ja v a2 s .c om } ParserUtils pu = new ParserUtils(); TreeNode webApp = pu.parseXMLDocument(WEB_XML, is); if (webApp == null || !"2.4".equals(webApp.findAttribute("version"))) { defaultIsELIgnored = "true"; return; } TreeNode jspConfig = webApp.findChild("jsp-config"); if (jspConfig == null) { return; } jspProperties = new Vector(); Iterator jspPropertyList = jspConfig.findChildren("jsp-property-group"); while (jspPropertyList.hasNext()) { TreeNode element = (TreeNode) jspPropertyList.next(); Iterator list = element.findChildren(); Vector urlPatterns = new Vector(); String pageEncoding = null; String scriptingInvalid = null; String elIgnored = null; String isXml = null; Vector includePrelude = new Vector(); Vector includeCoda = new Vector(); while (list.hasNext()) { element = (TreeNode) list.next(); String tname = element.getName(); if ("url-pattern".equals(tname)) urlPatterns.addElement(element.getBody()); else if ("page-encoding".equals(tname)) pageEncoding = element.getBody(); else if ("is-xml".equals(tname)) isXml = element.getBody(); else if ("el-ignored".equals(tname)) elIgnored = element.getBody(); else if ("scripting-invalid".equals(tname)) scriptingInvalid = element.getBody(); else if ("include-prelude".equals(tname)) includePrelude.addElement(element.getBody()); else if ("include-coda".equals(tname)) includeCoda.addElement(element.getBody()); } if (urlPatterns.size() == 0) { continue; } // Add one JspPropertyGroup for each URL Pattern. This makes // the matching logic easier. for (int p = 0; p < urlPatterns.size(); p++) { String urlPattern = (String) urlPatterns.elementAt(p); String path = null; String extension = null; if (urlPattern.indexOf('*') < 0) { // Exact match path = urlPattern; } else { int i = urlPattern.lastIndexOf('/'); String file; if (i >= 0) { path = urlPattern.substring(0, i + 1); file = urlPattern.substring(i + 1); } else { file = urlPattern; } // pattern must be "*", or of the form "*.jsp" if (file.equals("*")) { extension = "*"; } else if (file.startsWith("*.")) { extension = file.substring(file.indexOf('.') + 1); } else { if (log.isWarnEnabled()) { log.warn(Localizer.getMessage("jsp.warning.bad.urlpattern.propertygroup", urlPattern)); } continue; } } JspProperty property = new JspProperty(isXml, elIgnored, scriptingInvalid, pageEncoding, includePrelude, includeCoda); JspPropertyGroup propertyGroup = new JspPropertyGroup(path, extension, property); jspProperties.addElement(propertyGroup); } } }
From source file:com.github.maven_nar.cpptasks.compiler.AbstractCompiler.java
/** * Returns dependency info for the specified source file * * @param task// w ww . j av a 2s. c o m * task for any diagnostic output * @param source * file to be parsed * @param includePath * include path to be used to resolve included files * * @param sysIncludePath * sysinclude path from build file, files resolved using * sysInclude path will not participate in dependency analysis * * @param envIncludePath * include path from environment variable, files resolved with * envIncludePath will not participate in dependency analysis * * @param baseDir * used to produce relative paths in DependencyInfo * @param includePathIdentifier * used to distinguish DependencyInfo's from different include * path settings * */ public final DependencyInfo parseIncludes(final CCTask task, final File source, final File[] includePath, final File[] sysIncludePath, final File[] envIncludePath, final File baseDir, final String includePathIdentifier) { // // if any of the include files can not be identified // change the sourceLastModified to Long.MAX_VALUE to // force recompilation of anything that depends on it long sourceLastModified = source.lastModified(); final File[] sourcePath = new File[1]; sourcePath[0] = new File(source.getParent()); final Vector onIncludePath = new Vector(); final Vector onSysIncludePath = new Vector(); String baseDirPath; try { baseDirPath = baseDir.getCanonicalPath(); } catch (final IOException ex) { baseDirPath = baseDir.toString(); } final String relativeSource = CUtil.getRelativePath(baseDirPath, source); String[] includes = emptyIncludeArray; if (canParse(source)) { final Parser parser = createParser(source); try { final Reader reader = new BufferedReader(new FileReader(source)); parser.parse(reader); includes = parser.getIncludes(); } catch (final IOException ex) { task.log("Error parsing " + source.toString() + ":" + ex.toString()); includes = new String[0]; } } for (final String include : includes) { if (!resolveInclude(include, sourcePath, onIncludePath)) { if (!resolveInclude(include, includePath, onIncludePath)) { if (!resolveInclude(include, sysIncludePath, onSysIncludePath)) { if (!resolveInclude(include, envIncludePath, onSysIncludePath)) { // // this should be enough to require us to reparse // the file with the missing include for dependency // information without forcing a rebuild sourceLastModified += 2 * CUtil.FILETIME_EPSILON; } } } } } for (int i = 0; i < onIncludePath.size(); i++) { final String relativeInclude = CUtil.getRelativePath(baseDirPath, (File) onIncludePath.elementAt(i)); onIncludePath.setElementAt(relativeInclude, i); } for (int i = 0; i < onSysIncludePath.size(); i++) { final String relativeInclude = CUtil.getRelativePath(baseDirPath, (File) onSysIncludePath.elementAt(i)); onSysIncludePath.setElementAt(relativeInclude, i); } return new DependencyInfo(includePathIdentifier, relativeSource, sourceLastModified, onIncludePath, onSysIncludePath); }
From source file:gov.nih.nci.evs.browser.utils.MappingSearchUtils.java
public ResolvedConceptReferencesIteratorWrapper searchByCode(Vector schemes, Vector versions, String matchText, String matchAlgorithm, SearchContext searchContext, int maxToReturn) { if (matchText == null || matchText.trim().length() == 0) return null; matchText = matchText.trim();//from w w w . j a va2s . c o m _logger.debug("searchByCode ... " + matchText); /* if (matchAlgorithm.compareToIgnoreCase("contains") == 0) { matchAlgorithm = new SearchUtils().findBestContainsAlgorithm(matchText); } */ LexBIGService lbSvc = RemoteServerUtil.createLexBIGService(); MappingExtension mappingExtension = null; try { mappingExtension = (MappingExtension) lbSvc.getGenericExtension("MappingExtension"); } catch (Exception ex) { ex.printStackTrace(); return null; } ResolvedConceptReferencesIterator itr = null; int lcv = 0; String scheme = null; String version = null; int numberRemaining = -1; while (itr == null && numberRemaining == -1 && lcv < schemes.size()) { scheme = (String) schemes.elementAt(lcv); version = (String) versions.elementAt(lcv); String containerName = getMappingRelationsContainerName(scheme, version); if (containerName != null) { try { CodingSchemeVersionOrTag versionOrTag = new CodingSchemeVersionOrTag(); if (version != null) { versionOrTag.setVersion(version); } Mapping mapping = mappingExtension.getMapping(scheme, versionOrTag, containerName); if (mapping != null) { ConceptReferenceList codeList = new ConceptReferenceList(); ConceptReference ref = new ConceptReference(); ref.setConceptCode(matchText); codeList.addConceptReference(ref); mapping = mapping.restrictToCodes(codeList, searchContext); itr = mapping.resolveMapping(); if (itr != null) { try { numberRemaining = itr.numberRemaining(); } catch (Exception ex) { ex.printStackTrace(); } } } } catch (Exception e) { e.printStackTrace(); } } lcv++; } if (itr != null) { ResolvedConceptReferencesIteratorWrapper wrapper = new ResolvedConceptReferencesIteratorWrapper(itr); wrapper.setCodingSchemeName(scheme); wrapper.setCodingSchemeVersion(version); return wrapper; } return null; }
From source file:com.github.maven_nar.cpptasks.CCTask.java
private BuildException runTargetPool(final CCTaskProgressMonitor monitor, BuildException compileException, final ArrayList<Vector<TargetInfo>> targetVectors) { int index;/*from w w w .ja v a 2 s . c om*/ for (final Vector<TargetInfo> targetsForConfig : targetVectors) { // // get the configuration from the first entry // final CompilerConfiguration config = (CompilerConfiguration) targetsForConfig.elementAt(0) .getConfiguration(); // // prepare the list of source files // // BEGINFREEHEP int noOfCores = Runtime.getRuntime().availableProcessors(); log("Found " + noOfCores + " processors available"); if (this.maxCores > 0) { noOfCores = Math.min(this.maxCores, noOfCores); log("Limited processors to " + noOfCores); } final int noOfFiles = targetsForConfig.size(); if (noOfFiles < noOfCores) { noOfCores = noOfFiles; log("Limited used processors to " + noOfCores); } if (this.ordered) { noOfCores = 1; log("Limited processors to 1 due to ordering of source files"); } final List<String>[] sourceFiles = new List[noOfCores]; for (int j = 0; j < sourceFiles.length; j++) { sourceFiles[j] = new ArrayList<>(noOfFiles / sourceFiles.length); } final Enumeration<TargetInfo> targetsEnum = targetsForConfig.elements(); index = 0; while (targetsEnum.hasMoreElements()) { final TargetInfo targetInfo = targetsEnum.nextElement(); sourceFiles[index++].add(targetInfo.getSources()[0].toString()); index %= sourceFiles.length; } // setup cores/cpus final Core[] cores = new Core[noOfCores]; for (int j = 0; j < cores.length; j++) { cores[j] = new Core(this, j, config, this._objDir, sourceFiles[j], this.relentless, monitor); log("\nStarting Core " + j + " with " + sourceFiles[j].size() + " source files..."); } // starting cores for (final Core core : cores) { core.start(); } // checking cores boolean alive = false; try { do { alive = false; for (int j = 0; j < cores.length; j++) { if (cores[j] != null) { if (cores[j].isAlive()) { alive = true; } else { final Exception exception = cores[j].getException(); if (exception != null) { if (compileException == null && exception instanceof BuildException) { compileException = (BuildException) exception; } else { log(cores[j].getName() + " " + exception + " ", Project.MSG_ERR); } if (!this.relentless) { cores[j] = null; alive = false; break; } } cores[j] = null; } } } if (alive) { // wait for a maximum of 5 seconds or #files*2 seconds. Thread.sleep(Math.min(5000, sourceFiles[0].size() * 2000)); } } while (alive); } catch (final InterruptedException e) { break; } // killing leftovers for (final Core core : cores) { if (core != null) { core.interrupt(); log(core.getName() + " interrupted "); } } if (!this.relentless && compileException != null) { break; } // ENDFREEHEP /* * OLD CODE * String[] sourceFiles = new String[targetsForConfig.size()]; * Enumeration targetsEnum = targetsForConfig.elements(); * index = 0; * while (targetsEnum.hasMoreElements()) { * TargetInfo targetInfo = ((TargetInfo) targetsEnum * .nextElement()); * sourceFiles[index++] = targetInfo.getSources()[0] * .toString(); * } * try { * config.compile(this, _objDir, sourceFiles, relentless, * monitor); * } catch (BuildException ex) { * if (compileException == null) { * compileException = ex; * } * if (!relentless) * break; * } */ } return compileException; }
From source file:nl.nn.adapterframework.ldap.LdapSender.java
/** * Return a list of all of the subcontexts of the current context, which is relative to parentContext. * @return an array of Strings containing a list of the subcontexts for a current context. *//*from w w w. j a va 2 s . com*/ public String[] getSubContextList(DirContext parentContext, String relativeContext, ParameterResolutionContext prc) { String[] retValue = null; try { // Create a vector object and add the names of all of the subcontexts // to it Vector n = new Vector(); NamingEnumeration list = parentContext.list(relativeContext); if (log.isDebugEnabled()) log.debug("getSubCOntextList(context) : context = " + relativeContext); for (int x = 0; list.hasMore(); x++) { NameClassPair nc = (NameClassPair) list.next(); n.addElement(nc); } // Create a string array of the same size as the vector object String contextList[] = new String[n.size()]; for (int x = 0; x < n.size(); x++) { // Add each name to the array contextList[x] = ((NameClassPair) (n.elementAt(x))).getName(); } retValue = contextList; } catch (NamingException e) { storeLdapException(e, prc); log.error("Exception in operation [" + getOperation() + "] ", e); } return retValue; }
From source file:org.apache.webdav.cmd.Client.java
void ls(String options, String path) { // set default option. char option = 'F'; if ((options != null) && (options.indexOf('l') > 0)) option = 'l'; try {//from ww w. ja va 2 s . c o m // Check that the path is ok. if (path != null) { path = checkUri(path + "/"); webdavResource.setPath(path); } else { path = checkUri("./"); webdavResource.setPath(path); } switch (option) { case 'l': Vector basiclist = webdavResource.listBasic(); for (int i = 0; i < basiclist.size(); i++) { String[] longFormat = (String[]) basiclist.elementAt(i); // name -> position 4 String s = longFormat[4]; int len = s.length(); out.print(s); for (int k = len; k < 20; k++) out.print(" "); // size -> position 1 s = longFormat[1]; len = s.length(); for (int k = 10 - len; k > 0; k--) out.print(" "); // don't cut the size. out.print(s + " "); // description -> position 2 // cut the description. s = longFormat[2]; len = s.length(); out.print(" " + ((len > 20) ? s.substring(0, 20) : s)); for (int k = len; k < 20; k++) out.print(" "); // date -> position 3 s = longFormat[3]; len = s.length(); out.println(" " + s); } break; case 'F': String[] list = webdavResource.list(); if (list != null) { int i = 0; for (; i < list.length; i++) { out.print(list[i] + " "); for (int j = list[i].length(); j < 25; j++) { out.print(" "); } if (i % 3 == 2) out.println(); } if (list.length > 0 && i % 3 != 0) out.println(); } break; default: } // end of switch } catch (Exception ex) { handleException(ex); } }
From source file:eionet.acl.PersistenceDB.java
private String[][] executeStringQuery(String sql) throws SQLException { Vector<String[]> rvec = new Vector<String[]>(); // Return value as Vector String[][] rval = {}; // Return value Connection con = null;// w w w . j ava 2s . com Statement stmt = null; ResultSet rset = null; // Process the result set con = getConnection(); try { stmt = con.createStatement(); rset = stmt.executeQuery(sql); ResultSetMetaData md = rset.getMetaData(); //number of columns in the result set int colCnt = md.getColumnCount(); while (rset.next()) { String[] row = new String[colCnt]; // Row of the result set // Retrieve the columns of the result set for (int i = 0; i < colCnt; ++i) { row[i] = rset.getString(i + 1); } rvec.addElement(row); } } catch (SQLException e) { e.printStackTrace(System.out); throw new SQLException("Error occurred when processing result set: " + sql); } finally { close(con, stmt, null); } // Build return value if (rvec.size() > 0) { rval = new String[rvec.size()][]; for (int i = 0; i < rvec.size(); ++i) rval[i] = (String[]) rvec.elementAt(i); } // Success return rval; }