Search in sources :

Example 1 with TextStreamResponse

use of org.apache.tapestry5.util.TextStreamResponse in project tapestry-5 by apache.

the class ComponentLibraries method generateJSONDescription.

@OnEvent("json")
Object generateJSONDescription(String libraryName) {
    for (LibraryMapping mapping : componentClassResolver.getLibraryMappings()) {
        if (libraryName.equalsIgnoreCase(mapping.libraryName)) {
            this.libraryMapping = mapping;
            break;
        }
    }
    JSONObject object = new JSONObject();
    object.put("libraryName", libraryName);
    object.put("rootPackage", libraryMapping.getRootPackage());
    final ComponentLibraryInfo info = getInfo();
    if (info != null) {
        JSONObject infoJsonObject = new JSONObject();
        putIfNotNull("description", info.getDescription(), infoJsonObject);
        putIfNotNull("homepage", info.getHomepageUrl(), infoJsonObject);
        putIfNotNull("documentationUrl", info.getDocumentationUrl(), infoJsonObject);
        putIfNotNull("javadocUrl", info.getJavadocUrl(), infoJsonObject);
        putIfNotNull("groupId", info.getGroupId(), infoJsonObject);
        putIfNotNull("artifactId", info.getArtifactId(), infoJsonObject);
        putIfNotNull("version", info.getVersion(), infoJsonObject);
        putIfNotNull("sourceBrowseUrl", info.getSourceBrowseUrl(), infoJsonObject);
        putIfNotNull("sourceRootUrl", info.getSourceRootUrl(), infoJsonObject);
        putIfNotNull("issueTrackerUrl", info.getIssueTrackerUrl(), infoJsonObject);
        putIfNotNull("dependencyInfoUrl", info.getDependencyManagementInfoUrl(), infoJsonObject);
        if (info.getTags() != null) {
            for (String tag : info.getTags()) {
                infoJsonObject.accumulate("tags", tag);
            }
        }
        object.put("info", infoJsonObject);
    }
    addClasses("components", filter(componentClassResolver.getComponentNames()), Type.COMPONENT, info, object);
    addClasses("pages", filter(componentClassResolver.getPageNames()), Type.PAGE, info, object);
    addClasses("mixins", filter(componentClassResolver.getMixinNames()), Type.MIXIN, info, object);
    return new TextStreamResponse("text/javascript", object.toString());
}
Also used : JSONObject(org.apache.tapestry5.json.JSONObject) ComponentLibraryInfo(org.apache.tapestry5.services.ComponentLibraryInfo) TextStreamResponse(org.apache.tapestry5.util.TextStreamResponse) LibraryMapping(org.apache.tapestry5.services.LibraryMapping) OnEvent(org.apache.tapestry5.annotations.OnEvent)

Example 2 with TextStreamResponse

use of org.apache.tapestry5.util.TextStreamResponse in project tapestry-5 by apache.

the class TestableResponseImplTest method action_link.

@Test
public void action_link() {
    Document document = tester.renderPage(TestPageForActionLinkWithStream.class.getSimpleName());
    Element link = document.getElementById("mylink");
    assertNotNull(link);
    TestableResponse response = tester.clickLinkAndReturnResponse(link);
    assertEquals(response.getOutput(), "<html><body>Rendered with TextStreamResponse</body></html>");
}
Also used : TestPageForActionLinkWithStream(org.apache.tapestry5.integration.app2.pages.TestPageForActionLinkWithStream) Element(org.apache.tapestry5.dom.Element) Document(org.apache.tapestry5.dom.Document) Test(org.testng.annotations.Test)

Aggregations

OnEvent (org.apache.tapestry5.annotations.OnEvent)1 Document (org.apache.tapestry5.dom.Document)1 Element (org.apache.tapestry5.dom.Element)1 TestPageForActionLinkWithStream (org.apache.tapestry5.integration.app2.pages.TestPageForActionLinkWithStream)1 JSONObject (org.apache.tapestry5.json.JSONObject)1 ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)1 LibraryMapping (org.apache.tapestry5.services.LibraryMapping)1 TextStreamResponse (org.apache.tapestry5.util.TextStreamResponse)1 Test (org.testng.annotations.Test)1