List of usage examples for java.util Scanner hasNext
public boolean hasNext()
From source file:com.axelor.controller.ConnectionToPrestashop.java
@SuppressWarnings("finally") @Transactional/*from w w w . j av a 2 s . c o m*/ public String syncCurrency() { String message = ""; try { List<Integer> currencyIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Currency> erpList = Currency.all().fetch(); for (Currency erpCurrency : erpList) { erpIdList.add(erpCurrency.getPrestashopCurrencyId()); } URL url = new URL( "http://localhost/client-lib/crud/action.php?resource=currencies&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); currencyIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop :: " + currencyIdList.size()); System.out.println("From ERP :: " + erpIdList.size()); scan.close(); // Check new entries in the prestahop Iterator<Integer> prestaListIterator = currencyIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current prestaid for operation ::" + tempId); if (erpIdList.contains(tempId)) { erpIdList.remove(tempId); } else { System.out.println("Current prestaid for insertion operation ::" + tempId); // insert new data in ERP Database insertCurrency(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { System.out.println("Currently in Erp ::" + tempId); Currency currencyDelete = Currency.all().filter("prestashopCurrencyId=?", tempId) .fetchOne(); String currencyName = currencyDelete.getName(); // customerGroupDelete.remove(); currencyDelete.setArchived(Boolean.TRUE); System.out.println("customer deleted ::" + currencyName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:com.axelor.controller.ConnectionToPrestashop.java
@Transactional @SuppressWarnings("finally") public String syncCustomer() { String message = ""; try {//ww w .j a v a2 s. c om List<Integer> prestashopIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Partner> erpList = Partner.all().fetch(); for (Partner prestahopCustomer : erpList) { erpIdList.add(prestahopCustomer.getPrestashopid()); } System.out.println("API KEY :: " + apiKey); URL url = new URL("http://localhost/client-lib/crud/action.php?resource=customers&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); prestashopIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop :: " + prestashopIdList.size()); System.out.println("From ERP :: " + erpIdList.size()); scan.close(); // Check new entries in the prestshop Iterator<Integer> prestaListIterator = prestashopIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current prestaid for operation ::" + tempId); if (erpIdList.contains(tempId)) { Customer tempCustomer = getCustomer(tempId); String dateUpdate = tempCustomer.getDate_upd(); LocalDateTime dt1 = LocalDateTime.parse(dateUpdate, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); Partner pCust = Partner.all().filter("prestashopId=?", tempId).fetchOne(); LocalDateTime dt2 = pCust.getUpdatedOn(); if (dt2 != null) { int diff = Seconds.secondsBetween(dt2, dt1).getSeconds(); if (diff > 1) updateCustomer(tempCustomer, tempId); } else { updateCustomer(tempCustomer, tempId); } erpIdList.remove(tempId); } else { System.out.println("Current prestaid for insertion operation ::" + tempId); // insert new data in ERP Database insertCustomer(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { System.out.println("Currently in Erp ::" + tempId); Partner customerDelete = Partner.all().filter("prestashopid=?", tempId).fetchOne(); String firstName = customerDelete.getFirstName(); customerDelete.setArchived(Boolean.TRUE); System.out.println("customer deleted ::" + firstName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:com.axelor.controller.ConnectionToPrestashop.java
@SuppressWarnings("finally") @Transactional// w w w .ja v a 2s . c o m public String syncAddress() { String message = ""; try { List<Integer> prestashopIdList = new ArrayList<Integer>(); List<Integer> erpIdList = new ArrayList<Integer>(); List<Address> erpList = Address.all().fetch(); for (Address prestahopAddress : erpList) { erpIdList.add(prestahopAddress.getPrestashopid()); } URL url = new URL("http://localhost/client-lib/crud/action.php?resource=addresses&action=getallid&Akey=" + apiKey); HttpURLConnection connection = (HttpURLConnection) url.openConnection(); connection.setRequestMethod("GET"); connection.connect(); InputStream inputStream = connection.getInputStream(); Scanner scan = new Scanner(inputStream); while (scan.hasNext()) { String data = scan.nextLine(); System.out.println(data); prestashopIdList.add(Integer.parseInt(data)); } System.out.println("From Prestashop Addresses :: " + prestashopIdList.size()); System.out.println("From ERP Addresses :: " + erpIdList.size()); scan.close(); // Check new entries in the prestashop Iterator<Integer> prestaListIterator = prestashopIdList.iterator(); while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Current AddressPrestashopId for operation ::" + tempId); if (erpIdList.contains(tempId)) { com.axelor.pojo.Address tempAddress = getAddress(tempId); String dateUpdate = tempAddress.getDate_upd(); LocalDateTime dt1 = LocalDateTime.parse(dateUpdate, DateTimeFormat.forPattern("yyyy-MM-dd HH:mm:ss")); Address pAddress = Address.all().filter("prestashopid=?", tempId).fetchOne(); LocalDateTime dt2 = pAddress.getUpdatedOn(); if (dt2 != null) { int diff = Seconds.secondsBetween(dt2, dt1).getSeconds(); if (diff > 1) updateAddress(tempAddress, tempId); } else { updateAddress(tempAddress, tempId); } erpIdList.remove(tempId); } else { System.out.println("Current AddressPrestashopId for insertion operation ::" + tempId); // insert new data in ERP Database insertAddress(tempId); erpIdList.remove(tempId); } } if (erpIdList.isEmpty()) { System.out.println("Synchronization is completed."); message = "done"; } else { // delete from ERP Iterator<Integer> erpListIterator = erpIdList.iterator(); while (erpListIterator.hasNext()) { Integer tempId = erpListIterator.next(); if (tempId != 0) { Address addressDelete = Address.all().filter("prestashopid=?", tempId).fetchOne(); String fullName = addressDelete.getFullName(); // addressDelete.remove(); addressDelete.setArchived(Boolean.TRUE); System.out.println("Address deleted ::" + fullName); } } while (prestaListIterator.hasNext()) { Integer tempId = prestaListIterator.next(); System.out.println("Currently in prestashop ::" + tempId); } System.out.println("Synchronization is completed."); message = "done"; } } catch (Exception e) { message = "Wrong Authentication Key or Key has been disabled."; } finally { return message; } }
From source file:gtu._work.ui.JSFMakerUI.java
void resetPasteClipboardHtmlToJtable() { String content = ClipboardUtil.getInstance().getContents(); Pattern tdStartPattern = Pattern.compile("<[tT][dDhH][^>]*>"); Pattern tdEndPattern = Pattern.compile("</[tT][dDhH]>"); Pattern innerPattern_HasTag = Pattern.compile("<[\\w:]+\\s[^>]*value=\"([^\"]*)\"[^>]*>", Pattern.MULTILINE);/*w ww.jav a2s .co m*/ Matcher innerMatcher = null; Scanner scan = new Scanner(content); Scanner tdScan = null; String currentContent = null; String tdContent = null; StringBuilder sb = new StringBuilder(); scan.useDelimiter("<tr>"); for (; scan.hasNext();) { boolean anyMatcher = false; tdScan = new Scanner(scan.next()); tdScan.useDelimiter(tdStartPattern); while (tdScan.hasNext()) { tdScan.useDelimiter(tdEndPattern); if (tdScan.hasNext()) { tdContent = tdScan.next().replaceAll(tdStartPattern.pattern(), ""); { innerMatcher = innerPattern_HasTag.matcher(tdContent.toString()); if (innerMatcher.find()) { currentContent = StringUtils.defaultIfEmpty(innerMatcher.group(1), " "); // System.out.format("1[%s]\n", currentContent); sb.append(currentContent + "\t"); continue; } currentContent = tdContent.toString().replaceAll("<[\\w:=,.#;/'?\"\\s\\{\\}\\(\\)\\[\\]]+>", ""); currentContent = currentContent.replaceAll("[\\s\t\n]", ""); currentContent = StringUtils.defaultIfEmpty(currentContent, " "); // System.out.format("2[%s]\n", currentContent); sb.append(currentContent + "\t"); anyMatcher = true; } } tdScan.useDelimiter(tdStartPattern); } if (anyMatcher) { sb.append("\n"); } } scan.close(); ClipboardUtil.getInstance().setContents(sb); System.out.println("####################################"); System.out.println(sb); System.out.println("####################################"); }
From source file:marytts.tools.voiceimport.HMMVoicePackager.java
/** * Load mapping of features from file/*from w w w . j av a 2 s . c o m*/ * @param fileName * @throws FileNotFoundException */ private Map<String, String> loadFeaturesMap(String fileName) throws FileNotFoundException { Scanner aliasList = null; try { aliasList = new Scanner(new BufferedReader(new FileReader(fileName))); String line; logger.info("loading features map from file: " + fileName); while (aliasList.hasNext()) { line = aliasList.nextLine(); String[] fea = line.split(" "); actualFeatureNames.put(fea[1], fea[0]); logger.info(" " + fea[0] + " --> " + fea[1]); } if (aliasList != null) { aliasList.close(); } } catch (FileNotFoundException e) { logger.debug("loadTrickyPhones: " + e.getMessage()); throw new FileNotFoundException(); } return actualFeatureNames; }
From source file:com.netcrest.pado.tools.pado.command.temporal.java
@SuppressWarnings({ "unchecked", "rawtypes" }) private void runHistory(ITemporalBiz temporalBiz, String commandLineArg) throws Exception { Scanner scanner = new Scanner(commandLineArg); if (scanner.hasNext()) { identityKeyStr = scanner.next(); } else {// w ww.j a v a2 s. c o m PadoShell.printlnError(this, "history: IdentityKey not specified."); return; } if (objectPattern.matcher(identityKeyStr).matches()) { identityKey = generateObject(identityKeyStr); } else { PadoShell.printlnError(this, "history: IdentityKey is not specified in proper format."); return; } identityKey = generateObject(identityKeyStr); TemporalDataList tdl = temporalBiz.getTemporalAdminBiz().getTemporalDataList(identityKey); if (tdl == null) { PadoShell.printlnError(this, "history: Identity key not found."); return; } TemporalPrintUtil.dump(tdl, rawFormat); }
From source file:org.kuali.kfs.sys.context.CheckModularization.java
protected boolean testOptionalModuleOjbConfiguration(ModuleGroup moduleGroup, StringBuffer errorMessage) throws FileNotFoundException { boolean testSucceeded = true; for (String referencedNamespaceCode : OPTIONAL_NAMESPACE_CODES_TO_SPRING_FILE_SUFFIX.keySet()) { if (!(moduleGroup.namespaceCode.equals(referencedNamespaceCode) || moduleGroup.optionalModuleDependencyNamespaceCodes.contains(referencedNamespaceCode))) { if (OJB_FILES_BY_MODULE.get(moduleGroup.namespaceCode).isEmpty()) continue; String firstDatabaseRepositoryFilePath = OJB_FILES_BY_MODULE.get(moduleGroup.namespaceCode) .iterator().next();/*from w w w . j a va 2s . c om*/ // the first database repository file path is typically the file that comes shipped with KFS. If institutions override it, this unit test will not test them Scanner scanner = new Scanner(new File("work/src/" + firstDatabaseRepositoryFilePath)); int count = 0; while (scanner.hasNext()) { String token = scanner.next(); String firstPackagePrefix = PACKAGE_PREFIXES_BY_MODULE.get(referencedNamespaceCode).iterator() .next(); // A module may be responsible for many packages, but the first one should be the KFS built-in package that is *not* the module's integration package if (token.contains(firstPackagePrefix)) { count++; } } if (count > 0) { if (testSucceeded) { testSucceeded = false; errorMessage.append("\n").append(moduleGroup.namespaceCode).append(": "); } else { errorMessage.append(", "); } errorMessage.append(count).append(" references to ").append(referencedNamespaceCode); } } } return testSucceeded; }
From source file:net.billylieurance.azuresearch.AbstractAzureSearchQuery.java
/** * * @param is An InputStream holding some XML that needs parsing * @return a parsed Document from the XML in the stream */// w w w. j a v a 2 s. c om public Document loadXMLFromStream(InputStream is) { DocumentBuilderFactory factory; DocumentBuilder builder; BOMInputStream bis; String dumpable = ""; try { factory = DocumentBuilderFactory.newInstance(); builder = factory.newDocumentBuilder(); bis = new BOMInputStream(is); if (_debug) { java.util.Scanner s = new java.util.Scanner(bis).useDelimiter("\\A"); dumpable = s.hasNext() ? s.next() : ""; // convert String into InputStream InputStream istwo = new java.io.ByteArrayInputStream(dumpable.getBytes()); return builder.parse(istwo); } else { return builder.parse(bis); } } catch (IOException e) { e.printStackTrace(); } catch (SAXException e) { if (e instanceof SAXParseException) { SAXParseException ex = (SAXParseException) e; System.out.println("Line: " + ex.getLineNumber()); System.out.println("Col: " + ex.getColumnNumber()); System.out.println("Data: " + dumpable); } e.printStackTrace(); } catch (ParserConfigurationException e) { e.printStackTrace(); } return null; }
From source file:org.fao.geonet.kernel.csw.services.GetRecords.java
/** * Retrieves the values of attribute typeNames. If typeNames contains csw:BriefRecord or csw:SummaryRecord, an * exception is thrown.//from www. j av a 2s.c o m * * @param query the query * @return list of typenames, or null if not found * @throws InvalidParameterValueEx if a typename is illegal */ private Set<String> getTypeNames(Element query) throws InvalidParameterValueEx { Set<String> typeNames = null; String typeNames$ = query.getAttributeValue("typeNames"); if (typeNames$ != null) { Scanner commaSeparatedScanner = new Scanner(typeNames$).useDelimiter(","); while (commaSeparatedScanner.hasNext()) { String typeName = commaSeparatedScanner.next().trim(); // These two are explicitly not allowed as search targets in CSW 2.0.2, so we throw an exception if the // client asks for them if (typeName.equals("csw:BriefRecord") || typeName.equals("csw:SummaryRecord")) { throw new InvalidParameterValueEx("typeName", typeName); } if (typeNames == null) { typeNames = new HashSet<String>(); } typeNames.add(typeName); } } // TODO in if(isDebugEnabled) condition. Jeeves LOG doesn't provide that useful function though. if (typeNames != null) { for (String typeName : typeNames) { if (Log.isDebugEnabled(Geonet.CSW)) Log.debug(Geonet.CSW, "TypeName: " + typeName); } } else { if (Log.isDebugEnabled(Geonet.CSW)) Log.debug(Geonet.CSW, "No TypeNames found in request"); } // TODO end if(isDebugEnabled) return typeNames; }
From source file:org.de.jmg.jmgphotouploader._MainActivity.java
private void AcceptLicenseAndPP(SharedPreferences prefs) throws Throwable { boolean blnLicenseAccepted = prefs.getBoolean("LicenseAccepted", false); if (!blnLicenseAccepted) { InputStream is = this.getAssets().open("LICENSE"); java.util.Scanner s = new java.util.Scanner(is).useDelimiter("\\A"); String strLicense = s.hasNext() ? s.next() : ""; s.close();//from w ww. ja v a 2s. c o m is.close(); lib.yesnoundefined res = (lib.ShowMessageYesNo(this, strLicense, getString(R.string.license), true)); lib.yesnoundefined res2 = lib.yesnoundefined.undefined; if (res == lib.yesnoundefined.yes) { res2 = lib.AcceptPrivacyPolicy(this, Locale.getDefault()); } if (res == lib.yesnoundefined.yes && res2 == lib.yesnoundefined.yes) { prefs.edit().putBoolean("LicenseAccepted", true).commit(); } else { prefs.edit().putBoolean("LicenseAccepted", false).commit(); finish(); } } }