Android Open Source - EBrowser Xml History Bookmarks Exporter






From Project

Back to project page EBrowser.

License

The source code is released under:

GNU General Public License

If you think the Android project EBrowser listed in this page is inappropriate, such as containing malicious code/tools or violating the copyright, please email info at java2s dot com, thanks.

Java Source Code

package org.zirco.ui.runnables;
/*from w w w .  j  a v a2s.c o  m*/
import java.io.File;
import java.io.FileWriter;
import java.io.IOException;
import java.net.URLEncoder;

import com.mrpej.ebrowser.R;
import org.zirco.utils.ApplicationUtils;
import org.zirco.utils.IOUtils;

import android.app.ProgressDialog;
import android.content.Context;
import android.database.Cursor;
import android.os.Handler;
import android.os.Message;
import android.provider.Browser;
import android.util.Log;

/**
 * Runnable to export history and bookmarks to an XML file.
 */
public class XmlHistoryBookmarksExporter implements Runnable {
  
  private Context mContext;
  private ProgressDialog mProgressDialog;
  private String mFileName;
  private Cursor mCursor;  
  
  private File mFile;
  private String mErrorMessage = null;
  
  /**
   * Constructor.
   * @param context The current context.
   * @param fileName The output file.
   * @param cursor The cursor to history and bookmarks.
   * @param progressDialog The progress dialog shown during export.
   */
  public XmlHistoryBookmarksExporter(Context context, String fileName, Cursor cursor, ProgressDialog progressDialog) {
    mContext = context;
    mFileName = fileName;
    mCursor = cursor;
    mProgressDialog = progressDialog;
  }

  @Override
  public void run() {
    try {
      
      mFile = new File(IOUtils.getBookmarksExportFolder(), mFileName);        
      FileWriter writer = new FileWriter(mFile);

      writer.write("<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n");
      writer.write("<itemlist>\n");
      
      if (mCursor.moveToFirst()) {
        
        int titleIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.TITLE);
        int urlIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.URL);
        int visitsIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.VISITS);
        int dateIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.DATE);
        int createdIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.CREATED);
        int bookmarkIndex = mCursor.getColumnIndex(Browser.BookmarkColumns.BOOKMARK);
        
        while (!mCursor.isAfterLast()) {
          
          writer.write("<item>\n");
          
          String title = mCursor.getString(titleIndex);
          writer.write(String.format("<title>%s</title>\n", title != null ? URLEncoder.encode(title) : ""));
          
          String url = mCursor.getString(urlIndex);
          writer.write(String.format("<url>%s</url>\n", url != null ? URLEncoder.encode(url) : ""));
          
          writer.write(String.format("<created>%s</created>\n", mCursor.getLong(createdIndex)));
          writer.write(String.format("<visits>%s</visits>\n", mCursor.getInt(visitsIndex)));
          
          writer.write(String.format("<date>%s</date>\n", mCursor.getLong(dateIndex)));
          writer.write(String.format("<bookmark>%s</bookmark>\n", mCursor.getInt(bookmarkIndex)));
          
          writer.write("</item>\n");
          
          mCursor.moveToNext();
        }        
      }
      
      writer.write("</itemlist>\n");

      writer.flush();
      writer.close();
      
    } catch (IOException e1) {
      Log.w("Bookmark export failed", e1.toString());        
      mErrorMessage = e1.toString();
    }
    
    mHandler.sendEmptyMessage(0);
  }
  
  private Handler mHandler = new Handler() {
    public void handleMessage(Message msg) {
      if (mProgressDialog != null) {
        mProgressDialog.dismiss();
      }
      
      if (mContext != null) {
        if (mErrorMessage == null) {
          ApplicationUtils.showOkDialog(mContext,
              android.R.drawable.ic_dialog_info,
              mContext.getResources().getString(R.string.Commons_HistoryBookmarksExportSDCardDoneTitle),
              String.format(mContext.getResources().getString(R.string.Commons_HistoryBookmarksExportSDCardDoneMessage), mFile.getAbsolutePath()));
        } else {
          ApplicationUtils.showOkDialog(mContext,
              android.R.drawable.ic_dialog_alert,
              mContext.getResources().getString(R.string.Commons_HistoryBookmarksExportSDCardFailedTitle),
              String.format(mContext.getResources().getString(R.string.Commons_HistoryBookmarksFailedMessage), mErrorMessage));
        }
      }
    }
  };

}




Java Source Code List

