Search in sources :

Example 1 with Version

use of org.apache.tapestry5.internal.services.SaxTemplateParser.Version in project tapestry-5 by apache.

the class SaxTemplateParser method element.

/**
 * Processes an element through to its matching end tag.
 *
 * An element can be:
 *
 * a Tapestry component via <t:type>
 *
 * a Tapestry component via t:type="type" and/or t:id="id"
 *
 * a Tapestry component via a library namespace
 *
 * A parameter element via <t:parameter>
 *
 * A parameter element via <p:name>
 *
 * A <t:remove> element (in the 5.1 schema)
 *
 * A <t:content> element (in the 5.1 schema)
 *
 * A <t:block> element
 *
 * The body <t:body>
 *
 * An ordinary element
 */
void element(TemplateParserState initialState) {
    TemplateParserState state = setupForElement(initialState);
    String uri = tokenStream.getNamespaceURI();
    String name = tokenStream.getLocalName();
    Version version = NAMESPACE_URI_TO_VERSION.get(uri);
    if (T_5_1.sameOrEarlier(version)) {
        if (name.equalsIgnoreCase("remove")) {
            removeContent();
            return;
        }
        if (name.equalsIgnoreCase("content")) {
            limitContent(state);
            return;
        }
        if (name.equalsIgnoreCase("extension-point")) {
            extensionPoint(state);
            return;
        }
        if (name.equalsIgnoreCase("replace")) {
            throw new RuntimeException("The <replace> element may only appear directly within an extend element.");
        }
        if (MUST_BE_ROOT.contains(name))
            mustBeRoot(name);
    }
    if (version != null) {
        if (name.equalsIgnoreCase("body")) {
            body();
            return;
        }
        if (name.equalsIgnoreCase("container")) {
            mustBeRoot(name);
        }
        if (name.equalsIgnoreCase("block")) {
            block(state);
            return;
        }
        if (name.equalsIgnoreCase("parameter")) {
            if (T_5_3.sameOrEarlier(version)) {
                throw new RuntimeException(String.format("The <parameter> element has been deprecated in Tapestry 5.3 in favour of '%s' namespace.", TAPESTRY_PARAMETERS_URI));
            }
            classicParameter(state);
            return;
        }
        possibleTapestryComponent(state, null, tokenStream.getLocalName().replace('.', '/'));
        return;
    }
    if (uri != null && uri.startsWith(LIB_NAMESPACE_URI_PREFIX)) {
        libraryNamespaceComponent(state);
        return;
    }
    if (TAPESTRY_PARAMETERS_URI.equals(uri)) {
        parameterElement(state);
        return;
    }
    // Just an ordinary element ... unless it has t:id or t:type
    possibleTapestryComponent(state, tokenStream.getLocalName(), null);
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version)

Example 2 with Version

use of org.apache.tapestry5.internal.services.SaxTemplateParser.Version in project tapestry-5 by apache.

the class SaxTemplateParser method possibleTapestryComponent.

/**
 * @param elementName
 * @param identifiedType
 *         the type of the element, usually null, but may be the
 *         component type derived from element
 */
private void possibleTapestryComponent(TemplateParserState state, String elementName, String identifiedType) {
    String id = null;
    String type = identifiedType;
    String mixins = null;
    int count = tokenStream.getAttributeCount();
    Location location = getLocation();
    List<TemplateToken> attributeTokens = CollectionFactory.newList();
    for (int i = 0; i < count; i++) {
        QName qname = tokenStream.getAttributeName(i);
        if (isXMLSpaceAttribute(qname))
            continue;
        // The name will be blank for an xmlns: attribute
        String localName = qname.getLocalPart();
        if (InternalUtils.isBlank(localName))
            continue;
        String uri = qname.getNamespaceURI();
        String value = tokenStream.getAttributeValue(i);
        Version version = NAMESPACE_URI_TO_VERSION.get(uri);
        if (version != null) {
            if (T_5_4.sameOrEarlier(version)) {
                strictMixinParameters = true;
            }
            if (localName.equalsIgnoreCase(ID_ATTRIBUTE_NAME)) {
                id = nullForBlank(value);
                validateId(id, "Component id '%s' is not valid; component ids must be valid Java identifiers: start with a letter, and consist of letters, numbers and underscores.");
                continue;
            }
            if (type == null && localName.equalsIgnoreCase(TYPE_ATTRIBUTE_NAME)) {
                type = nullForBlank(value);
                continue;
            }
            if (localName.equalsIgnoreCase(MIXINS_ATTRIBUTE_NAME)) {
                mixins = nullForBlank(value);
                continue;
            }
        // Anything else is the name of a Tapestry component parameter
        // that is simply
        // not part of the template's doctype for the element being
        // instrumented.
        }
        attributeTokens.add(new AttributeToken(uri, localName, value, location));
    }
    boolean isComponent = (id != null || type != null);
    if (mixins != null && !isComponent)
        throw new TapestryException(String.format("You may not specify mixins for element <%s> because it does not represent a component (which requires either an id attribute or a type attribute).", elementName), location, null);
    if (isComponent) {
        tokenAccumulator.add(new StartComponentToken(elementName, id, type, mixins, location));
    } else {
        tokenAccumulator.add(new StartElementToken(tokenStream.getNamespaceURI(), elementName, location));
    }
    addDefineNamespaceTokens();
    tokenAccumulator.addAll(attributeTokens);
    if (id != null)
        componentIds.put(id, location);
    processBody(state.insideComponent(isComponent));
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version) QName(javax.xml.namespace.QName) TapestryException(org.apache.tapestry5.commons.internal.util.TapestryException) Location(org.apache.tapestry5.commons.Location)

