Package org.apache.sling.commons.json

Examples of org.apache.sling.commons.json.JSONObject


     */
    private MavenProject project;

    public void execute() throws MojoExecutionException, MojoFailureException {
        try {
            final JSONObject descriptor = new JSONObject();

            final AnnotationDB annotationDb = new AnnotationDB();
            annotationDb.scanArchives(buildOutputDirectory.toURI().toURL());

            final Set<String> annotatedClassNames = new HashSet<String>();
            addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptable.class);
            addAnnotatedClasses(annotationDb, annotatedClassNames, Adaptables.class);

            for (final String annotatedClassName : annotatedClassNames) {
                getLog().info(String.format("found adaptable annotation on %s", annotatedClassName));
                final String pathToClassFile = annotatedClassName.replace('.', '/') + ".class";
                final File classFile = new File(buildOutputDirectory, pathToClassFile);
                final FileInputStream input = new FileInputStream(classFile);
                final ClassReader classReader;
                try {
                    classReader = new ClassReader(input);
                } finally {
                    input.close();
                }
                final ClassNode classNode = new ClassNode();
                classReader.accept(classNode, SKIP_CODE | SKIP_DEBUG | SKIP_FRAMES);

                @SuppressWarnings("unchecked")
                final List<AnnotationNode> annotations = classNode.invisibleAnnotations;
                for (final AnnotationNode annotation : annotations) {
                    if (ADAPTABLE_DESC.equals(annotation.desc)) {
                        parseAdaptableAnnotation(annotation, classNode, descriptor);
                    } else if (ADAPTABLES_DESC.equals(annotation.desc)) {
                        parseAdaptablesAnnotation(annotation, classNode, descriptor);
                    }
                }

            }

            final File outputFile = new File(outputDirectory, fileName);
            outputFile.getParentFile().mkdirs();
            final FileWriter writer = new FileWriter(outputFile);
            try {
                IOUtil.copy(descriptor.toString(JSON_INDENTATION), writer);
            } finally {
                IOUtil.close(writer);
            }
            addResource();

View Full Code Here


        if (adaptableClassName == null || adapters == null) {
            throw new IllegalArgumentException(
                    "Adaptable annotation is malformed. Expecting a classname and a list of adapter annotation.");
        }

        JSONObject adaptableDescription;
        if (descriptor.has(adaptableClassName)) {
            adaptableDescription = descriptor.getJSONObject(adaptableClassName);
        } else {
            adaptableDescription = new JSONObject();
            descriptor.put(adaptableClassName, adaptableDescription);
        }

        for (final AnnotationNode adapter : adapters) {
            parseAdapterAnnotation(adapter, annotatedClass, adaptableDescription);
View Full Code Here

    public void testObject() throws IOException, JSONException {
        final String toDelete = uploadTestScript("builder_object.groovy","json.groovy");
        try {
            final String content = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
            JSONObject jo = new JSONObject(content);
            assertEquals("Content contained wrong number of items", 1, jo.length());
            assertEquals("Content contained wrong key", "text", jo.keys().next());
            assertEquals("Content contained wrong data", testText, jo.get("text"));
        } finally {
            testClient.delete(toDelete);
        }
    }
View Full Code Here

    public void testRichObject() throws IOException, JSONException {
        final String toDelete = uploadTestScript("builder_rich_object.groovy","json.groovy");
        try {
            final String content = getContent(displayUrl + ".json", CONTENT_TYPE_JSON);
            log.debug("{} content: {}", displayUrl, content);
            JSONObject jo = new JSONObject(content);
            assertEquals("Content contained wrong number of items", 2, jo.length());
            assertEquals("Content contained wrong data", testText, jo.get("text"));
            assertEquals("Content contained wrong data", "bar", ((JSONObject) jo.get("obj")).get("foo"));
        } finally {
            testClient.delete(toDelete);
        }
    }
View Full Code Here

        res.onChange("modified", "argument1", "argument2");
        Object prop = res.getProperty("changes");
        JSONArray changes = assertInstanceOf(prop, JSONArray.class);
        assertEquals(1, changes.length());
        Object obj = changes.get(0);
        JSONObject change = assertInstanceOf(obj, JSONObject.class);
        assertEquals("modified", assertProperty(change, JSONResponse.PROP_TYPE, String.class));
        JSONArray arguments = assertProperty(change, JSONResponse.PROP_ARGUMENT, JSONArray.class);
        assertEquals(2, arguments.length());
    }
View Full Code Here

    public void testSetError() throws IOException, JSONException {
        String errMsg = "Dummy error";
        res.setError(new Error(errMsg));
        MockSlingHttpServletResponse resp = new MockSlingHttpServletResponse();
        res.send(resp, true);
        JSONObject json = res.getJson();
        JSONObject error = assertProperty(json, "error", JSONObject.class);
        assertProperty(error, "class", Error.class.getName());
        assertProperty(error, "message", errMsg);
    }
View Full Code Here

    public void testSend() throws Exception {
        res.onChange("modified", "argument1");
        MockSlingHttpServletResponse response = new MockSlingHttpServletResponse();
        res.send(response, true);
        JSONObject result = new JSONObject(response.getOutput().toString());
        assertProperty(result, HtmlResponse.PN_STATUS_CODE, HttpServletResponse.SC_OK);
        assertEquals(JSONResponse.RESPONSE_CONTENT_TYPE, response.getContentType());
        assertEquals(JSONResponse.RESPONSE_CHARSET, response.getCharacterEncoding());
    }
View Full Code Here

        res.onChange("modified", "argument1");
        res.setStatus(HttpServletResponse.SC_CREATED, "Created");
        res.setLocation(location);
        MockResponseWithHeader response = new MockResponseWithHeader();
        res.send(response, true);
        JSONObject result = new JSONObject(response.getOutput().toString());
        assertProperty(result, HtmlResponse.PN_STATUS_CODE, HttpServletResponse.SC_CREATED);
        assertEquals(location, response.getHeader("Location"));
    }
View Full Code Here

        for (int status = 300; status < 308; status++) {
            res.setStatus(status, "3xx Status");
            res.setLocation(location);
            MockResponseWithHeader response = new MockResponseWithHeader();
            res.send(response, true);
            JSONObject result = new JSONObject(response.getOutput().toString());
            assertProperty(result, HtmlResponse.PN_STATUS_CODE, status);
            assertEquals(location, response.getHeader("Location"));
        }
    }
View Full Code Here

    try {
      Session session = request.getResourceResolver().adaptTo(Session.class);
        String resourcePath = request.getResource().getPath();

        JSONObject acl = internalGetAcl(session, resourcePath);
          response.setContentType("application/json");
          response.setCharacterEncoding("UTF-8");

          boolean isTidy = false;
          final String[] selectors = request.getRequestPathInfo().getSelectors();
          if (selectors != null && selectors.length > 0) {
            for (final String level : selectors) {
                if("tidy".equals(level)) {
                  isTidy = true;
                  break;
                }
        }
          }

          if (isTidy) {
            response.getWriter().append(acl.toString(2));
          } else {
            acl.write(response.getWriter());
          }
        } catch (AccessDeniedException ade) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        } catch (ResourceNotFoundException rnfe) {
            response.sendError(HttpServletResponse.SC_NOT_FOUND, rnfe.getMessage());
View Full Code Here

TOP

Related Classes of org.apache.sling.commons.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.