Search in sources :

Example 1 with Document

use of org.apache.tapestry5.dom.Document 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 2 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class DocumentLinkerImpl method updateDocument.

/**
 * Updates the supplied Document, possibly adding <head> or <body> elements.
 *
 * @param document
 *         to be updated
 */
public void updateDocument(Document document) {
    Element root = document.getRootElement();
    if (root == null) {
        return;
    }
    // TAP5-2200: Generating XML from pages and templates is not possible anymore
    // only add JavaScript and CSS if we're actually generating
    final String mimeType = document.getMimeType();
    if (mimeType != null && !HTML_MIME_TYPES.contains(mimeType)) {
        return;
    }
    addStylesheetsToHead(root, includedStylesheets);
    // only add the generator meta only to html documents
    boolean isHtmlRoot = root.getName().equals("html");
    if (!omitGeneratorMetaTag && isHtmlRoot) {
        Element head = findOrCreateElement(root, "head", true);
        Element existingMeta = head.find("meta");
        addElementBefore(head, existingMeta, "meta", "name", "generator", "content", tapestryBanner);
    }
    addScriptElements(root);
}
Also used : Element(org.apache.tapestry5.dom.Element)

Example 3 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class TemplateInContextTest method template_in_web_context.

@Test
public void template_in_web_context() {
    tester = new PageTester(TestConstants.APP2_PACKAGE, TestConstants.APP2_NAME, "src/test/app2");
    Document doc = tester.renderPage("TestPageForTemplateInContext");
    assertTrue(doc.toString().contains("How are you?"));
}
Also used : PageTester(org.apache.tapestry5.test.PageTester) Document(org.apache.tapestry5.dom.Document) Test(org.testng.annotations.Test)

Example 4 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class UnlessTest method render.

@Test
public void render() {
    tester = new PageTester(TestConstants.APP2_PACKAGE, TestConstants.APP2_NAME);
    Document doc = tester.renderPage("TestPageForUnless");
    assertNotNull(doc.getElementById("2"));
    assertNotNull(doc.getElementById("4"));
    assertNotNull(doc.getElementById("6"));
    assertNotNull(doc.getElementById("7"));
    assertNull(doc.getElementById("1"));
    assertNull(doc.getElementById("3"));
    assertNull(doc.getElementById("5"));
    assertNull(doc.getElementById("8"));
}
Also used : PageTester(org.apache.tapestry5.test.PageTester) Document(org.apache.tapestry5.dom.Document) Test(org.testng.annotations.Test)

Example 5 with Document

use of org.apache.tapestry5.dom.Document in project tapestry-5 by apache.

the class PageTesterTest method on_activate_chain_is_followed.

@Test(dataProvider = "testers")
public void on_activate_chain_is_followed(PageTester tester) {
    Document launchDoc = tester.renderPage("Launch");
    Map<String, String> parameters = Collections.emptyMap();
    // Submit the form, which will then skip through Intermediate and
    // arrive at Final.
    Document finalDoc = tester.submitForm(launchDoc.getElementById("form"), parameters);
    assertEquals(finalDoc.getElementById("page-name").getChildMarkup(), "Final");
}
Also used : Document(org.apache.tapestry5.dom.Document) Test(org.testng.annotations.Test)

Aggregations

Document (org.apache.tapestry5.dom.Document)20 Test (org.testng.annotations.Test)19 PageTester (org.apache.tapestry5.test.PageTester)11 Element (org.apache.tapestry5.dom.Element)8 MarkupWriter (org.apache.tapestry5.MarkupWriter)4 Document (elemental2.dom.Document)2 Element (elemental2.dom.Element)2 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)2 IOException (java.io.IOException)1 DocumentBuilder (javax.xml.parsers.DocumentBuilder)1 XPathExpressionException (javax.xml.xpath.XPathExpressionException)1 TestPageForActionLinkWithStream (org.apache.tapestry5.integration.app2.pages.TestPageForActionLinkWithStream)1 TestPageForHttpHeaders (org.apache.tapestry5.integration.app2.pages.TestPageForHttpHeaders)1 Page (org.apache.tapestry5.internal.structure.Page)1 RenderCommand (org.apache.tapestry5.runtime.RenderCommand)1 ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)1 Test (org.junit.Test)1 Document (org.w3c.dom.Document)1