Package java.text

Examples of java.text.ParseException


     * @return FTPFile
     * @throws ParseException
     */
    public FTPFile parse(String line) throws ParseException {
        if (parser.isMultiLine())
            throw new ParseException("Cannot use this method with multi-line parsers", 0);
        FTPFile file = null;
        try {
            file = parser.parse(line);
        }
        catch (DateParseException ex) {
View Full Code Here


            }
            return null;
        }
        else {
            Iterator i = hhmmFormatters.iterator();
            ParseException ex = null;
            while (i.hasNext()) {
                try {
                    hhmmFormatter = (SimpleDateFormat)i.next();
                    return hhmmFormatter.parse(ts);
                }
                catch (ParseException ignore) {
                    ex = ignore; // record last one
                }
            }
            if (!ignoreDateParseErrors)
                throw new DateParseException(ex.getMessage());
            hhmmFormatter = null; // none of them worked
            return null;
        }
    }
View Full Code Here

    private long parseSize(String value) throws ParseException {
        try {
            return Long.parseLong(value);
        }
        catch (NumberFormatException ex) {
            throw new ParseException("Failed to parse size: " + value, 0);
        }
    }
View Full Code Here

        try {
            StringTokenizer st = new StringTokenizer(mediaType, "/");
            m_primaryType = st.nextToken().trim().toLowerCase();
            m_subtype = st.nextToken(";").trim().toLowerCase().substring(1); // substring to remove the "/" first char
            if (m_primaryType.length() == 0 || m_subtype.length() == 0) {
                throw new ParseException("Type and subtype must contain values in '" + mediaType + "'", -1);
            }
            if (ignoreParameters) {
                m_parameterList = Collections.EMPTY_LIST;
            } else {
                m_parameterList = new ArrayList();
                while (st.hasMoreTokens()) {
                    addParameter(Parameter.parse(st.nextToken().trim()));
                }
            }
        } catch (NoSuchElementException e) {
            throw new ParseException("Unable to parse mediaType '" + mediaType + "'", -1);
        }
    }
View Full Code Here

        _content = _content.replaceAll("\\n", " ");
        _content = _content.replaceAll("\\t", " ");
        //_content = _content.trim();     
        _cursorRelative = _cursorAbsolute - _documentRegion.getOffset(); //- filteredCharsBeforeCursor;       
      } catch (BadLocationException e) {
        throw new ParseException("Unable to extract content of region.", _documentRegion.getOffset());
      }
     
      if (_content.startsWith("</tml:")) {
        // stop tag - parse tagname only
        _tagName = _content.substring(_content.indexOf("</tml:") + "</tml:".length(), _content.indexOf(">"));
        _tagName = _tagName.trim();
      } else if (_content.startsWith(TML_REGION_PREFIX)){
        // perform start tag parsing
       
       
        // parse tagname
        String tagContent = _content.substring(_content.indexOf(":") + 1);
        Set<String> tagNameStopWords = new HashSet<String>();
        tagNameStopWords.add(" ");
        tagNameStopWords.add("/>");
        tagNameStopWords.add(">");
        tagNameStopWords.add("\"");
        tagNameStopWords.add("<");
        //tagNameStopWords.add("\n");
        int tagnameEndPos = searchForward(tagNameStopWords, tagContent);
        if (tagnameEndPos == -1) {
          tagnameEndPos = _cursorRelative - TML_REGION_PREFIX.length();
        }
        _tagName = tagContent.substring(0, tagnameEndPos).trim();
       
        // parse attributes
        int attributesStart = TML_REGION_PREFIX.length() + _tagName.length();
        int attributesEnd = _content.length();
        if (_content.endsWith("/>")) {
          attributesEnd = attributesEnd - 2;
        } else if (_content.endsWith(">")) {
          attributesEnd = attributesEnd - 1;
        }
       
        String attributes = _content.substring(attributesStart, attributesEnd);
        attributes = attributes.replaceAll("\n", "");
        attributes = attributes.replaceAll("\r", "");
        if (attributes.contains("<tml:")) {
          // attribute section might contain <tml: start sequence if current tag partion is not closed yet and current tag is followed by another tml tag
          // remove this
          attributes = attributes.substring(0, attributes.indexOf("<tml:"));
        }
        attributes = attributes.trim();
        if (attributes.length() > 0) {
          attributes = WGUtils.strReplace(attributes, "\\\"", "$IG_APO$", true);
          attributes = WGUtils.strReplace(attributes, "\"\"", "\"$IG_EMPTY$\"", true);
          String[] attributeTokens = attributes.split("\"*\"");
          for (int i=0; i < attributeTokens.length; i += 2) {
            String key = attributeTokens[i];
            boolean valueless = false;
            if (!key.contains("=")) {
              valueless = true;
            }
            key = key.replaceAll("=", "");
            String value = null;
            if (key.contains(" ")) {           
              String[] keys = key.split(" ");
              key = keys[keys.length -1];         
              key = key.trim();
              // all other strings in key array are attributes without = and value - add to attribute list
              for (int j=0; j < keys.length - 1; j++) {
                String sValueless = keys[j].trim();
                if (sValueless.length() > 0) {               
                  _valuelessAttributes.add(sValueless.toLowerCase());
                }
              }
            }
            if ((i + 1) < attributeTokens.length) {
              value = attributeTokens[i + 1];
            }
            if (!valueless) {
              value = WGUtils.strReplace(value, "$IG_APO$", "\\\"", true);
              value = WGUtils.strReplace(value, "$IG_EMPTY$","", true);
              _attributes.put(key.toLowerCase(), value);
            } else {
              _valuelessAttributes.add(key.toLowerCase());
            }
          }
        }
      }
    } catch (ParseException e) {
      throw e;
    } catch (Exception e) {
      throw new ParseException("Unknown parsing error '" + e.getMessage() + "'", -1);
    }
  }
View Full Code Here

        readToken();
        return token;
    }

    private RuntimeException getSyntaxException(String message) {
        return new RuntimeException(message, new ParseException(source, current.index));
    }
View Full Code Here

        }
        return s.substring(0, i);
    }

    private static RuntimeException getFormatException(String s, int i) {
        return new RuntimeException(new ParseException(s, i));
    }
View Full Code Here

                return parseWGA52Log(content);
            } else if (content.contains("WARN TML warning - Layout:")) {
                return parseWGA53Log(content);             
            }
        }
        throw new ParseException("Unable to parse TMLWarning", -1);
    }
View Full Code Here

                }          
            }
           
            return warning;
        } catch (Exception e) {
            ParseException ex = new ParseException("Unable to parse TMLWarning: " + e.getMessage(), -1);
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
    }
View Full Code Here

                }          
            }
           
            return warning;
        } catch (Exception e) {
            ParseException ex = new ParseException("Unable to parse TMLWarning: " + e.getMessage(), -1);
            ex.setStackTrace(e.getStackTrace());
            throw ex;
        }
    }
View Full Code Here

TOP

Related Classes of java.text.ParseException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.