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:net.naijatek.myalumni.util.date.DateConverterUtil.java

/**
 * This method converts a String to a date using the datePattern
 * //from  w  ww . j  av  a  2 s  .c o  m
 * @param strDate the date to convert (in format MM/dd/yyyy)
 * @return a date object
 * 
 * @throws ParseException
 */
public static Date convertStringToDate(String strDate) throws ParseException {
    Date aDate = null;

    try {
        if (log.isDebugEnabled()) {
            log.debug("converting date with pattern: " + getDatePattern());
        }

        aDate = convertStringToDate(getDatePattern(), strDate);
    } catch (ParseException pe) {
        log.error("Could not convert '" + strDate + "' to a date, throwing exception");
        pe.printStackTrace();
        throw new ParseException(pe.getMessage(), pe.getErrorOffset());

    }

    return aDate;
}

From source file:de.codesourcery.utils.xml.XmlHelper.java

public static List<Element> getNodeChildren(Element parent, String childTag, int minCount, int maxCount)
        throws ParseException {

    final List<Element> result = new LinkedList<Element>();

    if (parent != null) {

        NodeList list = parent.getChildNodes();

        for (int i = 0; i < list.getLength(); i++) {
            Node n = list.item(i);
            if (n.getNodeName().equals(childTag)) {
                if (n instanceof Element) {
                    result.add((Element) n);
                } else {
                    log.trace("getNodeChildren(): Ignoring non-Element " + n.getNodeName() + " , type "
                            + n.getNodeType());
                }//from   w  w  w. j av a 2s .co m
            }
        }
    }

    if (result.isEmpty() && minCount > 0) {
        final String msg = "XML is lacking required child tag <" + childTag + "> for parent tag <"
                + parent.getTagName() + ">";
        log.error("getElement(): " + msg);
        throw new ParseException(msg, -1);
    }

    if (maxCount > 0 && result.size() > maxCount) {
        final String msg = "XML may contain at most " + maxCount + " child tags <" + childTag
                + "> for parent tag <" + parent.getTagName() + ">";
        log.error("getElement(): " + msg);
        throw new ParseException(msg, -1);
    }
    return result;
}

From source file:com.asp.tranlog.TsvImporterMapper.java

/**
 * To find a date parser from the datetimeParsers array
 * //from  ww w  .j av  a  2 s.  c  om
 * @return
 */
protected Date parseTimestamp(byte[] byteVal, int colIdx) throws ParseException {
    Date rtnDate = null;
    String dateString = Bytes.toString(byteVal);
    if (colDatetimeFormater != null && colDatetimeFormater.length > colIdx) {
        int fmtrIdx = colDatetimeFormater[colIdx];
        try {
            rtnDate = datetimeParsers[fmtrIdx].parse(dateString);
        } catch (java.text.ParseException e) {
        }

        if (rtnDate == null) {
            for (int i = 0; i < datetimeParsers.length; i++) {
                try {
                    rtnDate = datetimeParsers[i].parse(dateString);
                } catch (java.text.ParseException e) {
                }
                if (rtnDate != null) {
                    colDatetimeFormater[colIdx] = (char) i;
                    break;
                }
            }
        }
    }
    if (rtnDate == null) {
        LOG.error("No supported data format found: " + dateString);
        throw new ParseException("Failed to parse date: " + dateString, 0);
    }
    return rtnDate;
}

From source file:NumericTextField.java

public Long getLongValue() throws ParseException {
    Number result = getNumberValue();
    if ((result instanceof Long) == false) {
        throw new ParseException("Not a valid long", 0);
    }/*from w  ww .  j  a v  a 2s.c  om*/

    return (Long) result;
}

From source file:org.apache.cassandra.jmeter.AbstractCassandaTestElement.java

private static int charToHexDigit(char ch) throws ParseException {
    int digit = Character.digit(ch, 16);
    if (digit == -1) {
        throw new ParseException("\"" + ch + "\" is an invalid character", 0);
    }/*w ww.  j  av a2 s . co m*/
    return digit;
}

From source file:org.sakaiproject.imagegallery.springutil.SqlScriptParser.java