org.emergent.android.weave.client.Base32.java
org.emergent.android.weave.client.Base64Encoder.java
org.emergent.android.weave.client.Base64.java
org.emergent.android.weave.client.BulkKeyCouplet.java
org.emergent.android.weave.client.Dbg.java
org.emergent.android.weave.client.HexEncoder.java
org.emergent.android.weave.client.Hex.java
org.emergent.android.weave.client.QueryParams.java
org.emergent.android.weave.client.QueryResult.java
org.emergent.android.weave.client.UserWeave.java
org.emergent.android.weave.client.WeaveAccountInfo.java
org.emergent.android.weave.client.WeaveBasicObject.java
org.emergent.android.weave.client.WeaveConstants.java
org.emergent.android.weave.client.WeaveCryptoUtil.java
org.emergent.android.weave.client.WeaveException.java
org.emergent.android.weave.client.WeaveFactory.java
org.emergent.android.weave.client.WeaveHeader.java
org.emergent.android.weave.client.WeaveResponse.java
org.emergent.android.weave.client.WeaveSSLSocketFactory.java
org.emergent.android.weave.client.WeaveTransport.java
org.emergent.android.weave.client.WeaveUtil.java
org.greendroid.QuickActionGrid.java
org.greendroid.QuickActionWidget.java
org.greendroid.QuickAction.java
org.zirco.controllers.Controller.java
org.zirco.events.EventConstants.java
org.zirco.events.EventController.java
org.zirco.events.IDownloadEventsListener.java
org.zirco.model.DbAdapter.java
org.zirco.model.UrlSuggestionItemComparator.java
org.zirco.model.adapters.BookmarksCursorAdapter.java
org.zirco.model.adapters.DownloadListAdapter.java
org.zirco.model.adapters.HistoryExpandableListAdapter.java
org.zirco.model.adapters.UrlSuggestionCursorAdapter.java
org.zirco.model.adapters.WeaveBookmarksCursorAdapter.java
org.zirco.model.items.BookmarkItem.java
org.zirco.model.items.DownloadItem.java
org.zirco.model.items.HistoryItem.java
org.zirco.model.items.UrlSuggestionItem.java
org.zirco.model.items.WeaveBookmarkItem.java
org.zirco.providers.BookmarksProviderWrapper.java
org.zirco.providers.WeaveColumns.java
org.zirco.providers.WeaveContentProvider.java
org.zirco.providers.ZircoBookmarksContentProvider.java
org.zirco.sync.ISyncListener.java
org.zirco.sync.WeaveSyncTask.java
org.zirco.ui.activities.AboutActivity.java
org.zirco.ui.activities.AdBlockerWhiteListActivity.java
org.zirco.ui.activities.BookmarksHistoryActivity.java
org.zirco.ui.activities.BookmarksListActivity.java
org.zirco.ui.activities.ChangelogActivity.java
org.zirco.ui.activities.DownloadsListActivity.java
org.zirco.ui.activities.EditBookmarkActivity.java
org.zirco.ui.activities.HistoryListActivity.java
org.zirco.ui.activities.IToolbarsContainer.java
org.zirco.ui.activities.MainActivity.java
org.zirco.ui.activities.MobileViewListActivity.java
org.zirco.ui.activities.WeaveBookmarksListActivity.java
org.zirco.ui.activities.preferences.BaseSpinnerCustomPreferenceActivity.java
org.zirco.ui.activities.preferences.HomepagePreferenceActivity.java
org.zirco.ui.activities.preferences.PreferencesActivity.java
org.zirco.ui.activities.preferences.SearchUrlPreferenceActivity.java
org.zirco.ui.activities.preferences.UserAgentPreferenceActivity.java
org.zirco.ui.activities.preferences.WeavePreferencesActivity.java
org.zirco.ui.activities.preferences.WeaveServerPreferenceActivity.java
org.zirco.ui.components.CustomWebViewClient.java
org.zirco.ui.components.CustomWebView.java
org.zirco.ui.runnables.DownloadRunnable.java
org.zirco.ui.runnables.FaviconUpdaterRunnable.java
org.zirco.ui.runnables.HideToolbarsRunnable.java
org.zirco.ui.runnables.HistoryUpdater.java
org.zirco.ui.runnables.XmlHistoryBookmarksExporter.java
org.zirco.ui.runnables.XmlHistoryBookmarksImporter.java
org.zirco.utils.AnimationManager.java
org.zirco.utils.ApplicationUtils.java
org.zirco.utils.Constants.java
org.zirco.utils.DateUtils.java
org.zirco.utils.IOUtils.java
org.zirco.utils.ProxyChangeReceiver.java
org.zirco.utils.ProxySettings.java
org.zirco.utils.UrlUtils.java