java.text.ParseException#getLocalizedMessage ( )源码实例Demo

下面列出了java.text.ParseException#getLocalizedMessage ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: sis   文件: AbstractParser.java
/**
 * Creates the object from a string and log the warnings if any.
 * This method is for implementation of {@code createFromWKT(String)} method is SIS factories only.
 *
 * @param  text  coordinate system encoded in Well-Known Text format (version 1 or 2).
 * @return the result of parsing the given text.
 * @throws FactoryException if the object creation failed.
 *
 * @see org.apache.sis.referencing.factory.GeodeticObjectFactory#createFromWKT(String)
 * @see org.apache.sis.referencing.operation.transform.DefaultMathTransformFactory#createFromWKT(String)
 */
@Override
public final Object createFromWKT(final String text) throws FactoryException {
    final Object value;
    try {
        value = parseObject(text, new ParsePosition(0));
    } catch (ParseException exception) {
        final Throwable cause = exception.getCause();
        if (cause instanceof FactoryException) {
            throw (FactoryException) cause;
        }
        throw new FactoryException(exception.getLocalizedMessage(), exception);
    }
    final Warnings warnings = getAndClearWarnings(value);
    if (warnings != null) {
        log(new LogRecord(Level.WARNING, warnings.toString()));
    }
    return value;
}
 
源代码2 项目: sis   文件: LocalizedParseExceptionTest.java
/**
 * Tests the {@link LocalizedParseException} constructor using the default string.
 * This method also tests {@link Exceptions#getLocalizedMessage(Throwable, Locale)}
 * as a side-effect.
 */
@Test
public void testAutomaticMessage() {
    final ParsePosition pos = new ParsePosition(0);
    pos.setErrorIndex(5);
    final ParseException e = new LocalizedParseException(
            Locale.CANADA, Angle.class, "Some text to parse", pos);
    String message = e.getLocalizedMessage();
    assertTrue(message, message.contains("Some text to parse"));
    assertTrue(message, message.contains("can not be parsed"));
    assertTrue(message, message.contains("Angle"));

    assertEquals(message, Exceptions.getLocalizedMessage(e, Locale.CANADA));
    message = Exceptions.getLocalizedMessage(e, Locale.FRANCE);
    assertTrue(message, message.contains("Some text to parse"));
    assertTrue(message, message.contains("n’est pas reconnu"));
    assertTrue(message, message.contains("Angle"));
}
 
源代码3 项目: cuba   文件: DoubleMinValidator.java
@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }

    NumberConstraint constraint = null;

    if (value instanceof Number) {
        constraint = getNumberConstraint((Number) value);
    } else if (value instanceof String) {
        try {
            Datatype datatype = datatypeRegistry.getNN(Double.class);
            Locale locale = userSessionSource.getUserSession().getLocale();
            Double num = (Double) datatype.parse((String) value, locale);
            if (num == null) {
                fireValidationException(value);
            }
            constraint = getNumberConstraint(num);
        } catch (ParseException e) {
            throw new ValidationException(e.getLocalizedMessage());
        }
    }

    if (constraint == null
            || value instanceof BigDecimal
            || value instanceof Float) {
        throw new IllegalArgumentException("DoubleMinValidator doesn't support following type: '" + value.getClass() + "'");
    }

    if (!constraint.isDoubleMin(min, inclusive)) {
        fireValidationException(value);
    }
}
 
源代码4 项目: cuba   文件: DecimalMinValidator.java
@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }

    NumberConstraint constraint = null;

    if (value instanceof Number) {
        constraint = getNumberConstraint((Number) value);
    } else if (value instanceof String) {
        try {
            Datatype datatype = datatypeRegistry.getNN(BigDecimal.class);
            Locale locale = userSessionSource.getUserSession().getLocale();
            BigDecimal bigDecimal = (BigDecimal) datatype.parse((String) value, locale);
            if (bigDecimal == null) {
                fireValidationException(value);
            }
            constraint = getNumberConstraint(bigDecimal);
        } catch (ParseException e) {
            throw new ValidationException(e.getLocalizedMessage());
        }
    }

    if (constraint == null
            || value instanceof Double
            || value instanceof Float) {
        throw new IllegalArgumentException("DecimalMinValidator doesn't support following type: '" + value.getClass() + "'");
    }

    if (!constraint.isDecimalMin(min, inclusive)) {
        fireValidationException(value);
    }
}
 
