Java Code Examples for org.xml.sax.SAXParseException

The following are top voted examples for showing how to use org.xml.sax.SAXParseException. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: myfaces-trinidad   File: FacesConfigParser.java   View source code 6 votes vote down vote up
@Override
public void addCompletedChild(
  ParseContext context,
  String       namespaceURI,
  String       localName,
  Object       child) throws SAXParseException
{
  if (child instanceof String)
  {
    String s = (String) child;
    if ("component-type".equals(localName))
      _info.componentType = s;
    else if ("component-class".equals(localName))
      _info.componentClass = s;
  }
}
 
Example 2
Project: OpenJSharp   File: ErrorHandlerWrapper.java   View source code 6 votes vote down vote up
/** Creates an XMLParseException from a SAXParseException. */
protected static XMLParseException createXMLParseException(SAXParseException exception) {
    final String fPublicId = exception.getPublicId();
    final String fExpandedSystemId = exception.getSystemId();
    final int fLineNumber = exception.getLineNumber();
    final int fColumnNumber = exception.getColumnNumber();
    XMLLocator location = new XMLLocator() {
        public String getPublicId() { return fPublicId; }
        public String getExpandedSystemId() { return fExpandedSystemId; }
        public String getBaseSystemId() { return null; }
        public String getLiteralSystemId() { return null; }
        public int getColumnNumber() { return fColumnNumber; }
        public int getLineNumber() { return fLineNumber; }
        public int getCharacterOffset() { return -1; }
        public String getEncoding() { return null; }
        public String getXMLVersion() { return null; }
    };
    return new XMLParseException(location, exception.getMessage(),exception);
}
 
Example 3
Project: myfaces-trinidad   File: FacesConfigParser.java   View source code 6 votes vote down vote up
@Override
public void addCompletedChild(
  ParseContext context,
  String       namespaceURI,
  String       localName,
  Object       child) throws SAXParseException
{
  if (child instanceof String)
  {
    String s = (String) child;
    if ("component-family".equals(localName))
      _info.componentFamily = s;
    else if ("renderer-type".equals(localName))
      _info.rendererType = s;
    else if ("renderer-class".equals(localName))
      _info.rendererClass = s;
  }
}
 
Example 4
Project: lams   File: PatternParser.java   View source code 6 votes vote down vote up
/**
 * Returns a string of the location.
 */
private String getLocationString(SAXParseException ex) {
  StringBuilder str = new StringBuilder();

  String systemId = ex.getSystemId();
  if (systemId != null) {
    int index = systemId.lastIndexOf('/');
    if (index != -1) {
      systemId = systemId.substring(index + 1);
    }
    str.append(systemId);
  }
  str.append(':');
  str.append(ex.getLineNumber());
  str.append(':');
  str.append(ex.getColumnNumber());

  return str.toString();

}
 
Example 5
Project: openjdk-jdk10   File: ErrorHandlerWrapper.java   View source code 6 votes vote down vote up
/** Creates an XMLParseException from a SAXParseException. */
protected static XMLParseException createXMLParseException(SAXParseException exception) {
    final String fPublicId = exception.getPublicId();
    final String fExpandedSystemId = exception.getSystemId();
    final int fLineNumber = exception.getLineNumber();
    final int fColumnNumber = exception.getColumnNumber();
    XMLLocator location = new XMLLocator() {
        public String getPublicId() { return fPublicId; }
        public String getExpandedSystemId() { return fExpandedSystemId; }
        public String getBaseSystemId() { return null; }
        public String getLiteralSystemId() { return null; }
        public int getColumnNumber() { return fColumnNumber; }
        public int getLineNumber() { return fLineNumber; }
        public int getCharacterOffset() { return -1; }
        public String getEncoding() { return null; }
        public String getXMLVersion() { return null; }
    };
    return new XMLParseException(location, exception.getMessage(),exception);
}
 
