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:Main.java

/**
 * Create a new blank XML document./*from  ww  w  .  j  a v a 2  s  . c o m*/
 * 
 * @return The new blank XML document.
 * 
 * @throws IOException
 *             If there is an error creating the XML document.
 * @throws ParseException
 */
public static Document newDocument() throws ParseException {

    final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder;
    try {
        builder = builderFactory.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        final ParseException thrown = new ParseException(e.getMessage(), 0);
        throw thrown;
    }
    return builder.newDocument();
}

From source file:security.SecurityManager.java

public static JSONObject validateToken(String token, String stringKey) throws JOSEException, ParseException {

    if (token == null) {
        throw new ParseException("invalidToken", 0);
    }//from   www.j av a 2s .c om

    byte[] key = Base64.decodeBase64(stringKey);
    SignedJWT signedJWT = SignedJWT.parse(token);

    JWSVerifier verifier = new MACVerifier(key);

    if (!signedJWT.verify(verifier)) {
        throw new ParseException("invalidToken", 0);
    }

    if (signedJWT.getJWTClaimsSet().getExpirationTime().compareTo(new Date(System.currentTimeMillis())) <= 0) { //expired token

        throw new JOSEException("expiredToken");
    }

    return signedJWT.getPayload().toJSONObject();

}

From source file:com.haulmont.cuba.security.global.UserUtils.java

public static String formatName(String pattern, String firstName, String lastName, String middleName)
        throws ParseException {
    if (pattern == null || pattern.length() == 0)
        throw new ParseException("Pattern error", 0);
    if (firstName == null || firstName.equals("null"))
        firstName = "";
    if (lastName == null || lastName.equals("null"))
        lastName = "";
    if (middleName == null || middleName.equals("null"))
        middleName = "";
    String[] params = StringUtils.substringsBetween(pattern, "{", "}");
    int i;//  w ww.ja  v a 2s .  co  m
    for (i = 0; i < params.length; i++) {
        pattern = StringUtils.replace(pattern, "{" + params[i] + "}", "{" + i + "}", 1);
        params[i] = parseParam(params[i], firstName, lastName, middleName);
    }
    for (i = 0; i < params.length; i++) {
        pattern = StringUtils.replace(pattern, "{" + i + "}", params[i], 1);
    }
    return pattern;
}

From source file:Main.java

/**
 * This will parse an InputSource and create a DOM document.
 * //from ww  w.j  av  a 2  s  .co  m
 * @param is
 *            The stream to get the XML from.
 * @return The DOM document.
 * @throws IOException
 *             It there is an error creating the dom.
 * @throws ParseException
 */
public static Document parse(InputSource is) throws IOException, ParseException {

    final DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
    DocumentBuilder builder = null;
    try {
        builder = builderFactory.newDocumentBuilder();
    } catch (final ParserConfigurationException e) {
        final ParseException thrown = new ParseException(e.getMessage(), 0);
        throw thrown;
    }
    try {
        return builder.parse(is);
    } catch (final IOException e) {
        final IOException thrown = new IOException(e.getMessage());
        throw thrown;

    } catch (final SAXException e) {
        final ParseException thrown = new ParseException(e.getMessage(), 0);
        throw thrown;
    }

}

From source file:se.vgregion.webbisar.types.Hospital.java

public static Hospital fromLongString(String str) throws ParseException {
    if (isEmpty(str)) {
        throw new ParseException("String empty or null in Hospital enum!", 0);
    }/* w  ww  . j a  va2  s .  c o  m*/

    for (Hospital h : EnumSet.allOf(Hospital.class)) {
        if (h.getLongName().equals(str)) {
            return h;
        }
    }
    throw new ParseException(str + " not in range in Hospital enum!", 0);
}

From source file:tiled.plugins.json.JSONUtils.java

/**
 * This method takes an object that is JSONArray already or JSONObject and
 * convert it into JSONArray this is useful because JSON turn an xml entry
 * into array or object according to number of entries using this method
 * will avoid to treat as special cases whether you have one entrie or
 * several./*from  w  w  w  .  j ava 2s  .c  o  m*/
 *
 * @param obj
 * @return JSONArray
 * @throws ParseException
 */
public static JSONArray getAsJSONArray(Object obj) throws ParseException {
    // We always convert to a json array: json object become a json array
    // with one item
    JSONArray result = null;

    if (obj instanceof JSONArray) {
        result = (JSONArray) obj;
    } else if (obj instanceof JSONObject) {
        result = new JSONArray();
        result.put(obj);
    } else {
        throw new ParseException("problem while interpreting " + obj, 0);
    }

    return result;
}

From source file:com.microsoftopentechnologies.auth.jwt.JWTParser.java