源代码5 项目: cuba   文件: DecimalMaxValidator.java
@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }

    NumberConstraint constraint = null;

    if (value instanceof Number) {
        constraint = getNumberConstraint((Number) value);
    } else if (value instanceof String) {
        try {
            Datatype datatype = Datatypes.getNN(BigDecimal.class);
            Locale locale = userSessionSource.getUserSession().getLocale();
            BigDecimal bigDecimal = (BigDecimal) datatype.parse((String) value, locale);
            if (bigDecimal == null) {
                fireValidationException(value);
            }
            constraint = getNumberConstraint(bigDecimal);
        } catch (ParseException e) {
            throw new ValidationException(e.getLocalizedMessage());
        }
    }

    if (constraint == null
            || value instanceof Double
            || value instanceof Float) {
        throw new IllegalArgumentException("DecimalMaxValidator doesn't support following type: '" + value.getClass() + "'");
    }

    if (!constraint.isDecimalMax(max, inclusive)) {
        fireValidationException(value);
    }
}
 
源代码6 项目: cuba   文件: DoubleMaxValidator.java
@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }

    NumberConstraint constraint = null;

    if (value instanceof Number) {
        constraint = getNumberConstraint((Number) value);
    } else if (value instanceof String) {
        try {
            Datatype datatype = datatypeRegistry.getNN(Double.class);
            Locale locale = userSessionSource.getUserSession().getLocale();
            Double num = (Double) datatype.parse((String) value, locale);
            if (num == null) {
                fireValidationException(value);
            }
            constraint = getNumberConstraint(num);
        } catch (ParseException e) {
            throw new ValidationException(e.getLocalizedMessage());
        }
    }

    if (constraint == null
            || value instanceof BigDecimal
            || value instanceof Float) {
        throw new IllegalArgumentException("DoubleMaxValidator doesn't support following type: '" + value.getClass() + "'");
    }

    if (!constraint.isDoubleMax(max, inclusive)) {
        fireValidationException(value);
    }
}
 
源代码7 项目: cuba   文件: DigitsValidator.java
@Override
public void accept(T value) throws ValidationException {
    // consider null value is valid
    if (value == null) {
        return;
    }

    NumberConstraint constraint = null;

    if (value instanceof Number) {
        constraint = getNumberConstraint((Number) value);
    } else if (value instanceof String) {
        try {
            Datatype datatype = Datatypes.getNN(BigDecimal.class);
            Locale locale = userSessionSource.getUserSession().getLocale();
            BigDecimal bigDecimal = (BigDecimal) datatype.parse((String) value, locale);
            if (bigDecimal == null) {
                fireValidationException(value);
            }
            constraint = getNumberConstraint(bigDecimal);
        } catch (ParseException e) {
            throw new ValidationException(e.getLocalizedMessage());
        }
    }

    if (constraint == null
            || value instanceof Double
            || value instanceof Float) {
        throw new IllegalArgumentException("DigitsValidator doesn't support following type: '" + value.getClass() + "'");
    }

    if (!constraint.isDigits(integer, fraction)) {
        fireValidationException(value);
    }
}
 
源代码8 项目: che   文件: ThreadPullLauncher.java
@Override
public void scheduleCron(Runnable runnable, String cron) {
  if (cron == null || cron.isEmpty()) {
    throw new ConfigurationException("Cron parameter can't be null");
  }
  try {
    CronExpression expression = new CronExpression(cron);
    service.schedule(runnable, expression);
    LOG.debug("Schedule method {} with cron  {} schedule", runnable, cron);
  } catch (ParseException e) {
    LOG.error(e.getLocalizedMessage(), e);
    throw new ConfigurationException(e.getLocalizedMessage());
  }
}
 
源代码9 项目: Llunatic   文件: DateComparator.java
@Override
public int compare(IValue v1, IValue v2) {
    try {
        Date d1 = dateFormat.parse(v1.toString());
        Date d2 = dateFormat.parse(v2.toString());
        return d1.compareTo(d2);
    } catch (ParseException ex) {
        throw new ChaseException("Unable to parse float value " + ex.getLocalizedMessage());
    }
}
 
源代码10 项目: sis   文件: LocalizedParseExceptionTest.java
/**
 * Tests the {@link LocalizedParseException} constructor using a given resource key
 * and the text that we failed to parse.
 */
@Test
public void testResourceKeyForText() {
    final ParseException e = new LocalizedParseException(
            Locale.CANADA, Errors.Keys.NodeHasNoParent_1, new Object[] {"text"}, 5);
    String message = e.getLocalizedMessage();
    assertTrue(message, message.contains("Node “text” has no parent."));
}
 
