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

1 package hudson.console;
2
3 import hudson.Extension;
4 import hudson.model.Item;
5 import hudson.model.ModelObject;
6 import hudson.model.Node;
7 import hudson.model.Run;
8 import hudson.model.User;
9
10 import java.io.IOException;
11 import java.util.logging.Level;
12 import java.util.logging.Logger;
13
14 /**
15 * {@link HyperlinkNote} that links to a {@linkplain ModelObject model object},
16 * which in the UI gets rendered with context menu and etc.
17 *
18 * @author Kohsuke Kawaguchi
19 * @since 1.464
20 */
21 public class ModelHyperlinkNote extends HyperlinkNote {
22 public ModelHyperlinkNote(String url, int length) {
23 super(url, length);
24 }
25
26 @Override
27 protected String extraAttributes() {
28 return " class='model-link'";
29 }
30
31 public static String encodeTo(User u) {
32 return encodeTo(u,u.getDisplayName());
33 }
34
35 public static String encodeTo(User u, String text) {
36 return encodeTo('/'+u.getUrl(),text);
37 }
38
39 public static String encodeTo(Item item) {
40 return encodeTo(item,item.getDisplayName());
41 }
42
43 public static String encodeTo(Item item, String text) {
44 return encodeTo('/'+item.getUrl(),text);
45 }
46
47 public static String encodeTo(Run r) {
48 return encodeTo('/'+r.getUrl(),r.getDisplayName());
49 }
50
51 public static String encodeTo(Node node) {
52 return encodeTo("/computer/"+ node.getNodeName(), node.getDisplayName());
53 }
54
55 public static String encodeTo(String url, String text) {
56 try {
57 return new ModelHyperlinkNote(url,text.length()).encode()+text;
58 } catch (IOException e) {
59 // impossible, but don't make this a fatal problem
60 LOGGER.log(Level.WARNING, "Failed to serialize "+ModelHyperlinkNote.class,e);
61 return text;
62 }
63 }
64
65 @Extension
66 public static class DescriptorImpl extends HyperlinkNote.DescriptorImpl {
67 public String getDisplayName() {
68 return "Hyperlinks to models";
69 }
70 }
71
72 private static final long serialVersionUID = 1L;
73
74 private static final Logger LOGGER = Logger.getLogger(ModelHyperlinkNote.class.getName());
75 }
76