Package com.oroinc.text.regex

Examples of com.oroinc.text.regex.MatchResult


    {
        privateCheckHtml();
        boolean replacementOccured = false;
        while(true) {
            // Note: endtagM must be *after* starttagM.
            MatchResult starttagM = RegExp.match(cmdPattern("KfmIf", label), html);
            if(starttagM == null) {
                return replacementOccured;
            }

            int offset = starttagM.endOffset(0);
            String html2 = html.substring(offset);
            MatchResult endtagM = RegExp.match("\\</KfmIf\\s*\\>", html2);
            if(endtagM == null) {
                return replacementOccured;
            }
            replacementOccured = true;
            String replacement = (keep ? html.substring(starttagM.endOffset(0), endtagM.beginOffset(0) + offset) : "" );
            if(domark) {
                //D KFMSystem.log.detail("replaceAllKfmIf: mark!");
                replacement = markTag(starttagM.group(0)) + replacement + markTag(endtagM.group(0));
            }
            if(debug) {
                replacement = commentifyTag(starttagM.group(0)) + replacement + commentifyTag(endtagM.group(0));
            }
            //D KFMSystem.log.detail("Replace of Command KfmIf " + label + ": "
            //D                + html.substring(starttagM.endOffset(0), endtagM.beginOffset(0))
            //D                + " -> " + replacement);
            html = html.substring(0, starttagM.beginOffset(0))
                + replacement
                + html2.substring(endtagM.endOffset(0));
        }
    }
View Full Code Here


     */
    public String getKfmParam (String label, String param)
    {
        privateCheckHtml();
        //D KFMSystem.log.detail("get: " + label + " " + param);
        MatchResult starttagM = RegExp.match(cmdPattern("Kfm", label), html);
        if(starttagM == null) {
            //D KFMSystem.log.detail("label not found.");
            return "";
        }
        MatchResult valueM = RegExp.match(
            "\\s" + param + "\\s*=\\s*"
            // This will allow something like "...', and does *not* allow embedded ">".
            // Note that "group(1)" does not contain the quotes.
            // + "[\"']([^>\"']*)[\"']"
            // This will allow "...'..." and '..."...' and *does* allow embedded ">".
            // Note that "group(1)" now contains the quotes.
             + "((?:\"[^\"]*\")|(?:'[^']*'))"
            , starttagM.group(0));
        if(valueM == null) {
            //D KFMSystem.log.detail("param not found.");
            return "";
        }
        // Now we must strip the quotes.
        // return valueM.group(1);
        String t = valueM.group(1);
        t = t.replace('�', '>');
        return t.substring(1, t.length()-1);
    }
View Full Code Here

     */
    public boolean replaceKfm (String label, boolean aKeep, String aBefore, String aAfter)
    {
        privateCheckHtml();
        // This regexp ensures that start tag is before end tag.
        MatchResult elementM = null;
        String p = "";
        try {
            p = "(" + cmdPattern("Kfm", label) + ")"            /*group 1: start tag*/
    // This seems very suspect (WARNING: it can cause StackOverflow Errors!):
    //            + "((?:.|\\n)*?)"                             /*group 2: content*/
    // lets try: .*?
                + "(.*?)"                                       /*group 2: content replaced*/
                + "(" + "\\</Kfm\\s*\\>" + ")";                 /*group 3: end tag */
            elementM = RegExp.match(p, html, false, true);
        } catch(Error e) {
            mLog.error(
                "Template::replace,RegExp.match caused Error: " + e + "\n"
                + "Arguments: p = '" + p + "'\n"
                + "html = '" + html + "'");
            return false;
        }
        final int starttagI = 1;
        final int contentI  = 2;
        final int endtagI   = 3;

        if(elementM == null) return false;
        String replacement = aBefore + (aKeep ? elementM.group(contentI) : "") + aAfter;
        if(domark) {
            //D KFMSystem.log.detail("replaceKfm: mark!");
            replacement = markTag(elementM.group(starttagI))
                + replacement + markTag(elementM.group(endtagI));
        }
        if(debug) {
            replacement = commentifyTag(elementM.group(starttagI))
                + replacement + commentifyTag(elementM.group(endtagI));
        }
        html = html.substring(0, elementM.beginOffset(0))
            + replacement
            + html.substring(elementM.endOffset(0));
        //D KFMSystem.log.detail("Replace of Command Kfm " + label + ": " + elementM.group(0) + " -> " + replacement);
        return true;
    }
View Full Code Here

        boolean replacementOccured = super.replaceAllKfmIf(label, keep);

        for(int i = 1; i <= 3; ++i) {
            lWhile: while(true) {
                // Note: endtagM must be *after* starttagM.
                MatchResult starttagM = RegExp.match(cmdPattern("KfmIf" + i, label), html);
                if(starttagM == null) {
                    break lWhile;
                }

                int offset = starttagM.endOffset(0);
                String html2 = html.substring(offset);
                MatchResult endtagM = RegExp.match("\\</KfmIf" + i + "\\s*\\>", html2);
                if(endtagM == null) {
                    break lWhile;
                }
                replacementOccured = true;
                String replacement = (keep ? html.substring(starttagM.endOffset(0), endtagM.beginOffset(0) + offset) : "" );
                if(domark) {
                    replacement = markTag(starttagM.group(0)) + replacement + markTag(endtagM.group(0));
                }
                if(debug) {
                    replacement = commentifyTag(starttagM.group(0)) + replacement + commentifyTag(endtagM.group(0));
                }
                html = html.substring(0, starttagM.beginOffset(0))
                    + replacement
                    + html2.substring(endtagM.endOffset(0));
            }
        }
        return replacementOccured;
    }
View Full Code Here

TOP

Related Classes of com.oroinc.text.regex.MatchResult

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.