001/* 002 * This library is part of OpenCms - 003 * the Open Source Content Management System 004 * 005 * Copyright (C) Alkacon Software (http://www.alkacon.com) 006 * 007 * This library is free software; you can redistribute it and/or 008 * modify it under the terms of the GNU Lesser General Public 009 * License as published by the Free Software Foundation; either 010 * version 2.1 of the License, or (at your option) any later version. 011 * 012 * This library is distributed in the hope that it will be useful, 013 * but WITHOUT ANY WARRANTY; without even the implied warranty of 014 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 015 * Lesser General Public License for more details. 016 * 017 * For further information about Alkacon Software, please see the 018 * company website: http://www.alkacon.com 019 * 020 * For further information about OpenCms, please see the 021 * project website: http://www.opencms.org 022 * 023 * You should have received a copy of the GNU Lesser General Public 024 * License along with this library; if not, write to the Free Software 025 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 026 */ 027 028package org.opencms.acacia.client; 029 030import java.util.HashMap; 031import java.util.HashSet; 032import java.util.Map; 033import java.util.Set; 034 035/** 036 * The validation context. Keeps track of valid and invalid entity id's.<p> 037 */ 038public class CmsValidationContext { 039 040 /** The invalid entity id's. */ 041 private Map<String, String> m_invalidEntityIds; 042 043 /** The valid entity id's. */ 044 private Set<String> m_validEntityIds; 045 046 /** 047 * Constructor.<p> 048 */ 049 public CmsValidationContext() { 050 051 m_invalidEntityIds = new HashMap<String, String>(); 052 m_validEntityIds = new HashSet<String>(); 053 } 054 055 /** 056 * Adds an invalid entity id.<p> 057 * 058 * @param entityId the entity id 059 * @param invalidFields the invalid fields 060 */ 061 public void addInvalidEntity(String entityId, String invalidFields) { 062 063 m_validEntityIds.remove(entityId); 064 m_invalidEntityIds.put(entityId, invalidFields); 065 } 066 067 /** 068 * Adds a valid entity id.<p> 069 * 070 * @param entityId the entity id 071 */ 072 public void addValidEntity(String entityId) { 073 074 m_invalidEntityIds.remove(entityId); 075 m_validEntityIds.add(entityId); 076 } 077 078 /** 079 * Returns the invalid entity id's.<p> 080 * 081 * @return the invalid entity id's 082 */ 083 public Set<String> getInvalidEntityIds() { 084 085 return m_invalidEntityIds.keySet(); 086 } 087 088 /** 089 * Returns the invalid fields of the given entity.<p> 090 * 091 * @param entityId the entity id 092 * 093 * @return the invalid fields 094 */ 095 public String getInvalidFields(String entityId) { 096 097 return m_invalidEntityIds.get(entityId); 098 } 099 100 /** 101 * Returns the valid entity id's.<p> 102 * 103 * @return the valid entity id's 104 */ 105 public Set<String> getValidEntityIds() { 106 107 return m_validEntityIds; 108 } 109 110 /** 111 * Returns if there are any invalid entities.<p> 112 * 113 * @return <code>true</code> if there are any invalid entities 114 */ 115 public boolean hasValidationErrors() { 116 117 return !m_invalidEntityIds.isEmpty(); 118 } 119 120 /** 121 * Removes the given entity id, use when validating the entity is no longer required.<p> 122 * 123 * @param entityId the entity id 124 */ 125 public void removeEntityId(String entityId) { 126 127 m_invalidEntityIds.remove(entityId); 128 m_validEntityIds.remove(entityId); 129 } 130}