org.apache.wicket.request.cycle.RequestCycle Java Examples

The following examples show how to use org.apache.wicket.request.cycle.RequestCycle. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PFAutoCompleteBehavior.java    From projectforge-webapp with GNU General Public License v3.0 7 votes vote down vote up
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);
   */
}
 
Example #2
Source File: OneWebApplication.java    From onedev with MIT License 6 votes vote down vote up
@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();
		}
		
	};
}
 
Example #3
Source File: RecommendationServiceImpl.java    From inception with Apache License 2.0 6 votes vote down vote up
@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);
    }
}
 
Example #4
Source File: LoginPage.java    From webanno with Apache License 2.0 6 votes vote down vote up
@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");
    }
}
 
Example #5
Source File: StorefrontApplication.java    From yes-cart with Apache License 2.0 6 votes vote down vote up
/**
 * 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;
}
 
Example #6
Source File: AbstractBasePage.java    From AppStash with Apache License 2.0 6 votes vote down vote up
@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"));
}
 
Example #7
Source File: DirectBuyRequestCycleListener.java    From the-app with Apache License 2.0 6 votes vote down vote up
@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);
        }
    }
}
 
Example #8
Source File: FeatureEditorListPanel.java    From webanno with Apache License 2.0 6 votes vote down vote up
@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()));
        }
    });
}
 
Example #9
Source File: SWFObject.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #10
Source File: PullRequestActivitiesPage.java    From onedev with MIT License 6 votes vote down vote up
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());
}
 
Example #11
Source File: IssueBoardsPage.java    From onedev with MIT License 6 votes vote down vote up
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();");
}
 
Example #12
Source File: NextServerApplication.java    From nextreports-server with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #13
Source File: AbstractActionLink.java    From JPPF with Apache License 2.0 6 votes vote down vote up
@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);
}
 
Example #14
Source File: AjaxButtonWithIcon.java    From JPPF with Apache License 2.0 6 votes vote down vote up
@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());
}
 
Example #15
Source File: AnyDataProvider.java    From syncope with Apache License 2.0 6 votes vote down vote up
@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;
}
 
Example #16
Source File: BlameMessageBehavior.java    From onedev with MIT License 6 votes vote down vote up
@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);
}
 
Example #17
Source File: JPPFTableTree.java    From JPPF with Apache License 2.0 6 votes vote down vote up
@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());
    }
  }
}
 
Example #18
Source File: OrientDefaultExceptionsHandlingListener.java    From wicket-orientdb with Apache License 2.0 6 votes vote down vote up
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;
}
 
Example #19
Source File: ProjectContribsPage.java    From onedev with MIT License 6 votes vote down vote up
@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();");
		}
		
	});
}
 
Example #20
Source File: DockerRequestCycleListener.java    From AppStash with Apache License 2.0 5 votes vote down vote up
@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");
    }
}
 
Example #21
Source File: CaptchaResource.java    From syncope with Apache License 2.0 5 votes vote down vote up
@Override
protected byte[] render() {
    LOG.debug("Generate captcha");

    String captcha = RANDOM_LETTERS.generate(6);
    HttpServletRequest request = ((HttpServletRequest) RequestCycle.get().getRequest().getContainerRequest());
    // store the captcha in the current session
    request.getSession().setAttribute(SyncopeEnduserConstants.CAPTCHA_SESSION_KEY, captcha);

    getChallengeIdModel().setObject(captcha);
    return super.render();
}
 
Example #22
Source File: EditParamsAware.java    From onedev with MIT License 5 votes vote down vote up
@Nullable
static String getUrlAfterEdit(Page page) {
	if (page instanceof EditParamsAware) {
		EditParamsAware editParamsAware = (EditParamsAware) page; 
		return RequestCycle.get()
				.urlFor(page.getClass(), editParamsAware.getParamsAfterEdit())
				.toString();
	} else {
		return null;
	}
}
 
Example #23
Source File: DownloadUtils.java    From projectforge-webapp with GNU General Public License v3.0 5 votes vote down vote up
/**
 * @param content The content of the file to download.
 * @param filename
 * @param contentType For setting contentType manually.
 */
public static void setDownloadTarget(final byte[] content, final String filename, final String contentType)
{
  final ByteArrayResourceStream byteArrayResourceStream;
  if (contentType != null) {
    byteArrayResourceStream = new ByteArrayResourceStream(content, filename, contentType);
  } else {
    byteArrayResourceStream = new ByteArrayResourceStream(content, filename);
  }
  final ResourceStreamRequestHandler handler = new ResourceStreamRequestHandler(byteArrayResourceStream);
  handler.setFileName(filename).setContentDisposition(ContentDisposition.ATTACHMENT);
  RequestCycle.get().scheduleRequestHandlerAfterCurrent(handler);
  log.info("Starting download for file. filename:" + filename + ", content-type:" + byteArrayResourceStream.getContentType());
}
 
