下面列出了org.apache.commons.io.monitor.FileAlterationListenerAdaptor#org.apache.wicket.request.cycle.RequestCycle 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
final Pair<String, String> pair = FileUtils.getFileNameAndExtension(imageName);
final String contextPath = RequestCycle.get().getRequest().getContextPath();
String imageKey = null;
if ((action != null) && (!action.isEnabled() || !action.isAuthorized())) {
tag.getAttributes().put("class", "button_link_disabled");
if (pair != null) imageKey = pair.first() + "-disabled";
} else {
if (pair != null) imageKey = pair.first();
}
if (imageKey != null) {
imageKey = "images/toolbar/" + imageKey + "." + pair.second();
final String resourceURL = JPPFWebConsoleApplication.get().getSharedImageURL(imageKey);
final String html = "<img src='" + contextPath + resourceURL + "'/>";
setBody(Model.of(html));
if (debugEnabled) log.debug("image html for key = {}, contextPath = {}: {}", imageKey, contextPath, html);
}
setEscapeModelStrings(false);
}
@Override
protected void onComponentTag(final ComponentTag tag) {
super.onComponentTag(tag);
final Pair<String, String> pair = FileUtils.getFileNameAndExtension(imageName);
final StringBuilder style = new StringBuilder();
final String contextPath = RequestCycle.get().getRequest().getContextPath();
String imageKey = null;
if ((action != null) && (!action.isEnabled() || !action.isAuthorized())) {
tag.getAttributes().put("class", "button_link_disabled");
if (pair != null) imageKey = pair.first() + "-disabled";
} else {
if (pair != null) imageKey = pair.first();
}
if (imageKey != null) {
imageKey = "images/toolbar/" + imageKey + "." + pair.second();
final String resourceURL = JPPFWebConsoleApplication.get().getSharedImageURL(imageKey);
style.append("background-image: url(" + contextPath + resourceURL + ")");
}
tag.getAttributes().put("style", style.append(FIXED_STYLE).toString());
}
@Override
protected void onEvent(final AjaxRequestTarget target) {
final JPPFWebSession session = (JPPFWebSession) target.getPage().getSession();
final TableTreeData data = session.getTableTreeData(type);
final SelectionHandler selectionHandler = data.getSelectionHandler();
final DefaultMutableTreeNode node = TreeTableUtils.findTreeNode((DefaultMutableTreeNode) data.getModel().getRoot(), uuid, selectionHandler.getFilter());
if (node != null) {
final IRequestParameters params = RequestCycle.get().getRequest().getRequestParameters();
final TypedProperties props = new TypedProperties()
.setBoolean("ctrl", params.getParameterValue("ctrl").toBoolean(false))
.setBoolean("shift", params.getParameterValue("shift").toBoolean(false));
final Page page = target.getPage();
if (selectionHandler.handle(target, node, props) && (page instanceof TableTreeHolder)) {
final TableTreeHolder holder = (TableTreeHolder) page;
target.add(holder.getTableTree());
target.add(holder.getToolbar());
}
}
}
@Override
public void onBeginRequest(RequestCycle cycle) {
StringValue directBuyParameterValue = cycle.getRequest().getRequestParameters().getParameterValue(DIRECT_BUY_PARAMETER);
if (!directBuyParameterValue.isEmpty()) {
try {
ProductInfo productInfo = productService.findByQuery(ProductQuery.create().withUrlname(directBuyParameterValue.toString()));
if (productInfo != null) {
cart.addItem(productInfo);
} else {
ShopSession.get().error(String.format("Das Product '%s' konnte nicht gefunden werden.", directBuyParameterValue));
}
Url urlWithoutDirectBuy = removeDirectBuyFromUrl(cycle);
redirectTo(cycle, urlWithoutDirectBuy);
} catch (Exception e) {
ShopSession.get().error(DIRECT_BUY_PROCESSING_FAILED_MESSAGE);
LOGGER.error(DIRECT_BUY_PROCESSING_FAILED_MESSAGE, e);
}
}
}
@Override
public void renderHead(IHeaderResponse response) {
super.renderHead(response);
String contextPath = RequestCycle.get().getRequest().getContextPath();
Map<String, String> replacements = Collections.singletonMap("contextPath", getContextPath());
MapVariableInterpolator variableInterpolator = new MapVariableInterpolator(FAVICON_HEADER, replacements);
response.render(StringHeaderItem.forString(variableInterpolator.toString()));
String designUrl = String.format("/assets/css/bootstrap-%s.min.css", designSelector.getDesignType());
response.render(CssHeaderItem.forUrl(contextPath + designUrl));
response.render(CssHeaderItem.forUrl(contextPath + "/assets/css/bootstrap-theme-shop.css"));
response.render(JavaScriptHeaderItem.forUrl(contextPath + "/assets/js/bootstrap.min.js"));
response.render(CssHeaderItem.forUrl(contextPath + "/assets/css/bootstrap-addon.css"));
}
@Override
public void onEndRequest(RequestCycle cycle)
{
Set<RecommendationStateKey> dirties = cycle.getMetaData(DIRTIES);
Set<RecommendationStateKey> committed = cycle.getMetaData(COMMITTED);
if (dirties == null || committed == null) {
return;
}
for (RecommendationStateKey committedKey : committed) {
if (!dirties.contains(committedKey)) {
// Committed but not dirty, so nothing to do.
continue;
}
Project project = projectService.getProject(committedKey.getProjectId());
if (project == null) {
// Concurrent action has deleted project, so we can ignore this
continue;
}
triggerTrainingAndClassification(committedKey.getUser(), project,
"Committed dirty CAS at end of request", currentDocument);
}
}
@Override
protected void onSubmit()
{
AuthenticatedWebSession session = AuthenticatedWebSession.get();
if (session.signIn(username, password)) {
log.debug("Login successful");
if (sessionRegistry != null) {
// Form-based login isn't detected by SessionManagementFilter. Thus handling
// session registration manually here.
HttpSession containerSession = ((ServletWebRequest) RequestCycle.get()
.getRequest()).getContainerRequest().getSession(false);
sessionRegistry.registerNewSession(containerSession.getId(), username);
}
setDefaultResponsePageIfNecessary();
}
else {
error("Login failed");
}
}
public String getJavaScript() {
final String id = component.getMarkupId();
String parObj = buildDataObject(getParameters());
String attObj = buildDataObject(getAttributes());
// embedSWF: function(swfUrlStr, replaceElemIdStr, widthStr, heightStr, swfVersionStr, xiSwfUrlStr, flashvarsObj, parObj, attObj)
String javascript = String.format("swfobject.embedSWF('%s','%s', '%s', '%s', '%s', '%s', %s, %s );",
flashUrl, id, width, height, version, "expressInstall.swf", parObj, attObj);
// see http://old.nabble.com/Re%3A-Graphs%2C-Charts-and-Wicket-p21987222.html
AjaxRequestTarget target = RequestCycle.get().find(AjaxRequestTarget.class);
if (target != null) {
target.appendJavaScript(javascript);
}
return javascript;
}
@Override
protected void respond(AjaxRequestTarget target) {
IRequestParameters params = RequestCycle.get().getRequest().getPostParameters();
String tooltipId = params.getParameterValue("tooltip").toString();
String commitHash = params.getParameterValue("commit").toString();
RevCommit commit = getProject().getRevCommit(commitHash, true);
String authoring;
if (commit.getAuthorIdent() != null) {
authoring = commit.getAuthorIdent().getName();
if (commit.getCommitterIdent() != null)
authoring += " " + DateUtils.formatAge(commit.getCommitterIdent().getWhen());
authoring = "'" + JavaScriptEscape.escapeJavaScript(authoring) + "'";
} else {
authoring = "undefined";
}
String message = JavaScriptEscape.escapeJavaScript(commit.getFullMessage());
String script = String.format("onedev.server.blameMessage.show('%s', %s, '%s');", tooltipId, authoring, message);
target.appendJavaScript(script);
}
@Override
public void onBeginRequest(RequestCycle cycle) {
String username = "";
if (NextServerSession.get().isSignedIn()) {
username = NextServerSession.get().getUsername();
}
Session session = NextServerSession.get();
String sessionId = NextServerSession.get().getId();
if (sessionId == null) {
session.bind();
sessionId = session.getId();
}
HttpServletRequest request = ((ServletWebRequest) RequestCycle.get().getRequest()).getContainerRequest();
String ip = request.getHeader("X-Forwarded-For");
if (ip == null) {
ip = request.getRemoteHost();
}
MDC.put("username", username);
MDC.put("session", sessionId);
MDC.put("ip", ip);
}
protected final void onRequest(final String val, final RequestCycle requestCycle)
{
// final PageParameters pageParameters = new PageParameters(requestCycle.getRequest().getParameterMap());
final List<T> choices = getChoices(val);
final MyJsonBuilder builder = new MyJsonBuilder();
final String json = builder.append(choices).getAsString();
requestCycle.scheduleRequestHandlerAfterCurrent(new TextRequestHandler("application/json", "utf-8", json));
/*
* IRequestTarget target = new IRequestTarget() {
*
* public void respond(RequestCycle requestCycle) {
*
* WebResponse r = (WebResponse) requestCycle.getResponse(); // Determine encoding final String encoding =
* Application.get().getRequestCycleSettings().getResponseRequestEncoding(); r.setCharacterEncoding(encoding);
* r.setContentType("application/json"); // Make sure it is not cached by a r.setHeader("Expires", "Mon, 26 Jul 1997 05:00:00 GMT");
* r.setHeader("Cache-Control", "no-cache, must-revalidate"); r.setHeader("Pragma", "no-cache");
*
* final List<T> choices = getChoices(val); renderer.renderHeader(r); renderer.render(JsonBuilder.buildRows(false, choices), r, val);
* renderer.renderFooter(r); }
*
* public void detach(RequestCycle requestCycle) { } }; requestCycle.setRequestTarget(target);
*/
}
/**
* Get existing or create new {@link MultiWebApplicationPath} for new request
*
* @return instance of {@link MultiWebApplicationPath}
*/
private MultiWebApplicationPath configureMultiWebApplicationPath() {
HttpServletRequest rawRequest = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
final Object resolver = rawRequest.getAttribute("SFW_APP_MULTIWEBAPP_RESOLVER");
if (resolver == null) {
MultiWebApplicationPath multiWebApplicationPath = new MultiWebApplicationPath(getServletContext());
final List<String> themesChain = ApplicationDirector.getCurrentThemeChain();
for (final String theme : themesChain) {
multiWebApplicationPath.add(theme + "/markup"); // shop specific markup folder
}
rawRequest.setAttribute("SFW_APP_MULTIWEBAPP_RESOLVER", multiWebApplicationPath);
return multiWebApplicationPath;
}
return (MultiWebApplicationPath) resolver;
}
@Override
protected void onAfterRender()
{
super.onAfterRender();
RequestCycle.get().find(AjaxRequestTarget.class).ifPresent(_target -> {
// Put focus on hidden input field if we are in forward-mode unless the user has
// selected an annotation which is not on the forward-mode layer
AnnotatorState state = getModelObject();
AnnotationLayer layer = state.getSelectedAnnotationLayer();
if (
getModelObject().isForwardAnnotation() &&
layer != null &&
layer.equals(state.getDefaultAnnotationLayer())
) {
focusForwardAnnotationComponent(_target, false);
}
// If the user selects or creates an annotation then we put the focus on the
// first of the feature editors
else if (!Objects.equals(getRequestCycle().getMetaData(IsSidebarAction.INSTANCE),
true)) {
getFirstFeatureEditor().ifPresent(_editor ->
autoFocus(_target, _editor.getFocusComponent()));
}
});
}
public PullRequestActivitiesPage(PageParameters params) {
super(params);
WebRequest request = (WebRequest) RequestCycle.get().getRequest();
Cookie cookie = request.getCookie(COOKIE_SHOW_COMMENTS);
if (cookie != null)
showComments = Boolean.valueOf(cookie.getValue());
cookie = request.getCookie(COOKIE_SHOW_COMMITS);
if (cookie != null)
showCommits = Boolean.valueOf(cookie.getValue());
cookie = request.getCookie(COOKIE_SHOW_CHANGE_HISTORY);
if (cookie != null)
showChangeHistory = Boolean.valueOf(cookie.getValue());
}
private void doQuery(AjaxRequestTarget target) {
if (backlog) {
backlogQueryString = queryInput.getModelObject();
getPageParameters().set(PARAM_BACKLOG_QUERY, backlogQueryString);
} else {
queryString = queryInput.getModelObject();
getPageParameters().set(PARAM_QUERY, queryString);
}
PageParameters params = IssueBoardsPage.paramsOf(getProject(), getBoard(),
getMilestone(), backlog, queryString, backlogQueryString);
CharSequence url = RequestCycle.get().urlFor(IssueBoardsPage.class, params);
pushState(target, url.toString(), queryInput.getModelObject());
target.add(body);
target.appendJavaScript("$(window).resize();");
}
@Override
protected void onInitialize() {
super.onInitialize();
if (getProject().getDefaultBranch() != null)
add(new Label("note", "Contributions to " + getProject().getDefaultBranch() + " branch, excluding merge commits"));
else
add(new WebMarkupContainer("note").setVisible(false));
add(new WebMarkupContainer(USER_CARD_ID).setOutputMarkupId(true));
add(userCardBehavior = new AbstractPostAjaxBehavior() {
@Override
protected void respond(AjaxRequestTarget target) {
String name = RequestCycle.get().getRequest().getPostParameters()
.getParameterValue("name").toString();
String emailAddress = RequestCycle.get().getRequest().getPostParameters()
.getParameterValue("emailAddress").toString();
PersonIdent author = new PersonIdent(name, emailAddress);
Component userCard = new PersonCardPanel(USER_CARD_ID, author, "Author");
userCard.setOutputMarkupId(true);
replace(userCard);
target.add(userCard);
target.appendJavaScript("onedev.server.stats.contribs.onUserCardAvailable();");
}
});
}
private Page extractCurrentPage(boolean fullSearch)
{
final RequestCycle requestCycle = RequestCycle.get();
IRequestHandler handler = requestCycle.getActiveRequestHandler();
if (handler == null)
{
handler = requestCycle.getRequestHandlerScheduledAfterCurrent();
if(handler==null && fullSearch) {
handler = OrientDbWebApplication.get().getRootRequestMapper().mapRequest(requestCycle.getRequest());
}
}
if (handler instanceof IPageRequestHandler)
{
IPageRequestHandler pageRequestHandler = (IPageRequestHandler)handler;
return (Page)pageRequestHandler.getPage();
}
return null;
}
@Override
public long size() {
long result = 0;
try {
if (filtered) {
result = Optional.ofNullable(fiql).map(s -> restClient.count(realm, s, type)).orElse(0);
} else {
result = restClient.count(realm, null, type);
}
} catch (Exception e) {
LOG.error("While requesting for size() with FIQL {}", fiql, e);
SyncopeConsoleSession.get().onException(e);
RequestCycle.get().find(AjaxRequestTarget.class).
ifPresent(target -> ((BasePage) pageRef.getPage()).getNotificationPanel().refresh(target));
}
return result;
}
@Override
public WebRequest newWebRequest(HttpServletRequest servletRequest, String filterPath) {
return new ServletWebRequest(servletRequest, filterPath) {
@Override
public boolean shouldPreserveClientUrl() {
if (RequestCycle.get().getActiveRequestHandler() instanceof RenderPageRequestHandler) {
RenderPageRequestHandler requestHandler =
(RenderPageRequestHandler) RequestCycle.get().getActiveRequestHandler();
/*
* Add this to make sure that the page url does not change upon errors, so that
* user can know which page is actually causing the error. This behavior is common
* for main stream applications.
*/
if (requestHandler.getPage() instanceof GeneralErrorPage)
return true;
}
return super.shouldPreserveClientUrl();
}
};
}
@Override
public void onBeginRequest(RequestCycle cycle) {
if (((HttpServletRequest) cycle.getRequest().getContainerRequest()).getHeaders(HEADER_NAME).hasMoreElements()) {
((ShopSession) ShopSession.get()).setDockerMode(true);
LOGGER.debug("Docker mode Enabled");
}
}
/**
*
* @return the roles of the current signed-in user, if any.
*/
private static List<String> getUserRoles() {
final List<String> result = new ArrayList<>();
final HttpServletRequest req = (HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest();
for (final JPPFRole r: JPPFRole.values()) {
final String role = r.getRoleName();
if (req.isUserInRole(role)) result.add(role);
}
return result;
}
protected static CharSequence urlFor(ResourceReference ref, ODocument document, String field, String contentType, Integer imageSize, Double imageQuality, boolean fullUrl) {
PageParameters params = new PageParameters();
params.add("rid", document.getIdentity().toString().substring(1));
params.add("field", field);
params.add("v", document.getVersion());
if(!Strings.isEmpty(contentType)) params.add("type", contentType);
if(imageSize!=null && imageSize>0) params.add("s", imageSize);
if(imageQuality!=null && imageQuality>0 && imageQuality<1.0) params.add("q", imageQuality);
if(fullUrl) {
return RequestCycle.get().getUrlRenderer()
.renderFullUrl(Url.parse(RequestCycle.get().urlFor(ref, params)));
} else {
return RequestCycle.get().mapUrlFor(ref, params).toString(StringMode.LOCAL);
}
}
/**
*
* @param key the resource key.
* @return the url of the shared image.
*/
public String getSharedImageURL(final String key) {
final ResourceReference ref = getSharedImageResource(key);
if (ref == null) return null;
String resourceURL = RequestCycle.get().urlFor(ref, null).toString();
if (resourceURL.startsWith("./")) resourceURL = resourceURL.substring(1);
return resourceURL;
}
@Override
protected void onConfigure() {
super.onConfigure();
if (debugEnabled) log.debug("in onConfigure() for page {} ==> '{}'", getClass().getSimpleName(), RequestCycle.get().urlFor(getClass(), null));
if (!JPPFWebSession.get().isSignedIn()) {
if (debugEnabled) log.debug("not signed in: {]", this);
JPPFWebConsoleApplication.get().restartResponseAtSignInPage();
}
}
/**
* If true then a tick-mark icon is returned, otherwise an invisible label.
* @param requestCycle
* @param componentId
* @param value
* @return
*/
public static Component createBooleanLabel(final RequestCycle requestCycle, final String componentId, final boolean value)
{
if (value == true) {
return new IconPanel(componentId, IconType.ACCEPT);
}
return new Label(componentId, "invisible").setVisible(false);
}
/**
* Checks if auto-logout is enabled. For Winstone, we get a max session length of 0, so here it
* is disabled.
*/
private int getAutoLogoutTime()
{
int duration = 0;
Request request = RequestCycle.get().getRequest();
if (request instanceof ServletWebRequest) {
HttpSession session = ((ServletWebRequest) request).getContainerRequest().getSession();
if (session != null) {
duration = session.getMaxInactiveInterval();
}
}
return duration;
}
public AbstractInfoPanel(String aId, IModel<KnowledgeBase> aKbModel,
IModel<? extends KBObject> aHandleModel, IModel<T> aKbObjectModel) {
super(aId, aHandleModel);
kbModel = aKbModel;
handleModel = aHandleModel;
kbObjectModel = aKbObjectModel;
setOutputMarkupId(true);
// when creating a new KBObject, activate the form and obtain the AjaxRequestTarget to set
// the focus to the name field
Component content;
modal = new SubclassCreationDialog("createSubclass", kbModel, handleModel);
add(modal);
boolean isNew = kbObjectModel.getObject() != null
&& isEmpty(kbObjectModel.getObject().getIdentifier());
if (isNew) {
EditMode editMode = new EditMode(CONTENT_MARKUP_ID,
CompoundPropertyModel.of(kbObjectModel));
// obtain AjaxRequestTarget and set the focus
RequestCycle.get()
.find(AjaxRequestTarget.class)
.ifPresent(target -> target.focusComponent(editMode.getFocusComponent()));
content = editMode;
} else {
content = new ViewMode(CONTENT_MARKUP_ID, CompoundPropertyModel.of(handleModel),
getDetailPreference());
}
add(content);
confirmationDialog = new ConfirmationDialog("confirmationDialog");
add(confirmationDialog);
}
@Override
public void onBeginRequest(RequestCycle cycle) {
Enumeration<String> headers = ((HttpServletRequest) cycle.getRequest().getContainerRequest()).getHeaders(HEADER_NAME);
if (headers.hasMoreElements() && !designSelectorBean.isUsedToSelectedDesign()) {
String themeName = headers.nextElement();
if (designSelectorBean.getAvailableDesignTypes().contains(themeName)) {
designSelectorBean.setDesignType(themeName);
LOGGER.debug(format("Bootstrap Design is set to %s.", themeName));
} else {
LOGGER.error(format("Bootstrap Design '%s' is present.", themeName));
}
}
}
/**
* Creates anchor: <a href="${buildUrl(href)}">
* @param response
* @param buf
* @param href Will be modified via buildUrl.
* @return
*/
public HtmlHelper appendAncorStartTag(final RequestCycle requestCycle, final StringBuffer buf, final String href)
{
final HtmlTagBuilder tag = new HtmlTagBuilder(buf, "a");
tag.addAttribute("href", WicketUtils.getImageUrl(requestCycle, href));
tag.finishStartTag();
return this;
}
public void removeFromFooter(Component aComponent)
{
List<Component> items = footerItems.getObject();
items.remove(aComponent);
RequestCycle.get().find(IPartialPageRequestHandler.class).ifPresent(handler -> {
handler.add(footer);
});
}