Android Open Source - inotes Header Utils






From Project

Back to project page inotes.

License

The source code is released under:

GNU General Public License

If you think the Android project inotes 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 com.codeminders.inotes.imap;
//from   w w w  . jav  a  2s.c o  m
import android.util.Log;
import com.codeminders.inotes.Constants;
import com.codeminders.inotes.model.Note;
import org.json.JSONObject;

import javax.mail.Message;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;

public class HeaderUtils {

    public static String INOTES_ID_HEADER = "X-Inotes-Unique-Identifier";

    enum AppleHeaders {
        IDENTIFIER("X-Universally-Unique-Identifier"),
        NOTE_TYPE("X-Uniform-Type-Identifier"),
        CREATED_DATE("X-Mail-Created-Date"),
        DEFAULT_NOTE_TYPE("com.apple.mail-note"),
    CONTENT_TYPE("Content-Type");

        private String name;

        private AppleHeaders(String name) {
            this.name = name;
        }

        public String toString() {
            return name;
        }
    }

    public static HashMap<String, String> getHeaders(Message message) throws Exception {
        HashMap<String, String> headers = new HashMap<String, String>();
        String[] identifier = message.getHeader(AppleHeaders.IDENTIFIER.toString());
        if (identifier != null) {
            headers.put(AppleHeaders.IDENTIFIER.toString(), identifier[0]);
        }
        String[] createdDate = message.getHeader(AppleHeaders.CREATED_DATE.toString());
        if (createdDate != null) {
            headers.put(AppleHeaders.CREATED_DATE.toString(), createdDate[0]);
        }
        headers.put(AppleHeaders.NOTE_TYPE.toString(), AppleHeaders.DEFAULT_NOTE_TYPE.toString());

        String[] inoteId = message.getHeader(INOTES_ID_HEADER);
        if (inoteId != null) {
            headers.put(INOTES_ID_HEADER, inoteId[0]);
        }

    String[] contentType = message.getHeader(AppleHeaders.CONTENT_TYPE.toString());
    if (contentType != null) {
      headers.put(AppleHeaders.CONTENT_TYPE.toString(), contentType[0]);
    }

        return headers;
    }

    public static void addDefaultHeader(Note note) {
        note.getHeaders().put(AppleHeaders.NOTE_TYPE.toString(), AppleHeaders.DEFAULT_NOTE_TYPE.toString());
    }

    public static Map<String, String> getHeaders(String string) {
        Map<String, String> headers = new HashMap<String, String>();
        try {
            JSONObject jsonObject = new JSONObject(string);
            Iterator iterator = jsonObject.keys();
            while (iterator.hasNext()) {
                String key = (String) iterator.next();
                headers.put(key, jsonObject.getString(key));
            }
        } catch (Exception e) {
            Log.e(Constants.TAG, e.getMessage());
        }

        return headers;
    }

}




Java Source Code List

com.codeminders.inotes.AccountReceiver.java
com.codeminders.inotes.Constants.java
com.codeminders.inotes.Utils.java
com.codeminders.inotes.auth.AuthenticationService.java
com.codeminders.inotes.auth.AuthenticatorActivity.java
com.codeminders.inotes.auth.Authenticator.java
com.codeminders.inotes.auth.ConfigurationActivity.java
com.codeminders.inotes.db.DBCreator.java
com.codeminders.inotes.db.DBManager.java
com.codeminders.inotes.db.DBUpgradeHelper.java
com.codeminders.inotes.imap.HeaderUtils.java
com.codeminders.inotes.imap.ImapService.java
com.codeminders.inotes.imap.ImapSession.java
com.codeminders.inotes.model.AccountInfo.java
com.codeminders.inotes.model.Note.java
com.codeminders.inotes.sync.NotesProvider.java
com.codeminders.inotes.sync.NotesSyncService.java
com.codeminders.inotes.sync.SyncAccountInfo.java
com.codeminders.inotes.sync.SyncAdapter.java
com.codeminders.inotes.sync.SyncAllAccountsInfo.java
com.codeminders.inotes.sync.SyncHelper.java
com.codeminders.inotes.sync.SyncInfo.java
com.codeminders.inotes.ui.AccountsListActivity.java
com.codeminders.inotes.ui.LinedEditText.java
com.codeminders.inotes.ui.NoteEditorActivity.java
com.codeminders.inotes.ui.NotesListActivity.java
com.codeminders.inotes.ui.SettingsActivity.java