@Test public void testGetIntParam() { String[] attrs = {"a", "b", "c", "d", "e", "f", "g", "h"}; int[] values = {1, 100, -1, 2, 200, 3000, -200, 3000}; DummyHttpServletRequest req = new DummyHttpServletRequest() { @Override public String getParameter(String name) { switch(name) { case "a": return "1"; case "b": return "100"; case "c": return null; case "d": return "2"; case "e": return "200"; case "f": return "3000"; case "g": return null; case "h": return "abcdef"; } return null; } }; PageConfig cfg = PageConfig.get(req); assertEquals(attrs.length, values.length); for (int i = 0; i < attrs.length; i++) { assertEquals(values[i], cfg.getIntParam(attrs[i], values[i])); } }
public int getIntParam(String name, int defaultValue) { int ret = defaultValue; String s = req.getParameter(name); if (s != null && s.length() != 0) { try { int x = Integer.parseInt(s, 10); if (x >= 0) { ret = x; } } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Failed to parse " + name + " integer " + s, e); } } return ret; }
PageConfig { public int getIntParam(String name, int defaultValue) { int ret = defaultValue; String s = req.getParameter(name); if (s != null && s.length() != 0) { try { int x = Integer.parseInt(s, 10); if (x >= 0) { ret = x; } } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Failed to parse " + name + " integer " + s, e); } } return ret; } }
PageConfig { public int getIntParam(String name, int defaultValue) { int ret = defaultValue; String s = req.getParameter(name); if (s != null && s.length() != 0) { try { int x = Integer.parseInt(s, 10); if (x >= 0) { ret = x; } } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Failed to parse " + name + " integer " + s, e); } } return ret; } private  PageConfig(HttpServletRequest req); }
PageConfig { public int getIntParam(String name, int defaultValue) { int ret = defaultValue; String s = req.getParameter(name); if (s != null && s.length() != 0) { try { int x = Integer.parseInt(s, 10); if (x >= 0) { ret = x; } } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Failed to parse " + name + " integer " + s, e); } } return ret; } private  PageConfig(HttpServletRequest req); void setRequestAttribute(String attr, Object val); Object getRequestAttribute(String attr); void removeAttribute(String string); void addHeaderData(String data); String getHeaderData(); DiffData getDiffData(); DiffType getDiffType(); boolean fullDiff(); String canProcess(); List<String> getResourceFileList(); long getLastModified(); String getHistoryDirs(); int getIntParam(String name, int defaultValue); int getSearchStart(); int getSearchMaxItems(); int getRevisionMessageCollapseThreshold(); int getCurrentIndexedCollapseThreshold(); int getGroupsCollapseThreshold(); List<SortOrder> getSortOrder(); QueryBuilder getQueryBuilder(); EftarFileReader getEftarReader(); String getDefineTagsIndex(); String getRequestedRevision(); boolean hasHistory(); boolean hasAnnotations(); boolean annotate(); Annotation getAnnotation(); String[] getSearchOnlyIn(); Project getProject(); String getRequestedProjectsAsString(); SortedSet<String> getRequestedProjects(); List<String> getCookieVals(String cookieName); ProjectHelper getProjectHelper(); void setTitle(String title); String getTitle(); String getCssDir(); RuntimeEnvironment getEnv(); IgnoredNames getIgnoredNames(); String getSourceRootPath(); Prefix getPrefix(); String getPath(); File getResourceFile(String path); File getResourceFile(); String getResourcePath(); boolean resourceNotAvailable(); boolean isDir(); File[] findDataFiles(List<String> filenames); File findDataFile(); String getLatestRevision(); boolean isLatestRevision(String rev); String getRevisionLocation(String revStr); String getDirectoryRedirect(); String getUriEncodedPath(); PageConfig addScript(String name); Scripts getScripts(); File getDataRoot(); SearchHelper prepareSearch(); SearchHelper prepareInternalSearch(); static PageConfig get(HttpServletRequest request); static void cleanup(ServletRequest sr); boolean isAllowed(Project t); boolean isAllowed(Group g); SortedSet<AcceptedMessage> getMessages(); SortedSet<AcceptedMessage> getMessages(String tag); String getShortPath(String path); String getSearchTitle(); String getHistoryTitle(); String getPathTitle(); void checkSourceRootExistence(); boolean isNotModified(HttpServletRequest request, HttpServletResponse response); static String getRelativePath(String root, String path); boolean evaluateMatchOffset(); }
PageConfig { public int getIntParam(String name, int defaultValue) { int ret = defaultValue; String s = req.getParameter(name); if (s != null && s.length() != 0) { try { int x = Integer.parseInt(s, 10); if (x >= 0) { ret = x; } } catch (NumberFormatException e) { LOGGER.log(Level.INFO, "Failed to parse " + name + " integer " + s, e); } } return ret; } private  PageConfig(HttpServletRequest req); void setRequestAttribute(String attr, Object val); Object getRequestAttribute(String attr); void removeAttribute(String string); void addHeaderData(String data); String getHeaderData(); DiffData getDiffData(); DiffType getDiffType(); boolean fullDiff(); String canProcess(); List<String> getResourceFileList(); long getLastModified(); String getHistoryDirs(); int getIntParam(String name, int defaultValue); int getSearchStart(); int getSearchMaxItems(); int getRevisionMessageCollapseThreshold(); int getCurrentIndexedCollapseThreshold(); int getGroupsCollapseThreshold(); List<SortOrder> getSortOrder(); QueryBuilder getQueryBuilder(); EftarFileReader getEftarReader(); String getDefineTagsIndex(); String getRequestedRevision(); boolean hasHistory(); boolean hasAnnotations(); boolean annotate(); Annotation getAnnotation(); String[] getSearchOnlyIn(); Project getProject(); String getRequestedProjectsAsString(); SortedSet<String> getRequestedProjects(); List<String> getCookieVals(String cookieName); ProjectHelper getProjectHelper(); void setTitle(String title); String getTitle(); String getCssDir(); RuntimeEnvironment getEnv(); IgnoredNames getIgnoredNames(); String getSourceRootPath(); Prefix getPrefix(); String getPath(); File getResourceFile(String path); File getResourceFile(); String getResourcePath(); boolean resourceNotAvailable(); boolean isDir(); File[] findDataFiles(List<String> filenames); File findDataFile(); String getLatestRevision(); boolean isLatestRevision(String rev); String getRevisionLocation(String revStr); String getDirectoryRedirect(); String getUriEncodedPath(); PageConfig addScript(String name); Scripts getScripts(); File getDataRoot(); SearchHelper prepareSearch(); SearchHelper prepareInternalSearch(); static PageConfig get(HttpServletRequest request); static void cleanup(ServletRequest sr); boolean isAllowed(Project t); boolean isAllowed(Group g); SortedSet<AcceptedMessage> getMessages(); SortedSet<AcceptedMessage> getMessages(String tag); String getShortPath(String path); String getSearchTitle(); String getHistoryTitle(); String getPathTitle(); void checkSourceRootExistence(); boolean isNotModified(HttpServletRequest request, HttpServletResponse response); static String getRelativePath(String root, String path); boolean evaluateMatchOffset(); static final String OPEN_GROK_PROJECT; }