Example usage for java.text ParseException ParseException

List of usage examples for java.text ParseException ParseException

Introduction

In this page you can find the example usage for java.text ParseException ParseException.

Prototype

public ParseException(String s, int errorOffset) 

Source Link

Document

Constructs a ParseException with the specified detail message and offset.

Usage

From source file:cgeo.geocaching.cgBase.java

public Date parseGcCustomDate(String input) throws ParseException {
    if (StringUtils.isBlank(input)) {
        throw new ParseException("Input is null", 0);
    }//from www .j  a va2 s .c o  m

    input = input.trim();

    if (null != settings
            //&& null != settings.getGcCustomDate()
            && gcCustomDateFormats.containsKey(settings.getGcCustomDate())) {
        try {
            return gcCustomDateFormats.get(settings.getGcCustomDate()).parse(input);
        } catch (ParseException e) {
        }
    }

    for (SimpleDateFormat format : gcCustomDateFormats.values()) {
        try {
            return format.parse(input);
        } catch (ParseException e) {
        }
    }

    throw new ParseException("No matching pattern", 0);
}

From source file:io.warp10.continuum.gts.GTSHelper.java

/**
 * Parse labels selectors and return a map of label name to selector.
 * //  w  w  w .  j a  v  a 2 s. c  o m
 * The syntaxt of the 'selectors' String is:
 * 
 * NAME<TYPE>VALUE,NAME<TYPE>VALUE,...
 * 
 * where <TYPE> is either '=' for exact matches or '~' for regular expression matches.
 * NAME and VALUE are percent-encoded UTF-8 Strings.
 * 
 * @param selectors 
 * @return A map from label name to selector.
 */
public static final Map<String, String> parseLabelsSelectors(String selectors) throws ParseException {
    //
    // Split selectors on ',' boundaries
    //

    //String[] tokens = selectors.split(",");
    String[] tokens = UnsafeString.split(selectors, ',');

    //Iterable<String> tokens = Splitter.on(",").split(selectors);

    //
    // Loop over the tokens
    //

    Map<String, String> result = new HashMap<String, String>(tokens.length);

    for (String token : tokens) {

        token = token.trim();

        if ("".equals(token)) {
            continue;
        }

        //
        // Split on '=' or '~'
        //

        boolean exact = true;

        Iterable<String> stokens;

        String[] subtokens;

        if (token.contains("=")) {
            exact = true;
            //subtokens = token.split("=");
            subtokens = UnsafeString.split(token, '=');

            //stokens = Splitter.on("=").split(token);
        } else if (token.contains("~")) {
            exact = false;
            //subtokens = token.split("~");
            subtokens = UnsafeString.split(token, '~');

            //stokens = Splitter.on("~").split(token);
        } else {
            throw new ParseException(token, 0);
        }

        //Iterator<String> iter = stokens.iterator();

        //String name = iter.next();
        //String value = iter.hasNext() ? iter.next() : "";
        String name = subtokens[0];
        String value = subtokens.length > 1 ? subtokens[1] : "";

        try {
            if (name.contains("%")) {
                name = URLDecoder.decode(name, "UTF-8");
            }

            if (value.contains("%")) {
                value = URLDecoder.decode(value, "UTF-8");
            }
        } catch (UnsupportedEncodingException uee) {
            // Can't happen, we're using UTF-8 which is a standard JVM encoding.
        }

        result.put(name, (exact ? "=" : "~") + value);
    }

    return result;
}

From source file:edu.hawaii.soest.kilonalu.ctd.CTDParser.java

