List of usage examples for java.text ParseException ParseException
public ParseException(String s, int errorOffset)
From source file:org.cometd.common.Jackson2JSONContext.java
public T[] parse(Reader reader) throws ParseException { try {/*from w ww. j a v a2 s . com*/ return getObjectMapper().readValue(reader, rootArrayType); } catch (IOException x) { throw (ParseException) new ParseException("", -1).initCause(x); } }
From source file:org.unitedinternet.cosmo.model.text.XhtmlTicketFormat.java
public Ticket parse(String source, EntityFactory entityFactory) throws ParseException { String key = null;//from w w w.j a v a2 s .c o m TicketType type = null; Integer timeout = null; try { if (source == null) { throw new ParseException("Source has no XML data", -1); } StringReader sr = new StringReader(source); XMLStreamReader reader = createXmlReader(sr); boolean inTicket = false; while (reader.hasNext()) { reader.next(); if (!reader.isStartElement()) { continue; } if (hasClass(reader, "ticket")) { if (LOG.isDebugEnabled()) { LOG.debug("found ticket element"); } inTicket = true; continue; } if (inTicket && hasClass(reader, "key")) { if (LOG.isDebugEnabled()) { LOG.debug("found key element"); } key = reader.getElementText(); if (StringUtils.isBlank(key)) { handleParseException("Key element must not be empty", reader); } continue; } if (inTicket && hasClass(reader, "type")) { if (LOG.isDebugEnabled()) { LOG.debug("found type element"); } String typeId = reader.getAttributeValue(null, "title"); if (StringUtils.isBlank(typeId)) { handleParseException("Ticket type title must not be empty", reader); } type = TicketType.createInstance(typeId); continue; } if (inTicket && hasClass(reader, "timeout")) { if (LOG.isDebugEnabled()) { LOG.debug("found timeout element"); } String timeoutString = reader.getAttributeValue(null, "title"); if (StringUtils.isBlank(timeoutString)) { timeout = null; } else { timeout = Integer.getInteger(timeoutString); } continue; } } if (type == null || key == null) { handleParseException("Ticket must have type and key", reader); } reader.close(); } catch (XMLStreamException e) { handleXmlException("Error reading XML", e); } Ticket ticket = entityFactory.createTicket(type); ticket.setKey(key); if (timeout == null) { ticket.setTimeout(Ticket.TIMEOUT_INFINITE); } else { ticket.setTimeout(timeout); } return ticket; }
From source file:org.osaf.cosmo.model.text.XhtmlSubscriptionFormat.java
public CollectionSubscription parse(String source, EntityFactory entityFactory) throws ParseException { CollectionSubscription sub = entityFactory.createCollectionSubscription(); try {/* www . j a va 2 s . c o m*/ if (source == null) throw new ParseException("Source has no XML data", -1); StringReader sr = new StringReader(source); XMLStreamReader reader = createXmlReader(sr); boolean inLocalSub = false; boolean inCollection = false; boolean inTicket = false; while (reader.hasNext()) { reader.next(); if (!reader.isStartElement()) continue; if (hasClass(reader, "local-subscription")) { if (log.isDebugEnabled()) log.debug("found local-subscription element"); inLocalSub = true; continue; } if (inLocalSub && hasClass(reader, "name")) { if (log.isDebugEnabled()) log.debug("found name element"); String name = reader.getElementText(); if (StringUtils.isBlank(name)) handleParseException("Name element must not be empty", reader); sub.setDisplayName(name); continue; } if (inLocalSub && hasClass(reader, "collection")) { if (log.isDebugEnabled()) log.debug("found collection element"); inCollection = true; inTicket = false; continue; } if (inCollection && hasClass(reader, "uuid")) { if (log.isDebugEnabled()) log.debug("found uuid element"); String uuid = reader.getElementText(); if (StringUtils.isBlank(uuid)) handleParseException("Uuid element must not be empty", reader); sub.setCollectionUid(uuid); continue; } if (inLocalSub && hasClass(reader, "ticket")) { if (log.isDebugEnabled()) log.debug("found ticket element"); inCollection = false; inTicket = true; continue; } if (inTicket && hasClass(reader, "key")) { if (log.isDebugEnabled()) log.debug("found key element"); String key = reader.getElementText(); if (StringUtils.isBlank(key)) handleParseException("Key element must not be empty", reader); sub.setTicketKey(key); continue; } } reader.close(); } catch (XMLStreamException e) { handleXmlException("Error reading XML", e); } return sub; }
From source file:org.freedesktop.icons.Directory.java
public Directory(IconTheme theme, String key, Properties properties) throws ParseException, IOException { this.key = key; this.theme = theme; if (!properties.containsKey(SIZE)) { throw new ParseException("Size entry is required.", 0); }//w w w . j av a 2 s . c om size = Integer.parseInt(properties.getProperty(SIZE)); context = properties.getProperty(CONTEXT); if (properties.containsKey(TYPE)) { String typeName = properties.getProperty(TYPE).toLowerCase(); try { type = Type.valueOf(typeName); } catch (IllegalArgumentException iae) { throw new ParseException("Invalid Type ' " + typeName + "' in " + key, 0); } } if (properties.containsKey(MAX_SIZE)) { maxSize = Integer.parseInt(properties.getProperty(MAX_SIZE)); } else { maxSize = size; } if (properties.containsKey(MIN_SIZE)) { minSize = Integer.parseInt(properties.getProperty(MIN_SIZE)); } else { minSize = size; } if (properties.containsKey(THRESHOLD)) { minSize = Integer.parseInt(properties.getProperty(THRESHOLD)); } for (FileObject base : theme.getBases()) { FileObject dirBase = base.resolveFile(getKey()); // Loop over the supported extensions so we get files in supported // extension order for (String extension : DefaultIconService.SUPPORTED_EXTENSIONS) { FileObject[] files = dirBase.findFiles(new ExtensionSelector(extension)); if (files != null) { for (FileObject file : files) { String name = file.getName().getBaseName(); int lidx = name.lastIndexOf('.'); String basename = name.substring(0, lidx); if (!cache.containsKey(basename)) { cache.put(basename, file); } } } } } }
From source file:org.unitedinternet.cosmo.model.text.XhtmlCollectionFormat.java
public CollectionItem parse(String source, EntityFactory entityFactory) throws ParseException { CollectionItem collection = entityFactory.createCollection(); try {/* ww w .j a v a 2 s .c om*/ if (source == null) { throw new ParseException("Source has no XML data", -1); } StringReader sr = new StringReader(source); XMLStreamReader reader = createXmlReader(sr); boolean inCollection = false; while (reader.hasNext()) { reader.next(); if (!reader.isStartElement()) { continue; } if (hasClass(reader, "collection")) { if (LOG.isDebugEnabled()) { LOG.debug("found collection element"); } inCollection = true; continue; } if (inCollection && hasClass(reader, "name")) { if (LOG.isDebugEnabled()) { LOG.debug("found name element"); } String name = reader.getElementText(); if (StringUtils.isBlank(name)) { throw new ParseException("Empty name not allowed", reader.getLocation().getCharacterOffset()); } collection.setDisplayName(name); continue; } if (inCollection && hasClass(reader, "uuid")) { if (LOG.isDebugEnabled()) { LOG.debug("found uuid element"); } String uuid = reader.getElementText(); if (StringUtils.isBlank(uuid)) { throw new ParseException("Empty uuid not allowed", reader.getLocation().getCharacterOffset()); } collection.setUid(uuid); continue; } } reader.close(); } catch (XMLStreamException e) { handleXmlException("Error reading XML", e); } return collection; }
From source file:edu.cornell.kfs.fp.businessobject.USBankRecordFieldUtils.java
/** * Extracts a substring less any ending whitespace for a given beginning and ending position. * /*from w ww.j a va 2 s . c o m*/ * @param line Superstring * @param begin Beginning index * @param end Ending index * @param required True if the value is required to not be empty * @param lineCount The current line number * @return The trimmed substring * @throws ParseException When a required value is missing * @throws StringIndexOutOfBoundsException When taking the actual substring if the provided bounds are beyond the limits of the superstring */ public static String extractNormalizedString(String line, int begin, int end, boolean required, int lineCount) throws ParseException { String theValue = extractNormalizedString(line, begin, end); if (required) { if (theValue == null) { throw new ParseException( "A required value was missing at " + begin + " " + end + " on line " + lineCount, lineCount); } } return theValue; }
From source file:Main.java
/** * Parses a string as an opaque color, either as a decimal hue (example: {@code 330}) using a * standard set of saturation and value) or as six digit hex code (example: {@code #BB66FF}). * If the string cannot be parsed, a {@link ParseException} is thrown. * * @param str The input to parse./*from www. j a v a2 s . com*/ * @param tempHsvArray An optional previously allocated array for HSV calculations. * @return The parsed color, in {@code int} form. * @throws ParseException */ public static int parseColor(@NonNull String str, @Nullable float[] tempHsvArray) throws ParseException { Integer result = null; char firstChar = str.charAt(0); if (firstChar == '#' && str.length() == 7) { try { result = Integer.parseInt(str.substring(1, 7), 16); } catch (NumberFormatException e) { throw new ParseException("Invalid hex color: " + str, 0); } return result; } else if (Character.isDigit(firstChar) && str.length() <= 3) { try { int hue = Integer.parseInt(str); result = getBlockColorForHue(hue, tempHsvArray); } catch (NumberFormatException e) { throw new ParseException("Invalid color hue: " + str, 0); } } // Maybe other color formats? 3 digit hex, CSS color functions, etc. return result; }
From source file:cz.muni.fi.editor.webapp.formatters.UserPermissionFormatter.java
@Override public UserPermissionForm parse(String text, Locale locale) throws ParseException { if (StringUtils.isEmpty(text)) { throw new ParseException("Empty text.", 0); }/*from w ww . j av a 2 s. c om*/ UserPermissionForm upf = new UserPermissionForm(); upf.setId(Long.valueOf(text)); return upf; }
From source file:org.unitedinternet.cosmo.model.text.XhtmlSubscriptionFormat.java
public CollectionSubscription parse(String source, EntityFactory entityFactory) throws ParseException { CollectionSubscription sub = entityFactory.createCollectionSubscription(); try {/*from www. ja v a2s. c o m*/ if (source == null) { throw new ParseException("Source has no XML data", -1); } StringReader sr = new StringReader(source); XMLStreamReader reader = createXmlReader(sr); boolean inLocalSub = false; boolean inCollection = false; boolean inTicket = false; while (reader.hasNext()) { reader.next(); if (!reader.isStartElement()) { continue; } if (hasClass(reader, "local-subscription")) { if (LOG.isDebugEnabled()) { LOG.debug("found local-subscription element"); } inLocalSub = true; continue; } if (inLocalSub && hasClass(reader, "name")) { if (LOG.isDebugEnabled()) { LOG.debug("found name element"); } String name = reader.getElementText(); if (StringUtils.isBlank(name)) { handleParseException("Name element must not be empty", reader); } sub.setDisplayName(name); continue; } if (inLocalSub && hasClass(reader, "collection")) { if (LOG.isDebugEnabled()) { LOG.debug("found collection element"); } inCollection = true; inTicket = false; continue; } if (inCollection && hasClass(reader, "uuid")) { if (LOG.isDebugEnabled()) { LOG.debug("found uuid element"); } String uuid = reader.getElementText(); if (StringUtils.isBlank(uuid)) { handleParseException("Uuid element must not be empty", reader); } sub.setCollectionUid(uuid); continue; } if (inLocalSub && hasClass(reader, "ticket")) { if (LOG.isDebugEnabled()) { LOG.debug("found ticket element"); } inCollection = false; inTicket = true; continue; } if (inTicket && hasClass(reader, "key")) { if (LOG.isDebugEnabled()) { LOG.debug("found key element"); } String key = reader.getElementText(); if (StringUtils.isBlank(key)) { handleParseException("Key element must not be empty", reader); } sub.setTicketKey(key); continue; } } reader.close(); } catch (XMLStreamException e) { handleXmlException("Error reading XML", e); } return sub; }
From source file:de.codesourcery.utils.xml.XmlHelper.java
public static String getDirectChildValue(Element parent, String childTag, boolean isRequired) throws ParseException { NodeList list = parent.getChildNodes(); Node matchingNode = null;//from w w w . j a va 2 s .com for (int i = 0; i < list.getLength(); i++) { Node n = list.item(i); if (n.getNodeName().equals(childTag)) { if (matchingNode == null) { matchingNode = n; } else { throw new ParseException( "Node " + parent.getNodeName() + " contains more than one child <" + childTag + "> ?!", -1); } } } if (matchingNode == null) { if (isRequired) { throw new ParseException( "Node " + parent.getNodeName() + " contains no child node <" + childTag + "> ?!", -1); } return null; } return getNodeValue(matchingNode, null, isRequired); }