org.xml.sax.SAXNotRecognizedException#org.xml.sax.SAXParseException源码实例Demo

下面列出了org.xml.sax.SAXNotRecognizedException#org.xml.sax.SAXParseException 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: mycore   文件: MCRXMLParserErrorHandler.java
/**
 * Returns a text indicating at which line and column the error occured.
 * 
 * @param ex the SAXParseException exception
 * @return the location string
 */
public static String getSAXErrorMessage(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).append(": ");
    }

    str.append("line ").append(ex.getLineNumber());
    str.append(", column ").append(ex.getColumnNumber());
    str.append(", ");
    str.append(ex.getLocalizedMessage());

    return str.toString();
}
 
源代码2 项目: ade   文件: AdeUtilMain.java
protected void validateGood(File file) throws IOException, SAXException,
		AdeException {
	System.out.println("Starting");

	String fileName_Flowlayout_xsd = Ade.getAde().getConfigProperties()
			.getXsltDir()
			+ FLOW_LAYOUT_XSD_File_Name;
	Source schemaFile = new StreamSource(fileName_Flowlayout_xsd);
	SchemaFactory sf = SchemaFactory
			.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI);
	Schema mSchema = sf.newSchema(schemaFile);

	System.out.println("Validating " + file.getPath());
	Validator val = mSchema.newValidator();
	FileInputStream fis = new FileInputStream(file);
	StreamSource streamSource = new StreamSource(fis);

	try {
		val.validate(streamSource);
	} catch (SAXParseException e) {
		System.out.println(e);
		throw e;
	}
	System.out.println("SUCCESS!");
}
 
源代码3 项目: EventCoreference   文件: EsoReader.java
public void parseFile(String filePath) {
    String myerror = "";
    try {
        SAXParserFactory factory = SAXParserFactory.newInstance();
        factory.setValidating(false);
        SAXParser parser = factory.newSAXParser();
        InputSource inp = new InputSource (new FileReader(filePath));
        parser.parse(inp, this);
    } catch (SAXParseException err) {
        myerror = "\n** Parsing error" + ", line " + err.getLineNumber()
                + ", uri " + err.getSystemId();
        myerror += "\n" + err.getMessage();
        System.out.println("myerror = " + myerror);
    } catch (SAXException e) {
        Exception x = e;
        if (e.getException() != null)
            x = e.getException();
        myerror += "\nSAXException --" + x.getMessage();
        System.out.println("myerror = " + myerror);
    } catch (Exception eee) {
        eee.printStackTrace();
        myerror += "\nException --" + eee.getMessage();
        System.out.println("myerror = " + myerror);
    }
}
 
源代码4 项目: openjdk-8   文件: Internalizer.java
private void reportError( Element errorSource,
    String formattedMsg, Exception nestedException ) {

    SAXParseException e = new SAXParseException2( formattedMsg,
        forest.locatorTable.getStartLocation(errorSource),
        nestedException );
    errorHandler.error(e);
}
 
public void fatalError(SAXParseException exception) throws SAXException {
   if (this.accept(exception)) {
      String msg = "FATAL " + this.toString(exception);
      this.exceptionFatalList.add(msg);
   }

}
 
源代码6 项目: RADL   文件: Xml.java
private boolean isMissingSchemaError(SAXParseException exception) {
  String message = exception.getMessage();
  if (message == null) {
    return false;
  }
  return message.contains("no grammar found") || message.contains("must match DOCTYPE root \"null\"");
}
 
源代码7 项目: Bytecoder   文件: ErrorHandlerProxy.java
public void error(SAXParseException e) throws SAXException {
    XMLErrorHandler eh = getErrorHandler();
    if (eh instanceof ErrorHandlerWrapper) {
        ((ErrorHandlerWrapper)eh).fErrorHandler.error(e);
    }
    else {
        eh.error("","",ErrorHandlerWrapper.createXMLParseException(e));
    }
    // if an XNIException is thrown, just let it go.
    // REVISIT: is this OK? or should we try to wrap it into SAXException?
}
 
源代码8 项目: jasperreports   文件: SimpleFontExtensionHelper.java
@Override
public void fatalError(SAXParseException e) {
	if (log.isFatalEnabled())
	{
		log.fatal("Error parsing styled text.", e);
	}
}
 
