⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 abstractbodyparser.java

📁 Jamon是一个Java文本模板引擎
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
        {            handleAnnotationTag(p_tagLocation);        }        else        {            if (checkForTagClosure(p_tagLocation))            {                addError(p_tagLocation, "Unknown tag <%" + p_tagName + ">");            }        }    }    /**     * Handle a tag closure     * @param p_tagName The tag name     * @param p_tagLocation The tag location     * @throws IOException     */    @SuppressWarnings("unused") protected void handleTagClose(        final String p_tagName,        final Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, "Unexpected tag close </%" + p_tagName + ">");    }    /**     * This method is called when an end of file is reached, and should add an     * error if this is not acceptable     **/    abstract protected void handleEof();    /**     * Handle the occurence of a '&lt;/|;&gt;' tag     * @return <code>true</code> if this parser is done     * @throws IOException     **/    @SuppressWarnings("unused")    protected boolean handleNamedFragmentClose(Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, UNEXPECTED_NAMED_FRAGMENT_CLOSE_ERROR);        return false;    }    /**     * Handle the occurence of a '&lt;/&amp;&gt;' tag     * @return <code>true</code> if this parser is done     * @throws IOException     **/    @SuppressWarnings("unused")    protected boolean handleFragmentsClose(Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, UNEXPECTED_FRAGMENTS_CLOSE_ERROR);        return false;    }    /**     * @param p_tagLocation location of the def tag     */    @SuppressWarnings("unused")    protected void handleMethodTag(Location p_tagLocation) throws IOException    {        addError(            p_tagLocation,            "<%method> sections only allowed at the top level of a document");    }    /**     * @param p_tagLocation location of the def tag     */    @SuppressWarnings("unused")    protected void handleOverrideTag(Location p_tagLocation) throws IOException    {        addError(            p_tagLocation,            "<%override> sections only allowed at the top level of a document");    }    /**     * @param p_tagLocation location of the def tag     */    @SuppressWarnings("unused")    protected void handleDefTag(Location p_tagLocation) throws IOException    {        addError(            p_tagLocation,            "<%def> sections only allowed at the top level of a document");    }    @SuppressWarnings("unused")    protected void handleAbsMethodTag(Location p_tagLocation) throws IOException    {        addError(            p_tagLocation,            "<%absmeth> sections only allowed at the top level of a document");    }    private class ConditionEndDetector implements TagEndDetector    {        public ConditionEndDetector(String p_tagName)        {           m_tagName = p_tagName;        }        public int checkEnd(char p_char)        {            switch (p_char)            {                case '%' :                    m_seenPercent = true;                    return 0;                case '>' :                    if (m_seenPercent)                    {                        return 2;                    }                    else                    {                       m_seenPercent = false;                       return 0;                    }                default :                   m_seenPercent = false;                   return 0;            }        }        public ParserError getEofError(Location p_startLocation)        {            return new ParserError(               p_startLocation,               "Reached end of file while reading " + m_tagName + " tag");        }        public void resetEndMatch()        {        }        private boolean m_seenPercent = false;        private final String m_tagName;    }    protected void handleWhileTag(Location p_tagLocation) throws IOException    {        try        {            m_root.addSubNode(new WhileParser(                new WhileNode(                    p_tagLocation, readCondition(p_tagLocation, "while")),                m_reader,                m_errors)                .parse()                .getRootNode());        }        catch (ParserError e)        {            addError(e);        }    }    protected void handleForTag(Location p_tagLocation) throws IOException    {        try        {            m_root.addSubNode(new ForParser(                new ForNode(p_tagLocation, readCondition(p_tagLocation, "for")),                m_reader,                m_errors)                .parse()                .getRootNode());        }        catch (ParserError e)        {            addError(e);        }    }    protected void handleIfTag(Location p_tagLocation) throws IOException    {        try        {            IfParser parser = new IfParser(                new IfNode(p_tagLocation,                           readCondition(p_tagLocation, "if")),                m_reader,                m_errors);            parser.parse();            for ( ; parser != null; parser = parser.getContinuation() )            {                m_root.addSubNode(parser.getRootNode());            }        }        catch (ParserError e)        {            addError(e);        }    }    protected String readCondition(Location p_tagLocation, String p_tagName)        throws IOException, ParserError    {        if (!soakWhitespace())        {            throw new ParserError(                p_tagLocation, "Malformed <%" + p_tagName + " ...%> tag");        }        else        {            return readJava(                p_tagLocation,                new ConditionEndDetector("<%" + p_tagName + " ...%>"));        }    }    @SuppressWarnings("unused")    protected void handleElseTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, ENCOUNTERED_ELSE_TAG_WITHOUT_PRIOR_IF_TAG);    }    @SuppressWarnings("unused")    protected void handleElseIfTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, ENCOUNTERED_ELSEIF_TAG_WITHOUT_PRIOR_IF_TAG);    }    @SuppressWarnings("unused")    protected void handleParentArgsNode(Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, PARENT_ARGS_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleParentMarkerTag(Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, PARENT_MARKER_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleEscapeTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, ESCAPE_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleGenericTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, GENERIC_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleAnnotationTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, ANNOTATE_TAG_IN_SUBCOMPONENT);    }    private void handleJavaTag(final Location p_tagLocation)        throws IOException    {        if (readChar('>'))        {            handleJavaCode(p_tagLocation, new JavaTagEndDetector());        }        else        {            soakWhitespace();            handleJavaCode(p_tagLocation, new JavaSnippetTagEndDetector());        }    }    private void handleJavaCode(final Location p_tagLocation, TagEndDetector p_endTagDetector)    throws IOException    {        try        {            m_root.addSubNode(                new JavaNode(                    p_tagLocation,                    readJava(p_tagLocation, p_endTagDetector)));            soakWhitespace();        }        catch (ParserError e)        {            addError(e);        }    }    private static class JavaTagEndDetector extends AbstractTagEndDetector    {        public JavaTagEndDetector()        {            super("</%java>");        }    }    protected static class JavaSnippetTagEndDetector extends AbstractTagEndDetector    {        protected JavaSnippetTagEndDetector()        {            super("%>");        }    }    protected void handleLiteralTag(final Location p_tagLocation)        throws IOException    {        if (checkForTagClosure(p_tagLocation))        {            m_root.addSubNode(                new LiteralNode(                    p_tagLocation,                    readUntil("</%LITERAL>", p_tagLocation)));        }    }    @SuppressWarnings("unused")    protected void handleClassTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, CLASS_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleExtendsTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, EXTENDS_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleImplementsTag(Location p_tagLocation)        throws IOException    {        addError(p_tagLocation, IMPLEMENTS_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleImportTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, IMPORT_TAG_IN_SUBCOMPONENT);    }    @SuppressWarnings("unused")    protected void handleAliasesTag(Location p_tagLocation) throws IOException    {        addError(p_tagLocation, ALIASES_TAG_IN_SUBCOMPONENT);    }    private void handleDocTag(Location p_tagLocation) throws IOException    {        if (checkForTagClosure(p_tagLocation))        {            m_root.addSubNode(                new DocNode(p_tagLocation, readUntil("</%doc>", p_tagLocation)));        }        soakWhitespace();    }    protected String readTagName() throws IOException    {        StringBuilder buffer = new StringBuilder();        int c;        while ((c = m_reader.read()) >= 0            && !Character.isWhitespace((char) c)            && c != '>')        {            buffer.append((char) c);        }        if (c >= 0)        {            m_reader.unread(c);        }        return buffer.toString();    }    protected String readLine() throws IOException    {        int c;        StringBuilder line = new StringBuilder();        while ((c = m_reader.read()) >= 0)        {            line.append((char) c);            if (c == '\n')            {                break;            }        }        return line.toString();    }    public Node getRootNode()    {        return m_root;    }    protected StringBuilder m_text = new StringBuilder();    protected final Node m_root;    protected final Location m_bodyStart;    private boolean m_doneParsing;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -