PageRenderTime 20ms CodeModel.GetById 1ms app.highlight 13ms RepoModel.GetById 2ms app.codeStats 0ms

/hudson-core/src/main/java/hudson/model/MyView.java

http://github.com/hudson/hudson
Java | 109 lines | 61 code | 13 blank | 35 comment | 2 complexity | 2e040ba2509a17230456310aae749737 MD5 | raw file
  1/*
  2 * The MIT License
  3 * 
  4 * Copyright (c) 2004-2009, Sun Microsystems, Inc., Kohsuke Kawaguchi, Seiji Sogabe, Tom Huybrechts
  5 * 
  6 * Permission is hereby granted, free of charge, to any person obtaining a copy
  7 * of this software and associated documentation files (the "Software"), to deal
  8 * in the Software without restriction, including without limitation the rights
  9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
 10 * copies of the Software, and to permit persons to whom the Software is
 11 * furnished to do so, subject to the following conditions:
 12 * 
 13 * The above copyright notice and this permission notice shall be included in
 14 * all copies or substantial portions of the Software.
 15 * 
 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
 19 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
 21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
 22 * THE SOFTWARE.
 23 */
 24package hudson.model;
 25
 26import java.io.IOException;
 27import java.util.ArrayList;
 28import java.util.Collection;
 29import java.util.Collections;
 30import java.util.List;
 31
 32import javax.servlet.ServletException;
 33
 34import org.kohsuke.stapler.StaplerRequest;
 35import org.kohsuke.stapler.StaplerResponse;
 36import org.kohsuke.stapler.DataBoundConstructor;
 37import hudson.model.Descriptor.FormException;
 38import hudson.Extension;
 39
 40/**
 41 * {@link View} that only contains projects for which the current user has access to.
 42 *
 43 * @since 1.220
 44 * @author Tom Huybrechts
 45 */
 46public class MyView extends View {
 47    @DataBoundConstructor
 48    public MyView(String name) {
 49        super(name);
 50    }
 51
 52    public MyView(String name, ViewGroup owner) {
 53        this(name);
 54        this.owner = owner;
 55    }
 56
 57    @Override
 58    public boolean contains(TopLevelItem item) {
 59        return item.hasPermission(Job.CONFIGURE);
 60    }
 61
 62    @Override
 63    public Item doCreateItem(StaplerRequest req, StaplerResponse rsp)
 64            throws IOException, ServletException {
 65        return Hudson.getInstance().doCreateItem(req, rsp);
 66    }
 67
 68    @Override
 69    public Collection<TopLevelItem> getItems() {
 70        List<TopLevelItem> items = new ArrayList<TopLevelItem>();
 71        for (TopLevelItem item : Hudson.getInstance().getItems()) {
 72            if (item.hasPermission(Job.CONFIGURE)) {
 73                items.add(item);
 74            }
 75        }
 76        return Collections.unmodifiableList(items);
 77    }
 78
 79    @Override
 80    public String getPostConstructLandingPage() {
 81        return ""; // there's no configuration page
 82    }
 83
 84    @Override
 85    public void onJobRenamed(Item item, String oldName, String newName) {
 86        // noop
 87    }
 88
 89    @Override
 90    protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
 91        // noop
 92    }
 93
 94    @Extension
 95    public static final class DescriptorImpl extends ViewDescriptor {
 96        /**
 97         * If the security is not enabled, there's no point in having
 98         * this type of views.
 99         */
100        @Override
101        public boolean isInstantiable() {
102            return Hudson.getInstance().isUseSecurity();
103        }
104
105        public String getDisplayName() {
106            return Messages.MyView_DisplayName();
107        }
108    }
109}