源代码9 项目: openjdk-jdk8u-backup   文件: SchemaBuilderImpl.java
private void error(SAXParseException message) throws BuildException {
    noteError();
    try {
        if (eh != null) {
            eh.error(message);
        }
    } catch (SAXException e) {
        throw new BuildException(e);
    }
}
 
源代码10 项目: caja   文件: Driver.java
/**
 * Reports a warning without line/col
 * 
 * @param message
 *            the message
 * @throws SAXException
 */
protected void warnWithoutLocation(String message) throws SAXException {
    ErrorHandler errorHandler = tokenizer.getErrorHandler();
    if (errorHandler == null) {
        return;
    }
    SAXParseException spe = new SAXParseException(message, null,
            tokenizer.getSystemId(), -1, -1);
    errorHandler.warning(spe);
}
 
源代码11 项目: flex-blazeds   文件: AmfxMessageDeserializer.java
/**
 * Process FatalError of a SAXParseException.
 *
 * @param exception SAXParseException
 * @throws SAXException rethrow the SAXException
 */
public void fatalError(SAXParseException exception) throws SAXException
{
    if ((exception.getException() != null) && (exception.getException() instanceof MessageException))
        throw (MessageException)exception.getException();
    throw new MessageException(exception.getMessage());
}
 
源代码12 项目: lams   文件: ErrorLogger.java
public void logErrors() {
	if ( errors != null ) {
		for ( SAXParseException e : errors ) {
			if ( file == null ) {
				LOG.parsingXmlError( e.getLineNumber(), e.getMessage() );
			}
			else {
				LOG.parsingXmlErrorForFile( file, e.getLineNumber(), e.getMessage() );
			}
		}
	}
}
 
public void fatalError(SAXParseException exception) throws SAXException {
   if (this.accept(exception)) {
      String msg = "FATAL " + this.toString(exception);
      this.exceptionFatalList.add(msg);
   }

}
 
源代码14 项目: Java8CN   文件: XMLFilterImpl.java
/**
 * Filter a warning event.
 *
 * @param e The warning as an exception.
 * @exception org.xml.sax.SAXException The client may throw
 *            an exception during processing.
 */
public void warning (SAXParseException e)
    throws SAXException
{
    if (errorHandler != null) {
        errorHandler.warning(e);
    }
}
 
源代码15 项目: openjdk-jdk8u-backup   文件: ErrorReceiver.java
/**
 * Returns the human readable string representation of the
 * {@link org.xml.sax.Locator} part of the specified
 * {@link SAXParseException}.
 *
 * @return  non-null valid object.
 */
protected final String getLocationString( SAXParseException e ) {
    if(e.getLineNumber()!=-1 || e.getSystemId()!=null) {
        int line = e.getLineNumber();
        return Messages.format( Messages.LINE_X_OF_Y,
            line==-1?"?":Integer.toString( line ),
            getShortName( e.getSystemId() ) );
    } else {
        return Messages.format( Messages.UNKNOWN_LOCATION );
    }
}
 
源代码16 项目: jdk8u60   文件: ParserAdapter.java
/**
 * Construct an exception for the current context.
 *
 * @param message The error message.
 */
private SAXParseException makeException (String message)
{
    if (locator != null) {
        return new SAXParseException(message, locator);
    } else {
        return new SAXParseException(message, null, null, -1, -1);
    }
}
 
源代码17 项目: kogito-runtimes   文件: BaseAbstractHandler.java
public void emptyContentCheck(final String element,
                              final String content,
                              final ExtensibleXmlParser xmlPackageReader) throws SAXException {
    if ( content == null || content.trim().equals( "" ) ) {
        throw new SAXParseException( "<" + element + "> requires content",
                                     xmlPackageReader.getLocator() );
    }
}
 
源代码18 项目: openjdk-8   文件: CompactSyntax.java
private void doError(String message, Token tok) {
  hadError = true;
  if (eh != null) {
    LocatorImpl loc = new LocatorImpl();
    loc.setLineNumber(tok.beginLine);
    loc.setColumnNumber(tok.beginColumn);
    loc.setSystemId(sourceUri);
    try {
      eh.error(new SAXParseException(message, loc));
    }
    catch (SAXException se) {
      throw new BuildException(se);
    }
  }
}
 
