Package com.ibm.commons.util.io.json

Examples of com.ibm.commons.util.io.json.JsonJavaArray


        Vector<?> values = item.getValues();
        if(values==null || values.size()==0) {
          return;
        }
        if(values.size()>1) {
          JsonJavaArray array = new JsonJavaArray();
          for(int i=0; i<values.size(); i++) {
            array.add(asJsonValue(values.get(i)));
          }
          jsonDocument.put(item.getName(),array);
        } else {
          jsonDocument.put(item.getName(),asJsonValue(values.get(0)));
        }
View Full Code Here


    /*
     * returns an array of the json objects describing each image in the wikiPage.
     */
    public JsonJavaArray extractImagesFromWikiPage(String pageHTML){
      JsonJavaArray imageAttributeObjects = new JsonJavaArray();
       
        Pattern p = Pattern.compile("<img([^>]*)>([^<>]*)</img>");
        Matcher m = p.matcher(pageHTML);
        while(m.find()) {
          String imgAttrs = m.group(1);
          if(imgAttrs==null){
            break;
          }
          JsonJavaObject jsonAttrs = new JsonJavaObject();
          imgAttrs = imgAttrs.trim();
          String[] attrs = imgAttrs.split("\" ");
         
          for(int i = 0; i < attrs.length; i++){
            String attr = attrs[i];
            attr = attr.replaceAll("\"", "");
            String[] nameValue = attr.split("=");
            if(nameValue.length == 2){
              jsonAttrs.put(nameValue[0], nameValue[1]);
            }else if(nameValue.length == 1){
              jsonAttrs.put(nameValue[0], "");
            }
          }
          imageAttributeObjects.add(jsonAttrs);
        }
       
        return imageAttributeObjects;
    }
View Full Code Here

        params.put("ps", "20");
        Wiki wiki = wikiService.getWiki(wikiLabel, params);
        JsonJavaObject result = entityToJsonObject(wiki, WikiXPath.values(),
                null);
       
        JsonJavaArray pagesArray = new JsonJavaArray();
        int page = 1;
        int writtenPages = 0;
        boolean morePages = true;
        do{
          params.put("page", Integer.toString(page));
          EntityList<WikiPage> wikiPages = wikiService.getWikiPages(wikiLabel, params);
          for (Iterator<WikiPage> iter = wikiPages.iterator(); iter.hasNext();) {
              JsonJavaObject wikiEntry = new JsonJavaObject();
              WikiPage wikiPage = iter.next();
              entityToJsonObject(wikiPage, AtomXPath.values(), wikiEntry);
              entityToJsonObject(wikiPage, WikiXPath.values(), wikiEntry);
              String pageHTML = wikiPage.getContent();
              wikiEntry.put("content", pageHTML);

              wikiEntry.putArray("pageImages", extractImagesFromWikiPage(pageHTML));
              pagesArray.add(wikiEntry);
          }
          writtenPages += wikiPages.size();
          int total = wikiPages.getTotalResults();
          if(writtenPages < total){
              morePages = true;
View Full Code Here

TOP

Related Classes of com.ibm.commons.util.io.json.JsonJavaArray

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.