public void setMetadata(String xmlString) throws ParseException {
    logger.debug("CTDParser.setMetadata(xmlString) called.");

    try {//from  w w  w  .  j  a v  a2  s  .c o m
        // create an XML Document object from the instrument XML string
        XMLUtilities xmlUtil = new XMLUtilities();
        StringReader xmlReader = new StringReader(xmlString);
        this.xmlMetadata = xmlUtil.getXMLReaderAsDOMDocument(xmlReader);
        logger.debug(xmlUtil.getDOMTreeAsXPathMap(xmlMetadata.getDocumentElement()));

        // set the configuration metadata fields
        if (this.xmlMetadata.getDocumentElement().getTagName().equals("ConfigurationData")) {

            // Extract the metadata fields from the XML and populate the fields

            // set the device type field
            this.deviceType = xmlUtil
                    .getAttributeNodeWithXPath(xmlMetadata, "//ConfigurationData/@" + this.DEVICE_TYPE)
                    .getNodeValue().trim();
            logger.info("Device type is: " + this.deviceType);

            // set the instrument serial number field
            this.instrumentSerialNumber = xmlUtil.getAttributeNodeWithXPath(xmlMetadata,
                    "//ConfigurationData/@" + this.INSTRUMENT_SERIAL_NUMBER).getNodeValue().trim();
            logger.info("Instrument serial number is: " + this.instrumentSerialNumber);

            // set the pressure installed field
            this.pressureInstalled = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//ConfigurationData/" + this.PRESSURE_INSTALLED)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Pressure installed is: " + this.pressureInstalled);

            if (this.pressureInstalled.equals("yes")) {
                this.hasPressure = true;

            }

            // set the pump installed field
            this.pumpInstalled = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//ConfigurationData/" + this.PUMP_INSTALLED).getFirstChild()
                    .getNodeValue().trim();
            logger.info("Pump installed is: " + this.pumpInstalled);

            if (this.pumpInstalled.equals("yes")) {
                this.hasPump = true;

            }

            // set the minimum conductivity frequency field
            this.minimumConductivityFrequency = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//ConfigurationData/" + this.MINIMUM_CONDUCTIVITY_FREQUENCY)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Minimum conductivity frequency is: " + this.minimumConductivityFrequency);

            // set the output format field
            this.outputFormat = xmlUtil.getNodeWithXPath(xmlMetadata, "//ConfigurationData/SampleDataFormat")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Output format is: " + this.outputFormat);

            // set the output salinity state field
            this.outputSalinity = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//ConfigurationData/" + this.OUTPUT_SALINITY)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Output salinity state is: " + this.outputSalinity);

            if (this.outputSalinity.equals("yes")) {
                this.willOutputSalinity = true;

            }

            // set the output sound velocity state field
            this.outputSoundVelocity = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//ConfigurationData/" + this.OUTPUT_SOUND_VELOCITY)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Output sound velocity state is: " + this.outputSoundVelocity);

            if (this.outputSoundVelocity.equals("yes")) {
                this.willOutputSoundVelocity = true;

            }

            // set the output transmit real time state field
            this.transmitRealtime = xmlUtil.getNodeWithXPath(xmlMetadata, "//ConfigurationData/TxRealTime")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Transmit real time state is: " + this.transmitRealtime);

            if (this.transmitRealtime.equals("yes")) {

                // set the sampling mode to moored since profile mode doesn't support this
                this.samplingMode = "moored";
                logger.info("Sampling mode is: " + this.samplingMode);

            }

            // set the sample interval field
            this.sampleInterval = xmlUtil.getNodeWithXPath(xmlMetadata, "//ConfigurationData/SampleInterval")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Sample interval is: " + this.sampleInterval);

            // set the synchronization mode state field
            this.synchronizationMode = xmlUtil.getNodeWithXPath(xmlMetadata, "//ConfigurationData/SyncMode")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Synchronization mode state state is: " + this.synchronizationMode);

            this.hasConfigurationMetadata = true;

            // add the status metadata fields to the metadataValuesMap
        } else if (this.xmlMetadata.getDocumentElement().getTagName().equals("StatusData")) {

            this.deviceType = xmlUtil
                    .getAttributeNodeWithXPath(xmlMetadata, "//StatusData/@" + this.DEVICE_TYPE).getNodeValue()
                    .trim();
            logger.info("Device type is: " + this.deviceType);

            // set the instrument serial number field
            this.instrumentSerialNumber = xmlUtil
                    .getAttributeNodeWithXPath(xmlMetadata, "//StatusData/@" + this.INSTRUMENT_SERIAL_NUMBER)
                    .getNodeValue().trim();
            logger.info("Instrument serial number is: " + this.instrumentSerialNumber);

            // set the instrument date time field
            this.instrumentDateTime = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//StatusData/" + this.INSTRUMENT_DATE_TIME).getFirstChild()
                    .getNodeValue().trim();
            logger.info("Instrument date time is: " + this.instrumentDateTime);

            // set the number of instrument events field
            this.numberOfInstrumentEvents = xmlUtil
                    .getAttributeNodeWithXPath(xmlMetadata, "//StatusData/" + this.NUMBER_OF_INSTRUMENT_EVENTS)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Number of instrument events is: " + this.numberOfInstrumentEvents);

            // set the main battery voltage field
            this.mainBatteryVoltage = xmlUtil.getNodeWithXPath(xmlMetadata, "//StatusData/Power/vMain")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Main battery voltage is: " + this.mainBatteryVoltage);

            // set the lithium battery voltage field
            this.lithiumBatteryVoltage = xmlUtil.getNodeWithXPath(xmlMetadata, "//StatusData/Power/vLith")
                    .getFirstChild().getNodeValue().trim();
            logger.info("Lithium battery voltage is: " + this.lithiumBatteryVoltage);

            // set the number of bytes in memory field
            this.numberOfBytes = xmlUtil.getNodeWithXPath(xmlMetadata, "//StatusData/" + this.NUMBER_OF_BYTES)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Number of bytes in memory is: " + this.numberOfBytes);

            // set the number of samples in memory field
            this.numberOfSamples = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//StatusData/" + this.NUMBER_OF_SAMPLES).getFirstChild()
                    .getNodeValue().trim();
            logger.info("Number of samples in memory is: " + this.numberOfSamples);

            // set the number of available samples in memory field
            this.numberOfAvailableSamples = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//StatusData/" + this.NUMBER_OF_AVAILABLE_SAMPLES)
                    .getFirstChild().getNodeValue().trim();
            logger.info("Number of available samples in memory is: " + this.numberOfAvailableSamples);

            // set the number of bytes per sample in memory field
            this.sampleByteLength = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//StatusData/" + this.SAMPLE_BYTE_LENGTH).getFirstChild()
                    .getNodeValue().trim();
            logger.info("Number of bytes per sample in memory is: " + this.sampleByteLength);

            // set the autonomous sampling state field
            this.autonomousSampling = xmlUtil
                    .getNodeWithXPath(xmlMetadata, "//StatusData/" + this.AUTONOMOUS_SAMPLING).getFirstChild()
                    .getNodeValue().trim();
            logger.info("Autonomous sampling state is: " + this.autonomousSampling);

            this.hasStatusMetadata = true;

            // add the calibration metadata fields to the metadataValuesMap
        } else if (this.xmlMetadata.getDocumentElement().getTagName().equals("CalibrationCoefficients")) {

            NodeList calibrationList = xmlUtil.getNodeListWithXPath(this.xmlMetadata.getDocumentElement(),
                    "//CalibrationCoefficients/Calibration");

            // iterate through each calibration and set the metadata fields
            for (int itemNumber = 0; itemNumber < calibrationList.getLength(); itemNumber++) {
                Node calibrationNode = calibrationList.item(itemNumber);
                String idString = xmlUtil.getAttributeNodeWithXPath(calibrationNode, "@id").getNodeValue()
                        .trim();

                if (idString.equals("Temperature")) {

                    // set the temperature calibration format field
                    this.temperatureCalibrationFormat = xmlUtil
                            .getAttributeNodeWithXPath(calibrationNode, this.TEMPERATURE_CALIBRATION_FORMAT)
                            .getNodeValue().trim();
                    logger.info("Temperature calibration format is: " + this.temperatureCalibrationFormat);

                    // set the temperature serial number field
                    this.temperatureSerialNumber = xmlUtil.getNodeWithXPath(calibrationNode, "SerialNum")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature serial number is: " + this.temperatureSerialNumber);

                    // set the temperature calibration date field
                    this.temperatureCalibrationDate = xmlUtil.getNodeWithXPath(calibrationNode, "CalDate")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature calibration date is: " + this.temperatureCalibrationDate);

                    // set the temperature calibration A0 field
                    this.temperatureCoefficientTA0 = xmlUtil.getNodeWithXPath(calibrationNode, "A0")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature calibration A0 is: " + this.temperatureCoefficientTA0);

                    // set the temperature calibration A1 field
                    this.temperatureCoefficientTA1 = xmlUtil.getNodeWithXPath(calibrationNode, "A1")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature calibration A1 is: " + this.temperatureCoefficientTA1);

                    // set the temperature calibration A2 field
                    this.temperatureCoefficientTA2 = xmlUtil.getNodeWithXPath(calibrationNode, "A2")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature calibration A2 is: " + this.temperatureCoefficientTA2);

                    // set the temperature calibration A3 field
                    this.temperatureCoefficientTA3 = xmlUtil.getNodeWithXPath(calibrationNode, "A3")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Temperature calibration A3 is: " + this.temperatureCoefficientTA3);

                } else if (idString.equals("Conductivity")) {

                    // set the conductivity calibration format field
                    this.conductivityCalibrationFormat = xmlUtil
                            .getAttributeNodeWithXPath(calibrationNode, this.CONDUCTIVITY_CALIBRATION_FORMAT)
                            .getNodeValue().trim();
                    logger.info("Conductivity calibration format is: " + this.conductivityCalibrationFormat);

                    // set the conductivity serial number field
                    this.conductivitySerialNumber = xmlUtil.getNodeWithXPath(calibrationNode, "SerialNum")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity serial number is: " + this.conductivitySerialNumber);

                    // set the conductivity calibration date field
                    this.conductivityCalibrationDate = xmlUtil.getNodeWithXPath(calibrationNode, "CalDate")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration date is: " + this.conductivityCalibrationDate);

                    // set the conductivity calibration G field
                    this.conductivityCoefficientG = xmlUtil.getNodeWithXPath(calibrationNode, "G")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration G is: " + this.conductivityCoefficientG);

                    // set the conductivity calibration H field
                    this.conductivityCoefficientH = xmlUtil.getNodeWithXPath(calibrationNode, "H")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration H is: " + this.conductivityCoefficientH);

                    // set the conductivity calibration I field
                    this.conductivityCoefficientI = xmlUtil.getNodeWithXPath(calibrationNode, "I")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration I is: " + this.conductivityCoefficientI);

                    // set the conductivity calibration J field
                    this.conductivityCoefficientJ = xmlUtil.getNodeWithXPath(calibrationNode, "J")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration J is: " + this.conductivityCoefficientJ);

                    // set the conductivity calibration PCOR field
                    this.conductivityCoefficientCPCOR = xmlUtil.getNodeWithXPath(calibrationNode, "PCOR")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration PCOR is: " + this.conductivityCoefficientCPCOR);

                    // set the conductivity calibration TCOR field
                    this.conductivityCoefficientCTCOR = xmlUtil.getNodeWithXPath(calibrationNode, "TCOR")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration TCOR is: " + this.conductivityCoefficientCTCOR);

                    // set the conductivity calibration WBOTC field
                    this.conductivityCoefficientWBOTC = xmlUtil.getNodeWithXPath(calibrationNode, "WBOTC")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Conductivity calibration WBOTC is: " + this.conductivityCoefficientWBOTC);

                } else if (idString.equals("Pressure")) {

                    // set the pressure calibration format field
                    this.pressureCalibrationFormat = xmlUtil
                            .getAttributeNodeWithXPath(calibrationNode, this.PRESSURE_CALIBRATION_FORMAT)
                            .getNodeValue().trim();
                    logger.info("Pressure calibration format is: " + this.pressureCalibrationFormat);

                    // set the pressure serial number field
                    this.pressureSerialNumber = xmlUtil.getNodeWithXPath(calibrationNode, "SerialNum")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure serial number is: " + this.pressureSerialNumber);

                    // set the pressure calibration date field
                    this.pressureCalibrationDate = xmlUtil.getNodeWithXPath(calibrationNode, "CalDate")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration date is: " + this.pressureCalibrationDate);

                    // set the pressure calibration PA0 field
                    this.pressureCoefficientPA0 = xmlUtil.getNodeWithXPath(calibrationNode, "PA0")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PA0 is: " + this.pressureCoefficientPA0);

                    // set the pressure calibration PA1 field
                    this.pressureCoefficientPA1 = xmlUtil.getNodeWithXPath(calibrationNode, "PA1")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PA1 is: " + this.pressureCoefficientPA1);

                    // set the pressure calibration PA2 field
                    this.pressureCoefficientPA2 = xmlUtil.getNodeWithXPath(calibrationNode, "PA2")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PA2 is: " + this.pressureCoefficientPA2);

                    // set the pressure calibration PTCA0 field
                    this.pressureCoefficientPTCA0 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCA0")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCA0 is: " + this.pressureCoefficientPTCA0);

                    // set the pressure calibration PTCA1 field
                    this.pressureCoefficientPTCA1 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCA1")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCA1 is: " + this.pressureCoefficientPTCA1);

                    // set the pressure calibration PTCA2 field
                    this.pressureCoefficientPTCA2 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCA2")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCA2 is: " + this.pressureCoefficientPTCA2);

                    // set the pressure calibration PTCB0 field
                    this.pressureCoefficientPTCB0 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCB0")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCB0 is: " + this.pressureCoefficientPTCB0);

                    // set the pressure calibration PTCB1 field
                    this.pressureCoefficientPTCB1 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCB1")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCB1 is: " + this.pressureCoefficientPTCB1);

                    // set the pressure calibration PTCB2 field
                    this.pressureCoefficientPTCB2 = xmlUtil.getNodeWithXPath(calibrationNode, "PTCB2")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTCB2 is: " + this.pressureCoefficientPTCB2);

                    // set the pressure calibration PTEMPA0 field
                    this.pressureCoefficientPTEMPA0 = xmlUtil.getNodeWithXPath(calibrationNode, "PTEMPA0")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTEMPA0 is: " + this.pressureCoefficientPTEMPA0);

                    // set the pressure calibration PTEMPA1 field
                    this.pressureCoefficientPTEMPA1 = xmlUtil.getNodeWithXPath(calibrationNode, "PTEMPA1")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTEMPA1 is: " + this.pressureCoefficientPTEMPA1);

                    // set the pressure calibration PTEMPA2 field
                    this.pressureCoefficientPTEMPA2 = xmlUtil.getNodeWithXPath(calibrationNode, "PTEMPA2")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure calibration PTEMPA2 is: " + this.pressureCoefficientPTEMPA2);

                    // set the pressure calibration POFFSET field
                    this.pressureOffsetCoefficient = xmlUtil.getNodeWithXPath(calibrationNode, "POFFSET")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure offset calibration is: " + this.pressureOffsetCoefficient);

                    // set the pressure sensor range field
                    this.pressureSensorRange = xmlUtil.getNodeWithXPath(calibrationNode, "PRANGE")
                            .getFirstChild().getNodeValue().trim();
                    logger.info("Pressure sensor range is: " + this.pressureSensorRange);

                } else {
                    throw new ParseException("There was an error parsing the XML string. "
                            + "The calibration coefficient was not recognized. " + "The identifier was: "
                            + idString, 0);

                }
            }

            this.hasCalibrationMetadata = true;

            // add the event metadata fields to the metadataValuesMap
        } else if (this.xmlMetadata.getDocumentElement().getTagName().equals("EventCounters")) {

            this.hasEventMetadata = true;

            // add the hardware metadata fields to the metadataValuesMap
        } else if (this.xmlMetadata.getDocumentElement().getTagName().equals("HardwareData")) {

            this.hasHardwareMetadata = true;

        } else {
            throw new ParseException("The XML metadata is not recognized.", 0);
        }

    } catch (IOException ioe) {
        logger.info(
                "There was an error reading the XML metadata. " + "The error message was: " + ioe.getMessage());
        throw new ParseException(ioe.getMessage(), 0);

    } catch (TransformerException te) {
        logger.info("There was an error creating the XML configuration. " + "The error message was: "
                + te.getMessage());
        throw new ParseException(te.getMessage(), 0);

    }

}

