mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-17 22:12:25 +00:00
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
This commit is contained in:
1 parent
52d05640c8
commit
e2b7fb64bf
10 files changed
+60
-44
No files matched your search
@@ -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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user