public class EvernoteUtil {
private static final int N = 50;
- //private String username;
- //private String password;
+
+ // private String username;
+ // private String password;
public enum Error {
NONE, CONNECT, INVALID_AUTH, NOT_FOUND, OTHER
private NoteStore.Client noteStore = null;
private EvernoteSession session = null;
- //public void setConfig(String username, String password) {
- // this.username = username;
- // this.password = password;
- // authenticationToken = null;
- // noteStore = null;
- //}
+ // public void setConfig(String username, String password) {
+ // this.username = username;
+ // this.password = password;
+ // authenticationToken = null;
+ // noteStore = null;
+ // }
private void init() {
return note;
}
- private NoteFilter getDefaultFilter(){
+ private NoteFilter getDefaultFilter() {
// 検索条件として、検索語なし、更新日順ソートを指定
NoteFilter filter = new NoteFilter();
filter.setOrder(NoteSortOrder.UPDATED.getValue());
- filter.setAscending(false);
+ filter.setAscending(false);
return filter;
}
-
+
public List<NoteList> getNoteList() {
NoteFilter filter = getDefaultFilter();
return getNoteList(filter);
filter.setNotebookGuid(notebookGuid);
return getNoteList(filter);
}
-
+
public List<NoteList> getNoteListByTag(String tagGuid) {
NoteFilter filter = getDefaultFilter();
List<String> tagGuids = new ArrayList<String>();
filter.setTagGuids(tagGuids);
return getNoteList(filter);
}
-
+
public List<NoteList> getNoteList(NoteFilter filter) {
errorCode = Error.OTHER;
return null;
}
int index = 0;
- while (true){
- NoteList noteList = noteStore.findNotes(token, filter, index, N);
+ while (true) {
+ NoteList noteList = noteStore
+ .findNotes(token, filter, index, N);
int size = noteList.getNotesSize();
-
- if (size <= 0){
+
+ if (size <= 0) {
break;
}
list.add(noteList);
- if (size < N){
+ if (size < N) {
break;
}
index += size;
}
-
+
errorCode = Error.NONE;
} catch (EDAMUserException e) {
Debug.d(this, null, e);
}
private String getAuthenticationToken() {
-// try {
-// if (authenticationToken == null) {
-// // String userStoreUrl =
-// // "https://sandbox.evernote.com/edam/user";
-// String userStoreUrl = "https://www.evernote.com/edam/user";
-// THttpClient userStoreTrans = new THttpClient(userStoreUrl);
-// TBinaryProtocol userStoreProt = new TBinaryProtocol(
-// userStoreTrans);
-// UserStore.Client userStore = new UserStore.Client(userStoreProt);
-//
-// // #27612
-// // http://www.antun.net/tips/api/evernote.html
-// // expiredTime=time.time()+(authResult.expiration/1000.0-authResult.currentTime/1000.0)
-// // # expiredTime<time.time() なら認証し直して、authenticationToken
-// // を取得し直すべし
-//
-// String consumerKey = "yuji_k64613";
-// String consumerSecret = "d5528b4fdb3a7fee";
-// AuthenticationResult authResult = userStore.authenticate(
-// username, password, consumerKey, consumerSecret);
-// authenticationToken = authResult.getAuthenticationToken();
-//
-// // String noteStoreUrlBase =
-// // "https://sandbox.evernote.com/edam/note/";
-// String noteStoreUrlBase = "https://www.evernote.com/edam/note/";
-// User user = authResult.getUser();
-// String noteStoreUrl = noteStoreUrlBase + user.getShardId();
-// THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
-// TBinaryProtocol noteStoreProt = new TBinaryProtocol(
-// noteStoreTrans);
-// noteStore = new NoteStore.Client(noteStoreProt);
-// }
-// } catch (TTransportException e) {
-// authenticationToken = null;
-// noteStore = null;
-// Debug.d(this, null, e);
-//
-// errorCode = Error.CONNECT;
-// } catch (EDAMUserException e) {
-// Debug.d(this, null, e);
-//
-// EDAMErrorCode code = e.getErrorCode();
-// if (code.equals(EDAMErrorCode.INVALID_AUTH)) {
-// errorCode = Error.INVALID_AUTH;
-// }
-// } catch (EDAMSystemException e) {
-// Debug.d(this, null, e);
-// } catch (TException e) {
-// Debug.d(this, null, e);
-//
-// if (e.getCause() instanceof ConnectException) {
-// errorCode = Error.CONNECT;
-// }
-// }
-//
-// return authenticationToken;
+ // try {
+ // if (authenticationToken == null) {
+ // // String userStoreUrl =
+ // // "https://sandbox.evernote.com/edam/user";
+ // String userStoreUrl = "https://www.evernote.com/edam/user";
+ // THttpClient userStoreTrans = new THttpClient(userStoreUrl);
+ // TBinaryProtocol userStoreProt = new TBinaryProtocol(
+ // userStoreTrans);
+ // UserStore.Client userStore = new UserStore.Client(userStoreProt);
+ //
+ // // #27612
+ // // http://www.antun.net/tips/api/evernote.html
+ // //
+ // expiredTime=time.time()+(authResult.expiration/1000.0-authResult.currentTime/1000.0)
+ // // # expiredTime<time.time() なら認証し直して、authenticationToken
+ // // を取得し直すべし
+ //
+ // String consumerKey = "yuji_k64613";
+ // String consumerSecret = "d5528b4fdb3a7fee";
+ // AuthenticationResult authResult = userStore.authenticate(
+ // username, password, consumerKey, consumerSecret);
+ // authenticationToken = authResult.getAuthenticationToken();
+ //
+ // // String noteStoreUrlBase =
+ // // "https://sandbox.evernote.com/edam/note/";
+ // String noteStoreUrlBase = "https://www.evernote.com/edam/note/";
+ // User user = authResult.getUser();
+ // String noteStoreUrl = noteStoreUrlBase + user.getShardId();
+ // THttpClient noteStoreTrans = new THttpClient(noteStoreUrl);
+ // TBinaryProtocol noteStoreProt = new TBinaryProtocol(
+ // noteStoreTrans);
+ // noteStore = new NoteStore.Client(noteStoreProt);
+ // }
+ // } catch (TTransportException e) {
+ // authenticationToken = null;
+ // noteStore = null;
+ // Debug.d(this, null, e);
+ //
+ // errorCode = Error.CONNECT;
+ // } catch (EDAMUserException e) {
+ // Debug.d(this, null, e);
+ //
+ // EDAMErrorCode code = e.getErrorCode();
+ // if (code.equals(EDAMErrorCode.INVALID_AUTH)) {
+ // errorCode = Error.INVALID_AUTH;
+ // }
+ // } catch (EDAMSystemException e) {
+ // Debug.d(this, null, e);
+ // } catch (TException e) {
+ // Debug.d(this, null, e);
+ //
+ // if (e.getCause() instanceof ConnectException) {
+ // errorCode = Error.CONNECT;
+ // }
+ // }
+ //
+ // return authenticationToken;
if (authenticationToken == null) {
authenticationToken = session.getAuthToken();
+ if (authenticationToken == null) {
+ return null;
+ }
try {
noteStore = session.createNoteStore();
} catch (TTransportException e) {
return note;
}
- public List<com.yuji.ec.db.Note> getNoteContentList(List<NoteList> noteListList) {
+ public List<com.yuji.ec.db.Note> getNoteContentList(
+ List<NoteList> noteListList) {
List<com.yuji.ec.db.Note> list = new ArrayList<com.yuji.ec.db.Note>();
- for (NoteList noteList : noteListList){
+ for (NoteList noteList : noteListList) {
List<com.yuji.ec.db.Note> l = getNoteContentList(noteList);
- if (l == null){
+ if (l == null) {
return null;
}
list.addAll(l);
}
return list;
}
-
+
public List<com.yuji.ec.db.Note> getNoteContentList(NoteList noteList) {
errorCode = Error.OTHER;
String guid = n.getGuid();
Note nc = getNote(guid);
String content = nc.getContent();
- if (!parser.parse(content)){
+ if (!parser.parse(content)) {
return null;
}
String text = parser.getText();
}
public boolean isLoggedIn() {
- if (session == null){
+ if (session == null) {
return false;
}
return session.isLoggedIn();