private void processComponentStart()

in tapestry-framework/src/org/apache/tapestry/parse/TemplateParser.java [1044:1168]


    private void processComponentStart(
        String tagName,
        String jwcId,
        boolean emptyTag,
        int startLine,
        int cursorStart,
        ILocation startLocation)
        throws TemplateParseException
    {
        if (jwcId.equalsIgnoreCase(CONTENT_ID))
        {
            processContentTag(tagName, startLine, cursorStart, emptyTag);

            return;
        }

        boolean isRemoveId = jwcId.equalsIgnoreCase(REMOVE_ID);

        if (_ignoring && !isRemoveId)
            templateParseProblem(
                Tapestry.format("TemplateParser.component-may-not-be-ignored", tagName, Integer.toString(startLine)),
                startLocation,
                startLine,
                cursorStart);

        String type = null;
        boolean allowBody = false;

        if (_patternMatcher.matches(jwcId, _implicitIdPattern))
        {
            MatchResult match = _patternMatcher.getMatch();

            jwcId = match.group(IMPLICIT_ID_PATTERN_ID_GROUP);
            type = match.group(IMPLICIT_ID_PATTERN_TYPE_GROUP);

            String libraryId = match.group(IMPLICIT_ID_PATTERN_LIBRARY_ID_GROUP);
            String simpleType = match.group(IMPLICIT_ID_PATTERN_SIMPLE_TYPE_GROUP);

            // If (and this is typical) no actual component id was specified,
            // then generate one on the fly.
            // The allocated id for anonymous components is
            // based on the simple (unprefixed) type, but starts
            // with a leading dollar sign to ensure no conflicts
            // with user defined component ids (which don't allow dollar signs
            // in the id).

            if (jwcId == null)
                jwcId = _idAllocator.allocateId("$" + simpleType);

            try
            {
                allowBody = _delegate.getAllowBody(libraryId, simpleType, startLocation);
            } catch (ApplicationRuntimeException e)
            {
                // give subclasses a chance to handle and rethrow
                templateParseProblem(e, startLine, cursorStart);
            }

        } else
        {
            if (!isRemoveId)
            {
                if (!_patternMatcher.matches(jwcId, _simpleIdPattern))
                    templateParseProblem(
                        Tapestry.format(
                            "TemplateParser.component-id-invalid",
                            tagName,
                            Integer.toString(startLine),
                            jwcId),
                        startLocation,
                        startLine,
                        cursorStart);

                if (!_delegate.getKnownComponent(jwcId))
                    templateParseProblem(
                        Tapestry.format(
                            "TemplateParser.unknown-component-id",
                            tagName,
                            Integer.toString(startLine),
                            jwcId),
                        startLocation,
                        startLine,
                        cursorStart);

                try
                {
                    allowBody = _delegate.getAllowBody(jwcId, startLocation);
                } catch (ApplicationRuntimeException e)
                {
                    // give subclasses a chance to handle and rethrow
                    templateParseProblem(e, startLine, cursorStart);
                }
            }
        }

        // Ignore the body if we're removing the entire tag,
        // of if the corresponding component doesn't allow
        // a body.

        boolean ignoreBody = !emptyTag && (isRemoveId || !allowBody);

        if (_ignoring && ignoreBody)
            templateParseProblem(
                Tapestry.format("TemplateParser.nested-ignore", tagName, Integer.toString(startLine)),
                new Location(_resourceLocation, startLine),
                startLine,
                cursorStart);

        if (!emptyTag)
            pushNewTag(tagName, startLine, isRemoveId, ignoreBody);

        // End any open block.

        addTextToken(cursorStart - 1);

        if (!isRemoveId)
        {
            addOpenToken(tagName, jwcId, type, startLocation);

            if (emptyTag)
                _tokens.add(_factory.createCloseToken(tagName, getCurrentLocation()));
        }

        advance();
    }