@CheckForNull public static String nullify(@CheckForNull String v) { return fixEmpty(v); }
/** * Convert empty string to null, and trim whitespace. * * @since 1.154 */ @CheckForNull public static String fixEmptyAndTrim(@CheckForNull String s) { if(s==null) return null; return fixEmpty(s.trim()); }
/** * Checks if the include regular expression is valid. */ public FormValidation doCheckIncludeRegex( @QueryParameter String value ) throws IOException, ServletException, InterruptedException { String v = Util.fixEmpty(value); if (v != null) { try { Pattern.compile(v); } catch (PatternSyntaxException pse) { return FormValidation.error(pse.getMessage()); } } return FormValidation.ok(); } }
/** * @deprecated as of 1.294 * Define your own check method, instead of relying on this generic one. */ @Deprecated public void doFieldCheck(StaplerRequest req, StaplerResponse rsp) throws IOException, ServletException { doFieldCheck( fixEmpty(req.getParameter("value")), fixEmpty(req.getParameter("type")), fixEmpty(req.getParameter("errorText")), fixEmpty(req.getParameter("warningText"))).generateResponse(req,rsp,this); }
public WarningVersionRange(JSONObject o) { this.name = Util.fixEmpty(o.optString("name")); this.firstVersion = Util.intern(Util.fixEmpty(o.optString("firstVersion"))); this.lastVersion = Util.intern(Util.fixEmpty(o.optString("lastVersion"))); Pattern p; try { p = Pattern.compile(o.getString("pattern")); } catch (PatternSyntaxException ex) { LOGGER.log(Level.WARNING, "Failed to compile pattern '" + o.getString("pattern") + "', using '.*' instead", ex); p = Pattern.compile(".*"); } this.pattern = p; }
/** * Checks if a top-level view with the given name exists. * @deprecated 1.512 */ @Deprecated public FormValidation doViewExistsCheck(@QueryParameter String value) { checkPermission(View.CREATE); String view = fixEmpty(value); if(view==null) return FormValidation.ok(); if(getView(view)==null) return FormValidation.ok(); else return FormValidation.error(Messages.Hudson_ViewAlreadyExists(view)); }
/** * Fails if a global view with the given name does not exist. */ public FormValidation doViewExistsCheck(@QueryParameter String value) { checkPermission(View.CREATE); String view = Util.fixEmpty(value); if(view==null) return FormValidation.ok(); if(Jenkins.getInstance().getView(view)!=null) return FormValidation.ok(); else return FormValidation.error(Messages.ProxyView_NoSuchViewExists(value)); }
/** * Makes sure that the given name is good as an agent name. */ public FormValidation doCheckName(@QueryParameter String value) throws IOException, ServletException { Jenkins.getInstance().checkPermission(Computer.CREATE); if(Util.fixEmpty(value)==null) return FormValidation.ok(); try { checkName(value); return FormValidation.ok(); } catch (Failure e) { return FormValidation.error(e.getMessage()); } }
/** * Checks if a private view with the given name exists. * An error is returned if exists==true but the view does not exist. * An error is also returned if exists==false but the view does exist. **/ public FormValidation doViewExistsCheck(@QueryParameter String value, @QueryParameter boolean exists) { checkPermission(View.CREATE); String view = Util.fixEmpty(value); if (view == null) return FormValidation.ok(); if (exists) { return (getView(view)!=null) ? FormValidation.ok() : FormValidation.error(Messages.MyViewsProperty_ViewExistsCheck_NotExist(view)); } else { return (getView(view)==null) ? FormValidation.ok() : FormValidation.error(Messages.MyViewsProperty_ViewExistsCheck_AlreadyExists(view)); } }
protected void check() throws IOException, ServletException { String value = fixEmpty(request.getParameter("value")); if(value==null) {// nothing entered yet ok(); return; } if(!value.endsWith("/")) value+='/'; try { URL url = new URL(value); HttpURLConnection con = (HttpURLConnection)url.openConnection(); con.connect(); if(con.getResponseCode()!=200 || con.getHeaderField("X-Hudson")==null) { error(value+" is not Hudson ("+con.getResponseMessage()+")"); return; } ok(); } catch (IOException e) { handleIOException(value,e); } } }
public FormValidation doCheckURIEncoding(StaplerRequest request) throws IOException { Jenkins.getInstance().checkPermission(Jenkins.ADMINISTER); // expected is non-ASCII String final String expected = "\u57f7\u4e8b"; final String value = fixEmpty(request.getParameter("value")); if (!expected.equals(value)) return FormValidation.warningWithMarkup(hudson.model.Messages.Hudson_NotUsesUTF8ToDecodeURL()); return FormValidation.ok(); } }
/** * Checks if a top-level view with the given name exists and * make sure that the name is good as a view name. */ public FormValidation doCheckViewName(@QueryParameter String value) { checkPermission(View.CREATE); String name = fixEmpty(value); if (name == null) return FormValidation.ok(); // already exists? if (getView(name) != null) return FormValidation.error(Messages.Hudson_ViewAlreadyExists(name)); // good view name? try { checkGoodName(name); } catch (Failure e) { return FormValidation.error(e.getMessage()); } return FormValidation.ok(); }
public static BuildAuthorizationToken create(StaplerRequest req) { if (req.getParameter("pseudoRemoteTrigger") != null) { String token = Util.fixEmpty(req.getParameter("authToken")); if(token!=null) return new BuildAuthorizationToken(token); } return null; }
public void scan(File dir, FileVisitor visitor) throws IOException { if(fixEmpty(includes)==null && excludes==null) { // optimization new Full().scan(dir,visitor); return; } FileSet fs = Util.createFileSet(dir,includes,excludes); fs.setDefaultexcludes(useDefaultExcludes); if(dir.exists()) { DirectoryScanner ds = fs.getDirectoryScanner(new org.apache.tools.ant.Project()); for( String f : ds.getIncludedFiles()) { File file = new File(dir, f); scanSingle(file, f, visitor); } } }
/** * Checks the GLOB-style file mask. See {@link #validateAntFileMask(String)}. * Requires configure permission on ancestor AbstractProject object in request, * or admin permission if no such ancestor is found. * @since 1.294 */ public FormValidation validateFileMask(String value, boolean errorIfNotExist, boolean caseSensitive) throws IOException { checkPermissionForValidate(); value = fixEmpty(value); if(value==null) return FormValidation.ok(); try { if(!exists()) // no workspace. can't check return FormValidation.ok(); String msg = validateAntFileMask(value, VALIDATE_ANT_FILE_MASK_BOUND, caseSensitive); if(errorIfNotExist) return FormValidation.error(msg); else return FormValidation.warning(msg); } catch (InterruptedException e) { return FormValidation.ok(Messages.FilePath_did_not_manage_to_validate_may_be_too_sl(value)); } }
private static View copy(StaplerRequest req, ViewGroup owner, String name) throws IOException { View v; String from = req.getParameter("from"); View src = src = owner.getView(from); if(src==null) { if(Util.fixEmpty(from)==null) throw new Failure("Specify which view to copy"); else throw new Failure("No such view: "+from); } String xml = Jenkins.XSTREAM.toXML(src); v = createViewFromXML(name, new StringInputStream(xml)); return v; }
/** * Makes sure that the given name is good as a job name. * For use from {@code newJob}. */ @Restricted(DoNotUse.class) // called from newJob view public FormValidation doCheckJobName(@QueryParameter String value) { // this method can be used to check if a file exists anywhere in the file system, // so it should be protected. getOwner().checkPermission(Item.CREATE); if (Util.fixEmpty(value) == null) { return FormValidation.ok(); } try { Jenkins.checkGoodName(value); value = value.trim(); // why trim *after* checkGoodName? not sure, but ItemGroupMixIn.createTopLevelItem does the same Jenkins.getInstance().getProjectNamingStrategy().checkName(value); } catch (Failure e) { return FormValidation.error(e.getMessage()); } if (getOwner().getItemGroup().getItem(value) != null) { return FormValidation.error(Messages.Hudson_JobAlreadyExists(value)); } // looks good return FormValidation.ok(); }
@Override public Details newInstance(StaplerRequest req, JSONObject formData) throws FormException { if (req == null) { // Should never happen, see newInstance() Javadoc throw new FormException("Stapler request is missing in the call", "staplerRequest"); } String pwd = Util.fixEmpty(req.getParameter("user.password")); String pwd2= Util.fixEmpty(req.getParameter("user.password2")); if(!Util.fixNull(pwd).equals(Util.fixNull(pwd2))) throw new FormException("Please confirm the password by typing it twice","user.password2"); String data = Protector.unprotect(pwd); if(data!=null) { String prefix = Stapler.getCurrentRequest().getSession().getId() + ':'; if(data.startsWith(prefix)) return Details.fromHashedPassword(data.substring(prefix.length())); } User user = Util.getNearestAncestorOfTypeOrThrow(req, User.class); // the UserSeedProperty is not touched by the configure page UserSeedProperty userSeedProperty = user.getProperty(UserSeedProperty.class); if (userSeedProperty != null) { userSeedProperty.renewSeed(); } return Details.fromPlainPassword(Util.fixNull(pwd)); }
protected void check() throws IOException, ServletException { String value = fixEmpty(request.getParameter("value")); AbstractProject<?,?> p = (AbstractProject<?,?>)subject; if(value==null || p==null) { ok(); // none entered yet, or something is seriously wrong return; } try { FilePath ws = getBaseDirectory(p); if(ws==null || !ws.exists()) {// no workspace. can't check ok(); return; } String msg = ws.validateAntFileMask(value, FilePath.VALIDATE_ANT_FILE_MASK_BOUND); if(errorIfNotExist) error(msg); else warning(msg); } catch (InterruptedException e) { ok(Messages.FormFieldValidator_did_not_manage_to_validate_may_be_too_sl(value)); } }
String filter = Util.fixEmpty(req.getParameter("statusFilter")); statusFilter = filter != null ? "1".equals(filter) : null;