//# 0 errors, 54 messages
//#
/*
    //#ExcessLinksCommentValidator.java:1:1: class: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
    //#ExcessLinksCommentValidator.java:1:1: method: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init
 * Licensed to the Apache Software Foundation (ASF) under one or more
 *  contributor license agreements.  The ASF licenses this file to You
 * under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.  For additional information regarding
 * copyright in this work, please see the NOTICE file in the top level
 * directory of this distribution.
 */

package org.apache.roller.weblogger.ui.rendering.plugins.comments;

import java.util.ResourceBundle;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.roller.weblogger.config.WebloggerConfig;
import org.apache.roller.weblogger.pojos.WeblogEntryComment;
import org.apache.roller.weblogger.util.RollerMessages;

/**
 * Validates comment only if it has fewer links than comment.validator.excessSize.threshold
 */
public class ExcessLinksCommentValidator implements CommentValidator {
    private ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");  
    private Pattern linkPattern = Pattern.compile("<a\\s*href\\s*=");    
    private int threshold;
        
    public ExcessLinksCommentValidator() {
    //#ExcessLinksCommentValidator.java:36: method: void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()
    //#input(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): this
    //#output(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): this.bundle
    //#output(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): this.linkPattern
    //#output(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): this.threshold
    //#post(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): init'ed(this.bundle)
    //#post(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): init'ed(this.linkPattern)
    //#post(void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()): init'ed(this.threshold)
        threshold = WebloggerConfig.getIntProperty("comment.validator.excessLinks.threshold");
    //#ExcessLinksCommentValidator.java:37: Warning: method not available
    //#    -- call on int org.apache.roller.weblogger.config.WebloggerConfig:getIntProperty(String)
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
    //#    method: void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()
    //#    unanalyzed callee: int org.apache.roller.weblogger.config.WebloggerConfig:getIntProperty(String)
    }
    //#ExcessLinksCommentValidator.java:38: end of method: void org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator()
        
    public String getName() {
        return bundle.getString("comment.validator.excessLinksName");
    //#ExcessLinksCommentValidator.java:41: method: String org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.getName()
    //#input(String getName()): this
    //#input(String getName()): this.bundle
    //#output(String getName()): return_value
    //#pre[2] (String getName()): this.bundle != null
    //#post(String getName()): init'ed(return_value)
    //#ExcessLinksCommentValidator.java:41: end of method: String org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.getName()
    }

    public int validate(WeblogEntryComment comment, RollerMessages messages) {
        Matcher m = linkPattern.matcher(comment.getContent());
    //#ExcessLinksCommentValidator.java:45: method: int org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.validate(WeblogEntryComment, RollerMessages)
    //#ExcessLinksCommentValidator.java:45: Warning: method not available
    //#    -- call on String org.apache.roller.weblogger.pojos.WeblogEntryComment:getContent()
    //#    severity: INFORMATIONAL
    //#    class: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
    //#    method: int validate(WeblogEntryComment, RollerMessages)
    //#    unanalyzed callee: String org.apache.roller.weblogger.pojos.WeblogEntryComment:getContent()
    //#input(int validate(WeblogEntryComment, RollerMessages)): comment
    //#input(int validate(WeblogEntryComment, RollerMessages)): messages
    //#input(int validate(WeblogEntryComment, RollerMessages)): messages.__Tag
    //#input(int validate(WeblogEntryComment, RollerMessages)): messages.mErrors
    //#input(int validate(WeblogEntryComment, RollerMessages)): org/apache/roller/weblogger/util/RollerMessages.__Descendant_Table[org/apache/roller/weblogger/util/RollerMessages]
    //#input(int validate(WeblogEntryComment, RollerMessages)): org/apache/roller/weblogger/util/RollerMessages.__Descendant_Table[others]
    //#input(int validate(WeblogEntryComment, RollerMessages)): org/apache/roller/weblogger/util/RollerMessages.__Dispatch_Table.addError(Ljava/lang/String;Ljava/lang/String;)V
    //#input(int validate(WeblogEntryComment, RollerMessages)): this
    //#input(int validate(WeblogEntryComment, RollerMessages)): this.linkPattern
    //#input(int validate(WeblogEntryComment, RollerMessages)): this.threshold
    //#output(int validate(WeblogEntryComment, RollerMessages)): return_value
    //#pre[1] (int validate(WeblogEntryComment, RollerMessages)): comment != null
    //#pre[6] (int validate(WeblogEntryComment, RollerMessages)): this.linkPattern != null
    //#pre[2] (int validate(WeblogEntryComment, RollerMessages)): (soft) messages != null
    //#pre[3] (int validate(WeblogEntryComment, RollerMessages)): (soft) messages.__Tag == org/apache/roller/weblogger/util/RollerMessages
    //#pre[4] (int validate(WeblogEntryComment, RollerMessages)): (soft) messages.mErrors != null
    //#pre[7] (int validate(WeblogEntryComment, RollerMessages)): (soft) this.threshold <= 4_294_967_293
    //#presumption(int validate(WeblogEntryComment, RollerMessages)): java.util.regex.Pattern:matcher(...)@45 != null
    //#post(int validate(WeblogEntryComment, RollerMessages)): return_value in {0, 100}
    //#unanalyzed(int validate(WeblogEntryComment, RollerMessages)): Effects-of-calling:org.apache.roller.weblogger.util.RollerMessages$RollerMessage
    //#unanalyzed(int validate(WeblogEntryComment, RollerMessages)): Effects-of-calling:java.util.List:add
    //#test_vector(int validate(WeblogEntryComment, RollerMessages)): java.util.regex.Matcher:find(...)@47: {0}, {1}
        int count = 0;
        while (m.find()) {
            if (count++ > threshold) {
                messages.addError("comment.validator.excessLinksMessage", Integer.toString(threshold));
                return 0;
            }
        }
        return 100;
    //#ExcessLinksCommentValidator.java:53: end of method: int org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.validate(WeblogEntryComment, RollerMessages)
    }
    
}
    //#output(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/plugins/comments/ExcessLinksCommentValidator]
    //#output(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Dispatch_Table.getName()Ljava/lang/String;
    //#output(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Dispatch_Table.validate(Lorg/apache/roller/weblogger/pojos/WeblogEntryComment;Lorg/apache/roller/weblogger/util/RollerMessages;)I
    //#output(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): org/apache/roller/weblogger/ui/rendering/plugins/comments/CommentValidator.__Descendant_Table[org/apache/roller/weblogger/ui/rendering/plugins/comments/ExcessLinksCommentValidator]
    //#post(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Descendant_Table[org/apache/roller/weblogger/ui/rendering/plugins/comments/ExcessLinksCommentValidator] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): org/apache/roller/weblogger/ui/rendering/plugins/comments/CommentValidator.__Descendant_Table[org/apache/roller/weblogger/ui/rendering/plugins/comments/ExcessLinksCommentValidator] == &__Dispatch_Table
    //#post(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Dispatch_Table.getName()Ljava/lang/String; == &getName
    //#post(org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init): __Dispatch_Table.validate(Lorg/apache/roller/weblogger/pojos/WeblogEntryComment;Lorg/apache/roller/weblogger/util/RollerMessages;)I == &validate
    //#ExcessLinksCommentValidator.java:: end of method: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator.org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator__static_init
    //#ExcessLinksCommentValidator.java:: end of class: org.apache.roller.weblogger.ui.rendering.plugins.comments.ExcessLinksCommentValidator