源代码11 项目: birt   文件: JSEditor.java
/**
 * Validates the contents of this editor.
 */
public void doValidate( )
{
	Image image = null;
	String message = null;

	if ( scriptValidator == null )
	{
		return;
	}

	try
	{
		scriptValidator.validate( true, true );
		image = ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_SCRIPT_NOERROR );
		message = Messages.getString( "JSEditor.Validate.NoError" ); //$NON-NLS-1$
	}
	catch ( ParseException e )
	{
		image = ReportPlatformUIImages.getImage( IReportGraphicConstants.ICON_SCRIPT_ERROR );
		message = e.getLocalizedMessage( );
	}
	finally
	{
		setValidateIcon( image, message );
		setFocus( );
	}
}
 
源代码12 项目: XACML   文件: IpAddressValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			IPAddress.newInstance((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized IP Address");
}
 
源代码13 项目: XACML   文件: DateTimeValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			ISO8601DateTime.fromISO8601DateTimeString((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized DateTime");
}
 
源代码14 项目: XACML   文件: RFC822NameValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			RFC822Name.newInstance((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized RFC822 Name");
}
 
源代码15 项目: XACML   文件: TimeValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			ISO8601Time.fromISO8601TimeString((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized Time");
}
 
源代码16 项目: XACML   文件: DNSNameValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			RFC2396DomainName.newInstance((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized DNS Name");
}
 
源代码17 项目: XACML   文件: YearMonthDurationValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			XPathYearMonthDuration.newInstance((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized YearMonthDuration");
}
 
源代码18 项目: XACML   文件: DayTimeDurationValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			XPathDayTimeDuration.newInstance((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized DayTimeDuration");
}
 
源代码19 项目: XACML   文件: DateValidator.java
@Override
public void validate(Object value) throws InvalidValueException {
	if (value instanceof String) {
		try {
			ISO8601Date.fromISO8601DateString((String) value);
		} catch (ParseException e) {
			throw new InvalidValueException(e.getLocalizedMessage());
		}
	} else
		throw new InvalidValueException("Unrecognized Date");
}
 
源代码20 项目: birt   文件: ScriptValidator.java
/**
 * Validates the current script, and selects the error if the specified falg
 * is <code>true</code>.
 * 
 * @param isFunctionBody
 *            <code>true</code> if a function body is validated,
 *            <code>false</code> otherwise.
 * @param isErrorSelected
 *            <code>true</code> if error will be selected after
 *            validating, <code>false</code> otherwise.
 * @throws ParseException
 *             if an syntax error is found.
 */
public void validate( boolean isFunctionBody, boolean isErrorSelected )
		throws ParseException
{
	if ( scriptViewer == null )
	{
		return;
	}

	clearAnnotations( );

	StyledText textField = scriptViewer.getTextWidget( );

	if ( textField == null || !textField.isEnabled( ) )
	{
		return;
	}

	String functionTag = "function(){"; //$NON-NLS-1$
	IDocument document = scriptViewer.getDocument( );
	String text = document == null ? null : scriptViewer.getDocument( )
			.get( );

	String script = text;

	if ( isFunctionBody )
	{
		script = functionTag + script + "\n}"; //$NON-NLS-1$
	}

	try
	{
		validateScript( script );
	}
	catch ( ParseException e )
	{
		int offset = e.getErrorOffset( );

		if ( isFunctionBody )
		{
			offset -= functionTag.length( );
			while ( offset >= text.length( ) )
			{
				offset--;
			}
		}

		String errorMessage = e.getLocalizedMessage( );
		Position position = getErrorPosition( text, offset );

		if ( position != null )
		{
			IAnnotationModel annotationModel = scriptViewer.getAnnotationModel( );

			if ( annotationModel != null )
			{
				annotationModel.addAnnotation( new Annotation( IReportGraphicConstants.ANNOTATION_ERROR,
						true,
						errorMessage ),
						position );
			}
			if ( isErrorSelected )
			{
				if ( scriptViewer instanceof SourceViewer )
				{
					( (SourceViewer) scriptViewer ).setSelection( new TextSelection( position.getOffset( ),
							position.getLength( ) ) );
				}
				scriptViewer.revealRange( position.getOffset( ),
						position.getLength( ) );
			}
		}
		throw new ParseException( e.getLocalizedMessage( ), position.offset );
	}
}