File D:\maven-qcr-plugin-testsunitaires\qcr4java\jenkins-master\target\site\qc\core\src\main\java\hudson\model\MyView.java.html

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 */
24 package hudson.model;
25
26 import java.io.IOException;
27 import java.util.ArrayList;
28 import java.util.Collection;
29 import java.util.Collections;
30 import java.util.List;
31
32 import javax.servlet.ServletException;
33
34 import jenkins.model.Jenkins;
35 import org.kohsuke.stapler.StaplerRequest;
36 import org.kohsuke.stapler.StaplerResponse;
37 import org.kohsuke.stapler.DataBoundConstructor;
38 import hudson.model.Descriptor.FormException;
39 import hudson.Extension;
40
41 /**
42 * {@link View} that only contains projects for which the current user has access to.
43 *
44 * @since 1.220
45 * @author Tom Huybrechts
46 */
47 public class MyView extends View {
48 @DataBoundConstructor
49 public MyView(String name) {
50 super(name);
51 }
52
53 public MyView(String name, ViewGroup owner) {
54 this(name);
55 this.owner = owner;
56 }
57
58 @Override
59 public boolean contains(TopLevelItem item) {
60 return item.hasPermission(Job.CONFIGURE);
61 }
62
63 @Override
64 public TopLevelItem doCreateItem(StaplerRequest req, StaplerResponse rsp)
65 throws IOException, ServletException {
66 ItemGroup<? extends TopLevelItem> ig = getOwnerItemGroup();
67 if (ig instanceof ModifiableItemGroup) {
68 return ((ModifiableItemGroup<? extends TopLevelItem>)ig).doCreateItem(req, rsp);
69 }
70 return null;
71 }
72
73 @Override
74 public Collection<TopLevelItem> getItems() {
75 List<TopLevelItem> items = new ArrayList<TopLevelItem>();
76 for (TopLevelItem item : getOwnerItemGroup().getItems()) {
77 if (item.hasPermission(Job.CONFIGURE)) {
78 items.add(item);
79 }
80 }
81 return Collections.unmodifiableList(items);
82 }
83
84 @Override
85 public String getPostConstructLandingPage() {
86 return ""; // there's no configuration page
87 }
88
89 @Override
90 public void onJobRenamed(Item item, String oldName, String newName) {
91 // noop
92 }
93
94 @Override
95 protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
96 // noop
97 }
98
99 @Extension
100 public static final class DescriptorImpl extends ViewDescriptor {
101 /**
102 * If the security is not enabled, there's no point in having
103 * this type of views.
104 */
105 @Override
106 public boolean isInstantiable() {
107 return Jenkins.getInstance().isUseSecurity();
108 }
109
110 public String getDisplayName() {
111 return Messages.MyView_DisplayName();
112 }
113 }
114 }
115