Esempio n. 1
0
 public static boolean matchesMedia(final String mediaValues, final UserAgentContext rcontext) {
   if ((mediaValues == null) || (mediaValues.length() == 0)) {
     return true;
   }
   if (rcontext == null) {
     return false;
   }
   final StringTokenizer tok = new StringTokenizer(mediaValues, ",");
   while (tok.hasMoreTokens()) {
     final String token = tok.nextToken().trim();
     final String mediaName = Strings.trimForAlphaNumDash(token);
     if (rcontext.isMedia(mediaName)) {
       return true;
     }
   }
   return false;
 }
 private String getBookmarks(String searchQuery) {
   // This is more of a scan. Not efficient but it does the
   // job for now considering the number of entries is limited.
   String[] keywords = Strings.split(searchQuery);
   BookmarksHistory history = BookmarksHistory.getInstance();
   Collection<HistoryEntry<BookmarkInfo>> entries = history.getAllEntries();
   Collection<ScoredEntry> sortedEntries = new TreeSet<ScoredEntry>();
   for (HistoryEntry<BookmarkInfo> entry : entries) {
     int matchScore = this.getMatchScore(entry.getItemInfo(), keywords);
     if (matchScore > 0) {
       sortedEntries.add(new ScoredEntry(entry, matchScore));
     }
   }
   Collection<HistoryEntry<BookmarkInfo>> finalEntries =
       new ArrayList<HistoryEntry<BookmarkInfo>>();
   for (ScoredEntry scoredEntry : sortedEntries) {
     finalEntries.add(scoredEntry.getHistoryEntry());
   }
   return this.getBookmarks(finalEntries);
 }
Esempio n. 3
0
 /**
  * Gets the charset.
  *
  * @param connection the connection
  * @return the charset
  */
 public static String getCharset(URLConnection connection) {
   String contentType = connection.getContentType();
   if (contentType == null) {
     return getDefaultCharset(connection);
   }
   StringTokenizer tok = new StringTokenizer(contentType, ";");
   if (tok.hasMoreTokens()) {
     tok.nextToken();
     while (tok.hasMoreTokens()) {
       String assignment = tok.nextToken().trim();
       int eqIdx = assignment.indexOf('=');
       if (eqIdx != -1) {
         String varName = assignment.substring(0, eqIdx).trim();
         if ("charset".equalsIgnoreCase(varName)) {
           String varValue = assignment.substring(eqIdx + 1);
           return Strings.unquote(varValue.trim());
         }
       }
     }
   }
   return getDefaultCharset(connection);
 }