Example 6
Project: openjdk-jdk10   File: MetadataFinder.java   View source code 6 votes vote down vote up
private @Nullable Element getFromMetadataResolver(String systemId, Exception ex) {
    //try MEX
    MetaDataResolver resolver;
    ServiceDescriptor serviceDescriptor = null;
    for (MetadataResolverFactory resolverFactory : ServiceFinder.find(MetadataResolverFactory.class)) {
        resolver = resolverFactory.metadataResolver(options.entityResolver);
        try {
            serviceDescriptor = resolver.resolve(new URI(systemId));
            //we got the ServiceDescriptor, now break
            if (serviceDescriptor != null)
                break;
        } catch (URISyntaxException e) {
            throw new ParseException(e);
        }
    }

    if (serviceDescriptor != null) {
        errorReceiver.warning(new SAXParseException(WsdlMessages.TRY_WITH_MEX(ex.getMessage()), null, ex));
        return parseMetadata(systemId, serviceDescriptor);
    } else {
        errorReceiver.error(null, WsdlMessages.PARSING_UNABLE_TO_GET_METADATA(ex.getMessage(), WscompileMessages.WSIMPORT_NO_WSDL(systemId)), ex);
    }
    return null;
}
 
Example 7
Project: OpenJSharp   File: XMLFilterImpl.java   View source code 5 votes vote down vote up
/**
 * Filter a fatal error event.
 *
 * @param e The error as an exception.
 * @exception org.xml.sax.SAXException The client may throw
 *            an exception during processing.
 */
public void fatalError (SAXParseException e)
    throws SAXException
{
    if (errorHandler != null) {
        errorHandler.fatalError(e);
    }
}
 
Example 8
Project: OpenJSharp   File: SchemaBuilderImpl.java   View source code 5 votes vote down vote up
private void error(SAXParseException message) throws BuildException {
    noteError();
    try {
        if (eh != null) {
            eh.error(message);
        }
    } catch (SAXException e) {
        throw new BuildException(e);
    }
}
 
Example 9
Project: tomcat7   File: Digester.java   View source code 5 votes vote down vote up
/**
 * Forward notification of a parsing error to the application supplied
 * error handler (if any).
 *
 * @param exception The error information
 *
 * @exception SAXException if a parsing exception occurs
 */
@Override
public void error(SAXParseException exception) throws SAXException {

    log.error("Parse Error at line " + exception.getLineNumber() +
            " column " + exception.getColumnNumber() + ": " +
            exception.getMessage(), exception);
    if (errorHandler != null) {
        errorHandler.error(exception);
    }

}
 
Example 10
Project: lazycat   File: Digester.java   View source code 5 votes vote down vote up
/**
 * Forward notification of a parsing error to the application supplied error
 * handler (if any).
 *
 * @param exception
 *            The error information
 *
 * @exception SAXException
 *                if a parsing exception occurs
 */
@Override
public void error(SAXParseException exception) throws SAXException {

	log.error("Parse Error at line " + exception.getLineNumber() + " column " + exception.getColumnNumber() + ": "
			+ exception.getMessage(), exception);
	if (errorHandler != null) {
		errorHandler.error(exception);
	}

}
 
Example 11
Project: incubator-netbeans   File: LogRecords.java   View source code 5 votes vote down vote up
@Override
public void fatalError(SAXParseException e) throws SAXException {
    if (fatalErrors == null) {
        fatalErrors = new LinkedList<SAXParseException>();
    }
    fatalErrors.add(e);
    if (fatalErrors.size() > 100) {
        throw e;
    }
}
 
Example 12
Project: alfresco-repository   File: DefaultContentHandler.java   View source code 5 votes vote down vote up
public void fatalError(SAXParseException exception) throws SAXException
{
    try
    {
        targetHandler.error(exception);
    }
    finally
    {
        importer.error(exception);
    }
}
 
Example 13
Project: freecol   File: SerializationTest.java   View source code 5 votes vote down vote up
public void testValidation() throws Exception {
    Game game = ServerTestHelper.startServerGame(getTestMap(true));

    Colony colony = getStandardColony(6);
    Player player = game.getPlayerByNationId("model.nation.dutch");

    ServerTestHelper.newTurn();
    ServerTestHelper.newTurn();

    String serialized = null;
    try {
        Validator validator = buildValidator("schema/data/data-game.xsd");
        serialized = game.serialize();
        validator.validate(new StreamSource(new StringReader(serialized)));
    } catch (SAXParseException e) {
        int col = e.getColumnNumber();
        String errMsg = e.getMessage()
            + "\nAt line=" + e.getLineNumber()
            + ", column=" + col + ":\n";
        if (serialized != null) {
            errMsg += serialized.substring(Math.max(0, col - 100),
                                           Math.min(col + 100, serialized.length()));
        }
        fail(errMsg);
    }

    ServerTestHelper.stopServerGame();
}
 
