Package com.dotcms.repackage.org.codehaus.jettison.json

Examples of com.dotcms.repackage.org.codehaus.jettison.json.JSONObject


  private void doJSON(List<Contentlet> cons, HttpServletResponse response) throws IOException{
   
 
   
        // get our JSON Going
        JSONObject json = new JSONObject()
    JSONArray jsonCons = new JSONArray()

    for(Contentlet c : cons){
     
     
      try {
       
        jsonCons.put(contentletToJSON(c));
       
      } catch (Exception e) {
        Logger.error(this.getClass(), "unable JSON contentlet " + c.getIdentifier());
        Logger.debug(this.getClass(), "unable to find contentlet", e);
      }
    }


    try {
      json.put("contentlets", jsonCons);
    } catch (JSONException e) {
      Logger.error(this.getClass(), "unable to create JSONObject");
      Logger.debug(this.getClass(), "unable to create JSONObject", e);
    }

   
    
        response.getWriter().println(json.toString())
    response.getWriter().flush()
    response.getWriter().close()
   
   
  }
View Full Code Here


 
 
 
 
  private JSONObject contentletToJSON(Contentlet con) throws JSONException{
    JSONObject jo = new JSONObject();
   
    Structure s = con.getStructure();
    Map map = con.getMap();
    for (Iterator it = map.keySet().iterator(); it.hasNext(); ) { 
      String key = (String) it.next()
      if(Arrays.binarySearch(ignoreFields, key) < 0){
        jo.put(key, map.get(key));
      }

    } 

    for(Field f : s.getFields()){
      if(f.getFieldType().equals(Field.FieldType.BINARY.toString())){

          jo.put(f.getVelocityVarName(), "/contentAsset/raw-data/" +  con.getIdentifier() + "/" + f.getVelocityVarName()  );
       
          jo.put(f.getVelocityVarName() + "ContentAsset", con.getIdentifier() + "/" +f.getVelocityVarName()  );
      }
     
    }
   
View Full Code Here

        User sysuser=APILocator.getUserAPI().getSystemUser();
        String demoId=demo.getIdentifier();
        ClientResponse response=
                contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                       .header(authheader, authvalue).put(ClientResponse.class,
                                new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest")
                                .put("body", "this is an example text")
                                .put("contentHost", demoId).toString());
        Assert.assertEquals(200, response.getStatus());
        Assert.assertTrue(response.getLocation().toString().contains("/api/content/inode/"));
        String location=response.getLocation().toString();
        String inode=location.substring(location.lastIndexOf("/")+1);
        Contentlet cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertNotNull(cont);
        Assert.assertTrue(InodeUtils.isSet(cont.getIdentifier()));
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertEquals(st.getInode(), cont.getStructureInode());
        Assert.assertEquals(1,cont.getLanguageId());
        Assert.assertEquals("Test content from ContentResourceTest",cont.getStringProperty("title"));
        Assert.assertEquals("this is an example text",cont.getStringProperty("body"));
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: folderId
        Folder folder=APILocator.getFolderAPI().findFolderByPath("/home", demo, sysuser, false);
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                       .header(authheader, authvalue).put(ClientResponse.class,
                                new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "test content with folderid")
                                .put("body", "this is an example text")
                                .put("contentHost", folder.getInode()).toString());
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(folder.getInode(), cont.getFolder());
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: hostname
        response=contRes.path("/publish/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest folderId")
                                .put("body", "this is an example text")
                                .put("contentHost", "demo.dotcms.com").toString());
        location=response.getLocation().toString();
        inode=location.substring(location.lastIndexOf("/")+1);
        cont=APILocator.getContentletAPI().find(inode, sysuser, false);
        Assert.assertEquals(demoId, cont.getHost());
        Assert.assertTrue(cont.isLive());
       
        // testing other host_or_folder formats: hostname:path
        response=contRes.path("/justsave/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("title", "Test content from ContentResourceTest folderId")
                                .put("body", "this is an example text")
                                .put("contentHost", "demo.dotcms.com:/home").toString());
