List of usage examples for java.lang String compareToIgnoreCase
public int compareToIgnoreCase(String str)
From source file:com.magestore.app.pos.api.m1.config.POSConfigDataAccessM1.java
@Override public Map<String, ConfigCountry> getCountryGroup() throws DataAccessException, ConnectionException, ParseException, IOException, ParseException { // nu cha load config, cn khi to ch default if (mConfig == null) mConfig = new PosConfigDefault(); List<LinkedTreeMap> countryList = (ArrayList) mConfig.getValue("country"); Map<String, ConfigCountry> listConfigCountry = new LinkedTreeMap<>(); Collections.sort(countryList, new Comparator<LinkedTreeMap>() { @Override/*from ww w .j a v a 2 s. c om*/ public int compare(LinkedTreeMap linkedTreeMap, LinkedTreeMap linkedTreeMap1) { String name = linkedTreeMap.get("country_name").toString(); String name1 = linkedTreeMap1.get("country_name").toString(); return name.compareToIgnoreCase(name1); } }); for (LinkedTreeMap country : countryList) { ConfigCountry configCountry = new PosConfigCountry(); String country_id = country.get("country_id").toString(); String country_name = country.get("country_name").toString(); configCountry.setCountryID(country_id); configCountry.setCountryName(country_name); Map<String, ConfigRegion> mapRegion = getRegion(country_id); if (mapRegion != null) { configCountry.setRegions(mapRegion); } listConfigCountry.put(country_id, configCountry); } return listConfigCountry; }
From source file:io.hops.hopsworks.api.pythonDeps.PythonDepsService.java
private Collection<LibVersions> findCondaLib(PythonDepJson lib) throws ServiceException { String url = lib.getChannelUrl(); String library = lib.getLib(); List<LibVersions> all = new ArrayList<>(); String prog = settings.getHopsworksDomainDir() + "/bin/condasearch.sh"; ProcessBuilder pb = new ProcessBuilder(prog, url, library); try {/*w ww . j a v a 2 s. c o m*/ Process process = pb.start(); BufferedReader br = new BufferedReader(new InputStreamReader(process.getInputStream())); String line; String foundLib = ""; String foundVersion; while ((line = br.readLine()) != null) { // returns key,value pairs String[] libVersion = line.split(","); if (libVersion.length != 2) { throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_FORMAT_ERROR, Level.WARNING); } String key = libVersion[0]; String value = libVersion[1]; // if the key starts with a letter, it is a library name, otherwise it's a version number // Output searching for 'pandas' looks like this: // Loading,channels: // pandas-datareader,0.2.0 // 0.2.0,py34_0 //.... // pandasql,0.3.1 // 0.3.1,np16py27_0 //.... // 0.4.2,np18py33_0 // // Skip the first line if (key.compareToIgnoreCase("Loading") == 0 || value.compareToIgnoreCase("channels:") == 0) { continue; } // First row is sometimes empty if (key.isEmpty()) { continue; } if (key.contains("Name") || key.contains("#")) { continue; } char c = key.charAt(0); if (c >= 'a' && c <= 'z') { foundLib = key; foundVersion = value; } else { foundVersion = key; } LibVersions lv = null; for (LibVersions v : all) { if (v.getLib().compareTo(foundLib) == 0) { lv = v; break; } } if (lv == null) { lv = new LibVersions(url, foundLib); all.add(lv); } lv.addVersion(new Version(foundVersion)); } int errCode = process.waitFor(); if (errCode == 2) { throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_ERROR, Level.SEVERE, "errCode: " + errCode); } else if (errCode == 1) { throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_NOT_FOUND, Level.SEVERE, "errCode: " + errCode); } return all; } catch (IOException | InterruptedException ex) { throw new ServiceException(RESTCodes.ServiceErrorCode.ANACONDA_LIST_LIB_ERROR, Level.SEVERE, "lib: " + lib.getLib(), ex.getMessage(), ex); } }
From source file:org.apache.synapse.transport.nhttp.ClientHandler.java
private void setHeaders(HttpContext context, HttpResponse response, MessageContext outMsgCtx, MessageContext responseMsgCtx) { Header[] headers = response.getAllHeaders(); if (headers != null && headers.length > 0) { Map<String, String> headerMap = new TreeMap<String, String>(new Comparator<String>() { public int compare(String o1, String o2) { return o1.compareToIgnoreCase(o2); }//from www . j a v a2 s .co m }); String endpointURLPrefix = (String) context.getAttribute(NhttpConstants.ENDPOINT_PREFIX); String servicePrefix = (String) outMsgCtx.getProperty(NhttpConstants.SERVICE_PREFIX); for (int i = 0; i < headers.length; i++) { Header header = headers[i]; // if this header is already added if (headerMap.containsKey(header.getName())) { /* this is a multi-value header */ // generate the key String key = NhttpConstants.EXCESS_TRANSPORT_HEADERS; // get the old value String oldValue = headerMap.get(header.getName()); // adds additional values to a list in a property of message // context Map map; if (responseMsgCtx.getProperty(key) != null) { map = (Map) responseMsgCtx.getProperty(key); map.put(header.getName(), oldValue); } else { map = new MultiValueMap(); map.put(header.getName(), oldValue); // set as a property in message context responseMsgCtx.setProperty(key, map); } } if ("Location".equals(header.getName()) && endpointURLPrefix != null && servicePrefix != null) { // Here, we are changing only the host name and the port of // the new URI - value of the Location // header. // If the new URI is again referring to a resource in the // server to which the original request // is sent, then replace the hostname and port of the URI // with the hostname and port of synapse // We are not changing the request url here, only the host // name and the port. try { URI serviceURI = new URI(servicePrefix); URI endpointURI = new URI(endpointURLPrefix); URI locationURI = new URI(header.getValue()); if (locationURI.getHost().equalsIgnoreCase(endpointURI.getHost())) { URI newURI = new URI(locationURI.getScheme(), locationURI.getUserInfo(), serviceURI.getHost(), serviceURI.getPort(), locationURI.getPath(), locationURI.getQuery(), locationURI.getFragment()); headerMap.put(header.getName(), newURI.toString()); responseMsgCtx.setProperty(NhttpConstants.SERVICE_PREFIX, outMsgCtx.getProperty(NhttpConstants.SERVICE_PREFIX)); } } catch (URISyntaxException e) { log.error(e.getMessage(), e); } } else { headerMap.put(header.getName(), header.getValue()); } } responseMsgCtx.setProperty(MessageContext.TRANSPORT_HEADERS, headerMap); } }
From source file:org.openmrs.module.pmtct.web.controller.ExpectedMaternityPatientController.java
/** * @see org.springframework.web.servlet.mvc.ParameterizableViewController#handleRequestInternal(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) */// ww w . j ava2 s .com @SuppressWarnings({ "static-access", "deprecation" }) @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { StringBuilder parameters = new StringBuilder(); parameters.append("category=maternity&page=1"); ModelAndView mav = new ModelAndView(); mav.setViewName(getViewName()); PmtctService pmtct; List<Object> result = new ArrayList<Object>(); String pageNumber = request.getParameter("page"); String startDate = ""; String endDate = ""; List<Object> res; List<Integer> numberOfPages; // config = PMTCTConfiguration.getInstance(request.getRealPath(PMTCTConstants.CONFIGURATION_FILE_LOC)); // constants = config.getListOfConstants().get(0); // request.getSession().setAttribute("enableModification", "" + config.isModificationEnabled()); request.getSession().setAttribute("pmtctModuleConfigured", "" + PMTCTConfigurationUtils.isConfigured()); try { if (null != request.getParameter("startDate") && "" != request.getParameter("startDate").trim()) { startDate = request.getParameter("startDate").trim(); parameters.append("&startDate=" + startDate); } if (null != request.getParameter("endDate") && "" != request.getParameter("endDate").trim()) { endDate = request.getParameter("endDate").trim(); parameters.append("&endDate=" + endDate); } if (pageNumber.compareToIgnoreCase("1") == 0 || pageNumber.compareToIgnoreCase("") == 0) { pmtct = Context.getService(PmtctService.class); // pmtct.setPMTCTProgrmaId(config.getConstants()); res = new ArrayList<Object>(); if (request.getParameter("type").compareTo("3") == 0) { if (startDate.compareTo("") != 0 && endDate.compareTo("") != 0) { res = pmtct.getpatientsTestedInDeliveryRoom(startDate, endDate); request.getSession().setAttribute("exp_mat_pat_res", res); } mav.addObject("listHeaderTitle", "pmtct.menu.patientTestedInWorkroom"); } else if (request.getParameter("type").compareTo("2") == 0) { res = pmtct.getExpectedPatientsInMaternity(); request.getSession().setAttribute("exp_mat_pat_res", res); mav.addObject("listHeaderTitle", "pmtct.menu.expectedMaternityPatient"); } else if (request.getParameter("type").compareTo("1") == 0) { if (startDate.compareTo("") != 0 && endDate.compareTo("") != 0) { res = pmtct.getGeneralStatsForPatientsInMaternity(startDate, endDate); request.getSession().setAttribute("exp_mat_pat_res", res); } mav.addObject("listHeaderTitle", "pmtct.menu.generalStatsInMaternity"); } else if (request.getParameter("type").compareTo("4") == 0) { res = pmtct.getPatientsMissedTheirMaternityEncounter(); request.getSession().setAttribute("exp_mat_pat_res", res); mav.addObject("listHeaderTitle", "pmtct.menu.patientWhoMissedMaternityEncounter"); } for (int i = 0; i < PMTCTConfigurationUtils.getNumberOfRecordPerPage(); i++) { if (res.size() == 0) break; if (i >= res.size() - 1) { result.add(res.get(i)); break; } else result.add(res.get(i)); } //paging int n = (res.size() == ((int) (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage())) * PMTCTConfigurationUtils.getNumberOfRecordPerPage()) ? (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage()) : ((int) (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage())) + 1; numberOfPages = new ArrayList<Integer>(); for (int i = 1; i <= n; i++) { numberOfPages.add(i); } request.getSession().setAttribute("exp_mat_pat_numberOfPages", numberOfPages); } else { res = (List<Object>) request.getSession().getAttribute("exp_mat_pat_res"); numberOfPages = (List<Integer>) request.getSession().getAttribute("exp_mat_pat_numberOfPages"); for (int i = (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber) - 1)); i < PMTCTConfigurationUtils .getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)); i++) { if (i >= res.size()) break; else result.add(res.get(i)); } } //page infos Object[] pagerInfos = new Object[3]; pagerInfos[0] = (res.size() == 0) ? 0 : (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber) - 1)) + 1; pagerInfos[1] = (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)) <= res.size()) ? PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)) : res.size(); pagerInfos[2] = res.size(); ApplicationContext appContext = ContextProvider.getApplicationContext(); mav.addObject("pageInfos", appContext.getMessage("pmtct.pagingInfo.showingResults", pagerInfos, Context.getUserContext().getLocale())); mav.addObject("numberOfPages", numberOfPages); mav.addObject("patientList", result); mav.addObject("pageSize", PMTCTConfigurationUtils.getNumberOfRecordPerPage()); mav.addObject("startDate", startDate); mav.addObject("endDate", endDate); mav.addObject("parameters", parameters.toString()); mav.addObject("dpaId", PMTCTConstants.PREGNANT_DUE_DATE); mav.addObject("dateOfConfinementId", PMTCTConstants.DATE_OF_CONFINEMENT); mav.addObject("hivTestResultId", PMTCTConstants.RESULT_OF_HIV_TEST); mav.addObject("partnerStatusId", PMTCTConstants.TESTING_STATUS_OF_PARTNER); mav.addObject("childBornStatusId", PMTCTConfigurationUtils.getBornStatusConceptId()); mav.addObject("positiveId", PMTCTConstants.POSITIVE); mav.addObject("bornDeadId", PMTCTConfigurationUtils.getBornDeadConceptId()); mav.addObject("cpnIdentifierTypeId", PMTCTConfigurationUtils.getCPNIdentifierTypeId()); FileExporter fexp = new FileExporter(); if (request.getParameter("export") != null && request.getParameter("export").compareToIgnoreCase("csv") == 0) { if (request.getParameter("type").compareTo("1") == 0) fexp.exportGeneralStatisticsInMaternityToCSVFile(request, response, res, "general_statistics_in_Maternity_from_" + startDate + "_to_" + endDate + ".csv", "General statistics in Maternity"); else if (request.getParameter("type").compareTo("2") == 0) fexp.exportExpectedPatientInMaternityToCSVFile(request, response, res, "list_of_expected_patients_in_Maternity.csv", "List of expected patients in Maternity"); else if (request.getParameter("type").compareTo("3") == 0) fexp.exportPatientTestedInDeliveryRoomToCSVFile(request, response, res, "list_of_Patient_tested_in_Delivery_room.csv", "List of Patient tested in Delivery room"); else if (request.getParameter("type").compareTo("4") == 0) fexp.exportExpectedPatientInMaternityToCSVFile(request, response, res, "list_of_patients_who_missed_Maternity_Encounter.csv", "List of patients who missed Maternity Encounter"); } } catch (Exception ex) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "An error occured when trying to load data. Find the error in the log file."); log.error("MATERNITY STATISTICS : An error occured when trying to load data from database: \n" + ex.getMessage()); ex.printStackTrace(); } return mav; }
From source file:com.sldeditor.test.SLDTestRunner.java
/** * Run the test// w w w.ja v a 2 s .co m * * @param folder the folder * @param testConfig the test config */ public void runTest(String folder, String testConfig) { // read JSON file data as String String fullPath = "/" + folder + "/test/" + testConfig; SldEditorTest testSuite = (SldEditorTest) ParseXML.parseFile("", fullPath, SCHEMA_RESOURCE, SldEditorTest.class); Assert.assertNotNull("Failed to read test config file : " + fullPath, testSuite); String testsldfile = testSuite.getTestsldfile(); if (!testsldfile.startsWith("/")) { testsldfile = "/" + testsldfile; } System.out.println("Opening : " + testsldfile); List<XMLVendorOption> xmlVendorOptionList = testSuite.getVendorOption(); if ((xmlVendorOptionList != null) && !xmlVendorOptionList.isEmpty()) { List<VersionData> versionDataList = new ArrayList<VersionData>(); for (XMLVendorOption vo : xmlVendorOptionList) { try { String vendorOptionClassName = vo.getClassType().trim(); Class<?> vendorOptionClass = Class.forName(vendorOptionClassName); VersionData versionData = VersionData.decode(vendorOptionClass, vo.getVersion()); versionDataList.add(versionData); } catch (ClassNotFoundException e) { e.printStackTrace(); } } if (!versionDataList.contains(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData())) { versionDataList.add(VendorOptionManager.getInstance().getDefaultVendorOptionVersionData()); } sldEditor.setVendorOptions(versionDataList); } InputStream inputStream = SLDTestRunner.class.getResourceAsStream(testsldfile); if (inputStream == null) { Assert.assertNotNull("Failed to find sld test file : " + testsldfile, inputStream); } else { File f = null; try { f = stream2file(inputStream); sldEditor.openFile(f.toURI().toURL()); } catch (IOException e1) { e1.printStackTrace(); } GraphicPanelFieldManager mgr = sldEditor.getFieldDataManager(); for (XMLPanelTest test : testSuite.getPanelTests()) { XMLSetup selectedItem = test.getSetup(); TreeSelectionData selectionData = new TreeSelectionData(); selectionData.setLayerIndex(getXMLValue(selectedItem.getLayer())); selectionData.setStyleIndex(getXMLValue(selectedItem.getStyle())); selectionData.setFeatureTypeStyleIndex(getXMLValue(selectedItem.getFeatureTypeStyle())); selectionData.setRuleIndex(getXMLValue(selectedItem.getRule())); selectionData.setSymbolizerIndex(getXMLValue(selectedItem.getSymbolizer())); selectionData.setSymbolizerDetailIndex(getXMLValue(selectedItem.getSymbolizerDetail())); try { selectionData.setSelectedPanel(Class.forName(selectedItem.getExpectedPanel())); } catch (ClassNotFoundException e1) { Assert.fail("Unknown class : " + selectedItem.getExpectedPanel()); } boolean result = sldEditor.selectTreeItem(selectionData); Assert.assertTrue("Failed to select tree item", result); PopulateDetailsInterface panel = sldEditor.getSymbolPanel(); String panelClassName = panel.getClass().getName(); Assert.assertEquals(panelClassName, selectedItem.getExpectedPanel()); Assert.assertEquals("Check panel data present", panel.isDataPresent(), selectedItem.isEnabled()); Class<?> panelId = null; try { panelId = Class.forName(selectedItem.getExpectedPanel()); } catch (ClassNotFoundException e) { e.printStackTrace(); } if (test.getFieldTests() != null) { for (XMLFieldTest testItem : test.getFieldTests()) { if (testItem != null) { if (testItem.getDisabledOrLiteralStringOrLiteralInt() != null) { for (Object xmlTestValueObj : testItem.getDisabledOrLiteralStringOrLiteralInt()) { if (xmlTestValueObj instanceof XMLSetMultiOptionGroup) { XMLSetMultiOptionGroup testValue = (XMLSetMultiOptionGroup) xmlTestValueObj; GroupIdEnum groupId = testValue.getMultiOptionGroupId(); String outputText = "Checking multioption group : " + groupId; System.out.println(outputText); Assert.assertNotNull(outputText, groupId); MultiOptionGroup multiOptionGroup = mgr.getMultiOptionGroup(panelId, groupId); Assert.assertNotNull(panelId.getName() + "/" + groupId + " multi option group should exist", multiOptionGroup); multiOptionGroup.setOption(testValue.getOption()); OptionGroup optionGroupSelected = multiOptionGroup.getSelectedOptionGroup(); Assert.assertTrue(groupId + " should be set", optionGroupSelected.getId() == testValue.getOption()); } else if (xmlTestValueObj instanceof XMLSetGroup) { XMLSetGroup testValue = (XMLSetGroup) xmlTestValueObj; GroupIdEnum groupId = testValue.getGroupId(); String outputText = "Checking group : " + groupId; System.out.println(outputText); Assert.assertNotNull(outputText, groupId); GroupConfig groupConfig = mgr.getGroup(panelId, groupId); Assert.assertNotNull( panelId.getName() + "/" + groupId + " group should exist", groupConfig); groupConfig.enable(testValue.isEnable()); Assert.assertTrue(groupId + " should be set", groupConfig.isPanelEnabled() == testValue.isEnable()); } else { XMLFieldBase testValue = (XMLFieldBase) xmlTestValueObj; FieldId fieldId = new FieldId(testValue.getField()); String outputText = "Checking : " + fieldId; System.out.println(outputText); Assert.assertNotNull(outputText, fieldId); try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } FieldConfigBase fieldConfig = mgr.getData(panelId, fieldId); Assert.assertNotNull(String.format("Failed to field panel %s field %s", selectedItem.getExpectedPanel(), fieldId), fieldConfig); if (testValue instanceof XMLSetFieldLiteralBase) { XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue; testInterface.accept(fieldConfig, fieldId); if (!((XMLSetFieldLiteralBase) testValue).isIgnoreCheck()) { String sldContentString = sldEditor.getSLDString(); boolean actualResult = testOutput.testValue(sldContentString, selectionData, testValue.getField(), testValue); Assert.assertTrue(fieldId + " should be set", actualResult); } } else if (testValue instanceof XMLSetFieldAttribute) { XMLSetFieldLiteralInterface testInterface = (XMLSetFieldLiteralInterface) testValue; testInterface.accept(fieldConfig, fieldId); String sldContentString = sldEditor.getSLDString(); boolean actualResult = testOutput.testAttribute(sldContentString, selectionData, testValue.getField(), (XMLSetFieldAttribute) testValue); Assert.assertTrue(fieldId + " should be set", actualResult); } else if (testValue instanceof XMLFieldDisabled) { Assert.assertFalse(fieldId + " should be disabled", fieldConfig.isEnabled()); } else { Assert.assertTrue(fieldId + " should be enabled", fieldConfig.isEnabled()); Expression expression = null; if (fieldConfig.isValueOnly()) { String expectedValue = ""; if (testValue instanceof XMLFieldLiteralBase) { Object literalValue = getLiteralValue( (XMLFieldLiteralBase) testValue); expectedValue = String.valueOf(literalValue); } else if (testValue instanceof XMLFieldAttribute) { expectedValue = ((XMLFieldAttribute) testValue).getAttribute(); } else if (testValue instanceof XMLFieldExpression) { expectedValue = ((XMLFieldExpression) testValue) .getExpression(); } else { Assert.fail(fieldId + " has unsupported type " + testValue.getClass().getName()); } String actualValue = fieldConfig.getStringValue(); String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue); boolean condition; if (comparingFilename(fieldId)) { condition = actualValue.endsWith(expectedValue); } else { condition = (expectedValue.compareTo(actualValue) == 0); } Assert.assertTrue(msg, condition); } else { if (colourFieldsList.contains(fieldId.getFieldId())) { FieldConfigColour fieldColour = (FieldConfigColour) fieldConfig; expression = fieldColour.getColourExpression(); } else { expression = fieldConfig.getExpression(); if (fieldId.getFieldId() == FieldIdEnum.SYMBOL_TYPE) { String string = expression.toString(); expression = ff .literal(string.replace(File.separatorChar, '/')); } else if (fieldId.getFieldId() == FieldIdEnum.FONT_FAMILY) { // Handle the case where a font is not available on all operating systems String string = expression.toString(); if (string.compareToIgnoreCase(DEFAULT_FONT) != 0) { expression = ff.literal(getFontForOS()); System.out.println("Updated font family to test for : " + expression.toString()); } } } if (expression != null) { if (testValue instanceof XMLFieldLiteralBase) { Object literalValue = getLiteralValue( (XMLFieldLiteralBase) testValue); if (literalValue.getClass() == Double.class) { checkLiteralValue(outputText, expression, (Double) literalValue); } else if (literalValue.getClass() == Integer.class) { checkLiteralValue(outputText, expression, (Integer) literalValue); } else if (literalValue.getClass() == String.class) { if (fieldId.getFieldId() == FieldIdEnum.FONT_FAMILY) { // Handle the case where a font is not available on all operating systems checkLiteralValue(outputText, expression, getFontForOS()); } else { checkLiteralValue(outputText, expression, (String) literalValue); } } } } else { String actualValue; String expectedValue = fieldConfig.getStringValue(); Object literalValue = getLiteralValue( (XMLFieldLiteralBase) testValue); if (literalValue.getClass() == Double.class) { actualValue = String.valueOf((Double) literalValue); } else if (literalValue.getClass() == Integer.class) { actualValue = String.valueOf((Integer) literalValue); } else if (literalValue.getClass() == String.class) { actualValue = (String) literalValue; } else { actualValue = ""; } String msg = String.format("%s Expected : '%s' Actual : '%s'", outputText, expectedValue, actualValue); boolean condition = (expectedValue.compareTo(actualValue) == 0); Assert.assertTrue(msg, condition); } } } } } } } } } } } JFrame frame = sldEditor.getApplicationFrame(); frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING)); }
From source file:au.com.wallaceit.reddinator.SubredditSelectActivity.java
private void refreshSubredditsList() { subredditList = global.getSubredditManager().getSubredditNames(); subsAdapter.clear();//from w w w . j a va 2s . c o m subsAdapter.addAll(subredditList); subsAdapter.notifyDataSetChanged(); subsAdapter.sort(new Comparator<String>() { @Override public int compare(String s, String t1) { return s.compareToIgnoreCase(t1); } }); }
From source file:my.madet.function.HttpParser.java
public List<TimeTableStruct> Timetable() { String url = "http://info.uniten.edu.my/info/Ticketing.ASP?WCI=TimeTable"; // fetch html from url String html = FetchUrL(url);/*from w ww. j a va2 s . c o m*/ if (html == null || html == "No_Internet") return null; // fetch latest timetable String regex = "(?i)<td>1.<\\/td><td>[\\w\\d]+<\\/td><td><a[\\n\\s]+href=\"([\\w.?=&\\d]+)"; Pattern pattern = Pattern.compile(regex); Matcher matcher = pattern.matcher(html); if (matcher.find()) { url = matcher.group(1); Log.i("Timetable latest url", matcher.group(1)); } // fetch html from second url html = FetchUrL("http://info.uniten.edu.my/info/" + url); //debug //html = FetchUrL("http://sandbox.mahadirlab.com/uniteninfo/Ticketing.htm"); if (html == null || html == "No_Internet") return null; //Log.i("Debug html",html); // fetch table regex = "(?i)<table.*?>(.*?)<\\/table>"; pattern = Pattern.compile(regex); matcher = pattern.matcher(html); while (matcher.find()) { // System.out.println(matcher.group(1)); html = matcher.group(1); // get the last one } // fetch tr of the timetable regex = "(?i)<\\/THEAD>(.*)"; pattern = Pattern.compile(regex); matcher = pattern.matcher(html); if (matcher.find()) { // System.out.println(matcher.group(1)); html = matcher.group(1); } // fetch td regex = "(?i)<td.*?>(.*?)<\\/td>"; pattern = Pattern.compile(regex); matcher = pattern.matcher(html); int time = 8; String currentday = null; List<TimeTableStruct> timeTableStrc2 = new ArrayList<TimeTableStruct>(); TimeTableStruct d2 = null; String prev = null; while (matcher.find()) { String str = matcher.group(1); if (str.matches("(?i)monday|tuesday|wednesday|thursday|friday|saturday|sunday")) { currentday = str; time = 8; prev = null; // new day // System.out.println(currentday); // save last subject for yesterday if (d2 != null) { timeTableStrc2.add(d2); d2 = null; } } else if (str.matches(" ")) { time++; //fetch the subject code + location } else if (str.matches("(?i)[\\d\\w]+<br>[\\d\\w-\\s/]+")) { // System.out.println(str+" vs "+prev+"\n"); if (prev != null) { if (str.compareToIgnoreCase(prev) == 0) { // the subject same from previous // don't initilialize new instance // change the end time d2.insertEndTime(d2.timeConverterampm(time + 1)); time++; continue; } else { // save the previous value // save to timeTableStrc2 timeTableStrc2.add(d2); d2 = null; } } d2 = new TimeTableStruct(); d2.insertDay(currentday); String[] splitStrings = str.split("<BR>"); d2.insertsubject(splitStrings[0]); d2.insertLocation(splitStrings[1]); // start time d2.insertStartTime(d2.timeConverterampm(time)); // end time = start time + 1 hour d2.insertEndTime(d2.timeConverterampm(time + 1)); prev = str; time++; } } return timeTableStrc2; }
From source file:org.openmrs.module.pmtct.web.controller.PatientInCPNController.java
/** * @see org.springframework.web.servlet.mvc.ParameterizableViewController#handleRequestInternal(javax.servlet.http.HttpServletRequest, * javax.servlet.http.HttpServletResponse) *//*from ww w . jav a 2 s .c o m*/ @SuppressWarnings("static-access") @Override protected ModelAndView handleRequestInternal(HttpServletRequest request, HttpServletResponse response) throws Exception { ModelAndView mav = new ModelAndView(); mav.setViewName(getViewName()); String startDate = ""; String endDate = ""; int year = (new Date()).getYear(); int month = (new Date()).getMonth(); PmtctService pmtct; List<Object> result = new ArrayList<Object>(); String pageNumber = request.getParameter("page"); List<Object> res; List<Integer> numberOfPages; // config = PMTCTConfiguration.getInstance(request.getRealPath(PMTCTConstants.CONFIGURATION_FILE_LOC)); // PMTCTConstants constants = config.getListOfConstants().get(0); // request.getSession().setAttribute("enableModification", "" + config.isModificationEnabled()); request.getSession().setAttribute("pmtctModuleConfigured", "" + PMTCTConfigurationUtils.isConfigured()); try { if (null != request.getParameter("startDate") && "" != request.getParameter("startDate").trim()) { startDate = request.getParameter("startDate").trim(); } if (null != request.getParameter("endDate") && "" != request.getParameter("endDate").trim()) { endDate = request.getParameter("endDate").trim(); } // } // catch (Exception ex) { // ex.printStackTrace(); // } // // try { if (pageNumber.compareToIgnoreCase("1") == 0 || pageNumber.compareToIgnoreCase("") == 0) { pmtct = Context.getService(PmtctService.class); // pmtct.setPMTCTProgrmaId(config.getConstants()); res = new ArrayList<Object>(); mav.addObject("monthsList", monthsList); if (request.getParameter("category").equalsIgnoreCase("cpn")) { if (request.getParameter("type").equalsIgnoreCase("1")) { if (startDate.compareTo("") != 0 && endDate.compareTo("") != 0) { res = pmtct.getGeneralStatsForPatientsInCPN(startDate, endDate); request.getSession().setAttribute("pat_in_cpn_res", res); } mav.addObject("listHeaderTitle", "pmtct.menu.generalStatsInCPN"); } else if (request.getParameter("type").equalsIgnoreCase("2")) { if (request.getParameter("month") != null && request.getParameter("month").trim().compareTo("") != 0) month = Integer.parseInt(request.getParameter("month")); if (request.getParameter("year") != null && request.getParameter("year").trim().compareTo("") != 0) year = Integer.parseInt(request.getParameter("year")); res = pmtct.getPatientByMoisDeRapportageDPA(month, year); request.getSession().setAttribute("pat_in_cpn_res", res); mav.addObject("listHeaderTitle", "pmtct.menu.patientWhoMoisDeRapportageDPAIsTheCurrentMois"); } else if (request.getParameter("type").equalsIgnoreCase("3")) { res = pmtct.getCouplesDiscordant(); request.getSession().setAttribute("pat_in_cpn_res", res); mav.addObject("listHeaderTitle", "pmtct.menu.couplesDiscordant"); } } for (int i = 0; i < PMTCTConfigurationUtils.getNumberOfRecordPerPage(); i++) { if (res.size() == 0) break; if (i >= res.size() - 1) { result.add(res.get(i)); break; } else result.add(res.get(i)); } //paging int n = (res.size() == ((int) (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage())) * PMTCTConfigurationUtils.getNumberOfRecordPerPage()) ? (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage()) : ((int) (res.size() / PMTCTConfigurationUtils.getNumberOfRecordPerPage())) + 1; numberOfPages = new ArrayList<Integer>(); for (int i = 1; i <= n; i++) { numberOfPages.add(i); } request.getSession().setAttribute("pat_in_cpn_numberOfPages", numberOfPages); } else { res = (List<Object>) request.getSession().getAttribute("pat_in_cpn_res"); numberOfPages = (List<Integer>) request.getSession().getAttribute("pat_in_cpn_numberOfPages"); for (int i = (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber) - 1)); i < PMTCTConfigurationUtils .getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)); i++) { if (i >= res.size()) break; else result.add(res.get(i)); } } //page infos Object[] pagerInfos = new Object[3]; pagerInfos[0] = (res.size() == 0) ? 0 : (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber) - 1)) + 1; pagerInfos[1] = (PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)) <= res.size()) ? PMTCTConfigurationUtils.getNumberOfRecordPerPage() * (Integer.parseInt(pageNumber)) : res.size(); pagerInfos[2] = res.size(); ApplicationContext appContext = ContextProvider.getApplicationContext(); mav.addObject("pageInfos", appContext.getMessage("pmtct.pagingInfo.showingResults", pagerInfos, Context.getUserContext().getLocale())); mav.addObject("numberOfPages", numberOfPages); mav.addObject("patientList", result); mav.addObject("pageSize", PMTCTConfigurationUtils.getNumberOfRecordPerPage()); mav.addObject("startDate", startDate); mav.addObject("endDate", endDate); mav.addObject("hivTestResultId", PMTCTConstants.RESULT_OF_HIV_TEST); mav.addObject("dpaId", PMTCTConstants.PREGNANT_DUE_DATE); mav.addObject("dateOfConfinementId", PMTCTConstants.DATE_OF_CONFINEMENT); mav.addObject("positiveId", PMTCTConstants.POSITIVE); List<Integer> years = new ArrayList<Integer>(); for (int yr = 2000; yr < 2016; yr++) years.add(yr); mav.addObject("years", years); FileExporter fexp = new FileExporter(); if (request.getParameter("export") != null && request.getParameter("export").compareToIgnoreCase("csv") == 0) { if (request.getParameter("type").equalsIgnoreCase("1")) fexp.exportGeneralStatisticsInCPNToCSVFile(request, response, res, "list_of_patients_in_CPN.csv", "List of Patients in CPN"); else if (request.getParameter("type").equalsIgnoreCase("2")) { fexp.exportToCSVFile(request, response, res, "list_of_patients_in_CPN_DPA_" + month + "_" + year + ".csv", "List of Patients in CPN(DPA=" + month + "-" + year + ")"); } else if (request.getParameter("type").equalsIgnoreCase("3")) fexp.exportToCSVFile(request, response, res, "couples_discordants.csv", "Couples discordants"); } } catch (Exception ex) { request.getSession().setAttribute(WebConstants.OPENMRS_ERROR_ATTR, "An error occured when trying to load data. Find the error in the log file."); log.error("An error occured when trying to load data from database: \n" + ex.getMessage()); ex.printStackTrace(); } return mav; }
From source file:org.apache.nifi.monitor.thresholds.ui.ThresholdResource.java
/** * Updates a threshold value, size or count. * * @param processorid/*from www . j a v a 2 s. c o m*/ * @param uuid * @param rulevalue * @param size * @param count * @return */ @POST @Consumes(MediaType.APPLICATION_FORM_URLENCODED) @Produces(MediaType.APPLICATION_XML) @Path("/rule/{" + RULEVALUE + "}") public Response ruleUpdate(@PathParam(PROCID) String processorid, @PathParam(ATTRIBUTE_UUID) String uuid, // @PathParam(RULEUUID) String ruleuuid, @PathParam(RULEVALUE) String rulevalue, // @FormParam(RULEVALUE) @DefaultValue(StringUtils.EMPTY) String rulevalue, @FormParam(SIZE) @DefaultValue(StringUtils.EMPTY) String size, @FormParam(COUNT) @DefaultValue(StringUtils.EMPTY) String count) { //logger.debug("Invoking ThresholdResource.java @POST @PATH(\"/rule/{\"+RULEVALUE+\"}\"): ruleUpdate(...). RULEVALUE is: " + rulevalue); try { // if(rulevalue.isEmpty()&& ruleuuid.compareTo("-1")!=0) // validation_error_list.add(INVALIDRULEID); if (!validateStringAsLong(size)) { validation_error_list.add(INVALID_SIZE); } if (!validateStringAsInt(count)) { validation_error_list.add(INVALID_COUNT); } if (!validation_error_list.isEmpty()) { return Response.status(400).entity(setValidationErrorMessage(validation_error_list)).build(); } ThresholdsConfigFile config = getConfigFile(request, servletContext); Attribute attr = config.findAttribute(uuid); // if(ruleuuid.compareTo("-1")==0){ if (rulevalue.compareToIgnoreCase("default") == 0) { Rule rule = attr.getNoMatchRule(); rule.setCount(getBigIntValueOf(count)); rule.setSize(getBigIntValueOf(size)); } else { Thresholds rule = config.findRule(attr, rulevalue);//ruleuuid); // rule.setValue(rulevalue); rule.setCount(getBigIntValueOf(count)); rule.setSize(getBigIntValueOf(size)); } config.save(); } catch (Exception ex) { logger.error(ex.getMessage()); return Response.status(400).entity(GENERAL_ERROR + ex.getMessage()).build(); } return generateOkResponse(Status.OK.toString()).build(); }
From source file:edu.mit.isda.permitws.permitclient.java
private String getUserInput(HttpServletRequest request) { UserName = request.getParameter("username"); PName = request.getParameter("proxyname"); Catagory = request.getParameter("catagory"); Category = request.getParameter("category"); Function = request.getParameter("function"); Qualifier = request.getParameter("qualifier"); String willExpand = request.getParameter("willExpand"); bwillExpand = false;//ww w . ja v a 2 s. c om if (willExpand != null) { if (willExpand.length() != 0) { if (willExpand.compareToIgnoreCase("yes") == 0) { bwillExpand = true; } } } String isActive = request.getParameter("isActive"); bisActive = true; if (isActive != null) { if (isActive.length() != 0) { if (isActive.compareToIgnoreCase("no") == 0) { bisActive = false; } } } String sName = getRemoteUser(request); X509Certificate[] certificate = (X509Certificate[]) request .getAttribute("javax.servlet.request.X509Certificate"); // Check for Remote User. Enable for Touchstone if (null != sName) { sName = sName.toUpperCase().trim(); int j = sName.indexOf('@'); if (j != -1) { if (sName.substring(j + 1, j + 1 + "MIT.EDU".length()).equals("MIT.EDU")) { log.info("***** REMOTE_USER without Domain - " + sName.substring(0, j)); return (sName.substring(0, j)); } } } // If no Touchstone .. look for certificate else if (certificate != null) { sName = certificate[0].getSubjectDN().getName(); if (sName == null) return (PName); else { int i = sName.indexOf('=', 0); if (i != -1) { ++i; int j = sName.indexOf('@', i); if (j != -1) { if (sName.substring(j + 1, j + 1 + "MIT.EDU".length()).equals("MIT.EDU")) { return (sName.substring(i, j)); } } } } } return (PName); }