8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2005 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
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 *
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 * opensso/legal/CDDLv1.0.txt
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * at opensso/legal/CDDLv1.0.txt.
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: XSDurationValidator.java,v 1.6 2008/06/25 05:42:31 qcheng Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/*
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted [2011] [ForgeRock AS]
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpackage com.sun.identity.common.validation;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.shared.validation.ValidationException;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster/**
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 *
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @deprecated As of OpenSSO version 8.0
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * {@link com.sun.identity.shared.validation.XSDurationValidator}
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterpublic class XSDurationValidator
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster extends ValidatorBase
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster{
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static XSDurationValidator instance = new XSDurationValidator();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static boolean debug = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /**
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Avoid instantiation of this class.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private XSDurationValidator() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static XSDurationValidator getInstance() {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return instance;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* validate the cache duration string */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void performValidation(String strData)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws ValidationException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
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 || (strData.trim().length() < 3)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // expecting this format P1Y2M4DT9H8M20S
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // first character should be a P
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (strData.charAt(0) != 'P') {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // time data validation
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String timeStr = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String dateStr = null;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (strData.indexOf('T') != -1) {
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 }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int strIndex = strData.indexOf("T");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster timeStr = strData.substring(strIndex+1,strData.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dateStr = strData.substring(1,strIndex);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else {
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 }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster dateStr = strData.substring(1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster processTimeStr(timeStr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster processDateStr(dateStr);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private int getIntegerValue(String strData, int start, int end)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws ValidationException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int value = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String str = strData.substring(start, end);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = Integer.parseInt(str);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (value < 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (NumberFormatException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private double getDoubleValue(String strData, int start, int end)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throws ValidationException
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster double value = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String str = strData.substring(start, end);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster value = Double.parseDouble(str);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (value < 0) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (NumberFormatException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return value;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Process the Time String in the Duration */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void processTimeStr(String timeStr) throws ValidationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (timeStr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((timeStr.indexOf("Y") != -1) || (timeStr.indexOf("D") != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
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 int idxH = timeStr.indexOf('H');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idxM = timeStr.indexOf('M');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idxS = timeStr.indexOf('S');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxH != -1) && ((idxM != -1 && idxM < idxH)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster || (idxS != -1 && idxS < idxH))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxM != -1) && (idxS != -1 && idxS < idxM)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start=0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxH != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int a = getIntegerValue(timeStr,start,idxH);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idxM = timeStr.indexOf('M',idxH+1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = idxH+1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxM != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int b = getIntegerValue(timeStr,start,idxM);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idxS = timeStr.indexOf('S',idxM +1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = idxM + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxS != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (timeStr.charAt(idxS-1) == '.') {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster resourceBundleName, "errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getDoubleValue(timeStr,start,idxS);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Process the Date String in the Duration */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void processDateStr(String dateStr) throws ValidationException {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (dateStr != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((dateStr.indexOf("H") != 1) && (dateStr.indexOf("S") != -1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idxY = dateStr.indexOf('Y');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idxM = dateStr.indexOf('M');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idxD = dateStr.indexOf('D');
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxY != -1) && ((idxM != -1 && idxM < idxY)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster || (idxD != -1 && idxD < idxY))) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((idxM != -1) && (idxD != -1 && idxD < idxM)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster throw new ValidationException(resourceBundleName,"errorCode4");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start = 0;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxY != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getIntegerValue(dateStr, start, idxY);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idxM = dateStr.indexOf('M',idxY+1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = idxY +1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxM != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getIntegerValue(dateStr,start,idxM);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster idxD = dateStr.indexOf('D',idxM+1);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster start = idxM + 1;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (idxD != -1) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster getIntegerValue(dateStr, start, idxD);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster /* Test */
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void main(String[] args) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (args[0] != null) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster debug = Boolean.valueOf(args[0]).booleanValue();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster XSDurationValidator inst = getInstance();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster try {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4D");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("PT9H8M1.1S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("PT9H");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("PT9M");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("PT9S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("PT9H8M111S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4DT9H8M20S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4D");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2MD");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4DT");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4DT1.S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("1Y2M4DT9H8MS");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4DT9H8M20S");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster inst.validate("P1Y2M4DT9H8MS");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch (ValidationException e) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println(e.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } catch(Exception ee ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster System.out.println("Error " + ee.getMessage());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster }
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster}