List of usage examples for java.util StringTokenizer StringTokenizer
public StringTokenizer(String str, String delim)
From source file:com.bigdata.dastor.utils.FBUtilities.java
public static String[] strip(String string, String token) { StringTokenizer st = new StringTokenizer(string, token); List<String> result = new ArrayList<String>(); while (st.hasMoreTokens()) { result.add((String) st.nextElement()); }/* w w w. jav a2 s . c om*/ return result.toArray(new String[0]); }
From source file:net.sourceforge.dita4publishers.impl.dita.DitaClassImpl.java
/** * @param classSpec/*from w w w .j av a2s .c o m*/ * @throws DitaException */ public DitaClassImpl(String classSpec) throws DitaException { if (classSpec == null || classSpec.trim().equals("")) throw new DitaClassSpecificationException("Null or empty class specification."); this.classSpec = classSpec; StringTokenizer tokens = new StringTokenizer(classSpec, " "); String token = tokens.nextToken(); this.isDomainType = false; this.isStructuralType = false; if (token.equals("+")) this.isDomainType = true; else if (token.equals("-")) this.isStructuralType = true; else throw new DitaClassSpecificationException( "First token of class specification \"" + classSpec + " is not '+' or '-'"); if (!tokens.hasMoreTokens()) throw new DitaClassSpecificationException( "Class specification missing required first token following +/-: \"" + classSpec + "\""); while (tokens.hasMoreTokens()) { token = tokens.nextToken(); typeList.add(token); } }
From source file:com.GTDF.server.Transxchange2GoogleTransitServiceImpl.java
public String transxchange2GoogleTransit_transform(String inArgs) { String rootDirectory = getServletConfig().getInitParameter("TRANSFORM_HOME"); String workDirectory = getServletConfig().getInitParameter("TRANSFORM_DIR"); int maxargs = 5; String[] args = new String[maxargs]; int argv = 0; String result = ""; TransxchangeHandler handler = null;/*from www . j av a 2s. com*/ /* * Parse input string to extract arguments (similar command line arguments) */ StringTokenizer st = new StringTokenizer(inArgs, " "); while (st.hasMoreTokens() && argv < maxargs) { args[argv] = st.nextToken(); argv++; } if (argv < maxargs) // Don't let in if too few arguments return "Not enough arguments. Required: <url> <timezone> <default route type> <output-directory>"; String outdir = ""; if (argv == 5) outdir = args[4]; /* * Parse transxchange input file */ String fileName = FilenameUtils.getName(args[0]); try { handler = new TransxchangeHandler(); handler.parse(rootDirectory + workDirectory + '/' + outdir + '/' + fileName, args[1], args[2], args[3], rootDirectory, workDirectory + '/' + outdir); } catch (Exception e) { return e.getMessage(); } /* * Create Google Transit output files */ try { result = handler.writeOutput(rootDirectory, workDirectory + '/' + outdir); } catch (Exception e) { return e.getMessage(); } /* * Success - create return message */ String hostedOn = getServletConfig().getInitParameter("HOSTED_ON"); return "Created Google Transit Data Feed Spec archive at: " + hostedOn + result; }
From source file:de.mirkosertic.easydav.index.QueryParser.java
private void addSubQuery(BooleanQuery aQuery, String aTerm, boolean aNegated, String aSearchField) { if (!StringUtils.isEmpty(aTerm)) { if (!aTerm.contains("*")) { if (aTerm.contains(" ")) { PhraseQuery thePhraseQuery = new PhraseQuery(); for (StringTokenizer theTokenizer = new StringTokenizer(aTerm, " "); theTokenizer .hasMoreTokens();) { String theToken = theTokenizer.nextToken(); thePhraseQuery.add(new Term(aSearchField, theToken)); }/*from www .j av a 2 s . com*/ thePhraseQuery.setSlop(1); if (aNegated) { aQuery.add(thePhraseQuery, BooleanClause.Occur.MUST_NOT); } else { aQuery.add(thePhraseQuery, BooleanClause.Occur.MUST); } } else { Query theQuery; if (!aTerm.endsWith("~")) { theQuery = new TermQuery(new Term(aSearchField, aTerm)); } else { theQuery = new FuzzyQuery(new Term(aSearchField, aTerm.substring(0, aTerm.length() - 1))); } if (aNegated) { aQuery.add(theQuery, BooleanClause.Occur.MUST_NOT); } else { aQuery.add(theQuery, BooleanClause.Occur.MUST); } } } else { WildcardQuery theWildcardQuery = new WildcardQuery(new Term(aSearchField, aTerm)); if (aNegated) { aQuery.add(theWildcardQuery, BooleanClause.Occur.MUST_NOT); } else { aQuery.add(theWildcardQuery, BooleanClause.Occur.MUST); } } } }
From source file:com.salesmanager.core.module.impl.application.files.CoreFileImpl.java
public String uploadFile(int merchantid, String config, File file, String fileName, String contentType) throws FileException { /** Check content type **/ String imgct = conf.getString(config + ".contenttypes"); if (imgct != null) { List ct = new ArrayList(); StringTokenizer st = new StringTokenizer(imgct, ";"); while (st.hasMoreTokens()) { ct.add(st.nextToken());// ww w . j av a 2 s. c o m } // check content type if (!ct.contains(contentType)) { throw new FileException(LabelUtil.getInstance().getText("errors.unsupported.file ") + contentType); } } /** if an image check size **/ String imgwsz = conf.getString(config + ".maxwidth"); String imghsz = conf.getString(config + ".maxheight"); if (imgwsz != null && imghsz != null) { int wseize = 0; int hseize = 0; BufferedImage originalImage = null; try { wseize = Integer.parseInt(imgwsz); hseize = Integer.parseInt(imghsz); } catch (Exception e) { throw new FileException(e); } try { originalImage = ImageIO.read(file); int width = originalImage.getWidth(); int height = originalImage.getHeight(); if (width > wseize || height > hseize) { throw new FileException(LabelUtil.getInstance().getText("errors.filedimensiontoolarge")); } } catch (FileException fe) { throw fe; } catch (Exception e) { throw new FileException(e); } } // Check file size long fsize = file.length(); String smaxfsize = conf.getString(config + ".maxfilesize"); if (StringUtils.isBlank(smaxfsize)) { smaxfsize = conf.getString("core.branding.cart.maxfilesize"); } if (smaxfsize == null) { throw new FileException(FileException.ERROR, "Properties " + config + ".maxfilesize not defined"); } long maxsize = 0; try { maxsize = Long.parseLong(smaxfsize); } catch (Exception e) { throw new FileException(e); } if (fsize > maxsize) { throw new FileException(LabelUtil.getInstance().getText("errors.filetoolarge")); } return copyFile(merchantid, config, file, fileName, contentType); }
From source file:com.agimatec.annotations.jam.JAMTestMethod.java
public String getType(String path) { if (path == null || path.length() == 0) return getType(); StringTokenizer tokens = new StringTokenizer(path, "."); JClass current = jmethod.getReturnType(); while (tokens.hasMoreTokens() && current != null) { String each = tokens.nextToken(); JField field = findField(current, each); current = (field == null) ? null : field.getType(); }// www. j a va2 s. c o m if (current == null) return null; else return current.getQualifiedName(); }
From source file:com.acmeair.loader.FlightLoader.java
public void loadFlights() throws Exception { InputStream csvInputStream = FlightLoader.class.getResourceAsStream("/mileage.csv"); LineNumberReader lnr = new LineNumberReader(new InputStreamReader(csvInputStream)); String line1 = lnr.readLine(); StringTokenizer st = new StringTokenizer(line1, ","); ArrayList<AirportCodeMapping> airports = new ArrayList<AirportCodeMapping>(); // read the first line which are airport names while (st.hasMoreTokens()) { AirportCodeMapping acm = new AirportCodeMapping(); acm.setAirportName(st.nextToken()); airports.add(acm);//from ww w . j ava 2 s. c om } // read the second line which contains matching airport codes for the first line String line2 = lnr.readLine(); st = new StringTokenizer(line2, ","); int ii = 0; while (st.hasMoreTokens()) { String airportCode = st.nextToken(); airports.get(ii).setAirportCode(airportCode); ii++; } // read the other lines which are of format: // airport name, aiport code, distance from this airport to whatever airport is in the column from lines one and two String line; int flightNumber = 0; while (true) { line = lnr.readLine(); if (line == null || line.trim().equals("")) { break; } st = new StringTokenizer(line, ","); String airportName = st.nextToken(); String airportCode = st.nextToken(); if (!alreadyInCollection(airportCode, airports)) { AirportCodeMapping acm = new AirportCodeMapping(); acm.setAirportName(airportName); acm.setAirportCode(airportCode); airports.add(acm); } int indexIntoTopLine = 0; while (st.hasMoreTokens()) { String milesString = st.nextToken(); if (milesString.equals("NA")) { indexIntoTopLine++; continue; } int miles = Integer.parseInt(milesString); String toAirport = airports.get(indexIntoTopLine).getAirportCode(); String flightId = "AA" + flightNumber; FlightSegment flightSeg = new FlightSegment(flightId, airportCode, toAirport, miles); flightService.storeFlightSegment(flightSeg); Date now = new Date(); for (int daysFromNow = 0; daysFromNow < MAX_FLIGHTS_PER_SEGMENT; daysFromNow++) { Calendar c = Calendar.getInstance(); c.setTime(now); c.set(Calendar.HOUR_OF_DAY, 0); c.set(Calendar.MINUTE, 0); c.set(Calendar.SECOND, 0); c.set(Calendar.MILLISECOND, 0); c.add(Calendar.DATE, daysFromNow); Date departureTime = c.getTime(); Date arrivalTime = getArrivalTime(departureTime, miles); flightService.createNewFlight(flightId, departureTime, arrivalTime, new BigDecimal(500), new BigDecimal(200), 10, 200, "B747"); } flightNumber++; indexIntoTopLine++; } } for (int jj = 0; jj < airports.size(); jj++) { flightService.storeAirportMapping(airports.get(jj)); } lnr.close(); }
From source file:com.handpay.ibenefit.framework.util.WebUtils.java
public static boolean checkIfNoneMatchEtag(HttpServletRequest request, HttpServletResponse response, String etag) {/*w w w. j a v a 2 s. c o m*/ String headerValue = request.getHeader("If-None-Match"); if (headerValue != null) { boolean conditionSatisfied = false; if (!"*".equals(headerValue)) { StringTokenizer commaTokenizer = new StringTokenizer(headerValue, ","); while (!conditionSatisfied && commaTokenizer.hasMoreTokens()) { String currentToken = commaTokenizer.nextToken(); if (currentToken.trim().equals(etag)) { conditionSatisfied = true; } } } else { conditionSatisfied = true; } if (conditionSatisfied) { response.setStatus(HttpServletResponse.SC_NOT_MODIFIED); response.setHeader("ETag", etag); return false; } } return true; }
From source file:edu.illinois.cs.cogcomp.wikifier.utils.io.InFile.java
public static List<String> tokenize(String s, String delims) { if (s == null) return null; List<String> res = new ArrayList<String>(); StringTokenizer st = new StringTokenizer(s, delims); while (st.hasMoreTokens()) res.add(st.nextToken());/* w w w . j a va 2s . co m*/ return res; }
From source file:ddf.security.sts.claimsHandler.AttributeMapLoader.java
/** * Obtains the user name from the principal. * * @param principal Describing the current user that should be used for retrieving claims. * @return the user name if the principal has one, null if no name is specified or if principal * is null.// www . ja va2s.c om */ public static String getUser(Principal principal) { String user = null; if (principal instanceof KerberosPrincipal) { KerberosPrincipal kp = (KerberosPrincipal) principal; StringTokenizer st = new StringTokenizer(kp.getName(), "@"); st = new StringTokenizer(st.nextToken(), "/"); user = st.nextToken(); } else if (principal instanceof X500Principal) { X500Principal x500p = (X500Principal) principal; StringTokenizer st = new StringTokenizer(x500p.getName(), ","); while (st.hasMoreElements()) { // token is in the format: // syntaxAndUniqueId // cn // ou // o // loc // state // country String[] strArr = st.nextToken().split("="); if (strArr.length > 1 && strArr[0].equalsIgnoreCase("cn")) { user = strArr[1]; break; } } } else if (principal != null) { user = principal.getName(); } return user; }