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

📄 nonvalidator.java

📁 Nano的XML解析器
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
/* NonValidator.java                                               NanoXML/Java * * $Revision: 1.4 $ * $Date: 2002/02/03 21:19:38 $ * $Name: RELEASE_2_2_1 $ * * This file is part of NanoXML 2 for Java. * Copyright (C) 2000-2002 Marc De Scheemaecker, All Rights Reserved. * * This software is provided 'as-is', without any express or implied warranty. * In no event will the authors be held liable for any damages arising from the * use of this software. * * Permission is granted to anyone to use this software for any purpose, * including commercial applications, and to alter it and redistribute it * freely, subject to the following restrictions: * *  1. The origin of this software must not be misrepresented; you must not *     claim that you wrote the original software. If you use this software in *     a product, an acknowledgment in the product documentation would be *     appreciated but is not required. * *  2. Altered source versions must be plainly marked as such, and must not be *     misrepresented as being the original software. * *  3. This notice may not be removed or altered from any source distribution. */package net.n3.nanoxml;import java.io.Reader;import java.io.IOException;import java.io.StringReader;import java.util.Enumeration;import java.util.Hashtable;import java.util.Properties;import java.util.Stack;/** * NonValidator is a concrete implementation of IXMLValidator which processes * the DTD and handles entity definitions. It does not do any validation * itself. * * @author Marc De Scheemaecker * @version $Name: RELEASE_2_2_1 $, $Revision: 1.4 $ */public class NonValidator   implements IXMLValidator{   /**    * The parameter entity resolver.    */   protected IXMLEntityResolver parameterEntityResolver;   /**    * Contains the default values for attributes for the different element    * types.    */   protected Hashtable attributeDefaultValues;   /**    * The stack of elements to be processed.    */   protected Stack currentElements;   /**    * Creates the &quot;validator&quot;.    */   public NonValidator()   {      this.attributeDefaultValues = new Hashtable();      this.currentElements = new Stack();      this.parameterEntityResolver = new XMLEntityResolver();   }   /**    * Cleans up the object when it's destroyed.    */   protected void finalize()      throws Throwable   {      this.parameterEntityResolver = null;      this.attributeDefaultValues.clear();      this.attributeDefaultValues = null;      this.currentElements.clear();      this.currentElements = null;      super.finalize();   }   /**    * Sets the parameter entity resolver.    *    * @param resolver the entity resolver.    */   public void setParameterEntityResolver(IXMLEntityResolver resolver)   {      this.parameterEntityResolver = resolver;   }   /**    * Returns the parameter entity resolver.    *    * @return the entity resolver.    */   public IXMLEntityResolver getParameterEntityResolver()   {      return this.parameterEntityResolver;   }   /**    * Parses the DTD. The validator object is responsible for reading the    * full DTD.    *    * @param publicID       the public ID, which may be null.    * @param reader         the reader to read the DTD from.    * @param entityResolver the entity resolver.    * @param external       true if the DTD is external.    *    * @throws java.lang.Exception    *     If something went wrong.    */   public void parseDTD(String             publicID,                        IXMLReader         reader,                        IXMLEntityResolver entityResolver,                        boolean            external)      throws Exception   {      XMLUtil.skipWhitespace(reader, null);      int origLevel = reader.getStreamLevel();      for (;;) {         String str = XMLUtil.read(reader, '%');         char ch = str.charAt(0);         if (ch == '%') {            XMLUtil.processEntity(str, reader,                                  this.parameterEntityResolver);            continue;         } else if (ch == '<') {            this.processElement(reader, entityResolver);         } else if (ch == ']') {            return; // end internal DTD         } else {            XMLUtil.errorInvalidInput(reader.getSystemID(),                                      reader.getLineNr(),                                      str);         }         do {            ch = reader.read();            if (external && (reader.getStreamLevel() < origLevel)) {               reader.unread(ch);               return; // end external DTD            }         } while ((ch == ' ') || (ch == '\t') || (ch == '\n')                  || (ch == '\r'));         reader.unread(ch);      }   }   /**    * Processes an element in the DTD.    *    * @param reader         the reader to read data from.    * @param entityResolver the entity resolver.    *    * @throws java.lang.Exception    *     If something went wrong.    */   protected void processElement(IXMLReader         reader,                                 IXMLEntityResolver entityResolver)      throws Exception   {      String str = XMLUtil.read(reader, '%');      char ch = str.charAt(0);      if (ch != '!') {         XMLUtil.skipTag(reader);         return;      }      str = XMLUtil.read(reader, '%');      ch = str.charAt(0);      switch (ch) {         case '-':            XMLUtil.skipComment(reader);            break;         case '[':            this.processConditionalSection(reader, entityResolver);            break;         case 'E':            this.processEntity(reader, entityResolver);            break;         case 'A':            this.processAttList(reader, entityResolver);            break;         default:            XMLUtil.skipTag(reader);      }   }   /**    * Processes a conditional section.    *    * @param reader         the reader to read data from.    * @param entityResolver the entity resolver.    *    * @throws java.lang.Exception    *     If something went wrong.    */   protected void processConditionalSection(IXMLReader         reader,                                            IXMLEntityResolver entityResolver)      throws Exception   {      XMLUtil.skipWhitespace(reader, null);      String str = XMLUtil.read(reader, '%');      char ch = str.charAt(0);      if (ch != 'I') {         XMLUtil.skipTag(reader);         return;      }      str = XMLUtil.read(reader, '%');      ch = str.charAt(0);      switch (ch) {         case 'G':            this.processIgnoreSection(reader, entityResolver);            return;         case 'N':            break;         default:            XMLUtil.skipTag(reader);            return;      }      if (! XMLUtil.checkLiteral(reader, "CLUDE")) {         XMLUtil.skipTag(reader);         return;      }      XMLUtil.skipWhitespace(reader, null);      str = XMLUtil.read(reader, '%');      ch = str.charAt(0);      if (ch != '[') {         XMLUtil.skipTag(reader);         return;      }      Reader subreader = new CDATAReader(reader);      StringBuffer buf = new StringBuffer(1024);      for (;;) {         int ch2 = subreader.read();         if (ch2 < 0) {            break;         }         buf.append((char) ch2);      }      subreader.close();      reader.startNewStream(new StringReader(buf.toString()));   }   /**    * Processes an ignore section.    *    * @param reader         the reader to read data from.    * @param entityResolver the entity resolver.    *    * @throws java.lang.Exception    *     If something went wrong.    */   protected void processIgnoreSection(IXMLReader         reader,                                       IXMLEntityResolver entityResolver)      throws Exception   {      if (! XMLUtil.checkLiteral(reader, "NORE")) {

⌨️ 快捷键说明

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