提交 862b79cc 编写于 作者: K kohsuke

Added a new extension point called "PageDecorator" to add HTML fragments to all pages.

git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@11223 71c3de6d-444a-0410-be80-ed276b4c234a
上级 4678d496
......@@ -17,6 +17,7 @@ import hudson.model.Project;
import hudson.model.Run;
import hudson.model.TopLevelItem;
import hudson.model.View;
import hudson.model.PageDecorator;
import hudson.search.SearchableModelObject;
import hudson.security.AccessControlled;
import hudson.security.AuthorizationStrategy;
......@@ -932,5 +933,12 @@ public class Functions {
return null;
}
/**
* Gets all the {@link PageDecorator}s.
*/
public static List<PageDecorator> getPageDecorators() {
return (List)PageDecorator.ALL;
}
private static final Pattern SCHEME = Pattern.compile("[a-z]+://.+");
}
package hudson.model;
import hudson.ExtensionPoint;
import hudson.Plugin;
import hudson.util.DescriptorList;
/**
* Participates in the rendering of HTML pages for all pages of Hudson.
*
* <p>
* This class provides a few hooks to augument the HTML generation process of Hudson, across
* all the HTML pages that Hudson delivers.
*
* <p>
* For example, if you'd like to add a Google Analytics stat to Hudson, then you need to inject
* a small script fragment to all Hudson pages. This extension point provides a means to do that.
*
* <h2>Life-cycle</h2>
* <p>
* Instances of this class is singleton. {@link Plugin}s that contribute this extension point
* should instantiate a new decorator and add it to the {@link #ALL} list in {@link Plugin#start()}.
*
* <h2>Associated Views</h2>
* <h4>global.jelly</h4>
* <p>
* If this extension point needs to expose a global configuration, write this jelly page.
* See {@link Descriptor} for more about this. Optional.
*
* <h4>footer.jelly</h4>
* <p>
* This page is added right before the &lt;/body> tag. Convenient place for adding tracking beacons, etc.
*
* <h4>header.jelly</h4>
* <p>
* This page is added right before the &lt;/head> tag. Convenient place for additional stylesheet,
* &lt;meta> tags, etc.
*
*
* @author Kohsuke Kawaguchi
* @since 1.235
*/
public abstract class PageDecorator extends Descriptor<PageDecorator> implements ExtensionPoint, Describable<PageDecorator> {
/**
* @param yourClass
* pass-in "this.getClass()" (except that the constructor parameters cannot use 'this',
* so you'd have to hard-code the class name.
*/
protected PageDecorator(Class<? extends PageDecorator> yourClass) {
super(yourClass);
}
public final Descriptor<PageDecorator> getDescriptor() {
return this;
}
/**
* Unless this object has additional web presence, display name is not used at all.
* So default to "".
*/
public String getDisplayName() {
return "";
}
/**
* All the registered instances.
*/
public static final DescriptorList<PageDecorator> ALL = new DescriptorList<PageDecorator>();
}
......@@ -513,6 +513,19 @@ public class UpdateCenter implements ModelObject {
}
}
/**
* Adds the update center data retriever to HTML.
*/
public static class PageDecoratorImpl extends PageDecorator {
public PageDecoratorImpl() {
super(PageDecoratorImpl.class);
}
}
static {
PageDecorator.ALL.add(new PageDecoratorImpl());
}
/**
* Sequence number generator.
*/
......
<!--
If necessary, ask the client to fetch update-center data file for us.
This allows us to avoid proxy related configuration on the server,
and instead piggy-back on user connection.
This file is pulled into the layout.jelly
-->
<j:jelly xmlns:j="jelly:core" xmlns:st="jelly:stapler" xmlns:d="jelly:define" xmlns:l="/lib/layout" xmlns:t="/lib/hudson" xmlns:f="/lib/form">
<j:if test="${app.updateCenter.due or forcedUpdateCheck}">
<script>
updateCenter.postBackURL = "${rootURL}/updateCenter/postBack";
updateCenter.version = "${h.version}";
Behaviour.addLoadEvent(updateCenter.checkUpdates);
</script>
</j:if>
</j:jelly>
\ No newline at end of file
......@@ -74,6 +74,9 @@
<meta name="ROBOTS" content="INDEX,NOFOLLOW" />
<j:set var="mode" value="header" />
<d:invokeBody />
<j:forEach var="pd" items="${h.pageDecorators}">
<st:include it="${pd}" page="header.jelly" optional="true" />
</j:forEach>
</head>
<body class="yui-skin-sam">
<table id="header" cellpadding="0" cellspacing="0" width="100%" border="0">
......@@ -176,6 +179,9 @@
</table>
<!-- during the loading 'app' object is not Hudson, so it may not have update center -->
<st:include it="${app.updateCenter}" page="main.jelly" optional="true" />
<j:forEach var="pd" items="${h.pageDecorators}">
<st:include it="${pd}" page="footer.jelly" optional="true" />
</j:forEach>
</body>
</html>
</j:jelly>
\ No newline at end of file
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册