8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: XSDurationValidator.java,v 1.6 2008/06/25 05:42:31 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.validation.ValidationException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Validator for <code>xs:duration</code> format.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The validation of the cache duration is done based on the following:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If the number of years, months, days, hours, minutes, or seconds in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * any expression equals zero, the number and its corresponding
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * designator may be omitted. However, at least one number and its
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * designator must be present.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The seconds part may have a decimal fraction.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The designator 'T' must be absent if and only if all of the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * time items are absent.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The designator 'P' must always be present.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @deprecated As of OpenSSO version 8.0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * {@link com.sun.identity.shared.validation.XSDurationValidator}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static XSDurationValidator instance = new XSDurationValidator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Avoid instantiation of this class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static XSDurationValidator getInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* validate the cache duration string */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void performValidation(String strData)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // if the string is null or empty or less then 3 charactors
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // then throw error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((strData == null) || (strData.trim().length() == 0)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // expecting this format P1Y2M4DT9H8M20S
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // first character should be a P
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // time data validation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // T without time elements H M S error
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (strData.charAt(strData.length()-1) == 'T' ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster timeStr = strData.substring(strIndex+1,strData.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // time elements without T not allowed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (strData.indexOf("H") != -1 || strData.indexOf("S") != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int getIntegerValue(String strData, int start, int end)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private double getDoubleValue(String strData, int start, int end)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Process the Time String in the Duration */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void processTimeStr(String timeStr) throws ValidationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((timeStr.indexOf("Y") != -1) || (timeStr.indexOf("D") != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Seconds should be preceded by a decimal number , if there
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // is a "." then should have some number after it.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxH != -1) && ((idxM != -1 && idxM < idxH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxM != -1) && (idxS != -1 && idxS < idxM)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Process the Date String in the Duration */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void processDateStr(String dateStr) throws ValidationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((dateStr.indexOf("H") != 1) && (dateStr.indexOf("S") != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxY != -1) && ((idxM != -1 && idxM < idxY)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxM != -1) && (idxD != -1 && idxD < idxM)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug = Boolean.valueOf(args[0]).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Error " + ee.getMessage());