Example #1
0
 /**
  * Find an item in the list
  *
  * @param name String
  * @return NameValue
  */
 public final NameValue findItem(String name) {
   for (int i = 0; i < m_list.size(); i++) {
     NameValue nameVal = m_list.get(i);
     if (nameVal.getName().compareTo(name) == 0) return nameVal;
   }
   return null;
 }
Example #2
0
 /**
  * Find an item in the list using a caseless search
  *
  * @param name String
  * @return NameValue
  */
 public final NameValue findItemCaseless(String name) {
   for (int i = 0; i < m_list.size(); i++) {
     NameValue nameVal = m_list.get(i);
     if (nameVal.getName().equalsIgnoreCase(name)) return nameVal;
   }
   return null;
 }
  @Override
  public void setHeaders(
      List<NameValue> requestHeaders, boolean isFixedLengthStreamingMode, long totalBodyBytes)
      throws IOException {
    if (isFixedLengthStreamingMode) {
      if (android.os.Build.VERSION.SDK_INT >= 19) {
        mConnection.setFixedLengthStreamingMode(totalBodyBytes);

      } else {
        if (totalBodyBytes > Integer.MAX_VALUE)
          throw new RuntimeException(
              "You need Android API version 19 or newer to "
                  + "upload more than 2GB in a single request using "
                  + "fixed size content length. Try switching to "
                  + "chunked mode instead, but make sure your server side supports it!");

        mConnection.setFixedLengthStreamingMode((int) totalBodyBytes);
      }
    } else {
      mConnection.setChunkedStreamingMode(0);
    }

    for (final NameValue param : requestHeaders) {
      mConnection.setRequestProperty(param.getName(), param.getValue());
    }
  }
 /**
  * Store nv list to hash map.
  *
  * @param filename the filename
  * @param options the options
  * @param dstMap the dst map
  */
 public static void storeNVListToHashMap(
     String filename, OptionList options, Map<String, String> dstMap) {
   if (options == null || options.getOption() == null || options.getOption().isEmpty()) {
     return;
   }
   List<NameValue> optionNvList = options.getOption();
   for (int i = 0; i < optionNvList.size(); i++) {
     NameValue nv = optionNvList.get(i);
     dstMap.put(nv.getName(), nv.getValue());
   }
 }
Example #5
0
  /**
   * Return the name/value list as a string
   *
   * @return String
   */
  public String toString() {
    StringBuffer str = new StringBuffer(256);

    str.append("[");
    for (int i = 0; i < numberOfItems(); i++) {
      if (str.length() > 1) str.append(",");
      NameValue nameVal = getItemAt(i);

      str.append(nameVal.getName());
      str.append("=");
      str.append(nameVal.getValue());
    }
    str.append("]");

    return str.toString();
  }
  public CookieField(String fieldValue) {
    StringTokenizer s = new StringTokenizer(fieldValue);

    String name = null;
    String value = null;
    String domain = null;
    String path = null;

    while (s.hasMoreTokens()) {
      String next = s.nextToken(";");
      if (next != null) {
        next = next.trim();
        NameValue property = NameValue.parse(next.trim());

        if (property.name.equals("$Domain")) {
          domain = property.value;
        } else if (property.name.equals("$Path")) {
          path = property.value;
        } else {
          // Start of a new cookie .. record the previous one
          if (name != null) {
            cookies.add(new Cookie(name, value, path, domain));
          }
          name = property.name;
          value = property.value;
          domain = null;
          path = null;
        }
      }
    }

    if (name != null) {
      cookies.add(new Cookie(name, value, path, domain));
    }
  }
Example #7
0
  /**
   * Find all items with the specified name and return as a new list
   *
   * @param name String
   * @return NameValueList
   */
  public final NameValueList findAllItems(String name) {

    //	Allocate the list to hold the matching items

    NameValueList list = new NameValueList();

    //	Find the matching items

    for (int i = 0; i < m_list.size(); i++) {
      NameValue nameVal = m_list.get(i);
      if (nameVal.getName().compareTo(name) == 0) list.addItem(nameVal);
    }

    //	Check if the list is empty, return the list

    if (list.numberOfItems() == 0) list = null;
    return list;
  }
 /**
  * Put nv list.
  *
  * @param filename the filename
  * @param containerName the container name
  * @param optionContainer the option container
  * @param outList the out list
  * @throws Exception the exception
  */
 public static void putNVList(
     String filename, String containerName, Element optionContainer, List<NameValue> outList)
     throws Exception {
   NodeList childElements = DomParseUtil.getImmediateChildrenByTagName(optionContainer, "option");
   if (childElements == null) {
     return;
   }
   for (int i = 0; i < childElements.getLength(); i++) {
     Element option = (Element) childElements.item(i);
     String name = option.getAttribute("name");
     if (name == null || name.length() == 0) {
       throwError(filename, "Missing option name in option list: '" + containerName + "'");
     }
     String value = DomParseUtil.getText(option);
     if (value == null) {
       throwError(filename, "Missing option value for option list: '" + containerName + "'");
     }
     NameValue nv = new NameValue();
     nv.setName(name);
     nv.setValue(value);
     outList.add(nv);
   }
 }
Example #9
0
  public static List<? extends DomElement> getIdentitySiblings(DomElement element) {
    final GenericDomValue nameDomElement = element.getGenericInfo().getNameDomElement(element);
    if (nameDomElement == null) return Collections.emptyList();

    final NameValue nameValue = nameDomElement.getAnnotation(NameValue.class);
    if (nameValue == null || !nameValue.unique()) return Collections.emptyList();

    final String stringValue = ElementPresentationManager.getElementName(element);
    if (stringValue == null) return Collections.emptyList();

    final DomElement scope = element.getManager().getIdentityScope(element);
    if (scope == null) return Collections.emptyList();

    final DomGenericInfo domGenericInfo = scope.getGenericInfo();
    final String tagName = element.getXmlElementName();
    final DomCollectionChildDescription childDescription =
        domGenericInfo.getCollectionChildDescription(tagName, element.getXmlElementNamespaceKey());
    if (childDescription != null) {
      final ArrayList<DomElement> list = new ArrayList<>(childDescription.getValues(scope));
      list.remove(element);
      return list;
    }
    return Collections.emptyList();
  }
 // ******************************************************************************************************************
 // Specials handler -- Fragile!! Handle with care
 // ******************************************************************************************************************
 public static StringValue special(NameValue spl) {
   Map<String, Object> json = new HashMap<>();
   json.put("special", spl.toJson());
   return (new StringValue(Json.writeValueAsStringHard(json)));
 }
 public void write(Object o) {
   println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
   level = -1;
   NameValue traversal = traverse(Object.class, null, o, true);
   traversal.write();
 }