Example 14
Project: MARF-for-Android   File: NeuralNetwork.java   View source code 5 votes vote down vote up
/**
 * Issues a SAX warning.
 *
 * @param poParseException the parse exception to warn about
 * @throws SAXException
 */
public void warning(SAXParseException poParseException)
        throws SAXException {
    this.oOut.println
            (
                    "WARNING: "
                            + getParseExceptionInfo(poParseException)
            );
}
 
Example 15
Project: MARF-for-Android   File: NeuralNetwork.java   View source code 5 votes vote down vote up
/**
 * Returns a string describing parse exception details.
 *
 * @param poParseException exception to get info from
 * @return string representation of the info
 */
private String getParseExceptionInfo(SAXParseException poParseException) {
    String strSystemId = poParseException.getSystemId();

    if (strSystemId == null) {
        strSystemId = "null";
    }

    String strErrInfo =
            "URI=" + strSystemId +
                    " Line=" + poParseException.getLineNumber() +
                    ": " + poParseException.getMessage();

    return strErrInfo;
}
 
Example 16
Project: myfaces-trinidad   File: FacesConfigParser.java   View source code 5 votes vote down vote up
@Override
public Object endElement(
  ParseContext context,
  String       namespaceURI,
  String       localName) throws SAXParseException
{
  return _info;
}
 
Example 17
Project: openjdk-jdk10   File: Util.java   View source code 5 votes vote down vote up
public static SAXParseException toSAXParseException( XMLParseException e ) {
    if( e.getException() instanceof SAXParseException )
        return (SAXParseException)e.getException();
    return new SAXParseException( e.getMessage(),
    e.getPublicId(), e.getExpandedSystemId(),
    e.getLineNumber(), e.getColumnNumber(),
    e.getException() );
}
 
Example 18
Project: myfaces-trinidad   File: SkinAdditionParser.java   View source code 5 votes vote down vote up
@Override
public NodeParser startChildElement(
  ParseContext context,
  String       namespaceURI,
  String       localName,
  Attributes   attrs
  ) throws SAXParseException
{

  if ("skin-id".equals(localName) ||
      "style-sheet-name".equals(localName) ||
      "bundle-name".equals(localName) ||
      "translation-source".equals(localName))

  {
    return new StringParser();
  }
  else if ("features".equals(localName))
  {
    return context.getParser(SkinFeatures.class, namespaceURI, localName);
  }
  else if ("metadata".equals(localName))
  {
    return context.getParser(CustomMetadata.class, namespaceURI, localName);
  }

  return null;
}
 
Example 19
Project: openjdk-jdk10   File: DefaultErrorHandler.java   View source code 5 votes vote down vote up
public static void ensureLocationSet(TransformerException exception)
{
  // SourceLocator locator = exception.getLocator();
  SourceLocator locator = null;
  Throwable cause = exception;

  // Try to find the locator closest to the cause.
  do
  {
    if(cause instanceof SAXParseException)
    {
      locator = new SAXSourceLocator((SAXParseException)cause);
    }
    else if (cause instanceof TransformerException)
    {
      SourceLocator causeLocator = ((TransformerException)cause).getLocator();
      if(null != causeLocator)
        locator = causeLocator;
    }

    if(cause instanceof TransformerException)
      cause = ((TransformerException)cause).getCause();
    else if(cause instanceof SAXException)
      cause = ((SAXException)cause).getException();
    else
      cause = null;
  }
  while(null != cause);

  exception.setLocator(locator);
}
 
Example 20
Project: OpenJSharp   File: DTDParser.java   View source code 5 votes vote down vote up
void error(String messageId, Object parameters [])
        throws SAXException {

    SAXParseException e = new SAXParseException(messages.getMessage(locale, messageId, parameters),
            getPublicId(), getSystemId(), getLineNumber(), getColumnNumber());

    dtdHandler.error(e);
}
 
