private static int getIntegerAttribute(Attributes attrs, String name, int defValue) throws ParseException { String stringValue = attrs.getValue(name); if (stringValue == null) { return defValue; } try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidIntegerAttribute, e); pe.setInternalReason("Invalid integer in value of attribute " + name + ": '" + stringValue + "'"); throw pe; } }
public ParseException(String message, Throwable cause) { super(message, cause); initResponseCode(); }
private void initResponseCode() { setHttpErrorCodeOverride(HttpURLConnection.HTTP_BAD_REQUEST); } }
public void processEndElement() throws ParseException { if (title == null) { throw new ParseException( CoreErrorDomain.ERR.workspaceTitleRequired); } } }
/** Throws a parse exception with line/column information. */ protected void throwParseException(ParseException e) throws ParseException { if (locator != null) { String elementLocation = ""; if (curHandler != null) { elementLocation += ", element " + curHandler.qName; } String location = "[Line " + String.valueOf(locator.getLineNumber()) + ", Column " + String.valueOf(locator.getColumnNumber()) + elementLocation + "] "; LogUtils.logException(logger, Level.FINE, location, e); throw new ParseException(location + e.getMessage(), e); } else { LogUtils.logException(logger, Level.FINE, null, e); throw e; } }
/** * Converts a ContentValidationException to a parse exception, with a * separate exception for each parser error that was encountered. */ public ParseException toParseException() { ParseException result = null; Map<Element, List<ErrorContent>> errors = vc.getErrors(); for (Map.Entry<Element, List<ErrorContent>> entry : errors.entrySet()) { Element element = entry.getKey(); String location = element.getElementKey().getId().toString(); List<ErrorContent> codes = entry.getValue(); for (ErrorContent errorCode : codes) { ParseException pe = new ParseException(errorCode); pe.setLocation(location); if (result == null) { result = pe; } else { result.addSibling(pe); } } } return result; } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
public void setResponseBody(String body) { if (body == null) { throw new NullPointerException("Null response body"); } responseBody = body; // Create and invoke a ServiceExceptionInitializer to // do the dirty work of reading the stream, possibly // parsing the result if it is a GData structured error, // and set the instance variables accordingly. // In C++ terms, SEI is a friend class. ServiceExceptionInitializer initializer = new ServiceExceptionInitializer(this); try { initializer.parse(responseContentType, responseBody); } catch (ParseException pe) { throw new RuntimeException(pe.getMessage(), pe); } }
@Override public void processEndElement() throws ParseException { if (linkRequired && href == null) { throw new ParseException( CoreErrorDomain.ERR.missingHrefAttribute); } titleLang = xmlLang; // Allow undefined content. } }
/** Throws a parse exception with line/column information. */ protected void throwParseException(ParseException e) throws ParseException { if (locator != null) { String elementLocation = ""; if (curHandler != null) { elementLocation += ", element " + curHandler.qName; } String location = "[Line " + String.valueOf(locator.getLineNumber()) + ", Column " + String.valueOf(locator.getColumnNumber()) + elementLocation + "] "; LogUtils.logException(logger, Level.FINE, location, e); throw new ParseException(location + e.getMessage(), e); } else { LogUtils.logException(logger, Level.FINE, null, e); throw e; } }
/** * Converts a ContentValidationException to a parse exception, with a * separate exception for each parser error that was encountered. */ public ParseException toParseException() { ParseException result = null; Map<Element, List<ErrorContent>> errors = vc.getErrors(); for (Map.Entry<Element, List<ErrorContent>> entry : errors.entrySet()) { Element element = entry.getKey(); String location = element.getElementKey().getId().toString(); List<ErrorContent> codes = entry.getValue(); for (ErrorContent errorCode : codes) { ParseException pe = new ParseException(errorCode); pe.setLocation(location); if (result == null) { result = pe; } else { result.addSibling(pe); } } } return result; } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
public void setResponseBody(String body) { if (body == null) { throw new NullPointerException("Null response body"); } responseBody = body; // Create and invoke a ServiceExceptionInitializer to // do the dirty work of reading the stream, possibly // parsing the result if it is a GData structured error, // and set the instance variables accordingly. // In C++ terms, SEI is a friend class. ServiceExceptionInitializer initializer = new ServiceExceptionInitializer(this); try { initializer.parse(responseContentType, responseBody); } catch (ParseException pe) { throw new RuntimeException(pe.getMessage(), pe); } }
private static int getIntegerAttribute(Attributes attrs, String name, int defValue) throws ParseException { String stringValue = attrs.getValue(name); if (stringValue == null) { return defValue; } try { return Integer.parseInt(stringValue); } catch (NumberFormatException e) { ParseException pe = new ParseException( CoreErrorDomain.ERR.invalidIntegerAttribute, e); pe.setInternalReason("Invalid integer in value of attribute " + name + ": '" + stringValue + "'"); throw pe; } }
@Override public void processEndElement() throws ParseException { if (name == null) { throw new ParseException("apps:property/@name is required."); } if (val == null) { throw new ParseException("apps:property/@value is required."); } } }
/** Throws a parse exception with line/column information. */ protected void throwParseException(ParseException e) throws ParseException { if (locator != null) { String elementLocation = ""; if (curHandler != null) { elementLocation += ", element " + curHandler.qName; } String location = "[Line " + String.valueOf(locator.getLineNumber()) + ", Column " + String.valueOf(locator.getColumnNumber()) + elementLocation + "] "; LogUtils.logException(logger, Level.FINE, location, e); throw new ParseException(location + e.getMessage(), e); } else { LogUtils.logException(logger, Level.FINE, null, e); throw e; } }
/** * Converts a ContentValidationException to a parse exception, with a * separate exception for each parser error that was encountered. */ public ParseException toParseException() { ParseException result = null; Map<Element, List<ErrorContent>> errors = vc.getErrors(); for (Map.Entry<Element, List<ErrorContent>> entry : errors.entrySet()) { Element element = entry.getKey(); String location = element.getElementKey().getId().toString(); List<ErrorContent> codes = entry.getValue(); for (ErrorContent errorCode : codes) { ParseException pe = new ParseException(errorCode); pe.setLocation(location); if (result == null) { result = pe; } else { result.addSibling(pe); } } } return result; } }
@Override public String toString() { StringBuilder sb = new StringBuilder(); for (Map.Entry<Element, List<ErrorContent>> error : errors.entrySet()) { sb.append(error.getKey().getElementId()); sb.append(" { "); List<String> errors = Lists.newArrayList(); for (ErrorContent element : error.getValue()) { errors.add(new ParseException(element).toXmlErrorMessage()); } sb.append(Join.join(", ", errors)); sb.append(" }"); } return sb.toString(); } }
public ParseException(ErrorContent errorCode, Throwable cause) { super(errorCode, cause); initResponseCode(); }
public void setResponseBody(String body) { if (body == null) { throw new NullPointerException("Null response body"); } responseBody = body; // Create and invoke a ServiceExceptionInitializer to // do the dirty work of reading the stream, possibly // parsing the result if it is a GData structured error, // and set the instance variables accordingly. // In C++ terms, SEI is a friend class. ServiceExceptionInitializer initializer = new ServiceExceptionInitializer(this); try { initializer.parse(responseContentType, responseBody); } catch (ParseException pe) { throw new RuntimeException(pe.getMessage(), pe); } }