1 package org.apache.archiva.redback.policy; 2 3 /* 4 * Copyright 2001-2006 The Apache Software Foundation. 5 * 6 * Licensed under the Apache License, Version 2.0 (the "License"); 7 * you may not use this file except in compliance with the License. 8 * You may obtain a copy of the License at 9 * 10 * http://www.apache.org/licenses/LICENSE-2.0 11 * 12 * Unless required by applicable law or agreed to in writing, software 13 * distributed under the License is distributed on an "AS IS" BASIS, 14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 15 * See the License for the specific language governing permissions and 16 * limitations under the License. 17 */ 18 19 import org.apache.archiva.redback.users.Messages; 20 21 import java.util.ArrayList; 22 import java.util.List; 23 24 /** 25 * Password Rule Violations 26 * 27 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 28 * 29 */ 30 public class PasswordRuleViolations 31 { 32 private List<MessageReference> violations; 33 34 public static final class MessageReference 35 { 36 String key; 37 38 String[] args; 39 40 public String getKey() 41 { 42 return key; 43 } 44 45 public String[] getArgs() 46 { 47 return args; 48 } 49 } 50 51 /** 52 * Construct a Password Rule Violations object. 53 */ 54 public PasswordRuleViolations() 55 { 56 violations = new ArrayList<MessageReference>( 0 ); 57 } 58 59 /** 60 * Empty out the list of violations. 61 */ 62 public void reset() 63 { 64 violations.clear(); 65 } 66 67 /** 68 * Add a violation to the underlying list. 69 * 70 * @param key the bundle/localization key for the message. 71 */ 72 public void addViolation( String key ) 73 { 74 addViolation( key, null ); 75 } 76 77 /** 78 * Add a violation to the underlying list. 79 * 80 * @param key the bundle/localization key for the message. 81 * @param args the arguments for the message. 82 */ 83 public void addViolation( String key, String[] args ) 84 { 85 MessageReference mesgref = new MessageReference(); 86 mesgref.key = key; 87 mesgref.args = args; 88 violations.add( mesgref ); 89 } 90 91 /** 92 * Get the List of Violations as localized and post-processed {@link String}s. 93 * 94 * @return the List of {@link String} objects. 95 */ 96 public List<String> getLocalizedViolations() 97 { 98 List<String> msgs = new ArrayList<String>( violations.size() ); 99 100 for ( MessageReference msgref : violations ) 101 { 102 msgs.add( Messages.getString( msgref.key, msgref.args ) ); 103 } 104 105 return msgs; 106 } 107 108 /** 109 * Simple test to see if there are any violations. 110 * 111 * @return true if there are any violations. 112 */ 113 public boolean hasViolations() 114 { 115 return !violations.isEmpty(); 116 } 117 118 public List<MessageReference> getViolations() 119 { 120 return violations; 121 } 122 }