Example 21
Project: myfaces-trinidad   File: TestScriptParser.java   View source code 5 votes vote down vote up
@Override
public void startElement(
  ParseContext context,
  String       namespaceURI,
  String       localName,
  Attributes   attrs) throws SAXParseException
{
  boolean matchesBase = "true".equals(attrs.getValue("matchesBase"));

  String name = getRequiredAttribute(context, attrs, "name");
  String valueStr = attrs.getValue("value");

  FacesConfigInfo.PropertyInfo property = _componentInfo.getPropertyInfo(name);
  final Object value;
  if (!ComponentDefinition.isValueExpression(valueStr) &&
      (property != null) && (property.type != null))
    value = Coercions.coerce(null, valueStr, property.type);
  else
    value = valueStr;

  Set<Accessibility> unsupportedModes     = _parseUnsupportedAccessibilityModes(attrs);
  Set<String>        unsupportedDevices   = _parseUnsupportedDevices(attrs);
  Set<CapabilityKey> requiredCapabilities = _parseRequiredCapabilities(attrs);
  boolean            noRTL                = _parseNoRTL(attrs);

  _test = new TestScript.AttributeTest(name,
                                       value,
                                       matchesBase,
                                       null, 
                                       _componentId,
                                       unsupportedModes,
                                       unsupportedDevices,
                                       requiredCapabilities,
                                       noRTL);
}
 
Example 22
Project: OpenJSharp   File: ErrorHandlerProxy.java   View source code 5 votes vote down vote up
public void warning(SAXParseException e) throws SAXException {
    XMLErrorHandler eh = getErrorHandler();
    if (eh instanceof ErrorHandlerWrapper) {
        ((ErrorHandlerWrapper)eh).fErrorHandler.warning(e);
    }
    else {
        eh.warning("","",ErrorHandlerWrapper.createXMLParseException(e));
    }
}
 
Example 23
Project: rapidminer   File: XMLErrorHandler.java   View source code 5 votes vote down vote up
private String toString(SAXParseException e) {
	StringBuilder buf = new StringBuilder();
	buf.append(sourceName);
	buf.append(" (");
	buf.append(e.getLineNumber());
	buf.append(":");
	buf.append(e.getColumnNumber());
	buf.append(" at ");
	buf.append(e.getPublicId());
	buf.append(") ");
	buf.append(e.getLocalizedMessage());
	return buf.toString();
}
 
Example 24
Project: jdk8u-jdk   File: IgnoreAllErrorHandler.java   View source code 5 votes vote down vote up
/** @inheritDoc */
public void error(SAXParseException ex) throws SAXException {
    if (IgnoreAllErrorHandler.warnOnExceptions) {
        log.log(java.util.logging.Level.SEVERE, "", ex);
    }
    if (IgnoreAllErrorHandler.throwExceptions) {
        throw ex;
    }
}
 
Example 25
Project: parabuild-ci   File: LogErrorHandler.java   View source code 5 votes vote down vote up
/**
 * @param ex The exception to create a message from
 * @return A summary of what went wrong.
 */
private String getMessage(SAXParseException ex)
{
    if (ex.getSystemId() != null)
    {
        return "SystemID=" + ex.getSystemId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
    }

    if (ex.getPublicId() != null)
    {
        return "PublicID=" + ex.getPublicId() + " Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
    }

    return "Line=" + ex.getLineNumber() + ' ' + ex.getMessage();
}
 
Example 26
Project: apache-tomcat-7.0.73-with-comment   File: Digester.java   View source code 5 votes vote down vote up
/**
 * Create a SAX exception which also understands about the location in
 * the digester file where the exception occurs
 *
 * @return the new exception
 */
public SAXException createSAXException(String message, Exception e) {
    if ((e != null) &&
        (e instanceof InvocationTargetException)) {
        Throwable t = e.getCause();
        if (t instanceof ThreadDeath) {
            throw (ThreadDeath) t;
        }
        if (t instanceof VirtualMachineError) {
            throw (VirtualMachineError) t;
        }
        if (t instanceof Exception) {
            e = (Exception) t;
        }
    }
    if (locator != null) {
        String error = "Error at (" + locator.getLineNumber() + ", " +
                locator.getColumnNumber() + ") : " + message;
        if (e != null) {
            return new SAXParseException(error, locator, e);
        } else {
            return new SAXParseException(error, locator);
        }
    }
    log.error("No Locator!");
    if (e != null) {
        return new SAXException(message, e);
    } else {
        return new SAXException(message);
    }
}
 