Example 3 with Version

use of org.apache.tapestry5.internal.services.SaxTemplateParser.Version in project tapestry-5 by apache.

the class SaxTemplateParser method rootElement.

private void rootElement(TemplateParserState initialState) {
    TemplateParserState state = setupForElement(initialState);
    String uri = tokenStream.getNamespaceURI();
    String name = tokenStream.getLocalName();
    Version version = NAMESPACE_URI_TO_VERSION.get(uri);
    if (T_5_1.sameOrEarlier(version)) {
        if (name.equalsIgnoreCase("extend")) {
            extend(state);
            return;
        }
    }
    if (version != null) {
        if (name.equalsIgnoreCase("container")) {
            container(state);
            return;
        }
    }
    element(state);
}
Also used : Version(org.apache.tapestry5.internal.services.SaxTemplateParser.Version)

Example 4 with Version

use of org.apache.tapestry5.internal.services.SaxTemplateParser.Version 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 5 with Version

use of org.apache.tapestry5.internal.services.SaxTemplateParser.Version in project tapestry-5 by apache.

the class AbstractAssetFactory method createAsset.

protected Asset createAsset(final Resource resource, final String folder, final String resourcePath) {
    assert resource != null;
    assert InternalUtils.isNonBlank(folder);
    assert InternalUtils.isNonBlank(resourcePath);
    return new AbstractAsset(false) {

        public String toClientURL() {
            try {
                // Get the uncompressed version, so that we can identify its content type (and remember, the extension is not enough,
                // as some types get translated to new content types by the SRS).
                StreamableResource uncompressed = streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_DISABLED, resourceChangeTracker);
                StreamableResource forRequest = isCompressable(uncompressed) ? streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_ENABLED, resourceChangeTracker) : uncompressed;
                return assetPathConstructor.constructAssetPath(folder, resourcePath, forRequest);
            } catch (IOException ex) {
                throw new RuntimeException(String.format("Unable to construct asset path for %s: %s", resource, ExceptionUtils.toMessage(ex)), ex);
            }
        }

        public Resource getResource() {
            return resource;
        }
    };
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) IOException(java.io.IOException)

Aggregations

Test (org.testng.annotations.Test)12 MarkupWriter (org.apache.tapestry5.MarkupWriter)9 XMLMarkupModel (org.apache.tapestry5.dom.XMLMarkupModel)7 TypeReference (org.apache.tapestry5.internal.plastic.asm.TypeReference)5 IOException (java.io.IOException)3 Version (org.apache.tapestry5.internal.services.SaxTemplateParser.Version)3 URL (java.net.URL)2 Location (org.apache.tapestry5.commons.Location)2 Element (org.apache.tapestry5.dom.Element)2 MarkupWriterImpl (org.apache.tapestry5.internal.services.MarkupWriterImpl)2 Contribute (org.apache.tapestry5.ioc.annotations.Contribute)2 JSONObject (org.apache.tapestry5.json.JSONObject)2 ComponentLibraryInfo (org.apache.tapestry5.services.ComponentLibraryInfo)2 ConfigurableWebApplicationContext (org.springframework.web.context.ConfigurableWebApplicationContext)2 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 File (java.io.File)1 InputStream (java.io.InputStream)1 Formatter (java.util.Formatter)1 Extension (javax.enterprise.inject.spi.Extension)1