Esempio n. 1
0
  /**
   * Update the history. If the url is already present, the visited date is updated. If not, a new
   * record is created.
   *
   * @param title The page title.
   * @param url The page url.
   */
  public void updateHistory(String title, String url) {

    long existingId = getHistoryItemIdByUrl(url);

    if (existingId != -1) {
      ContentValues args = new ContentValues();
      args.put(HISTORY_TITLE, title);
      args.put(HISTORY_LAST_VISITED_DATE, DateUtils.getNow(mContext));

      mDb.update(HISTORY_DATABASE_TABLE, args, HISTORY_ROWID + "=" + existingId, null);
    } else {
      ContentValues initialValues = new ContentValues();
      initialValues.put(HISTORY_TITLE, title);
      initialValues.put(HISTORY_URL, url);
      initialValues.put(HISTORY_LAST_VISITED_DATE, DateUtils.getNow(mContext));

      mDb.insert(HISTORY_DATABASE_TABLE, null, initialValues);
    }
  }
    @Override
    public void run() {

      File file = new File(IOUtils.getBookmarksExportFolder(), mFileName);

      if ((file != null) && (file.exists()) && (file.canRead())) {

        try {

          DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
          DocumentBuilder builder = factory.newDocumentBuilder();

          Document document = builder.parse(file);

          Element root = document.getDocumentElement();

          if ((root != null) && (root.getNodeName().equals("bookmarkslist"))) {

            NodeList bookmarksList = root.getElementsByTagName("bookmark");

            Node bookmark;
            NodeList bookmarkItems;
            String title;
            String url;
            String creationDate;
            Node item;

            for (int i = 0; i < bookmarksList.getLength(); i++) {

              bookmark = bookmarksList.item(i);

              if (bookmark != null) {

                title = null;
                url = null;
                creationDate = null;

                bookmarkItems = bookmark.getChildNodes();

                for (int j = 0; j < bookmarkItems.getLength(); j++) {

                  item = bookmarkItems.item(j);

                  if ((item != null) && (item.getNodeName() != null)) {
                    if (item.getNodeName().equals("title")) {
                      title = getNodeContent(item);
                    } else if (item.getNodeName().equals("url")) {
                      url = URLDecoder.decode(getNodeContent(item));
                    } else if (item.getNodeName().equals("creationdate")) {
                      creationDate = getNodeContent(item);
                    }
                  }
                }

                if ((creationDate == null) || (creationDate.length() == 0)) {
                  creationDate = DateUtils.getNow(mContext);
                }

                mDbAdapter.addBookmark(title, url, creationDate);
              }
            }

          } else {
            Log.i("Bookmark import", "Empty or invalid file.");
          }

        } catch (ParserConfigurationException e) {
          Log.w("Bookmark import failed", e.getMessage());
        } catch (SAXException e) {
          Log.w("Bookmark import failed", e.getMessage());
        } catch (IOException e) {
          Log.w("Bookmark import failed", e.getMessage());
        }
      }

      handler.sendEmptyMessage(0);
    }
Esempio n. 3
0
 /**
  * Add a bookmark to database.
  *
  * @param title The title.
  * @param url The url.
  * @return The new bookmark id.
  */
 public long addBookmark(String title, String url) {
   return addBookmark(title, url, DateUtils.getNow(mContext), 0);
 }