⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gnomedocumentbuilder.java

📁 gcc的组建
💻 JAVA
字号:
/* GnomeDocumentBuilder.java -    Copyright (C) 2004 Free Software Foundation, Inc.This file is part of GNU Classpath.GNU Classpath is free software; you can redistribute it and/or modifyit under the terms of the GNU General Public License as published bythe Free Software Foundation; either version 2, or (at your option)any later version.GNU Classpath is distributed in the hope that it will be useful, butWITHOUT ANY WARRANTY; without even the implied warranty ofMERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNUGeneral Public License for more details.You should have received a copy of the GNU General Public Licensealong with GNU Classpath; see the file COPYING.  If not, write to theFree Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA02110-1301 USA.Linking this library statically or dynamically with other modules ismaking a combined work based on this library.  Thus, the terms andconditions of the GNU General Public License cover the wholecombination.As a special exception, the copyright holders of this library give youpermission to link this library with independent modules to produce anexecutable, regardless of the license terms of these independentmodules, and to copy and distribute the resulting executable underterms of your choice, provided that you also meet, for each linkedindependent module, the terms and conditions of the license of thatmodule.  An independent module is a module which is not derived fromor based on this library.  If you modify this library, you may extendthis exception to your version of the library, but you are notobligated to do so.  If you do not wish to do so, delete thisexception statement from your version. */package gnu.xml.libxmlj.dom;import java.io.InputStream;import java.io.IOException;import java.net.URL;import javax.xml.parsers.DocumentBuilder;import org.w3c.dom.Document;import org.w3c.dom.DocumentType;import org.w3c.dom.DOMImplementation;import org.xml.sax.EntityResolver;import org.xml.sax.ErrorHandler;import org.xml.sax.InputSource;import org.xml.sax.Locator;import org.xml.sax.SAXException;import org.xml.sax.SAXParseException;import gnu.xml.libxmlj.util.NamedInputStream;import gnu.xml.libxmlj.util.StandaloneDocumentType;import gnu.xml.libxmlj.util.StandaloneLocator;import gnu.xml.libxmlj.util.XMLJ;/** * A JAXP DOM implementation that uses Gnome libxml2 as the underlying * parser and node representation. * * @author <a href='mailto:dog@gnu.org'>Chris Burdess</a> */public class GnomeDocumentBuilder  extends DocumentBuilder  implements DOMImplementation{  static  {    XMLJ.init();  }  // -- DocumentBuilder --  private boolean validate;  private boolean coalesce;  private boolean expandEntities;  private EntityResolver entityResolver;  private ErrorHandler errorHandler;  private boolean seenFatalError;  /**   * Constructs a new validating document builder.   */  public GnomeDocumentBuilder()  {    this(true, false, false);  }    /**   * Constructs a new document builder.   * @param validate whether to validate during parsing   * @param coalesce whether to merge CDATA as text nodes   * @param expandEntities whether to expand entity references   */  public GnomeDocumentBuilder(boolean validate,                              boolean coalesce,                              boolean expandEntities)  {    this.validate = validate;    this.coalesce = coalesce;    this.expandEntities = expandEntities;  }  public DOMImplementation getDOMImplementation()  {    return this;  }  public boolean isNamespaceAware()  {    return true;  }  public boolean isValidating()  {    return validate;  }  public Document newDocument()  {    return createDocument(null, null, null);  }  public Document parse(InputSource input)    throws SAXException, IOException  {    NamedInputStream in = XMLJ.getInputStream(input);    byte[] detectBuffer = in.getDetectBuffer();    String publicId = input.getPublicId();    String systemId = input.getSystemId();    String base = XMLJ.getBaseURI(systemId);    // Handle zero-length document    if (detectBuffer == null)      {        throw new SAXParseException("No document element", publicId,                                    systemId, 0, 0);      }    seenFatalError = false;    return parseStream(in,                       detectBuffer,                       publicId,                       systemId,                       base,                       validate,                       coalesce,                       expandEntities,                       true, //entityResolver != null,                       errorHandler != null);  }    private native Document parseStream(InputStream in,                                      byte[] detectBuffer,                                      String publicId,                                      String systemId,                                      String base,                                      boolean validate,                                      boolean coalesce,                                      boolean expandEntities,                                      boolean entityResolver,                                      boolean errorHandler);    public void setEntityResolver(EntityResolver resolver)  {    entityResolver = resolver;  }  public void setErrorHandler(ErrorHandler handler)  {    errorHandler = handler;  }  // -- DOMImplementation --  public boolean hasFeature(String name, String version)  {    if (name.length() == 0)      {        return false;      }    name = name.toLowerCase();    if (name.charAt(0) == '+')      {        name = name.substring(1);      }        if ("xml".equals(name) || "core".equals(name))      {        return (version == null ||                "".equals(version) ||                "1.0".equals(version) ||                "2.0".equals(version) ||                "3.0".equals(version));            }    else if ("ls".equals(name) || "ls-async".equals(name))      {        // TODO        /*        return (version == null ||                "".equals(version) ||                "3.0".equals(version));                */        return false;      }    else if ("traversal".equals(name))      {        return (version == null ||                "".equals(version) ||		"2.0".equals(version));      }    else if ("xpath".equals(name))      {        return (version == null ||                "".equals(version) ||                "3.0".equals(version));      }    return false;  }    // DOM Level 3  public Object getFeature(String feature, String version)  {    if (hasFeature(feature, version))      {        return this;      }    return null;  }    public native Document createDocument(String namespaceURI,                                        String qualifiedName,                                        DocumentType doctype);    public DocumentType createDocumentType(String qualifiedName,                                         String publicId,                                         String systemId)  {    return new StandaloneDocumentType(qualifiedName, publicId, systemId);  }    // Callback hooks from JNI    private void setDocumentLocator(Object ctx, Object loc)  {    // ignore  }    private InputStream resolveEntity(String publicId, String systemId,                                    String base)    throws SAXException, IOException  {    String url = XMLJ.getAbsoluteURI(base, systemId);    InputStream in = null;    if (entityResolver != null)      {        InputSource source = entityResolver.resolveEntity(publicId, url);        if (source != null)          {            in = XMLJ.getInputStream(source);          }      }    if (in == null)      {        in  = XMLJ.getInputStream(new URL(url));      }    return in;  }    private void warning(String message,                       int lineNumber,                       int columnNumber,                       String publicId,                       String systemId)    throws SAXException  {    if (!seenFatalError && errorHandler != null)      {        Locator l = new StandaloneLocator(lineNumber,                                          columnNumber,                                          publicId,                                          systemId);        errorHandler.warning(new SAXParseException(message, l));      }  }  private void error(String message,                     int lineNumber,                     int columnNumber,                     String publicId,                     String systemId)    throws SAXException  {    if (!seenFatalError && errorHandler != null)      {        Locator l = new StandaloneLocator(lineNumber,                                          columnNumber,                                          publicId,                                          systemId);        errorHandler.error(new SAXParseException(message, l));      }  }  private void fatalError(String message,                          int lineNumber,                          int columnNumber,                          String publicId,                          String systemId)    throws SAXException  {    if (!seenFatalError && errorHandler != null)      {        seenFatalError = true;        Locator l = new StandaloneLocator(lineNumber,                                          columnNumber,                                          publicId,                                          systemId);        errorHandler.fatalError(new SAXParseException(message, l));      }  }}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -