Package org.kohsuke.stapler

Examples of org.kohsuke.stapler.StaplerRequest


    @Test
    @PrepareForTest({Hudson.class, StaplerRequest.class})
    public void testBuildExternalProperties() throws Exception {
        Job job = new FreeStyleProjectMock("job");
        StaplerRequest req = createMock(StaplerRequest.class);
        String javadocArchiverKey = "hudson-tasks-JavadocArchiver";
        JSONObject archiver = new JSONObject();
        archiver.put("javadoc_dir", "dir");
        archiver.put("keep_all", true);
        JSONObject json = new JSONObject();
        json.put(javadocArchiverKey, archiver);
        Hudson hudson = createMock(Hudson.class);
        Descriptor<Publisher> javadocDescriptor = new JavadocArchiver.DescriptorImpl();
        expect(hudson.getDescriptorOrDie(JavadocArchiver.class)).andReturn(javadocDescriptor);
        JavadocArchiver javadocArchiver = new JavadocArchiver("dir", true);
        expect(req.bindJSON(JavadocArchiver.class, archiver)).andReturn(javadocArchiver).anyTimes();

        List<Descriptor<Publisher>> descriptors = new ArrayList<Descriptor<Publisher>>();
        descriptors.add(javadocDescriptor);

        mockStatic(Hudson.class);
View Full Code Here


     */
    public static String getRelativeLinkTo(Item p) {
        Map<Object,String> ancestors = new HashMap<Object,String>();
        View view=null;

        StaplerRequest request = Stapler.getCurrentRequest();
        for( Ancestor a : request.getAncestors() ) {
            ancestors.put(a.getObject(),a.getRelativePath());
            if(a.getObject() instanceof View)
                view = (View) a.getObject();
        }

        String path = ancestors.get(p);
        if(path!=nullreturn path;

        Item i=p;
        String url = "";
        while(true) {
            ItemGroup ig = i.getParent();
            url = i.getShortUrl()+url;

            if(ig==Hudson.getInstance()) {
                assert i instanceof TopLevelItem;
                if(view!=null && view.contains((TopLevelItem)i)) {
                    // if p and the current page belongs to the same view, then return a relative path
                    return ancestors.get(view)+'/'+url;
                } else {
                    // otherwise return a path from the root Hudson
                    return request.getContextPath()+'/'+p.getUrl();
                }
            }

            path = ancestors.get(ig);
            if(path!=nullreturn path+'/'+url;
View Full Code Here

    public void onCopiedFrom(Item src) {
    }

    public final String getUrl() {
        // try to stick to the current view if possible
        StaplerRequest req = Stapler.getCurrentRequest();
        if (req != null) {
            String seed = Functions.getNearestAncestorUrl(req,this);
            if(seed!=null) {
                // trim off the context path portion and leading '/', but add trailing '/'
                return seed.substring(req.getContextPath().length()+1)+'/';
            }
        }

        // otherwise compute the path normally
        return getParent().getUrl()+getShortUrl();
View Full Code Here

        return getShortUrl();
    }

    @Exported(visibility=999,name="url")
    public final String getAbsoluteUrl() {
        StaplerRequest request = Stapler.getCurrentRequest();
        if(request==null)
            throw new IllegalStateException("Not processing a HTTP request");
        return Util.encode(Hudson.getInstance().getRootUrl()+getUrl());
    }
View Full Code Here

            // use the current request to determine the language
            LocaleProvider.setProvider(new LocaleProvider() {
                public Locale get() {
                    Locale locale=null;
                    StaplerRequest req = Stapler.getCurrentRequest();
                    if(req!=null)
                        locale = req.getLocale();
                    if(locale==null)
                        locale = Locale.getDefault();
                    return locale;
                }
            });
View Full Code Here

        super(project, buildDir);
    }

    @Override
    public String getUpUrl() {
        StaplerRequest req = Stapler.getCurrentRequest();
        if(req!=null) {
            List<Ancestor> ancs = req.getAncestors();
            for( int i=1; i<ancs.size(); i++) {
                if(ancs.get(i).getObject()==this) {
                    Object parentObj = ancs.get(i-1).getObject();
                    if(parentObj instanceof MatrixBuild || parentObj instanceof MatrixConfiguration) {
                        return ancs.get(i-1).getUrl()+'/';
View Full Code Here

        }
    };

    @Override
    public String getDisplayName() {
        StaplerRequest req = Stapler.getCurrentRequest();
        if(req!=null) {
            List<Ancestor> ancs = req.getAncestors();
            for( int i=1; i<ancs.size(); i++) {
                if(ancs.get(i).getObject()==this) {
                    if(ancs.get(i-1).getObject() instanceof MatrixBuild) {
                        return getParent().getCombination().toCompactString(getParent().getParent().getAxes());
                    }
View Full Code Here

        String url = Mailer.descriptor().getUrl();
        if (url != null) {
            return url;
        }

        StaplerRequest req = Stapler.getCurrentRequest();
        if (req != null) {
            return getRootUrlFromRequest();
        }
        return null;
    }
View Full Code Here

     * is that unless you are processing a request, this method doesn't work.
     *
     * @since 1.263
     */
    public String getRootUrlFromRequest() {
        StaplerRequest req = Stapler.getCurrentRequest();
        StringBuilder buf = new StringBuilder();
        buf.append(req.getScheme() + "://");
        buf.append(req.getServerName());
        if (req.getServerPort() != 80) {
            buf.append(':').append(req.getServerPort());
        }
        buf.append(req.getContextPath()).append('/');
        return buf.toString();
    }
View Full Code Here

    /**
     * Convenience method to verify that the current request is a POST request.
     */
    protected final void requirePOST() throws ServletException {
        StaplerRequest req = Stapler.getCurrentRequest();
        if (req==nullreturn; // invoked outside the context of servlet
        String method = req.getMethod();
        if(!method.equalsIgnoreCase("POST"))
            throw new ServletException("Must be POST, Can't be "+method);
    }
View Full Code Here

TOP

Related Classes of org.kohsuke.stapler.StaplerRequest

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.