コード例 #1
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;
  }
コード例 #2
0
 @Override
 public boolean equals(final Object obj) {
   if (this == obj) {
     return true;
   }
   if (obj instanceof BookAuthor) {
     final BookAuthor that = (BookAuthor) obj;
     return LengthUtils.equals(this.m_name, that.m_name);
   }
   return false;
 }
コード例 #3
0
ファイル: EnumUtils.java プロジェクト: dkulagin87/fb2-library
 /**
  * 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;
 }
コード例 #4
0
ファイル: EnumUtils.java プロジェクト: dkulagin87/fb2-library
 /**
  * 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;
 }
コード例 #5
0
 public static String normalize(final String name) {
   final StringBuffer buf = new StringBuffer();
   final Pattern p = Pattern.compile("\\w+");
   final Matcher m = p.matcher(LengthUtils.safeString(name).trim());
   while (m.find()) {
     final String group = m.group();
     final String newName =
         group.substring(0, 1).toUpperCase()
             + (group.length() > 1 ? group.substring(1).toLowerCase() : "");
     m.appendReplacement(buf, newName);
   }
   m.appendTail(buf);
   return buf.toString();
 }
コード例 #6
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 "";
 }
コード例 #7
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;
       }
     }
   }
 }
コード例 #8
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;
 }