/**
 * Parse a line of text to remove comments.
 * @param line The line to parse. The string must not have any new line,
 *            carriage return, or form feed characters. It also may not
 *            contain a double-quote outside of a string literal, and the
 *            statement delimiter character may only appear at the end of
 *            the line.// ww w .  ja  va  2s.co  m
 * @param sql String buffer that stores the result, which is appended to the
 *            end. When the method returns, it will contain the trimmed line
 *            with comments removed. If the line contains no usable SQL
 *            fragment, nothing is appended.
 * @param lineNumber Line number used for exceptions.
 * @throws ParseException 
 * @throws IllegalArgumentException if the line is null or contains one of
 *             the line terminating characters mentioned above.
 * @throws UncategorizedDataAccessException if parsing fails for some other reason.
 */
private static void parseLine(String line, StringBuffer sql, int lineNumber, char statementDelimiter) {

    // Parse line looking for single quote string delimiters. Anything
    // that's part of a string just passes through.
    StringTokenizer quoteTokenizer = new StringTokenizer(line, "'", true);
    // true if we're parsing through a string literal.
    boolean inLiteral = false;

    while (quoteTokenizer.hasMoreTokens()) {
        String token = quoteTokenizer.nextToken();
        if (token.equals("'")) {
            // Token is a string delimiter. Toggle "inLiteral" flag.
            inLiteral = !inLiteral;
        } else if (!inLiteral) {
            // Look for EOL comments.
            int commentIndex = indexOfComment(token);
            if (commentIndex >= 0) {
                // Truncate token to the comment marker.
                token = token.substring(0, commentIndex).trim();
            }

            // Thwart any attempt to use double-quote outside of a string
            // literal.
            if (token.indexOf("\"") >= 0) {
                throw new RuntimeException(
                        new ParseException("Double quote character" + " cannot be used in a string literal.",
                                token.indexOf("\"")));
            }
            // Thwart any attempt to have the statement delimiter embedded
            // in a line. Not supported at this point.
            int statementEndIndex = token.indexOf(statementDelimiter);
            if (statementEndIndex >= 0 && statementEndIndex != (token.length() - 1)) {
                throw new RuntimeException(new ParseException(
                        "SQL statement delimiter" + " embedded in a line. (Not supported at this point)",
                        statementEndIndex));
            }

            // If we've hit a comment, we're done with this line. Just
            // append the token and break out.
            if (commentIndex >= 0) {
                sql.append(token);
                break;
            }

        } // Else, we're in a string literal. Just let it pass through.
        sql.append(token);
    }

    if (inLiteral) {
        // If the inLiteral flag is set here, the line has an unterminated
        // string literal.
        throw new RuntimeException(new ParseException("Unterminated string literal.", 0));
    }
}

From source file:org.eclipse.mylyn.commons.net.HtmlStreamTokenizer.java

/**
 * Parses an HTML tag out of a string of characters.
 *//*from   w ww  . j  a  v  a2s .co  m*/
private static void parseTag(String s, HtmlTag tag, boolean escapeValues) throws ParseException {

    int i = 0;
    for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    if (i == s.length()) {
        throw new ParseException("parse empty tag", 0); //$NON-NLS-1$
    }

    int start = i;
    for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    tag.setTagName(s.substring(start, i));

    for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    if (i == s.length()) {
        return;
    } else {
        parseAttributes(tag, s, i, escapeValues);
        return;
    }
}

From source file:org.zotero.integration.ooo.comp.CommMessage.java

