/** * Finds the given object in the ancestor list and returns its URL. * This is used to determine the "current" URL assigned to the given object, * so that one can compute relative URLs from it. */ public static String getNearestAncestorUrl(StaplerRequest req,Object it) { List list = req.getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject()==it) return anc.getUrl(); } return null; }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
/** * @since 1.402 */ public static String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); // this override allows RenderOnDemandClosure to preserve the proper value Object url = req.getAttribute("currentDescriptorByNameUrl"); if (url!=null) return url.toString(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }
public static RunUrl decompose(StaplerRequest req) { List<Ancestor> ancestors = req.getAncestors(); // find the first and last Run instances Ancestor f=null,l=null; for (Ancestor anc : ancestors) { if(anc.getObject() instanceof Run) { if(f==null) f=anc; l=anc; } } if(l==null) return null; // there was no Run object String head = f.getPrev().getUrl()+'/'; String base = l.getUrl(); String reqUri = req.getOriginalRequestURI(); // Find "rest" or URI by removing N path components. // Not using reqUri.substring(f.getUrl().length()) to avoid mismatches due to // url-encoding or extra slashes. Former may occur in Tomcat (despite the spec saying // this string is not decoded, Tomcat apparently decodes this string. You see ' ' // instead of '%20', which is what the browser has sent), latter may occur in some // proxy or URL-rewriting setups where extra slashes are inadvertently added. String furl = f.getUrl(); int slashCount = 0; // Count components in ancestor URL for (int i = furl.indexOf('/'); i >= 0; i = furl.indexOf('/', i + 1)) slashCount++; // Remove that many from request URL, ignoring extra slashes String rest = reqUri.replaceFirst("(?:/+[^/]*){" + slashCount + "}", ""); return new RunUrl( (Run) f.getObject(), head, base, rest); }
if (view.getOwner().getItemGroup() == getParent() && !view.isDefault()) { String base = last.getUrl().substring(req.getContextPath().length() + 1) + '/'; LOGGER.log(Level.FINER, "using {0}{1} for {2} from {3}", new Object[] {base, shortUrl, this, uri}); return base + shortUrl;
/** * @see ContextMenuVisibility */ public ContextMenu add(Action a) { if (!Functions.isContextMenuVisible(a)) { return this; } StaplerRequest req = Stapler.getCurrentRequest(); String text = a.getDisplayName(); String base = Functions.getIconFilePath(a); if (base==null) return this; String icon = Stapler.getCurrentRequest().getContextPath()+(base.startsWith("images/")?Functions.getResourcePath():"")+'/'+base; String url = Functions.getActionUrl(req.findAncestor(ModelObject.class).getUrl(),a); return add(url,icon,text); }
/** * Finds the given object in the ancestor list and returns its URL. * This is used to determine the "current" URL assigned to the given object, * so that one can compute relative URLs from it. */ public static String getNearestAncestorUrl(StaplerRequest req,Object it) { List list = req.getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject()==it) return anc.getUrl(); } return null; }
protected void redirectAncestor(final StaplerRequest req, final StaplerResponse resp, final Class type) throws IOException { log.trace("Redirect ancestor: {}", type); redirect(req, resp, req.findAncestor(type).getUrl()); }
protected void redirectAncestor(final StaplerRequest req, final StaplerResponse resp, final Object obj) throws IOException { log.trace("Redirect ancestor: {}", obj); Ancestor ancestor = req.findAncestor(obj); redirect(req, resp, ancestor.getUrl()); }
protected void redirectAncestor(final StaplerRequest req, final StaplerResponse resp, final Object obj) throws IOException { log.trace("Redirect ancestor: {}", obj); Ancestor ancestor = req.findAncestor(obj); redirect(req, resp, ancestor.getUrl()); }
public static String getAncestorUrl(StaplerRequest req, Ancestor anc) { if (anc != null) { String ancUrl = anc.getUrl(); String reqRootPath = Functions.getRequestRootPath(req); return ancUrl.replaceFirst(req.getContextPath(), reqRootPath); } return ""; }
protected void redirectAncestor(final StaplerRequest req, final StaplerResponse resp, final Object obj) throws IOException { log.trace("Redirect ancestor: {}", obj); Ancestor ancestor = req.findAncestor(obj); redirect(req, resp, ancestor.getUrl()); }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
private String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
/** * Finds the inner-most {@link SearchableModelObject} in scope. */ public static String getSearchURL() { List list = Stapler.getCurrentRequest().getAncestors(); for( int i=list.size()-1; i>=0; i-- ) { Ancestor anc = (Ancestor) list.get(i); if(anc.getObject() instanceof SearchableModelObject) return anc.getUrl()+"/search/"; } return null; }
private String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }
private String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }
/** * @since 1.402 */ public static String getCurrentDescriptorByNameUrl() { StaplerRequest req = Stapler.getCurrentRequest(); // this override allows RenderOnDemandClosure to preserve the proper value Object url = req.getAttribute("currentDescriptorByNameUrl"); if (url!=null) return url.toString(); Ancestor a = req.findAncestor(DescriptorByNameOwner.class); return a.getUrl(); }