Search in sources :

Example 1 with ComponentLibraryInfo

use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.

the class MavenComponentLibraryInfoSource method find.

@Override
public ComponentLibraryInfo find(LibraryMapping libraryMapping) {
    ComponentLibraryInfo info = null;
    if (cache.containsKey(libraryMapping.libraryName)) {
        info = cache.get(libraryMapping.libraryName);
    } else {
        final String pomPath = getPomPath(libraryMapping);
        if (pomPath != null) {
            InputStream inputStream = getClass().getResourceAsStream("/" + pomPath);
            info = parse(inputStream);
            info.setLibraryMapping(libraryMapping);
            cache.put(libraryMapping.libraryName, info);
        } else {
            cache.put(libraryMapping.libraryName, null);
        }
    }
    return info;
}
Also used : ComponentLibraryInfo(org.apache.tapestry5.services.ComponentLibraryInfo) InputStream(java.io.InputStream)

Example 2 with ComponentLibraryInfo

use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.

the class MavenComponentLibraryInfoSource method parse.

private ComponentLibraryInfo parse(InputStream inputStream) {
    ComponentLibraryInfo info = null;
    if (inputStream != null) {
        Document document;
        try {
            DocumentBuilder documentBuilder = documentBuilderFactory.newDocumentBuilder();
            document = documentBuilder.parse(inputStream);
        } catch (Exception e) {
            logger.warn("Exception while parsing pom.xml", e);
            return null;
        }
        info = new ComponentLibraryInfo();
        info.setGroupId(extractText(document, "(/project/groupId | /project/parent/groupId)[1]"));
        info.setArtifactId(extractText(document, "/project/artifactId"));
        info.setVersion(extractText(document, "/project/version"));
        info.setName(extractText(document, "/project/name"));
        info.setDescription(extractText(document, "/project/description"));
        info.setDocumentationUrl(extractText(document, "/project/properties/documentationUrl"));
        info.setHomepageUrl(extractText(document, "/project/properties/homepageUrl"));
        info.setIssueTrackerUrl(extractText(document, "/project/issueManagement/url"));
        info.setJavadocUrl(extractText(document, "/project/properties/javadocUrl"));
        info.setSourceBrowseUrl(extractText(document, "/project/scm/url"));
        info.setSourceRootUrl(extractText(document, "/project/properties/sourceRootUrl"));
        info.setTapestryVersion(extractText(document, "(/project/dependencies/dependency[./groupId='org.apache.tapestry'][./artifactId='tapestry-core']/version | /project/properties/tapestryVersion)[1]"));
        String tags = extractText(document, "/project/properties/tags");
        if (tags != null && tags.length() > 0) {
            info.setTags(Arrays.asList(tags.split(",")));
        }
    }
    return info;
}
Also used : DocumentBuilder(javax.xml.parsers.DocumentBuilder) ComponentLibraryInfo(org.apache.tapestry5.services.ComponentLibraryInfo) Document(org.w3c.dom.Document) XPathExpressionException(javax.xml.xpath.XPathExpressionException) IOException(java.io.IOException)

Example 3 with ComponentLibraryInfo

use of org.apache.tapestry5.services.ComponentLibraryInfo 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 4 with ComponentLibraryInfo

use of org.apache.tapestry5.services.ComponentLibraryInfo in project tapestry-5 by apache.

the class ComponentLibraries method addClasses.

private void addClasses(final String property, List<String> classes, Type type, final ComponentLibraryInfo info, JSONObject object) {
    if (classes.size() > 0) {
        JSONArray classesJsonArray = new JSONArray();
        for (String logicalName : classes) {
            logicalName = logicalName.replace("core/", "");
            final String className = getClassName(logicalName, type, componentClassResolver);
            JSONObject classJsonObject = new JSONObject();
            classJsonObject.put("logicalName", logicalName);
            classJsonObject.put("class", className);
            if (info != null) {
                putIfNotNull("sourceUrl", info.getSourceUrl(className), classJsonObject);
                putIfNotNull("javadocUrl", info.getJavadocUrl(className), classJsonObject);
            }
            try {
                final Description description = getClass(className);
                if (description != null) {
                    putIfNotNull("description", description.text(), classJsonObject);
                    if (description.tags().length > 0) {
                        for (String tag : description.tags()) {
                            classJsonObject.accumulate("tag", tag);
                        }
                    }
                }
            } catch (ClassNotFoundException e) {
                throw new RuntimeException(e);
            }
            classesJsonArray.put(classJsonObject);
        }
        object.put(property, classesJsonArray);
    }
}
Also used : Description(org.apache.tapestry5.ioc.annotations.Description) JSONObject(org.apache.tapestry5.json.JSONObject) JSONArray(org.apache.tapestry5.json.JSONArray)

Aggregations

ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)3 JSONObject (org.apache.tapestry5.json.JSONObject)2 IOException (java.io.IOException)1 InputStream (java.io.InputStream)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 OnEvent (org.apache.tapestry5.annotations.OnEvent)1 Description (org.apache.tapestry5.ioc.annotations.Description)1 JSONArray (org.apache.tapestry5.json.JSONArray)1 LibraryMapping (org.apache.tapestry5.services.LibraryMapping)1 TextStreamResponse (org.apache.tapestry5.util.TextStreamResponse)1 Document (org.w3c.dom.Document)1