Example 27
Project: openjdk-jdk10   File: IncorrectNamespaceURIChecker.java   View source code 5 votes vote down vote up
@Override
public void endDocument() throws SAXException {
    if( isJAXBPrefixUsed && !isCustomizationUsed ) {
        SAXParseException e = new SAXParseException(
            Messages.format(Messages.WARN_INCORRECT_URI, Const.JAXB_NSURI),
            locator );
        errorHandler.warning(e);
    }

    super.endDocument();
}
 
Example 28
Project: openjdk-jdk10   File: ConsoleErrorReporter.java   View source code 5 votes vote down vote up
public void error(SAXParseException e) {
    if(debug)
        e.printStackTrace();
    hasError = true;
    if((e.getSystemId() == null && e.getPublicId() == null) && (e.getCause() instanceof UnknownHostException)) {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.toString()), e);
    } else {
        print(WscompileMessages.WSIMPORT_ERROR_MESSAGE(e.getMessage()), e);
    }
}
 
Example 29
Project: OpenJSharp   File: SchemaParser.java   View source code 4 votes vote down vote up
private void warning(String key, Locator loc) throws SAXException {
    warning(new SAXParseException(localizer.message(key), loc));
}
 
Example 30
Project: Reer   File: IvyXmlModuleDescriptorParser.java   View source code 4 votes vote down vote up
public void warning(SAXParseException ex) {
    LOGGER.warn("xml parsing: {}: {}", getLocationString(ex), ex.getMessage());
}
 
Example 31
Project: whackpad   File: XmlProcessor.java   View source code 4 votes vote down vote up
private void throwError(SAXParseException e) {
    throw ScriptRuntime.constructError("TypeError", e.getMessage(),
        e.getLineNumber() - 1);
}
 
Example 32
Project: openjdk-jdk10   File: DraconianErrorHandler.java   View source code 4 votes vote down vote up
public void fatalError(SAXParseException e) throws SAXException {
    throw e;
}
 
Example 33
Project: vexillo   File: FlagParser.java   View source code 4 votes vote down vote up
@Override
public void error(SAXParseException e) throws SAXException {
	System.err.print("Warning: Failed to compile flag " + name + ": ");
	System.err.println("ERROR on "+e.getLineNumber()+":"+e.getColumnNumber()+": "+e.getMessage());
}
 
Example 34
Project: OpenJSharp   File: EmptySerializer.java   View source code 4 votes vote down vote up
/**
 * @see org.xml.sax.ErrorHandler#fatalError(org.xml.sax.SAXParseException)
 */
public void fatalError(SAXParseException arg0) throws SAXException
{
    couldThrowSAXException();
}
 
Example 35
Project: openjdk-jdk10   File: ErrorReceiverFilter.java   View source code 4 votes vote down vote up
public void error(SAXParseException exception) {
    hadError = true;
    if(core!=null)  core.error(exception);
}
 
Example 36
Project: lams   File: ErrorLogger.java   View source code 4 votes vote down vote up
@Override
public void fatalError(SAXParseException error) {
	error( error );
}
 
Example 37
Project: server-utility   File: ParserErrorHandler.java   View source code 4 votes vote down vote up
public void warning(SAXParseException exception) throws SAXException {
    warnings.add(getString("Warning.7", //$NON-NLS-1$
            Integer.toString(exception.getLineNumber()), exception
                    .getMessage()));
}
 
Example 38
Project: server-utility   File: XmlCodeGenerationTest.java   View source code 4 votes vote down vote up
@Override
public void error(SAXParseException exception) throws SAXException {
    errors.add(exception.getMessage());
}
 
Example 39
Project: lazycat   File: XmlErrorHandler.java   View source code 4 votes vote down vote up
public List<SAXParseException> getErrors() {
	// Internal use only - don't worry about immutability
	return errors;
}
 
Example 40
Project: openjdk-jdk10   File: ErrorReceiver.java   View source code 4 votes vote down vote up
/**
 * Reports a warning.
 */
public final void warning( @Nullable Locator loc, String msg ) {
    warning( new SAXParseException(msg,loc) );
}