File Source: TrackbackLinkbackCommentValidator.java
/*
P/P * Method: org.apache.roller.weblogger.ui.rendering.plugins.comments.TrackbackLinkbackCommentValidator__static_init
*/
1 /*
2 * Licensed to the Apache Software Foundation (ASF) under one or more
3 * contributor license agreements. The ASF licenses this file to You
4 * under the Apache License, Version 2.0 (the "License"); you may not
5 * use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License. For additional information regarding
15 * copyright in this work, please see the NOTICE file in the top level
16 * directory of this distribution.
17 */
18
19 package org.apache.roller.weblogger.ui.rendering.plugins.comments;
20
21 import java.io.IOException;
22 import java.net.MalformedURLException;
23 import java.util.ResourceBundle;
24 import org.apache.roller.weblogger.business.WebloggerFactory;
25 import org.apache.roller.weblogger.config.WebloggerRuntimeConfig;
26 import org.apache.roller.weblogger.pojos.WeblogEntryComment;
27 import org.apache.roller.weblogger.util.LinkbackExtractor;
28 import org.apache.roller.weblogger.util.RollerMessages;
29
30 /**
31 * Validates comment if comment's URL links back to the comment's entry,
32 * intended for use with trackbacks only.
33 */
/*
P/P * Method: void org.apache.roller.weblogger.ui.rendering.plugins.comments.TrackbackLinkbackCommentValidator()
*
* Postconditions:
* init'ed(this.bundle)
*/
34 public class TrackbackLinkbackCommentValidator implements CommentValidator {
35
36 private ResourceBundle bundle = ResourceBundle.getBundle("ApplicationResources");
37
38 public String getName() {
/*
P/P * Method: String getName()
*
* Preconditions:
* this.bundle != null
*
* Postconditions:
* init'ed(return_value)
*/
39 return bundle.getString("comment.validator.trackbackLinkbackName");
40 }
41
42 public int validate(WeblogEntryComment comment, RollerMessages messages) {
43
44 // linkback validation can be toggled at runtime, so check if it's enabled
45 // if it's disabled then just return a score of 100
/*
P/P * Method: int validate(WeblogEntryComment, RollerMessages)
*
* Preconditions:
* (soft) comment != null
* (soft) messages != null
* (soft) messages.mErrors != null
* (soft) org/apache/roller/weblogger/util/LinkbackExtractor.mLogger != null
*
* Presumptions:
* org.apache.roller.weblogger.business.URLStrategy:getWeblogEntryURL(...)@53 != null
* org.apache.roller.weblogger.business.Weblogger:getUrlStrategy(...)@53 != null
* org.apache.roller.weblogger.business.WebloggerFactory:getWeblogger(...)@53 != null
* org.apache.roller.weblogger.pojos.WeblogEntryComment:getWeblogEntry(...)@53 != null
*
* Postconditions:
* return_value in {0, 100}
*
* Test Vectors:
* org.apache.roller.weblogger.config.WebloggerRuntimeConfig:getBooleanProperty(...)@46: {1}, {0}
*/
46 if(!WebloggerRuntimeConfig.getBooleanProperty("site.trackbackVerification.enabled")) {
47 return 100;
48 }
49
50 int ret = 0;
51 LinkbackExtractor linkback = null;
52 try {
53 linkback = new LinkbackExtractor(
54 comment.getUrl(),
55 WebloggerFactory.getWeblogger().getUrlStrategy().getWeblogEntryURL(
56 comment.getWeblogEntry().getWebsite(),
57 null,
58 comment.getWeblogEntry().getAnchor(),
59 true));
60 } catch (MalformedURLException ignored1) {
61 } catch (IOException ignored2) {}
62
63 if (linkback != null && linkback.getExcerpt() != null) {
64 ret = 100;
65 } else {
66 messages.addError("comment.validator.trackbackLinkbackMessage");
67 }
68 return ret;
69 }
70
71 }
SofCheck Inspector Build Version : 2.18479
| TrackbackLinkbackCommentValidator.java |
2009-Jan-02 14:24:48 |
| TrackbackLinkbackCommentValidator.class |
2009-Sep-04 03:12:45 |