net.sf.json.JSONObject.getString()方法的使用及代码示例

x33g5p2x  于2022-01-21 转载在 其他  
字(10.9k)|赞(0)|评价(0)|浏览(134)

本文整理了Java中net.sf.json.JSONObject.getString()方法的一些代码示例,展示了JSONObject.getString()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。JSONObject.getString()方法的具体详情如下:
包路径:net.sf.json.JSONObject
类名称:JSONObject
方法名:getString

JSONObject.getString介绍

暂无

代码示例

代码示例来源:origin: jenkinsci/jenkins

private void addJSONTokenIntoMap(Map<String, JSONObject> tokenMap, JSONObject tokenData) {
  String uuid = tokenData.getString("tokenUuid");
  tokenMap.put(uuid, tokenData);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
/*
 * We need this for JENKINS-26143 -- reflective creation cannot handle setChoices(Object). See that method for context.
 */
public ParameterDefinition newInstance(@Nullable StaplerRequest req, @Nonnull JSONObject formData) throws FormException {
  String name = formData.getString("name");
  String desc = formData.getString("description");
  String choiceText = formData.getString("choices");
  return new ChoiceParameterDefinition(name, choiceText, desc);
}

代码示例来源:origin: jenkinsci/jenkins

private static String get(JSONObject o, String prop) {
  if(o.has(prop))
    return o.getString(prop);
  else
    return null;
}

代码示例来源:origin: jenkinsci/jenkins

public ServerTcpPort(JSONObject o) {
  type = o.getString("type");
  value = o.optInt("value");
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Defensive approach to avoid involuntary change since the UUIDs are generated at startup only for UI
 * and so between restart they change
 */
public synchronized void reconfigure(@Nonnull Map<String, JSONObject> tokenStoreDataMap) {
  tokenList.forEach(hashedToken -> {
    JSONObject receivedTokenData = tokenStoreDataMap.get(hashedToken.uuid);
    if (receivedTokenData == null) {
      LOGGER.log(Level.INFO, "No token received for {0}", hashedToken.uuid);
      return;
    }
    
    String name = receivedTokenData.getString("tokenName");
    if (StringUtils.isBlank(name)) {
      LOGGER.log(Level.INFO, "Empty name received for {0}, we do not care about it", hashedToken.uuid);
      return;
    }
    
    hashedToken.setName(name);
  });
}

代码示例来源:origin: jenkinsci/jenkins

@Override
public BuildTrigger newInstance(StaplerRequest req, JSONObject formData) throws FormException {
  String childProjectsString = formData.getString("childProjects").trim();
  if (childProjectsString.endsWith(",")) {
    childProjectsString = childProjectsString.substring(0, childProjectsString.length() - 1).trim();
  }
  return new BuildTrigger(
    childProjectsString,
    formData.optString("threshold", Result.SUCCESS.toString()));
}

代码示例来源:origin: jenkinsci/jenkins

protected void submit(JSONObject json) throws IOException {
  setDisplayName(Util.fixEmptyAndTrim(json.getString("displayName")));
  setDescription(json.getString("description"));
}

代码示例来源:origin: jenkinsci/jenkins

Entry(String sourceId, JSONObject o, String baseURL) {
  this.sourceId = sourceId;
  this.name = Util.intern(o.getString("name"));
  this.version = Util.intern(o.getString("version"));
  // Trim this to prevent issues when the other end used Base64.encodeBase64String that added newlines
  // to the end in old commons-codec. Not the case on updates.jenkins-ci.org, but let's be safe.
  this.sha1 = Util.fixEmptyAndTrim(o.optString("sha1"));
  this.sha256 = Util.fixEmptyAndTrim(o.optString("sha256"));
  this.sha512 = Util.fixEmptyAndTrim(o.optString("sha512"));
  String url = o.getString("url");
  if (!URI.create(url).isAbsolute()) {
    if (baseURL == null) {
      throw new IllegalArgumentException("Cannot resolve " + url + " without a base URL");
    }
    url = URI.create(baseURL).resolve(url).toString();
  }
  this.url = url;
}

代码示例来源:origin: jenkinsci/jenkins

/**
 *
 * @param o the {@link JSONObject} representing the warning
 * @throws JSONException if the argument does not match the expected format
 */
@Restricted(NoExternalUse.class)
public Warning(JSONObject o) {
  try {
    this.type = Type.valueOf(o.getString("type").toUpperCase(Locale.US));
  } catch (IllegalArgumentException ex) {
    this.type = Type.UNKNOWN;
  }
  this.id = o.getString("id");
  this.component = Util.intern(o.getString("name"));
  this.message = o.getString("message");
  this.url = o.getString("url");
  if (o.has("versions")) {
    JSONArray versions = o.getJSONArray("versions");
    List<WarningVersionRange> ranges = new ArrayList<>(versions.size());
    for (int i = 0; i < versions.size(); i++) {
      WarningVersionRange range = new WarningVersionRange(versions.getJSONObject(i));
      ranges.add(range);
    }
    this.versionRanges = Collections.unmodifiableList(ranges);
  } else {
    this.versionRanges = Collections.emptyList();
  }
}

代码示例来源:origin: jenkinsci/jenkins

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;
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    int i=0;
    try {
      i = Integer.parseInt(json.getString("quietPeriod"));
    } catch (NumberFormatException e) {
      // fall through
    }
    try {
      // for compatibility reasons, this value is stored in Jenkins
      Jenkins.get().setQuietPeriod(i);
      return true;
    } catch (IOException e) {
      throw new FormException(e,"quietPeriod");
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
protected void submit(StaplerRequest req) throws IOException, ServletException, FormException {
  String proxiedViewName = req.getSubmittedForm().getString("proxiedViewName");
  if (Jenkins.getInstance().getView(proxiedViewName) == null) {
    throw new FormException("Not an existing global view", "proxiedViewName");
  }
  this.proxiedViewName = proxiedViewName;
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    // for compatibility reasons, the actual value is stored in Jenkins
    Jenkins j = Jenkins.get();
    if (json.has("primaryView")) {
      final String viewName = json.getString("primaryView");
      final View newPrimaryView = j.getView(viewName);
      if (newPrimaryView == null) {
        throw new FormException(Messages.GlobalDefaultViewConfiguration_ViewDoesNotExist(viewName), "primaryView");
      }
      j.setPrimaryView(newPrimaryView);
    } else {
      // Fallback if the view is not specified
      j.setPrimaryView(j.getViews().iterator().next());
    }
    
    return true;
  }
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    try {
      for( JSONObject o : StructuredForm.toList(json, "plugin"))
        Jenkins.get().pluginManager.getPlugin(o.getString("name")).getPlugin().configure(req, o);
      return true;
    } catch (IOException | ServletException e) {
      throw new FormException(e,"plugin");
    }
  }
}

代码示例来源:origin: jenkinsci/jenkins

fullName = json.getString("fullName");
description = json.getString("description");

代码示例来源:origin: jenkinsci/jenkins

/**
 * Accepts the update to the node configuration.
 */
@RequirePOST
public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
  checkPermission(CONFIGURE);
  String proposedName = Util.fixEmptyAndTrim(req.getSubmittedForm().getString("name"));
  Jenkins.checkGoodName(proposedName);
  Node node = getNode();
  if (node == null) {
    throw new ServletException("No such node " + nodeName);
  }
  if ((!proposedName.equals(nodeName))
      && Jenkins.getActiveInstance().getNode(proposedName) != null) {
    throw new FormException(Messages.ComputerSet_SlaveAlreadyExists(proposedName), "name");
  }
  String nExecutors = req.getSubmittedForm().getString("numExecutors");
  if (StringUtils.isBlank(nExecutors) || Integer.parseInt(nExecutors)<=0) {
    throw new FormException(Messages.Slave_InvalidConfig_Executors(nodeName), "numExecutors");
  }
  Node result = node.reconfigure(req, req.getSubmittedForm());
  Jenkins.getInstance().getNodesObject().replaceNode(this.getNode(), result);
  // take the user back to the agent top page.
  rsp.sendRedirect2("../" + result.getNodeName() + '/');
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws hudson.model.Descriptor.FormException {
    // for compatibility reasons, the actual value is stored in Jenkins
    Jenkins j = Jenkins.get();
    final JSONObject optJSONObject = json.optJSONObject("useProjectNamingStrategy");
    if (optJSONObject != null) {
      final JSONObject strategyObject = optJSONObject.getJSONObject("namingStrategy");
      final String className = strategyObject.getString("$class");
      try {
        Class clazz = Class.forName(className, true, j.getPluginManager().uberClassLoader);
        final ProjectNamingStrategy strategy = (ProjectNamingStrategy) req.bindJSON(clazz, strategyObject);
        j.setProjectNamingStrategy(strategy);
      } catch (ClassNotFoundException e) {
        throw new FormException(e, "namingStrategy");
      }
    }
    if (j.getProjectNamingStrategy() == null) {
      j.setProjectNamingStrategy(DefaultProjectNamingStrategy.DEFAULT_NAMING_STRATEGY);
    }
    return true;
  }
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Accepts submission from the configuration page.
 */
@RequirePOST
public synchronized void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException {
  JSONObject src = req.getSubmittedForm();
  String newName = src.getString("name"), redirect = ".";
  XmlFile oldFile = null;
  if(!name.equals(newName)) {
    Jenkins.checkGoodName(newName);
    oldFile = getConfigFile();
    // rename
    getParent().logRecorders.remove(name);
    this.name = newName;
    getParent().logRecorders.put(name,this);
    redirect = "../" + Util.rawEncode(newName) + '/';
  }
  List<Target> newTargets = req.bindJSONToList(Target.class, src.get("targets"));
  for (Target t : newTargets)
    t.enable();
  targets.replaceBy(newTargets);
  save();
  if (oldFile!=null) oldFile.delete();
  rsp.sendRedirect2(redirect);
}

代码示例来源:origin: jenkinsci/jenkins

/**
 * Accepts the update to the node configuration.
 */
@RequirePOST
public void doConfigSubmit( StaplerRequest req, StaplerResponse rsp ) throws IOException, ServletException, FormException {
  final Jenkins app = Jenkins.getInstance();
  app.checkPermission(Jenkins.ADMINISTER);
  properties.rebuild(req, req.getSubmittedForm(), getApplicablePropertyDescriptors());
  this.description = req.getSubmittedForm().getString("description");
  updateTransientActions();
  save();
  FormApply.success(".").generateResponse(req, rsp, null);
}

代码示例来源:origin: jenkinsci/jenkins

@Override
  public boolean configure(StaplerRequest req, JSONObject json) throws FormException {
    Jenkins j = Jenkins.get();
    try {
      // for compatibility reasons, this value is stored in Jenkins
      String num = json.getString("numExecutors");
      if (!num.matches("\\d+")) {
        throw new FormException(Messages.Hudson_Computer_IncorrectNumberOfExecutors(),"numExecutors");
      }
      
      j.setNumExecutors(json.getInt("numExecutors"));
      if (req.hasParameter("master.mode"))
        j.setMode(Mode.valueOf(req.getParameter("master.mode")));
      else
        j.setMode(Mode.NORMAL);

      j.setLabelString(json.optString("labelString", ""));

      return true;
    } catch (IOException e) {
      throw new FormException(e,"numExecutors");
    }
  }
}

相关文章

微信公众号

最新文章

更多