예제 #1
0
 /**
  * Returns enumeration item of the given class.
  *
  * @param <T> type of enumeration item
  * @param clazz enumeration class
  * @param value value of an enumeration item.
  * @return an instance of the given enumeration class or <code>null</code>if an appropriate item
  *     cannot be found
  */
 public static <T extends Enum<T> & IntConstant> T valueOf(final Class<T> clazz, final int value) {
   final T[] values = clazz.getEnumConstants();
   if (LengthUtils.isNotEmpty(values)) {
     for (final T item : values) {
       if (value == item.value()) {
         return item;
       }
     }
   }
   return null;
 }
예제 #2
0
 /**
  * Returns enumeration item of the given class.
  *
  * @param <T> type of enumeration item
  * @param clazz enumeration class
  * @param name name of enumeration item (case insensitive) a * @return an instance of the given
  *     enumeration class or <code>null</code> if an appropriate item cannot be found
  */
 public static <T extends Enum<T>> T valueOf(final Class<T> clazz, final String name) {
   final T[] values = clazz.getEnumConstants();
   if (LengthUtils.isNotEmpty(values)) {
     for (final T item : values) {
       if (item.name().equalsIgnoreCase(name)) {
         return item;
       }
     }
   }
   return null;
 }
예제 #3
0
 public String getExtension() {
   String s = m_type;
   do {
     String ext = MIME2EXT.get(s);
     if (ext != null) {
       return ext;
     }
     int index = s.lastIndexOf("/");
     if (index >= 0) {
       s = s.substring(0, index);
     } else {
       s = null;
     }
   } while (LengthUtils.isNotEmpty(s));
   return "";
 }
예제 #4
0
  public WebContentType(final URLConnection conn) {
    final String type = conn.getContentType();
    final String[] parts = type.split(";");
    m_type = parts[0].trim();

    String enc = conn.getContentEncoding();
    if (LengthUtils.isEmpty(enc) && parts.length > 0) {
      for (String s : parts) {
        s = s.trim().toLowerCase();
        if (s.startsWith(CHARSET_PREFIX)) {
          enc = s.substring(CHARSET_PREFIX.length());
          break;
        }
      }
    }
    m_charset = LengthUtils.isNotEmpty(enc) ? Charset.forName(enc) : null;
  }
예제 #5
0
 public BookAuthor(final String name, final boolean lastFirst) {
   m_name = normalize(name);
   if (LengthUtils.isNotEmpty(name)) {
     int pos = m_name.indexOf("/");
     if (pos >= 0) {
       if (lastFirst) {
         m_lastName = m_name.substring(0, pos).trim();
         m_firstName = m_name.substring(pos + 1).trim();
       } else {
         m_firstName = m_name.substring(0, pos).trim();
         m_lastName = m_name.substring(pos + 1).trim();
       }
       if (m_firstName.endsWith(".")) {
         m_firstName = m_firstName.substring(0, m_firstName.length() - 1);
       }
       m_name = getFullName(m_firstName, m_lastName);
     } else {
       pos = m_name.lastIndexOf(' ');
       if (pos >= 0) {
         if (lastFirst) {
           m_lastName = m_name.substring(0, pos).trim();
           m_firstName = m_name.substring(pos).trim();
         } else {
           m_firstName = m_name.substring(0, pos).trim();
           m_lastName = m_name.substring(pos).trim();
         }
         if (m_firstName.endsWith(".")) {
           m_firstName = m_firstName.substring(0, m_firstName.length() - 1);
         }
         m_name = getFullName(m_firstName, m_lastName);
       } else {
         m_lastName = m_name;
         m_firstName = null;
       }
     }
   }
 }
예제 #6
0
 public WebContentType(JSONObject object) throws JSONException {
   m_type = object.getString("type");
   String enc = object.getString("charset");
   m_charset = LengthUtils.isNotEmpty(enc) ? Charset.forName(enc) : null;
 }