View Full Code Here

       
        ClientResponse response = contRes.path("/publish/1").type(MediaType.MULTIPART_FORM_DATA_TYPE)
                                   .header(authheader, authvalue).put(ClientResponse.class,
                                           new MultiPart()
                                             .bodyPart(new BodyPart(
                                                     new JSONObject()
                                                        .put("hostFolder", "demo.dotcms.com:/resources")
                                                        .put("title", "newfile"+salt+".txt")
                                                        .put("fileName", "newfile"+salt+".txt")
                                                        .put("languageId", "1")
                                                        .put("stInode", StructureCache.getStructureByVelocityVarName("FileAsset").getInode())
View Full Code Here

        User sysuser=APILocator.getUserAPI().getSystemUser();
        Structure st=StructureCache.getStructureByVelocityVarName("Blog");
        String salt=Long.toString(System.currentTimeMillis());
        ClientResponse response=contRes.path("/justsave/1").type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                        new JSONObject()
                                .put("stInode", st.getInode())
                                .put("languageId", 1)
                                .put("host1", "demo.dotcms.com")
                                .put("title", "blog post "+salt)
                                .put("urlTitle", "blog-post-"+salt)
View Full Code Here

        User bill=APILocator.getUserAPI().loadUserById("dotcms.org.2806");
        Role billrole=APILocator.getRoleAPI().getUserRole(bill);
        ClientResponse response=contRes.path("/Save%20and%20Assign/1/wfActionComments/please%20do%20this%20for%20me/wfActionAssign/"+billrole.getId())
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stInode", st.getInode())
                    .put("languageId", 1)
                    .put(field.getVelocityVarName(), "test title "+salt)
                    .toString());
        Assert.assertEquals(200, response.getStatus());
View Full Code Here

        imga = APILocator.getContentletAPI().checkin(imga, sysuser, false);
       
        ClientResponse response=contRes.path("/publish/1")
            .type(MediaType.APPLICATION_JSON_TYPE)
            .header(authheader, authvalue).put(ClientResponse.class,
                new JSONObject()
                    .put("stName", st.getVelocityVarName())
                    .put(file.getVelocityVarName(),"//demo.dotcms.com/rest/"+salt+"/filefile.txt")
                    .put(image.getVelocityVarName(), "//demo.dotcms.com/rest/"+salt+"/imgimg.jpg")
                    .put(title.getVelocityVarName(), "a simple title")
                    .toString());
View Full Code Here

        RelationshipFactory.saveRelationship(rel);
       
        ClientResponse response=contRes.path("/publish/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", st1.getVelocityVarName())
                        .put(title1.getVelocityVarName(), "a simple title")
                        .put(rel.getRelationTypeValue(), "+structureName:"+st2.getVelocityVarName())
                        .toString());
        Assert.assertEquals(200, response.getStatus());
View Full Code Here

        final User sysuser=APILocator.getUserAPI().getSystemUser();
       
        ClientResponse response=contRes.path("/justSave/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", "webPageContent")
                        .put("contentHost", "demo.dotcms.com")
                        .put("title", "testing newVersion")
                        .put("body", "just testing")
                        .toString());
        Assert.assertEquals(200, response.getStatus());
       
        String inode=response.getHeaders().getFirst("inode");
       
       
        String identifier=response.getHeaders().getFirst("identifier");
       
        response=contRes.path("/justSave/1")
                .type(MediaType.APPLICATION_JSON_TYPE)
                .header(authheader, authvalue).put(ClientResponse.class,
                    new JSONObject()
                        .put("stName", "webPageContent")
                        .put("contentHost", "demo.dotcms.com")
                        .put("title", "testing newVersion 2")
                        .put("body", "just testing 2")
                        .put("identifier", identifier)
View Full Code Here

    if(jsonString.indexOf("{") <0 || jsonString.indexOf("}") <0){
      return false;
    }
    try {
      if (jsonString.startsWith("{"))
        new JSONObject(jsonString);
      else if (jsonString.startsWith("["))
        new JSONArray(jsonString);

      return true;
    } catch (Exception e) {
View Full Code Here

TOP

Related Classes of com.dotcms.repackage.org.codehaus.jettison.json.JSONObject

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.