源代码19 项目: Android-UPnP-Browser   文件: UPnPDevice.java
public void downloadSpecs() throws Exception {
	Request request = new Request.Builder()
		.url(mLocation)
		.build();

	Response response = mClient.newCall(request).execute();
	if (!response.isSuccessful()) {
		throw new IOException("Unexpected code " + response);
	}

	mRawXml = response.body().string();

	DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
	DocumentBuilder db = dbf.newDocumentBuilder();
	InputSource source = new InputSource(new StringReader(mRawXml));
	Document doc;
	try {
		doc = db.parse(source);
	}
	catch (SAXParseException e) {
		return;
	}
	XPath xPath = XPathFactory.newInstance().newXPath();

	mProperties.put("xml_icon_url", xPath.compile("//icon/url").evaluate(doc));
	generateIconUrl();
	mProperties.put("xml_friendly_name", xPath.compile("//friendlyName").evaluate(doc));
}
 
源代码20 项目: openjdk-8-source   文件: DefaultErrorHandler.java
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);
}
 
源代码21 项目: ontopia   文件: OntopiaErrorHandler.java
/**
 * This will report a fatal error that has occurred; this indicates
 * that a rule has been broken that makes continued parsing either
 * impossible or an almost certain waste of time.
 *
 * @param exception <code>SAXParseException</code> that occurred.
 * @throws <code>SAXException</code> when things go wrong
 */
@Override
public void fatalError(SAXParseException exception)
  throws SAXException {
 
  System.out.println("**Parsing Fatal Error**\n" +
       " Line: " +
       exception.getLineNumber() + "\n" +
       " URI: " +
       exception.getSystemId() + "\n" +
       " Message: " +
       exception.getMessage());
  throw new SAXException("Fatal Error encountered");
}
 
源代码22 项目: r-course   文件: ResponseParser.java
@Override
public void characters(char[] ch, int start, int length) throws SAXException {
    try {
        String thisElement = (String) this.elNames.peek();
        if (thisElement != null) {
            if (thisElement.equals("name")) {
                ((Member) this.objects.peek()).setName(new String(ch, start, length));
            } else if (thisElement.equals("value")) {
                ((Value) this.objects.peek()).appendString(new String(ch, start, length));
            } else if (thisElement.equals("i4") || thisElement.equals("int")) {
                ((Value) this.objects.peek()).setInt(new String(ch, start, length));
            } else if (thisElement.equals("boolean")) {
                ((Value) this.objects.peek()).setBoolean(new String(ch, start, length));
            } else if (thisElement.equals("string")) {
                ((Value) this.objects.peek()).appendString(new String(ch, start, length));
            } else if (thisElement.equals("double")) {
                ((Value) this.objects.peek()).setDouble(new String(ch, start, length));
            } else if (thisElement.equals("dateTime.iso8601")) {
                ((Value) this.objects.peek()).setDateTime(new String(ch, start, length));
            } else if (thisElement.equals("base64")) {
                ((Value) this.objects.peek()).setBase64(new String(ch, start, length).getBytes());
            }
        }
    } catch (Exception e) {
        throw new SAXParseException(e.getMessage(), null, e);
    }
}
 
源代码23 项目: tomcatsrc   文件: JspDocumentParser.java
@Override
public void startPrefixMapping(String prefix, String uri)
    throws SAXException {
    TagLibraryInfo taglibInfo;

    if (directivesOnly && !(JSP_URI.equals(uri))) {
        return;
    }

    try {
        taglibInfo = getTaglibInfo(prefix, uri);
    } catch (JasperException je) {
        throw new SAXParseException(
            Localizer.getMessage("jsp.error.could.not.add.taglibraries"),
            locator,
            je);
    }

    if (taglibInfo != null) {
        if (pageInfo.getTaglib(uri) == null) {
            pageInfo.addTaglib(uri, taglibInfo);
        }
        pageInfo.pushPrefixMapping(prefix, uri);
    } else {
        pageInfo.pushPrefixMapping(prefix, null);
    }
}
 