From source file:com.clark.func.Functions.java

/**
 * <p>//from w  ww.  j  av  a2  s.c  o  m
 * Parses a string representing a date by trying a variety of different
 * parsers.
 * </p>
 * 
 * <p>
 * The parse will try each parse pattern in turn. A parse is only deemed
 * successful if it parses the whole of the input string. If no parse
 * patterns match, a ParseException is thrown.
 * </p>
 * 
 * @param str
 *            the date to parse, not null
 * @param parsePatterns
 *            the date format patterns to use, see SimpleDateFormat, not
 *            null
 * @param lenient
 *            Specify whether or not date/time parsing is to be lenient.
 * @return the parsed date
 * @throws IllegalArgumentException
 *             if the date string or pattern array is null
 * @throws ParseException
 *             if none of the date patterns were suitable
 * @see java.util.Calender#isLenient()
 */
private static Date parseDateWithLeniency(String str, String[] parsePatterns, boolean lenient)
        throws ParseException {
    if (str == null || parsePatterns == null) {
        throw new IllegalArgumentException("Date and Patterns must not be null");
    }

    SimpleDateFormat parser = new SimpleDateFormat();
    parser.setLenient(lenient);
    ParsePosition pos = new ParsePosition(0);
    for (int i = 0; i < parsePatterns.length; i++) {

        String pattern = parsePatterns[i];

        // LANG-530 - need to make sure 'ZZ' output doesn't get passed to
        // SimpleDateFormat
        if (parsePatterns[i].endsWith("ZZ")) {
            pattern = pattern.substring(0, pattern.length() - 1);
        }

        parser.applyPattern(pattern);
        pos.setIndex(0);

        String str2 = str;
        // LANG-530 - need to make sure 'ZZ' output doesn't hit
        // SimpleDateFormat as it will ParseException
        if (parsePatterns[i].endsWith("ZZ")) {
            str2 = str.replaceAll("([-+][0-9][0-9]):([0-9][0-9])$", "$1$2");
        }

        Date date = parser.parse(str2, pos);
        if (date != null && pos.getIndex() == str2.length()) {
            return date;
        }
    }
    throw new ParseException("Unable to parse the date: " + str, -1);
}