Example #24
Source File: AnnotatorStateImpl.java    From webanno with Apache License 2.0 5 votes vote down vote up
private void fireViewStateChanged()
{
    RequestCycle requestCycle = RequestCycle.get();
    
    if (requestCycle == null) {
        return;
    }
    
    Optional<IPageRequestHandler> handler = requestCycle.find(IPageRequestHandler.class);
    if (handler.isPresent() && handler.get().isPageInstanceCreated()) {
        Page page = (Page) handler.get().getPage();
        page.send(page, BREADTH, new AnnotatorViewportChangedEvent(
                requestCycle.find(AjaxRequestTarget.class).orElse(null)));
    }
}
 
Example #25
Source File: SortBehavior.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected void respond(AjaxRequestTarget target) {
	int fromList = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("fromList").toInt();
	int fromItem = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("fromItem").toInt();
	int toList = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("toList").toInt();
	int toItem = RequestCycle.get().getRequest().getPostParameters()
			.getParameterValue("toItem").toInt();
	if (fromList != toList || fromItem != toItem) {
		onSort(target, new SortPosition(fromList, fromItem), new SortPosition(toList, toItem));
		String script = String.format("onedev.server.form.markDirty($('#%s').closest('form.leave-confirm'));", 
				getComponent().getMarkupId(true));
		target.appendJavaScript(script);
		
		for (Component each: target.getComponents()) {
			if (each == getComponent()) {
				target.appendJavaScript(getSortScript());
				break;
			}
			if (each instanceof MarkupContainer) {
				MarkupContainer container = (MarkupContainer) each;
				if (container.contains(getComponent(), true)) {
					target.appendJavaScript(getSortScript());
					break;
				}
			}
		}
	}
}
 
Example #26
Source File: SourceViewPanel.java    From onedev with MIT License 5 votes vote down vote up
private boolean isOutlineVisibleInitially() {
	if (hasOutline()) {
		WebRequest request = (WebRequest) RequestCycle.get().getRequest();
		Cookie cookie = request.getCookie(COOKIE_OUTLINE);
		if (cookie != null) {
			return cookie.getValue().equals("yes");
		} else {
			return !WicketUtils.isDevice();
		}
	} else {
		return false;
	}
}
 
Example #27
Source File: IssueActivitiesPanel.java    From onedev with MIT License 5 votes vote down vote up
public IssueActivitiesPanel(String panelId) {
	super(panelId);
	
	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_CHANGE_HISTORY);
	if (cookie != null)
		showChangeHistory = Boolean.valueOf(cookie.getValue());
}
 
Example #28
Source File: ProjectBlobPage.java    From onedev with MIT License 5 votes vote down vote up
@Override
public String getPositionUrl(String position) {
	State positionState = SerializationUtils.clone(state);
	positionState.blobIdent.revision = resolvedRevision.name();
	positionState.commentId = null;
	positionState.position = position;
	PageParameters params = paramsOf(getProject(), positionState);		
	return RequestCycle.get().urlFor(ProjectBlobPage.class, params).toString();
}
 
Example #29
Source File: RegistrationResource.java    From Orienteer with Apache License 2.0 5 votes vote down vote up
private WriteCallback createCallback(boolean success) {
    return new WriteCallback() {
        @Override
        public void writeData(Attributes attributes) throws IOException {
            PageParameters params = new PageParameters();
            if (success) {
                params.set(PARAMETER_ID, attributes.getParameters().get(PARAMETER_ID).toOptionalString());
            }
            RequestCycle.get().setResponsePage(usersService.getLoginPage(), params);
        }
    };
}
 
Example #30
Source File: SourceViewPanel.java    From onedev with MIT License 5 votes vote down vote up
private String getJsonOfBlameInfos(boolean blamed) {
	String jsonOfBlameInfos;
	if (blamed) {
		List<BlameInfo> blameInfos = new ArrayList<>();
		
		String commitHash = context.getCommit().name();
		
		BlameCommand cmd = new BlameCommand(context.getProject().getGitDir());
		cmd.commitHash(commitHash).file(context.getBlobIdent().path);
		for (BlameBlock blame: cmd.call()) {
			BlameInfo blameInfo = new BlameInfo();
			blameInfo.commitDate = DateUtils.formatDate(blame.getCommit().getCommitter().getWhen());
			blameInfo.authorName = HtmlEscape.escapeHtml5(blame.getCommit().getAuthor().getName());
			blameInfo.hash = blame.getCommit().getHash();
			blameInfo.abbreviatedHash = GitUtils.abbreviateSHA(blame.getCommit().getHash(), 7);
			CommitDetailPage.State state = new CommitDetailPage.State();
			state.revision = blame.getCommit().getHash();
			if (context.getBlobIdent().path != null)
				state.pathFilter = PatternSet.quoteIfNecessary(context.getBlobIdent().path);
			PageParameters params = CommitDetailPage.paramsOf(context.getProject(), state);
			blameInfo.url = RequestCycle.get().urlFor(CommitDetailPage.class, params).toString();
			blameInfo.ranges = blame.getRanges();
			blameInfos.add(blameInfo);
		}
		try {
			jsonOfBlameInfos = OneDev.getInstance(ObjectMapper.class).writeValueAsString(blameInfos);
		} catch (JsonProcessingException e) {
			throw new RuntimeException(e);
		}
	} else {
		jsonOfBlameInfos = "undefined";
	}
	return jsonOfBlameInfos;
}