源代码24 项目: openjdk-jdk9   文件: DTDHandlerBase.java
public void fatalError(SAXParseException e) throws SAXException {
    throw e;
}
 
源代码25 项目: cacheonix-core   文件: SAXErrorHandler.java
public final void error(final SAXParseException ex) {
   emitMessage("Continuable parsing error ", ex);
}
 
源代码26 项目: netbeans   文件: XMLFileSystem.java
@Override
public void warning(SAXParseException exception)
throws SAXException {
    throw exception;
}
 
源代码27 项目: tcases   文件: SystemTestDocReader.java
public void startElement( String uri, String localName, String qName, Attributes attributes) throws SAXException
{
InputHandler parent = (InputHandler) getParent();

String valueAtr = getAttribute( attributes, VALUE_ATR);
String naAtr = StringUtils.trimToNull( getAttribute( attributes, NA_ATR));
boolean na = naAtr != null && BooleanUtils.toBoolean( naAtr);

if( valueAtr == null && !na)
  {
  throw
    new SAXParseException
    ( "No \"value\" attribute specified",
      getDocumentLocator()); 
  }
else if( valueAtr != null && na)
  {
  throw
    new SAXParseException
    ( "No \"value\" attribute allowed for a variable that is \"not applicable\"",
      getDocumentLocator()); 
  }

VarBinding binding =
  na
  ? new VarNaBinding( requireIdPath( attributes, NAME_ATR), parent.getType())
  : new VarBinding( requireIdPath( attributes, NAME_ATR), parent.getType(), toObject( valueAtr));

TestCaseHandler testCaseHandler = getTestCaseHandler();
TestCase testCase = testCaseHandler.getTestCase();

String failureAtr = StringUtils.trimToNull( getAttribute( attributes, FAILURE_ATR));
boolean failure = failureAtr != null && BooleanUtils.toBoolean( failureAtr);
if( failure && !testCaseHandler.isFailure())
  {
  throw
    new SAXParseException
    ( "Unexpected failure value=\"" + binding.getValue()
      + "\" for success test case " + testCase.getId(),
      getDocumentLocator()); 
  }

binding.setValueValid( !failure);
try
  {
  testCase.addVarBinding( binding);
  }
catch( Exception e)
  {
  throw new SAXParseException( e.getMessage(), getDocumentLocator());
  }

setVarBinding( binding);
}
 
源代码28 项目: j2objc   文件: DocumentBuilderFactoryTest.java
public void fatalError(SAXParseException ex) {
    if (parseException == null) {
        parseException = ex;
    }
}
 
源代码29 项目: jdk8u60   文件: CodeModelClassFactory.java
public JDefinedClass createClass(
    JClassContainer parent, int mod, String name, Locator source, ClassType kind ) {

    if(!JJavaName.isJavaIdentifier(name)) {
        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_INVALID_CLASSNAME, name ), source ));
        return createDummyClass(parent);
    }


    try {
        if(parent.isClass() && kind==ClassType.CLASS)
            mod |= JMod.STATIC;

        JDefinedClass r = parent._class(mod,name,kind);
        // use the metadata field to store the source location,
        // so that we can report class name collision errors.
        r.metadata = source;

        return r;
    } catch( JClassAlreadyExistsException e ) {
        // class collision.
        JDefinedClass cls = e.getExistingClass();

        // report the error
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION, cls.fullName() ),
            (Locator)cls.metadata ));
        errorReceiver.error( new SAXParseException(
            Messages.format( Messages.ERR_CLASSNAME_COLLISION_SOURCE, name ),
            source ));

        if( !name.equals(cls.name()) ) {
            // on Windows, FooBar and Foobar causes name collision
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CASE_SENSITIVITY_COLLISION,
                    name, cls.name() ), null ) );
        }

        if(Util.equals((Locator)cls.metadata,source)) {
            errorReceiver.error( new SAXParseException(
                Messages.format( Messages.ERR_CHAMELEON_SCHEMA_GONE_WILD ),
                source ));
        }

        return createDummyClass(parent);
    }
}
 
源代码30 项目: openjdk-8-source   文件: AbstractLDMLHandler.java
@SuppressWarnings(value = "CallToThreadDumpStack")
@Override
public void warning(SAXParseException e) throws SAXException {
    e.printStackTrace();
}