@SuppressWarnings("unchecked")
private Object execute(ArrayList<Object> message) throws Exception {
    String command = (String) message.get(0);
    ArrayList<Object> args = (ArrayList<Object>) message.get(1);

    if (command.equals("Application_getActiveDocument")) {
        Object[] out = { Comm.API_VERSION, Comm.application.getActiveDocumentID() };
        return out;
    } else {/*  w  w w .j a  va  2  s .c  o  m*/
        int documentID = (Integer) args.get(0);
        Document document = Comm.application.getDocument(documentID);

        if (command.equals("Document_displayAlert")) {
            return document.displayAlert((String) args.get(1), (Integer) args.get(2), (Integer) args.get(3));
        } else if (command.equals("Document_activate")) {
            document.activate();
        } else if (command.equals("Document_canInsertField")) {
            return document.canInsertField((String) args.get(1));
        } else if (command.equals("Document_cursorInField")) {
            ReferenceMark field = document.cursorInField((String) args.get(1));
            if (field != null) {
                Object[] out = { document.mMarkManager.getIDForMark(field), field.getCode(),
                        field.getNoteIndex() };
                return out;
            }
        } else if (command.equals("Document_getDocumentData")) {
            return document.getDocumentData();
        } else if (command.equals("Document_setDocumentData")) {
            document.setDocumentData((String) args.get(1));
        } else if (command.equals("Document_insertField")) {
            ReferenceMark field = document.insertField((String) args.get(1), (Integer) args.get(2));
            Object[] out = { document.mMarkManager.getIDForMark(field), field.getCode(), field.getNoteIndex() };
            return out;
        } else if (command.equals("Document_getFields")) {
            ArrayList<ReferenceMark> fields = document.getFields((String) args.get(1));

            // get codes and rawCodes
            int numFields = fields.size();
            int[] fieldIndices = new int[numFields];
            String[] fieldCodes = new String[numFields];
            int[] noteIndices = new int[numFields];

            for (int i = 0; i < numFields; i++) {
                ReferenceMark field = fields.get(i);
                fieldIndices[i] = document.mMarkManager.getIDForMark(field);
                fieldCodes[i] = field.getCode();
                noteIndices[i] = field.getNoteIndex();
            }

            Object[] out = { fieldIndices, fieldCodes, noteIndices };
            return out;
        } else if (command.equals("Document_setBibliographyStyle")) {
            ArrayList<Number> arrayList = (ArrayList<Number>) args.get(5);
            document.setBibliographyStyle((Integer) args.get(1), (Integer) args.get(2), (Integer) args.get(3),
                    (Integer) args.get(4), arrayList, (Integer) args.get(6));
        } else if (command.equals("Document_cleanup")) {
            document.cleanup();
        } else if (command.equals("Document_complete")) {
            document.complete();
        } else if (command.startsWith("Field_")) {
            ReferenceMark field = document.mMarkManager.getMarkForID((Integer) args.get(1));
            if (command.equals("Field_delete")) {
                field.delete();
            } else if (command.equals("Field_select")) {
                field.select();
            } else if (command.equals("Field_removeCode")) {
                field.removeCode();
            } else if (command.equals("Field_getText")) {
                return field.getText();
            } else if (command.equals("Field_setText")) {
                field.setText((String) args.get(2), (Boolean) args.get(3));
            } else if (command.equals("Field_getCode")) {
                return field.getCode();
            } else if (command.equals("Field_setCode")) {
                field.setCode((String) args.get(2));
            } else if (command.equals("Field_convert")) {
                document.convert(field, (String) args.get(2), (Integer) args.get(3));
            }
        } else {
            throw new ParseException(command, 0);
        }
    }
    return null;
}

From source file:org.apache.metron.rest.config.KnoxSSOAuthenticationFilterTest.java

@Test
public void doFilterShouldContinueOnParseException() throws Exception {
    KnoxSSOAuthenticationFilter knoxSSOAuthenticationFilter = spy(new KnoxSSOAuthenticationFilter(
            "userSearchBase", mock(Path.class), "knoxKeyString", "knoxCookie", mock(LdapTemplate.class)));
    HttpServletRequest request = mock(HttpServletRequest.class);
    ServletResponse response = mock(ServletResponse.class);
    FilterChain chain = mock(FilterChain.class);
    SignedJWT signedJWT = mock(SignedJWT.class);
    mockStatic(SignedJWT.class);

    when(request.getHeader("Authorization")).thenReturn(null);
    doReturn("serializedJWT").when(knoxSSOAuthenticationFilter).getJWTFromCookie(request);
    when(SignedJWT.parse("serializedJWT")).thenThrow(new ParseException("parse exception", 0));

    knoxSSOAuthenticationFilter.doFilter(request, response, chain);

    verify(knoxSSOAuthenticationFilter, times(0)).getAuthentication("userName", request);
    verify(chain).doFilter(request, response);
    verifyNoMoreInteractions(chain);//from w w w.  j a  v  a 2  s . c o  m
}

From source file:com.tasktop.internal.hp.qc.core.model.comments.mylyn3_8.HtmlStreamTokenizer_m3_8.java

/**
 * Parses an HTML tag out of a string of characters.
 */// w ww .j ava 2  s  .c o  m
private static void parseTag(String s, HtmlTag_m3_8 tag, boolean escapeValues) throws ParseException {

    int i = 0;
    for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    if (i == s.length()) {
        throw new ParseException("parse empty tag", 0); //$NON-NLS-1$
    }

    int start = i;
    for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    tag.setTagName(s.substring(start, i));

    for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) {
        // just move forward
    }
    if (i == s.length()) {
        return;
    } else {
        parseAttributes(tag, s, i, escapeValues);
        return;
    }
}