提交 e2b7fb64 编写于 作者: K kohsuke

support inheritance in the help file auto-linking.

Node/Slave should rely more on the automatic help linking



git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@17883 71c3de6d-444a-0410-be80-ed276b4c234a
上级 52d05640
......@@ -367,25 +367,28 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
* The help files are assumed to be at "help/FIELDNAME.html" with possible
* locale variations.
*/
public String getHelpFile(String fieldName) {
String page = "/descriptor/" + clazz.getName() + "/help";
if(fieldName==null) {
fieldName="";
} else {
page += '/'+fieldName;
fieldName='-'+fieldName;
}
public String getHelpFile(final String fieldName) {
for(Class c=clazz; c!=null; c=c.getSuperclass()) {
String page = "/descriptor/" + clazz.getName() + "/help";
String suffix;
if(fieldName==null) {
suffix="";
} else {
page += '/'+fieldName;
suffix='-'+fieldName;
}
try {
if(Stapler.getCurrentRequest().getView(clazz,"help"+fieldName)!=null)
return page;
} catch (IOException e) {
throw new Error(e);
}
try {
if(Stapler.getCurrentRequest().getView(c,"help"+suffix)!=null)
return page;
} catch (IOException e) {
throw new Error(e);
}
InputStream in = getHelpStream(fieldName);
IOUtils.closeQuietly(in);
if(in!=null) return page;
InputStream in = getHelpStream(c,suffix);
IOUtils.closeQuietly(in);
if(in!=null) return page;
}
return null;
}
......@@ -514,40 +517,43 @@ public abstract class Descriptor<T extends Describable<T>> implements Saveable {
path = path.replace('/','-');
RequestDispatcher rd = Stapler.getCurrentRequest().getView(clazz, "help"+path);
if(rd!=null) {// Jelly-generated help page
rd.forward(req,rsp);
return;
}
for (Class c=clazz; c!=null; c=c.getSuperclass()) {
RequestDispatcher rd = Stapler.getCurrentRequest().getView(c, "help"+path);
if(rd!=null) {// Jelly-generated help page
rd.forward(req,rsp);
return;
}
InputStream in = getHelpStream(path);
if(in==null) {
rsp.sendError(SC_NOT_FOUND);
return;
InputStream in = getHelpStream(c,path);
if(in!=null) {
// TODO: generalize macro expansion and perhaps even support JEXL
rsp.setContentType("text/html;charset=UTF-8");
String literal = IOUtils.toString(in,"UTF-8");
rsp.getWriter().println(Util.replaceMacro(literal, Collections.singletonMap("rootURL",req.getContextPath())));
in.close();
return;
}
}
// TODO: generalize macro expansion and perhaps even support JEXL
rsp.setContentType("text/html;charset=UTF-8");
String literal = IOUtils.toString(in,"UTF-8");
rsp.getWriter().println(Util.replaceMacro(literal, Collections.singletonMap("rootURL",req.getContextPath())));
in.close();
rsp.sendError(SC_NOT_FOUND);
}
private InputStream getHelpStream(String suffix) {
private InputStream getHelpStream(Class c, String suffix) {
Locale locale = Stapler.getCurrentRequest().getLocale();
String base = c.getName().replace('.', '/') + "/help"+suffix;
String base = clazz.getName().replace('.', '/') + "/help"+suffix;
ClassLoader cl = c.getClassLoader();
if(cl==null) return null;
InputStream in;
in = clazz.getClassLoader().getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + '_' + locale.getVariant() + ".html");
in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + '_' + locale.getVariant() + ".html");
if(in!=null) return in;
in = clazz.getClassLoader().getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + ".html");
in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + '_' + locale.getCountry() + ".html");
if(in!=null) return in;
in = clazz.getClassLoader().getResourceAsStream(base + '_' + locale.getLanguage() + ".html");
in = cl.getResourceAsStream(base + '_' + locale.getLanguage() + ".html");
if(in!=null) return in;
// default
return clazz.getClassLoader().getResourceAsStream(base+".html");
return cl.getResourceAsStream(base+".html");
}
......
......@@ -28,12 +28,16 @@ import hudson.model.Slave;
import hudson.model.Node;
import hudson.model.Hudson;
import hudson.util.DescriptorList;
import hudson.util.FormValidation;
import hudson.Extension;
import hudson.DescriptorExtensionList;
import hudson.Util;
import java.util.List;
import java.util.ArrayList;
import org.kohsuke.stapler.QueryParameter;
/**
* {@link Descriptor} for {@link Slave}.
*
......@@ -72,6 +76,13 @@ public abstract class NodeDescriptor extends Descriptor<Node> {
return getViewPage(clazz, "configure-entries.jelly");
}
public FormValidation doCheckName(@QueryParameter String value ) {
if(Util.fixEmptyAndTrim(value)==null)
return FormValidation.error("Name is mandatory");
else
return FormValidation.ok();
}
/**
* Returns all the registered {@link NodeDescriptor} descriptors.
*/
......
......@@ -31,14 +31,13 @@ THE SOFTWARE.
<st:include page="sidepanel.jelly"/>
<l:main-panel>
<f:form method="post" action="configSubmit" name="config">
<f:entry title="${%Name}" help="/help/system-config/master-slave/name.html">
<f:textbox name="name" value="${it.name}"
checkUrl="'${rootURL}/fieldCheck?errorText=${h.jsStringEscape(h.encode('%Name is mandatory'))}&amp;value='+escape(this.value)"/>
</f:entry>
<j:set var="instance" value="${it.node}" />
<j:set var="descriptor" value="${instance.descriptor}" />
<f:entry title="${%Name}" field="name">
<f:textbox value="${it.name}" /><!-- anomaly. instance[field] isn't what we want. -->
</f:entry>
<!-- main body of the configuration -->
<st:include it="${instance}" page="configure-entries.jelly" />
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册