/**
 * Absolutely basic, bare minimum implementation of JWT parsing as needed
 * for parsing the ID token returned by Azure Active Directory as
 * documented here - https://msdn.microsoft.com/en-us/library/azure/dn645542.aspx.
 *
 * @param jwtInput The ID token JWT string.
 * @return The JWT object representing the information encoded in the JWT.
 * @throws ParseException//w w  w.j  a  v  a  2  s .  c o m
 */
public static JWT parse(String jwtInput) throws ParseException {
    if (Strings.isNullOrEmpty(jwtInput)) {
        throw new ParseException("jwt string is null/empty.", 0);
    }

    // split the period delimited string
    List<String> tokens = Splitter.on('.').omitEmptyStrings().splitToList(jwtInput);

    // the length of the list MUST be 2 or more
    if (tokens.size() < 2) {
        throw new ParseException("Invalid JWT string supplied.", 0);
    }

    // parse JWT header and claims
    JsonParser jsonParser = new JsonParser();
    JsonObject header = (JsonObject) jsonParser.parse(stringFromBase64(tokens.get(0)));
    JsonObject claims = (JsonObject) jsonParser.parse(new String(Base64.decodeBase64(tokens.get(1))));

    return JWT.parse(header, claims);
}

From source file:com.etesync.syncadapter.journalmanager.util.ByteUtil.java

public static byte[][] split(byte[] input, int firstLength, int secondLength, int thirdLength)
        throws ParseException {
    if (input == null || firstLength < 0 || secondLength < 0 || thirdLength < 0
            || input.length < firstLength + secondLength + thirdLength) {
        throw new ParseException("Input too small: " + (input == null ? null : Hex.encodeHex(input)), 0);
    }/*from   w  w  w .java 2 s .c  om*/

    byte[][] parts = new byte[3][];

    parts[0] = new byte[firstLength];
    System.arraycopy(input, 0, parts[0], 0, firstLength);

    parts[1] = new byte[secondLength];
    System.arraycopy(input, firstLength, parts[1], 0, secondLength);

    parts[2] = new byte[thirdLength];
    System.arraycopy(input, firstLength + secondLength, parts[2], 0, thirdLength);

    return parts;
}

From source file:Main.java

/**
 * Parses an xs:dateTime attribute value, returning the parsed timestamp in milliseconds since
 * the epoch.//from  w  ww  .j av a2  s.c o  m
 *
 * @param value The attribute value to parse.
 * @return The parsed timestamp in milliseconds since the epoch.
 */
public static long parseXsDateTime(String value) throws ParseException {
    Matcher matcher = XS_DATE_TIME_PATTERN.matcher(value);
    if (!matcher.matches()) {
        throw new ParseException("Invalid date/time format: " + value, 0);
    }

    int timezoneShift;
    if (matcher.group(9) == null) {
        // No time zone specified.
        timezoneShift = 0;
    } else if (matcher.group(9).equalsIgnoreCase("Z")) {
        timezoneShift = 0;
    } else {
        timezoneShift = ((Integer.parseInt(matcher.group(12)) * 60 + Integer.parseInt(matcher.group(13))));
        if (matcher.group(11).equals("-")) {
            timezoneShift *= -1;
        }
    }

    Calendar dateTime = new GregorianCalendar(TimeZone.getTimeZone("GMT"));

    dateTime.clear();
    // Note: The month value is 0-based, hence the -1 on group(2)
    dateTime.set(Integer.parseInt(matcher.group(1)), Integer.parseInt(matcher.group(2)) - 1,
            Integer.parseInt(matcher.group(3)), Integer.parseInt(matcher.group(4)),
            Integer.parseInt(matcher.group(5)), Integer.parseInt(matcher.group(6)));
    if (!TextUtils.isEmpty(matcher.group(8))) {
        final BigDecimal bd = new BigDecimal("0." + matcher.group(8));
        // we care only for milliseconds, so movePointRight(3)
        dateTime.set(Calendar.MILLISECOND, bd.movePointRight(3).intValue());
    }

    long time = dateTime.getTimeInMillis();
    if (timezoneShift != 0) {
        time -= timezoneShift * 60000;
    }

    return time;
}

From source file:org.jbpm.formModeler.service.bb.mvc.components.FactoryURL.java

public static FactoryURL getURL(String value) throws ParseException {
    ParsePosition pPos = new ParsePosition(0);
    Object[] o = msgf.parse(value, pPos);
    if (o == null)
        throw new ParseException("Cannot parse " + value + ". Error at position " + pPos.getErrorIndex(),
                pPos.getErrorIndex());/*from   ww w.j ava 2  s  .c o m*/
    String componentName = StringEscapeUtils.unescapeHtml4((String) o[0]);
    String propertyName = StringEscapeUtils.unescapeHtml4((String) o[1]);
    return new FactoryURL(componentName, propertyName);
}