List of usage examples for javax.servlet.jsp PageContext getRequest
abstract public ServletRequest getRequest();
From source file:dk.netarkivet.harvester.webinterface.SnapshotHarvestDefinition.java
/** * Flip the active status of a harvestdefinition named in the "flipactive" parameter. * * @param context The context of the web servlet * @param i18n Translation information//from w w w. ja v a2 s . co m * @return True if a harvest definition changed state. */ public boolean flipActive(PageContext context, I18n i18n) { ArgumentNotValid.checkNotNull(context, "PageContext context"); ArgumentNotValid.checkNotNull(i18n, "I18n i18n"); ServletRequest request = context.getRequest(); String flipactive = request.getParameter(Constants.FLIPACTIVE_PARAM); // Change activation if requested if (flipactive != null) { HarvestDefinition hd = hdDaoProvider.get().getHarvestDefinition(flipactive); if (hd != null) { boolean isActive = hd.getActive(); boolean useDeduplication = Settings.getBoolean(HarvesterSettings.DEDUPLICATION_ENABLED); if (!isActive) { if (hd instanceof FullHarvest) { FullHarvest fhd = (FullHarvest) hd; validatePreviousHd(fhd, context, i18n); if (useDeduplication) { // The client for requesting job index. JobIndexCache jobIndexCache = IndexClientFactory.getDedupCrawllogInstance(); Long harvestId = fhd.getOid(); Set<Long> jobSet = hdDaoProvider.get() .getJobIdsForSnapshotDeduplicationIndex(harvestId); jobIndexCache.requestIndex(jobSet, harvestId); } else { // If deduplication disabled set indexReady to true // right now, so the job generation can proceed. fhd.setIndexReady(true); } } else { // hd is not Fullharvest log.warn("Harvestdefinition #" + hd.getOid() + " is not a FullHarvest " + " but a " + hd.getClass().getName()); return false; } } hd.setActive(!hd.getActive()); hdDaoProvider.get().update(hd); return true; } else { HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvestdefinition.0.does.not.exist", flipactive); throw new ForwardedToErrorPage("Harvest definition " + flipactive + " doesn't exist"); } } return false; }
From source file:dk.netarkivet.harvester.webinterface.SnapshotHarvestDefinition.java
/** * Extracts all required parameters from the request, checks for any inconsistencies, and passes the requisite data * to the updateHarvestDefinition method for processing. If the "update" parameter is not set, this method does * nothing.//from www . ja va2 s. c om * <p> * The parameters in the request are defined in Definitions-edit-snapshot-harvest.jsp. * * @param context The context of the web request. * @param i18n Translation information * @throws ForwardedToErrorPage if an error happened that caused a forward to the standard error page, in which case * further JSP processing should be aborted. */ public void processRequest(PageContext context, I18n i18n) { ArgumentNotValid.checkNotNull(context, "PageContext context"); ArgumentNotValid.checkNotNull(i18n, "I18n i18n"); ServletRequest request = context.getRequest(); if (request.getParameter(Constants.UPDATE_PARAM) == null) { return; } HTMLUtils.forwardOnEmptyParameter(context, Constants.HARVEST_PARAM); String name = request.getParameter(Constants.HARVEST_PARAM); String comments = request.getParameter(Constants.COMMENTS_PARAM); long objectLimit = HTMLUtils.parseOptionalLong(context, Constants.DOMAIN_OBJECTLIMIT_PARAM, dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_OBJECTS); long byteLimit = HTMLUtils.parseOptionalLong(context, Constants.DOMAIN_BYTELIMIT_PARAM, dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_BYTES); long runningtimeLimit = HTMLUtils.parseOptionalLong(context, Constants.JOB_TIMELIMIT_PARAM, dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_JOB_RUNNING_TIME); Long oldHarvestId = HTMLUtils.parseOptionalLong(context, Constants.OLDSNAPSHOT_PARAM, null); if (oldHarvestId != null && !hdDaoProvider.get().exists(oldHarvestId)) { HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvestdefinition.0.does.not.exist", oldHarvestId); throw new ForwardedToErrorPage("Old harvestdefinition " + oldHarvestId + " does not exist"); } FullHarvest hd; if ((request.getParameter(Constants.CREATENEW_PARAM) != null)) { if (hdDaoProvider.get().getHarvestDefinition(name) != null) { HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvest.definition.0.already.exists", name); throw new ForwardedToErrorPage("Harvest definition '" + name + "' already exists"); } // Note, object/bytelimit set to default values, if not set hd = new FullHarvest(name, comments, oldHarvestId, objectLimit, byteLimit, runningtimeLimit, false, hdDaoProvider, jobDaoProvider, extendedFieldDAOProvider, domainDAOProvider); hd.setActive(false); hdDaoProvider.get().create(hd); } else { hd = (FullHarvest) hdDaoProvider.get().getHarvestDefinition(name); if (hd == null) { HTMLUtils.forwardWithErrorMessage(context, i18n, "errormsg;harvest.0.does.not.exist", name); throw new UnknownID("Harvest definition '" + name + "' doesn't exist!"); } long edition = HTMLUtils.parseOptionalLong(context, Constants.EDITION_PARAM, Constants.NO_EDITION); if (hd.getEdition() != edition) { HTMLUtils.forwardWithRawErrorMessage(context, i18n, "errormsg;harvest.definition.changed.0.retry.1", "<br/><a href=\"Definitions-edit-snapshot-harvest.jsp?" + Constants.HARVEST_PARAM + "=" + HTMLUtils.encodeAndEscapeHTML(name) + "\">", "</a>"); throw new ForwardedToErrorPage("Harvest definition '" + name + "' has changed"); } // MaxBytes is set to // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_BYTES // if parameter snapshot_byte_Limit is not defined hd.setMaxBytes(byteLimit); // MaxCountObjects is set to // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_OBJECTS // if parameter snapshot_object_limit is not defined hd.setMaxCountObjects(objectLimit); // MaxJobRunningTime is set to // dk.netarkivet.harvester.datamodel.Constants.DEFAULT_MAX_JOB_RUNNING_TIME // if parameter snapshot_time_limit is not defined hd.setMaxJobRunningTime(runningtimeLimit); hd.setPreviousHarvestDefinition(oldHarvestId); hd.setComments(comments); hdDaoProvider.get().update(hd); } }
From source file:org.terasoluna.gfw.web.token.transaction.TransactionTokenTagTest.java
/** * JspException occurs//from w w w .j ava 2s . co m */ @Test public void testWriteTagContentTagWriter03() { // setup arguments TransactionTokenTag tag = new TransactionTokenTag(); PageContext pageContext = mock(PageContext.class); tag.setPageContext(pageContext); HttpServletRequest request = mock(HttpServletRequest.class); TransactionToken token = new TransactionToken("tokenName", "tokenkey", "tokenValue"); TagWriter tagWriter = mock(TagWriter.class); // mock behavior when((HttpServletRequest) pageContext.getRequest()).thenReturn(request); when((TransactionToken) request.getAttribute(TransactionTokenInterceptor.NEXT_TOKEN_REQUEST_ATTRIBUTE_NAME)) .thenReturn(token); // run int result = 1; try { doThrow(new JspException()).when(tagWriter).startTag(anyString()); result = tag.writeTagContent(tagWriter); } catch (JspException e) { e.printStackTrace(); } assertThat(result, is(1)); }
From source file:org.terasoluna.gfw.web.token.transaction.TransactionTokenTagTest.java
/** * TransactionToken is not null/* ww w. java 2s . com*/ */ @Test public void testWriteTagContentTagWriter02() { // setup arguments TransactionTokenTag tag = new TransactionTokenTag(); PageContext pageContext = mock(PageContext.class); tag.setPageContext(pageContext); HttpServletRequest request = mock(HttpServletRequest.class); TransactionToken token = new TransactionToken("tokenName", "tokenkey", "tokenValue"); StringWriter sw = new StringWriter(); TagWriter tagWriter = new TagWriter(sw); // mock behavior when((HttpServletRequest) pageContext.getRequest()).thenReturn(request); when((TransactionToken) request.getAttribute(TransactionTokenInterceptor.NEXT_TOKEN_REQUEST_ATTRIBUTE_NAME)) .thenReturn(token); // run int result = 1; try { result = tag.writeTagContent(tagWriter); } catch (JspException e) { fail(); } // capture String expected = "<input type=\"hidden\" name=\"" + TransactionTokenInterceptor.TOKEN_REQUEST_PARAMETER + "\" value=\"" + token.getTokenString() + "\"/>"; // assert assertThat(sw.getBuffer().toString(), is(expected)); assertThat(result, is(0)); }
From source file:com.ideo.jso.Group.java
/** * Display the css import tags, depending of the group parameters set in the XML descriptor. * @param pageContext// w w w .jav a 2 s .c om * @param out the writer into which will be written the tags * @throws IOException */ public void printIncludeCSSTag(PageContext pageContext, Writer out) throws IOException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (!isMinimizeCss()) { //not minimized, just act as a normal stylesheet link for (int i = 0; i < getCssNames().size(); i++) includeResource(pageContext, out, (String) getCssNames().get(i), "<link rel=\"stylesheet\" type=\"text/css\" href=\"", "\"/>"); } else { // merge all this group stylesheet if (getCssNames().size() != 0) { long cssTimeStamp = getMaxCSSTimestamp(pageContext.getServletContext()); out.write("<link rel=\"stylesheet\" type=\"text/css\" href=\""); out.write(request.getContextPath()); out.write("/jso/"); out.write(getName()); out.write(".css?" + JsoServlet.TIMESTAMP + "="); out.write("" + cssTimeStamp); out.write("\"></link>\n"); } } // include the subgroups stylesheet. No recursivity for minimization for (Iterator iterator = getSubgroups().iterator(); iterator.hasNext();) { Group subGroup = (Group) iterator.next(); subGroup.printIncludeCSSTag(pageContext, out); } }
From source file:com.ideo.jso.Group.java
/** * Display the js import tags, depending of the group parameters set in the XML descriptor and of the tag exploded parameter. * @param pageContext//from www .ja va 2 s. c o m * @param out the writer into which will be written the tags * @param exploded the way to import JS files : merged or not * @throws IOException */ public void printIncludeJSTag(PageContext pageContext, Writer out, boolean exploded) throws IOException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); if (exploded) { for (int i = 0; i < getDeepJsNames().size(); i++) includeResource(pageContext, out, (String) getDeepJsNames().get(i), "<script type=\"text/javascript\" src=\"", "\"></script>"); } else { long maxJSTimestamp = getMaxJSTimestamp(pageContext.getServletContext()); out.write("<script type=\"text/javascript\" src=\""); out.write(request.getContextPath()); out.write("/jso/"); out.write(getName()); out.write(".js?" + JsoServlet.TIMESTAMP + "="); out.write("" + maxJSTimestamp); out.write("\"></script>\n"); } }
From source file:com.glaf.core.tag.TagUtils.java
/** * Look up and return current user locale, based on the specified * parameters.// w ww . j av a 2 s . co m * * @param pageContext * The PageContext associated with this request * @param locale * Name of the session attribute for our user's Locale. If this * is <code>null</code>, the default locale key is used for the * lookup. * @return current user locale */ public Locale getUserLocale(PageContext pageContext, String locale) { return ResponseUtils.getUserLocale((HttpServletRequest) pageContext.getRequest(), locale); }
From source file:com.ideo.jso.Group.java
/** * Adds a tag into the flow to include a resource "the classic way", and suffix by a timestamp corresponding to the last modification date of the file * @param pageContext/*from w w w.java 2 s . co m*/ * @param out * @param webPath * @param tagBegin * @param tagEnd * @throws IOException */ private void includeResource(PageContext pageContext, Writer out, String webPath, String tagBegin, String tagEnd) throws IOException { HttpServletRequest request = (HttpServletRequest) pageContext.getRequest(); String fileName = pageContext.getServletContext().getRealPath(webPath); out.write(tagBegin); out.write(request.getContextPath()); if (!webPath.startsWith("/")) out.write("/"); out.write(webPath); if (fileName != null && fileName.length() > 0) { long timestamp = new File(fileName).lastModified(); out.write("?" + JsoServlet.TIMESTAMP + "=" + timestamp); } out.write(tagEnd); out.write("\n"); }
From source file:com.draagon.meta.web.view.html.HotLinkView.java
/** * Creates the hotlink by reading the url attribute and inserting the field * values/*from w w w.j a va 2s .c o m*/ */ protected String createLink(PageContext page, Object o, int mode, Map params) throws MetaException { String url = (String) getAttribute("url"); if (url == null) { throw new MetaException( "No 'url' attribute found for view [" + getName() + "] in field [" + getMetaField(o) + "]"); } // If the URL starts with a "/" then prepend the Context Path if (url.startsWith("/")) { String context = ((HttpServletRequest) page.getRequest()).getContextPath(); url = context + url; } MetaObject mc = MetaDataLoader.findMetaObject(o); HashMap map = new HashMap(); // Extract the possible fields for insertion int i = 0; while (true) { int j = url.indexOf("${", i); if (j >= 0) { int k = url.indexOf("}", j); if (k >= 0) { // Increment to the next search segment i = k + 1; // Get the MetaField String name = url.substring(j + 2, k); MetaField mf = mc.getMetaField(name); //get value out of data object using String value = mf.getString(o); if (value == null) { value = ""; } // Add the the HashMap map.put(name, value); continue; } } break; } //while // Construct the HotLink URL and return it return URLConstructor.constructURL(url, map); }
From source file:it.scoppelletti.wui.HeadTag.java
/** * Implementazione./*from ww w .j a va 2s .co m*/ */ @Override public void doTag() throws IOException, JspException { URI uri; UriComponentsBuilder uriBuilder; WebApplicationManager applMgr; List<String> applList; ApplicationContext applCtx; PageContext pageCtx = (PageContext) getJspContext(); applCtx = WebApplicationContextUtils.getRequiredWebApplicationContext(pageCtx.getServletContext()); applMgr = applCtx.getBean(WebApplicationManager.BEAN_NAME, WebApplicationManager.class); applList = applMgr.listRunningApplications(); for (String ctxPath : applList) { uriBuilder = UriComponentsBuilder.fromHttpUrl(applMgr.getBaseUrl()); uriBuilder.path(ctxPath).path(HeadTag.HEAD_PATH); uriBuilder.queryParam(AbstractServerResource.QUERY_LOCALE, pageCtx.getRequest().getLocale().toString()); uri = uriBuilder.build().toUri(); try { head(uri, pageCtx.getOut()); } catch (Exception ex) { myLogger.error(String.format("Failed to get %1$s.", uri), ex); } } }