001package org.apache.archiva.redback.policy; 002 003/* 004 * Copyright 2001-2006 The Apache Software Foundation. 005 * 006 * Licensed under the Apache License, Version 2.0 (the "License"); 007 * you may not use this file except in compliance with the License. 008 * You may obtain a copy of the License at 009 * 010 * http://www.apache.org/licenses/LICENSE-2.0 011 * 012 * Unless required by applicable law or agreed to in writing, software 013 * distributed under the License is distributed on an "AS IS" BASIS, 014 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 015 * See the License for the specific language governing permissions and 016 * limitations under the License. 017 */ 018 019import org.apache.archiva.redback.users.Messages; 020 021import java.util.ArrayList; 022import java.util.List; 023 024/** 025 * Password Rule Violations 026 * 027 * @author <a href="mailto:joakim@erdfelt.com">Joakim Erdfelt</a> 028 * 029 */ 030public class PasswordRuleViolations 031{ 032 private List<MessageReference> violations; 033 034 public static final class MessageReference 035 { 036 String key; 037 038 String[] args; 039 040 public String getKey() 041 { 042 return key; 043 } 044 045 public String[] getArgs() 046 { 047 return args; 048 } 049 } 050 051 /** 052 * Construct a Password Rule Violations object. 053 */ 054 public PasswordRuleViolations() 055 { 056 violations = new ArrayList<MessageReference>( 0 ); 057 } 058 059 /** 060 * Empty out the list of violations. 061 */ 062 public void reset() 063 { 064 violations.clear(); 065 } 066 067 /** 068 * Add a violation to the underlying list. 069 * 070 * @param key the bundle/localization key for the message. 071 */ 072 public void addViolation( String key ) 073 { 074 addViolation( key, null ); 075 } 076 077 /** 078 * Add a violation to the underlying list. 079 * 080 * @param key the bundle/localization key for the message. 081 * @param args the arguments for the message. 082 */ 083 public void addViolation( String key, String[] args ) 084 { 085 MessageReference mesgref = new MessageReference(); 086 mesgref.key = key; 087 mesgref.args = args; 088 violations.add( mesgref ); 089 } 090 091 /** 092 * Get the List of Violations as localized and post-processed {@link String}s. 093 * 094 * @return the List of {@link String} objects. 095 */ 096 public List<String> getLocalizedViolations() 097 { 098 List<String> msgs = new ArrayList<String>( violations.size() ); 099 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}