Package de.anomic.data.ymark

Examples of de.anomic.data.ymark.YMarkEntry


        final boolean isAdmin = (sb.verifyAuthentication(header, true));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
        final int queueSize = 20;
       
        Thread t;
        YMarkEntry bmk;
        String root = YMarkEntry.FOLDERS_IMPORTED;
        ByteArrayInputStream stream = null;
   
        if(isAdmin || isAuthUser) {
          String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);         
          final ArrayBlockingQueue<String> autoTaggingQueue = new ArrayBlockingQueue<String>(2*queueSize);
            boolean autotag = false;
          boolean merge = false;
          boolean empty = false;
           
          if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {                                       
            autotag = true;
            if(post.get("autotag").equals("merge")) {                 
                  merge = true;
                }
                if(post.get("autotag").equals("empty")) {
                  empty = true;
                }
                t = new Thread(new YMarkAutoTagger(autoTaggingQueue, sb.loader, sb.tables.bookmarks, bmk_user, merge),"YMarks - autoTagger");
                t.start();
          }
         
          if(isAdmin && post.containsKey("table") && post.get("table").length() > 0) {
            bmk_user = post.get("table").substring(0, post.get("table").indexOf('_'));
          }
            if(post.containsKey("redirect") && post.get("redirect").length() > 0) {
                prop.put("redirect_url", post.get("redirect"));
                prop.put("redirect", "1");
            }
            if(post.containsKey("root") && post.get("root").length() > 0) {
                root = post.get("root");
            }
          if(post.containsKey("bmkfile") && post.containsKey("importer")){
            stream = new ByteArrayInputStream(UTF8.getBytes(post.get("bmkfile$file")));
            if(post.get("importer").equals("surro") && stream != null) {
                    SurrogateReader surrogateReader;
                    try {
                        surrogateReader = new SurrogateReader(stream, queueSize);
                    } catch (IOException e) {
                        //TODO: display an error message
                        Log.logException(e);
                        prop.put("result", "0");
                        return prop;  
                    }
                    t = new Thread(surrogateReader, "YMarks - Surrogate Reader");
                    t.start();
                    while ((bmk = new YMarkEntry(surrogateReader.take())) != YMarkEntry.POISON) {
                        putBookmark(sb.tables.bookmarks, bmk_user, bmk, autoTaggingQueue, autotag, empty);
                    }
                    prop.put("result", "1");
                } else {
                    InputStreamReader reader = null;
View Full Code Here


      }
      if (!hasProtocol) {
          url=YMarkTables.PROTOCOLS.HTTP.protocol(url);
      }
       
          final YMarkEntry bmk = new YMarkEntry();       
           
          bmk.put(YMarkEntry.BOOKMARK.URL.key(), url);
          bmk.put(YMarkEntry.BOOKMARK.TITLE.key(), post.get(YMarkEntry.BOOKMARK.TITLE.key(),YMarkEntry.BOOKMARK.TITLE.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.DESC.key(), post.get(YMarkEntry.BOOKMARK.DESC.key(),YMarkEntry.BOOKMARK.DESC.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.PUBLIC.key(), post.get(YMarkEntry.BOOKMARK.PUBLIC.key(),YMarkEntry.BOOKMARK.PUBLIC.deflt()));
          bmk.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkUtil.cleanTagsString(post.get(YMarkEntry.BOOKMARK.TAGS.key(),YMarkEntry.BOOKMARK.TAGS.deflt())));
          bmk.put(YMarkEntry.BOOKMARK.FOLDERS.key(), YMarkUtil.cleanFoldersString(post.get(YMarkEntry.BOOKMARK.FOLDERS.key(),YMarkEntry.FOLDERS_UNSORTED)));
           
            try {
        sb.tables.bookmarks.addBookmark(bmk_user, bmk, false, false);
        } catch (IOException e) {
            Log.logException(e);
View Full Code Here

                }
            }
        }
       
        if (!post.get("commitrow", "").isEmpty()) {
            final YMarkEntry bmk = new YMarkEntry();
            for (final Map.Entry<String, String> entry: post.entrySet()) {
                if (entry.getKey().startsWith("col_")) {
                    bmk.put(entry.getKey().substring(4), entry.getValue());
                }
            }
            try {
                sb.tables.bookmarks.addBookmark(bmk_user, bmk, false, false);
            } catch (IOException e) {
View Full Code Here

        final boolean isAdmin = (sb.verifyAuthentication(header));
        final boolean isAuthUser = user!= null && user.hasRight(UserDB.AccessRight.BOOKMARK_RIGHT);
        final int queueSize = 200;

        Thread t;
        YMarkEntry bmk;
        // String root = YMarkEntry.FOLDERS_IMPORTED;
        String root = "";
        ByteArrayInputStream stream = null;

        if(isAdmin || isAuthUser) {
          String bmk_user = (isAuthUser ? user.getUserName() : YMarkTables.USER_ADMIN);
          final ArrayBlockingQueue<String> autoTaggingQueue = new ArrayBlockingQueue<String>(10*queueSize);
            boolean autotag = false;
          boolean merge = false;
          boolean empty = false;
          final String indexing = post.get("indexing", "off");
          final boolean medialink = post.getBoolean("medialink", false);

          if(post.containsKey("autotag") && !post.get("autotag", "off").equals("off")) {
            autotag = true;
            if(post.get("autotag").equals("merge")) {
                  merge = true;
                }
                if(post.get("autotag").equals("empty")) {
                  empty = true;
                }
                t = new Thread(new YMarkAutoTagger(autoTaggingQueue, sb.loader, sb.tables.bookmarks, bmk_user, merge),"YMarks - autoTagger");
                t.start();
          }

            if(isAdmin && post.containsKey("table") && post.get("table").length() > 0) {
            bmk_user = post.get("table").substring(0, post.get("table").indexOf('_',0));
          }
            if(post.containsKey("redirect") && post.get("redirect").length() > 0) {
                prop.put("redirect_url", post.get("redirect"));
                prop.put("redirect", "1");
            }
            if(post.containsKey("root") && post.get("root").length() > 0) {
                root = post.get("root");
            }
          if(post.containsKey("bmkfile") && !post.get("bmkfile").isEmpty() && post.containsKey("importer")){
            stream = new ByteArrayInputStream(UTF8.getBytes(post.get("bmkfile$file")));
            if(post.get("importer").equals("surro") && stream != null) {
                    SurrogateReader surrogateReader;
                    try {
                        surrogateReader = new SurrogateReader(stream, queueSize);
                    } catch (final IOException e) {
                        //TODO: display an error message
                        Log.logException(e);
                        prop.put("status", "0");
                        return prop;
                    }
                    t = new Thread(surrogateReader, "YMarks - Surrogate Reader");
                    t.start();
                    while ((bmk = new YMarkEntry(surrogateReader.take())) != YMarkEntry.POISON) {
                        putBookmark(sb, bmk_user, bmk, autoTaggingQueue, autotag, empty, indexing, medialink);
                    }
                    prop.put("status", "1");
                } else {
                    InputStreamReader reader = null;
                    try {
                        reader = new InputStreamReader(stream,"UTF-8");
                    } catch (final UnsupportedEncodingException e1) {
                        //TODO: display an error message
                        Log.logException(e1);
                        prop.put("status", "0");
                        return prop;
                    }
                    if(post.get("importer").equals("html") && reader != null) {
                        final YMarkHTMLImporter htmlImporter = new YMarkHTMLImporter(reader, queueSize, root);
                        t = new Thread(htmlImporter, "YMarks - HTML Importer");
                        t.start();
                        while ((bmk = htmlImporter.take()) != YMarkEntry.POISON) {
                            putBookmark(sb, bmk_user, bmk, autoTaggingQueue, autotag, empty, indexing, medialink);
                        }
                        prop.put("status", "1");
                    } else if(post.get("importer").equals("xbel") && reader != null) {
                        final YMarkXBELImporter xbelImporter;
                        try {
                            //TODO: make RootFold
                            xbelImporter = new YMarkXBELImporter(reader, queueSize, root);
                        } catch (final SAXException e) {
                            //TODO: display an error message
                            Log.logException(e);
                            prop.put("status", "0");
                            return prop;
                        }
                        t = new Thread(xbelImporter, "YMarks - XBEL Importer");
                        t.start();
                        while ((bmk = xbelImporter.take()) != YMarkEntry.POISON) {
                            putBookmark(sb, bmk_user, bmk, autoTaggingQueue, autotag, empty, indexing, medialink);
                        }
                        prop.put("status", "1");
                    } else if(post.get("importer").equals("json") && reader != null) {
                        YMarkJSONImporter jsonImporter;
                        jsonImporter = new YMarkJSONImporter(reader, queueSize, root);
                        t = new Thread(jsonImporter, "YMarks - JSON Importer");
                        t.start();
                        while ((bmk = jsonImporter.take()) != YMarkEntry.POISON) {
                          putBookmark(sb, bmk_user, bmk, autoTaggingQueue, autotag, empty, indexing, medialink);
                        }
                        prop.put("status", "1");
                    }
                }
          } else if(post.containsKey("importer") && post.get("importer").equals("crawls")) {
            if(!isAdmin) {
              prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.ADMIN_AUTHENTICATE_MSG);
              return prop;
            }
            try {
            final Pattern pattern = Pattern.compile("^crawl start for.*");
          final Iterator<Tables.Row> APIcalls = sb.tables.iterator(WorkTables.TABLE_API_NAME, WorkTables.TABLE_API_COL_COMMENT, pattern);
            Tables.Row row = null;
            while(APIcalls.hasNext()) {
              row = APIcalls.next();
              if(row.get(WorkTables.TABLE_API_COL_TYPE, "").equals("crawler")) {
                final String url = row.get(WorkTables.TABLE_API_COL_COMMENT, "").substring(16);
                sb.tables.bookmarks.createBookmark(sb.loader, url, bmk_user, autotag, "crawlStart", "/Crawl Start");
              }
            }
            prop.put("status", "1");
        } catch (final IOException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (final RowSpaceExceededException e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        } catch (final Failure e) {
          // TODO Auto-generated catch block
          e.printStackTrace();
        }
          } else if(post.containsKey("importer") && post.get("importer").equals("bmks")) {
            if(!isAdmin) {
              prop.put(YMarkTables.USER_AUTHENTICATE,YMarkTables.ADMIN_AUTHENTICATE_MSG);
              return prop;
            }
            final Iterator<String> bit=sb.bookmarksDB.getBookmarksIterator(isAdmin);
              BookmarksDB.Bookmark bookmark;
              while(bit.hasNext()){
              bookmark=sb.bookmarksDB.getBookmark(bit.next());
              final YMarkEntry bmk_entry = new YMarkEntry(false);
              bmk_entry.put(YMarkEntry.BOOKMARK.URL.key(), bookmark.getUrl());
              try {
            if(!sb.tables.has(YMarkTables.TABLES.BOOKMARKS.tablename(bmk_user), YMarkUtil.getBookmarkId(bookmark.getUrl()))) {
                bmk_entry.put(YMarkEntry.BOOKMARK.PUBLIC.key(), bookmark.getPublic() ? "true" : "false");
                bmk_entry.put(YMarkEntry.BOOKMARK.TITLE.key(), bookmark.getTitle());
                bmk_entry.put(YMarkEntry.BOOKMARK.DESC.key(), bookmark.getDescription());
                bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), bookmark.getTagsString());
                bmk_entry.put(YMarkEntry.BOOKMARK.FOLDERS.key(), root+bookmark.getFoldersString().replaceAll(".*"+YMarkUtil.TAGS_SEPARATOR+YMarkUtil.FOLDERS_SEPARATOR, root+YMarkUtil.FOLDERS_SEPARATOR));
            }
            if(autotag) {
              bmk_entry.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkAutoTagger.autoTag(bookmark.getUrl(), sb.loader, 3, sb.tables.bookmarks.getTags(bmk_user)));
            }
            sb.tables.bookmarks.addBookmark(bmk_user, bmk_entry, merge, true);
                prop.put("status", "1");
          } catch (final MalformedURLException e) {
            // TODO Auto-generated catch block
View Full Code Here

        }
        if (!hasProtocol) {
            url=YMarkTables.PROTOCOLS.HTTP.protocol(url);
        }

            final YMarkEntry bmk = new YMarkEntry();
           
            bmk.put(YMarkEntry.BOOKMARK.URL.key(), url);
            bmk.put(YMarkEntry.BOOKMARK.TITLE.key(), post.get(YMarkEntry.BOOKMARK.TITLE.key(),YMarkEntry.BOOKMARK.TITLE.deflt()));
            bmk.put(YMarkEntry.BOOKMARK.DESC.key(), post.get(YMarkEntry.BOOKMARK.DESC.key(),YMarkEntry.BOOKMARK.DESC.deflt()));
            bmk.put(YMarkEntry.BOOKMARK.PUBLIC.key(), post.get(YMarkEntry.BOOKMARK.PUBLIC.key(),YMarkEntry.BOOKMARK.PUBLIC.deflt()));
            bmk.put(YMarkEntry.BOOKMARK.TAGS.key(), YMarkUtil.cleanTagsString(post.get(YMarkEntry.BOOKMARK.TAGS.key(),YMarkEntry.BOOKMARK.TAGS.deflt()),YMarkEntry.BOOKMARK.TAGS.deflt()));
            bmk.put(YMarkEntry.BOOKMARK.FOLDERS.key(), YMarkUtil.cleanFoldersString(post.get(YMarkEntry.BOOKMARK.FOLDERS.key(),YMarkEntry.BOOKMARK.FOLDERS.deflt()),YMarkEntry.BOOKMARK.FOLDERS.deflt()));

              try {
          sb.tables.bookmarks.addBookmark(bmk_user, bmk, false, false);
          } catch (final IOException e) {
              Log.logException(e);
View Full Code Here

                }
            }
        }

        if (!post.get("commitrow", "").isEmpty()) {
            final YMarkEntry bmk = new YMarkEntry();
            for (final Map.Entry<String, String> entry: post.entrySet()) {
                if (entry.getKey().startsWith("col_")) {
                    bmk.put(entry.getKey().substring(4), entry.getValue());
                }
            }
            try {
                sb.tables.bookmarks.addBookmark(bmk_user, bmk, false, false);
            } catch (final IOException e) {
View Full Code Here

TOP

Related Classes of de.anomic.data.ymark.YMarkEntry

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.