Save This Page
Home » Xerces-J-src.2.9.1 » sax » [javadoc | source]
    1   /*
    2    * Licensed to the Apache Software Foundation (ASF) under one or more
    3    * contributor license agreements.  See the NOTICE file distributed with
    4    * this work for additional information regarding copyright ownership.
    5    * The ASF licenses this file to You under the Apache License, Version 2.0
    6    * (the "License"); you may not use this file except in compliance with
    7    * the License.  You may obtain a copy of the License at
    8    * 
    9    *      http://www.apache.org/licenses/LICENSE-2.0
   10    * 
   11    * Unless required by applicable law or agreed to in writing, software
   12    * distributed under the License is distributed on an "AS IS" BASIS,
   13    * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   14    * See the License for the specific language governing permissions and
   15    * limitations under the License.
   16    */
   17   
   18   package sax;
   19   
   20   import java.io.PrintWriter;
   21   
   22   import org.xml.sax.Attributes;
   23   import org.xml.sax.Parser;
   24   import org.xml.sax.SAXException;
   25   import org.xml.sax.SAXNotRecognizedException;
   26   import org.xml.sax.SAXNotSupportedException;
   27   import org.xml.sax.SAXParseException;
   28   import org.xml.sax.XMLReader;
   29   import org.xml.sax.helpers.DefaultHandler;
   30   import org.xml.sax.helpers.ParserAdapter;
   31   import org.xml.sax.helpers.ParserFactory;
   32   import org.xml.sax.helpers.XMLReaderFactory;
   33   
   34   /**
   35    * A sample SAX2 counter. This sample program illustrates how to
   36    * register a SAX2 ContentHandler and receive the callbacks in
   37    * order to print information about the document. The output of
   38    * this program shows the time and count of elements, attributes,
   39    * ignorable whitespaces, and characters appearing in the document.
   40    * <p>
   41    * This class is useful as a "poor-man's" performance tester to
   42    * compare the speed and accuracy of various SAX parsers. However,
   43    * it is important to note that the first parse time of a parser
   44    * will include both VM class load time and parser initialization
   45    * that would not be present in subsequent parses with the same
   46    * file.
   47    * <p>
   48    * <strong>Note:</strong> The results produced by this program
   49    * should never be accepted as true performance measurements.
   50    *
   51    * @author Andy Clark, IBM
   52    *
   53    * @version $Id: Counter.java 447686 2006-09-19 02:38:34Z mrglavas $
   54    */
   55   public class Counter
   56       extends DefaultHandler {
   57   
   58       //
   59       // Constants
   60       //
   61   
   62       // feature ids
   63   
   64       /** Namespaces feature id (http://xml.org/sax/features/namespaces). */
   65       protected static final String NAMESPACES_FEATURE_ID = "http://xml.org/sax/features/namespaces";
   66   
   67       /** Namespace prefixes feature id (http://xml.org/sax/features/namespace-prefixes). */
   68       protected static final String NAMESPACE_PREFIXES_FEATURE_ID = "http://xml.org/sax/features/namespace-prefixes";
   69   
   70       /** Validation feature id (http://xml.org/sax/features/validation). */
   71       protected static final String VALIDATION_FEATURE_ID = "http://xml.org/sax/features/validation";
   72   
   73       /** Schema validation feature id (http://apache.org/xml/features/validation/schema). */
   74       protected static final String SCHEMA_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/schema";
   75   
   76       /** Schema full checking feature id (http://apache.org/xml/features/validation/schema-full-checking). */
   77       protected static final String SCHEMA_FULL_CHECKING_FEATURE_ID = "http://apache.org/xml/features/validation/schema-full-checking";
   78       
   79       /** Honour all schema locations feature id (http://apache.org/xml/features/honour-all-schemaLocations). */
   80       protected static final String HONOUR_ALL_SCHEMA_LOCATIONS_ID = "http://apache.org/xml/features/honour-all-schemaLocations";
   81       
   82       /** Validate schema annotations feature id (http://apache.org/xml/features/validate-annotations) */
   83       protected static final String VALIDATE_ANNOTATIONS_ID = "http://apache.org/xml/features/validate-annotations";
   84   
   85       /** Dynamic validation feature id (http://apache.org/xml/features/validation/dynamic). */
   86       protected static final String DYNAMIC_VALIDATION_FEATURE_ID = "http://apache.org/xml/features/validation/dynamic";
   87       
   88       /** XInclude feature id (http://apache.org/xml/features/xinclude). */
   89       protected static final String XINCLUDE_FEATURE_ID = "http://apache.org/xml/features/xinclude";
   90       
   91       /** XInclude fixup base URIs feature id (http://apache.org/xml/features/xinclude/fixup-base-uris). */
   92       protected static final String XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID = "http://apache.org/xml/features/xinclude/fixup-base-uris";
   93       
   94       /** XInclude fixup language feature id (http://apache.org/xml/features/xinclude/fixup-language). */
   95       protected static final String XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID = "http://apache.org/xml/features/xinclude/fixup-language";
   96   
   97       // default settings
   98   
   99       /** Default parser name. */
  100       protected static final String DEFAULT_PARSER_NAME = "org.apache.xerces.parsers.SAXParser";
  101   
  102       /** Default repetition (1). */
  103       protected static final int DEFAULT_REPETITION = 1;
  104   
  105       /** Default namespaces support (true). */
  106       protected static final boolean DEFAULT_NAMESPACES = true;
  107   
  108       /** Default namespace prefixes (false). */
  109       protected static final boolean DEFAULT_NAMESPACE_PREFIXES = false;
  110   
  111       /** Default validation support (false). */
  112       protected static final boolean DEFAULT_VALIDATION = false;
  113   
  114       /** Default Schema validation support (false). */
  115       protected static final boolean DEFAULT_SCHEMA_VALIDATION = false;
  116   
  117       /** Default Schema full checking support (false). */
  118       protected static final boolean DEFAULT_SCHEMA_FULL_CHECKING = false;
  119       
  120       /** Default honour all schema locations (false). */
  121       protected static final boolean DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS = false;
  122       
  123       /** Default validate schema annotations (false). */
  124       protected static final boolean DEFAULT_VALIDATE_ANNOTATIONS = false;
  125   
  126       /** Default dynamic validation support (false). */
  127       protected static final boolean DEFAULT_DYNAMIC_VALIDATION = false;
  128       
  129       /** Default XInclude processing support (false). */
  130       protected static final boolean DEFAULT_XINCLUDE = false;
  131       
  132       /** Default XInclude fixup base URIs support (true). */
  133       protected static final boolean DEFAULT_XINCLUDE_FIXUP_BASE_URIS = true;
  134       
  135       /** Default XInclude fixup language support (true). */
  136       protected static final boolean DEFAULT_XINCLUDE_FIXUP_LANGUAGE = true;
  137   
  138       /** Default memory usage report (false). */
  139       protected static final boolean DEFAULT_MEMORY_USAGE = false;
  140   
  141       /** Default "tagginess" report (false). */
  142       protected static final boolean DEFAULT_TAGGINESS = false;
  143   
  144       //
  145       // Data
  146       //
  147   
  148       /** Number of elements. */
  149       protected long fElements;
  150   
  151       /** Number of attributes. */
  152       protected long fAttributes;
  153   
  154       /** Number of characters. */
  155       protected long fCharacters;
  156   
  157       /** Number of ignorable whitespace characters. */
  158       protected long fIgnorableWhitespace;
  159   
  160       /** Number of characters of tags. */
  161       protected long fTagCharacters;
  162   
  163       /** Number of other content characters for the "tagginess" calculation. */
  164       protected long fOtherCharacters;
  165   
  166       //
  167       // Constructors
  168       //
  169   
  170       /** Default constructor. */
  171       public Counter() {
  172       } // <init>()
  173   
  174       //
  175       // Public methods
  176       //
  177   
  178       /** Prints the results. */
  179       public void printResults(PrintWriter out, String uri, long time,
  180                                long memory, boolean tagginess,
  181                                int repetition) {
  182   
  183           // filename.xml: 631 ms (4 elems, 0 attrs, 78 spaces, 0 chars)
  184           out.print(uri);
  185           out.print(": ");
  186           if (repetition == 1) {
  187               out.print(time);
  188           }
  189           else {
  190               out.print(time);
  191               out.print('/');
  192               out.print(repetition);
  193               out.print('=');
  194               out.print(time/repetition);
  195           }
  196           out.print(" ms");
  197           if (memory != Long.MIN_VALUE) {
  198               out.print(", ");
  199               out.print(memory);
  200               out.print(" bytes");
  201           }
  202           out.print(" (");
  203           out.print(fElements);
  204           out.print(" elems, ");
  205           out.print(fAttributes);
  206           out.print(" attrs, ");
  207           out.print(fIgnorableWhitespace);
  208           out.print(" spaces, ");
  209           out.print(fCharacters);
  210           out.print(" chars)");
  211           if (tagginess) {
  212               out.print(' ');
  213               long totalCharacters = fTagCharacters + fOtherCharacters
  214                                    + fCharacters + fIgnorableWhitespace;
  215               long tagValue = fTagCharacters * 100 / totalCharacters;
  216               out.print(tagValue);
  217               out.print("% tagginess");
  218           }
  219           out.println();
  220           out.flush();
  221   
  222       } // printResults(PrintWriter,String,long)
  223   
  224       //
  225       // ContentHandler methods
  226       //
  227   
  228       /** Start document. */
  229       public void startDocument() throws SAXException {
  230   
  231           fElements            = 0;
  232           fAttributes          = 0;
  233           fCharacters          = 0;
  234           fIgnorableWhitespace = 0;
  235           fTagCharacters       = 0;
  236   
  237       } // startDocument()
  238   
  239       /** Start element. */
  240       public void startElement(String uri, String local, String raw,
  241                                Attributes attrs) throws SAXException {
  242   
  243           fElements++;
  244           fTagCharacters++; // open angle bracket
  245           fTagCharacters += raw.length();
  246           if (attrs != null) {
  247               int attrCount = attrs.getLength();
  248               fAttributes += attrCount;
  249               for (int i = 0; i < attrCount; i++) {
  250                   fTagCharacters++; // space
  251                   fTagCharacters += attrs.getQName(i).length();
  252                   fTagCharacters++; // '='
  253                   fTagCharacters++; // open quote
  254                   fOtherCharacters += attrs.getValue(i).length();
  255                   fTagCharacters++; // close quote
  256               }
  257           }
  258           fTagCharacters++; // close angle bracket
  259   
  260       } // startElement(String,String,StringAttributes)
  261   
  262       /** Characters. */
  263       public void characters(char ch[], int start, int length)
  264           throws SAXException {
  265   
  266           fCharacters += length;
  267   
  268       } // characters(char[],int,int);
  269   
  270       /** Ignorable whitespace. */
  271       public void ignorableWhitespace(char ch[], int start, int length)
  272           throws SAXException {
  273   
  274           fIgnorableWhitespace += length;
  275   
  276       } // ignorableWhitespace(char[],int,int);
  277   
  278       /** Processing instruction. */
  279       public void processingInstruction(String target, String data)
  280           throws SAXException {
  281           fTagCharacters += 2; // "<?"
  282           fTagCharacters += target.length();
  283           if (data != null && data.length() > 0) {
  284               fTagCharacters++; // space
  285               fOtherCharacters += data.length();
  286           }
  287           fTagCharacters += 2; // "?>"
  288       } // processingInstruction(String,String)
  289   
  290       //
  291       // ErrorHandler methods
  292       //
  293   
  294       /** Warning. */
  295       public void warning(SAXParseException ex) throws SAXException {
  296           printError("Warning", ex);
  297       } // warning(SAXParseException)
  298   
  299       /** Error. */
  300       public void error(SAXParseException ex) throws SAXException {
  301           printError("Error", ex);
  302       } // error(SAXParseException)
  303   
  304       /** Fatal error. */
  305       public void fatalError(SAXParseException ex) throws SAXException {
  306           printError("Fatal Error", ex);
  307           //throw ex;
  308       } // fatalError(SAXParseException)
  309   
  310       //
  311       // Protected methods
  312       //
  313   
  314       /** Prints the error message. */
  315       protected void printError(String type, SAXParseException ex) {
  316   
  317           System.err.print("[");
  318           System.err.print(type);
  319           System.err.print("] ");
  320           if (ex== null) {
  321               System.out.println("!!!");
  322           }
  323           String systemId = ex.getSystemId();
  324           if (systemId != null) {
  325               int index = systemId.lastIndexOf('/');
  326               if (index != -1)
  327                   systemId = systemId.substring(index + 1);
  328               System.err.print(systemId);
  329           }
  330           System.err.print(':');
  331           System.err.print(ex.getLineNumber());
  332           System.err.print(':');
  333           System.err.print(ex.getColumnNumber());
  334           System.err.print(": ");
  335           System.err.print(ex.getMessage());
  336           System.err.println();
  337           System.err.flush();
  338   
  339       } // printError(String,SAXParseException)
  340   
  341       //
  342       // MAIN
  343       //
  344   
  345       /** Main program entry point. */
  346       public static void main(String argv[]) {
  347   
  348           // is there anything to do?
  349           if (argv.length == 0) {
  350               printUsage();
  351               System.exit(1);
  352           }
  353   
  354           // variables
  355           Counter counter = new Counter();
  356           PrintWriter out = new PrintWriter(System.out);
  357           XMLReader parser = null;
  358           int repetition = DEFAULT_REPETITION;
  359           boolean namespaces = DEFAULT_NAMESPACES;
  360           boolean namespacePrefixes = DEFAULT_NAMESPACE_PREFIXES;
  361           boolean validation = DEFAULT_VALIDATION;
  362           boolean schemaValidation = DEFAULT_SCHEMA_VALIDATION;
  363           boolean schemaFullChecking = DEFAULT_SCHEMA_FULL_CHECKING;
  364           boolean honourAllSchemaLocations = DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS;
  365           boolean validateAnnotations = DEFAULT_VALIDATE_ANNOTATIONS;
  366           boolean dynamicValidation = DEFAULT_DYNAMIC_VALIDATION;
  367           boolean xincludeProcessing = DEFAULT_XINCLUDE;
  368           boolean xincludeFixupBaseURIs = DEFAULT_XINCLUDE_FIXUP_BASE_URIS;
  369           boolean xincludeFixupLanguage = DEFAULT_XINCLUDE_FIXUP_LANGUAGE;
  370           boolean memoryUsage = DEFAULT_MEMORY_USAGE;
  371           boolean tagginess = DEFAULT_TAGGINESS;
  372   
  373           // process arguments
  374           for (int i = 0; i < argv.length; i++) {
  375               String arg = argv[i];
  376               if (arg.startsWith("-")) {
  377                   String option = arg.substring(1);
  378                   if (option.equals("p")) {
  379                       // get parser name
  380                       if (++i == argv.length) {
  381                           System.err.println("error: Missing argument to -p option.");
  382                           continue;
  383                       }
  384                       String parserName = argv[i];
  385   
  386                       // create parser
  387                       try {
  388                           parser = XMLReaderFactory.createXMLReader(parserName);
  389                       }
  390                       catch (Exception e) {
  391                           try {
  392                               Parser sax1Parser = ParserFactory.makeParser(parserName);
  393                               parser = new ParserAdapter(sax1Parser);
  394                               System.err.println("warning: Features and properties not supported on SAX1 parsers.");
  395                           }
  396                           catch (Exception ex) {
  397                               parser = null;
  398                               System.err.println("error: Unable to instantiate parser ("+parserName+")");
  399                           }
  400                       }
  401                       continue;
  402                   }
  403                   if (option.equals("x")) {
  404                       if (++i == argv.length) {
  405                           System.err.println("error: Missing argument to -x option.");
  406                           continue;
  407                       }
  408                       String number = argv[i];
  409                       try {
  410                           int value = Integer.parseInt(number);
  411                           if (value < 1) {
  412                               System.err.println("error: Repetition must be at least 1.");
  413                               continue;
  414                           }
  415                           repetition = value;
  416                       }
  417                       catch (NumberFormatException e) {
  418                           System.err.println("error: invalid number ("+number+").");
  419                       }
  420                       continue;
  421                   }
  422                   if (option.equalsIgnoreCase("n")) {
  423                       namespaces = option.equals("n");
  424                       continue;
  425                   }
  426                   if (option.equalsIgnoreCase("np")) {
  427                       namespacePrefixes = option.equals("np");
  428                       continue;
  429                   }
  430                   if (option.equalsIgnoreCase("v")) {
  431                       validation = option.equals("v");
  432                       continue;
  433                   }
  434                   if (option.equalsIgnoreCase("s")) {
  435                       schemaValidation = option.equals("s");
  436                       continue;
  437                   }
  438                   if (option.equalsIgnoreCase("f")) {
  439                       schemaFullChecking = option.equals("f");
  440                       continue;
  441                   }
  442                   if (option.equalsIgnoreCase("hs")) {
  443                       honourAllSchemaLocations = option.equals("hs");
  444                       continue;
  445                   }
  446                   if (option.equalsIgnoreCase("va")) {
  447                       validateAnnotations = option.equals("va");
  448                       continue;
  449                   }
  450                   if (option.equalsIgnoreCase("dv")) {
  451                       dynamicValidation = option.equals("dv");
  452                       continue;
  453                   }
  454                   if (option.equalsIgnoreCase("xi")) {
  455                       xincludeProcessing = option.equals("xi");
  456                       continue;
  457                   }
  458                   if (option.equalsIgnoreCase("xb")) {
  459                       xincludeFixupBaseURIs = option.equals("xb");
  460                       continue;
  461                   }
  462                   if (option.equalsIgnoreCase("xl")) {
  463                       xincludeFixupLanguage = option.equals("xl");
  464                       continue;
  465                   }
  466                   if (option.equalsIgnoreCase("m")) {
  467                       memoryUsage = option.equals("m");
  468                       continue;
  469                   }
  470                   if (option.equalsIgnoreCase("t")) {
  471                       tagginess = option.equals("t");
  472                       continue;
  473                   }
  474                   if (option.equals("-rem")) {
  475                       if (++i == argv.length) {
  476                           System.err.println("error: Missing argument to -# option.");
  477                           continue;
  478                       }
  479                       System.out.print("# ");
  480                       System.out.println(argv[i]);
  481                       continue;
  482                   }
  483                   if (option.equals("h")) {
  484                       printUsage();
  485                       continue;
  486                   }
  487                   System.err.println("error: unknown option ("+option+").");
  488                   continue;
  489               }
  490   
  491               // use default parser?
  492               if (parser == null) {
  493   
  494                   // create parser
  495                   try {
  496                       parser = XMLReaderFactory.createXMLReader(DEFAULT_PARSER_NAME);
  497                   }
  498                   catch (Exception e) {
  499                       System.err.println("error: Unable to instantiate parser ("+DEFAULT_PARSER_NAME+")");
  500                       continue;
  501                   }
  502               }
  503   
  504               // set parser features
  505               try {
  506                   parser.setFeature(NAMESPACES_FEATURE_ID, namespaces);
  507               }
  508               catch (SAXException e) {
  509                   System.err.println("warning: Parser does not support feature ("+NAMESPACES_FEATURE_ID+")");
  510               }
  511               try {
  512                   parser.setFeature(NAMESPACE_PREFIXES_FEATURE_ID, namespacePrefixes);
  513               }
  514               catch (SAXException e) {
  515                   System.err.println("warning: Parser does not support feature ("+NAMESPACE_PREFIXES_FEATURE_ID+")");
  516               }
  517               try {
  518                   parser.setFeature(VALIDATION_FEATURE_ID, validation);
  519               }
  520               catch (SAXException e) {
  521                   System.err.println("warning: Parser does not support feature ("+VALIDATION_FEATURE_ID+")");
  522               }
  523               try {
  524                   parser.setFeature(SCHEMA_VALIDATION_FEATURE_ID, schemaValidation);
  525               }
  526               catch (SAXNotRecognizedException e) {
  527                   System.err.println("warning: Parser does not recognize feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
  528   
  529               }
  530               catch (SAXNotSupportedException e) {
  531                   System.err.println("warning: Parser does not support feature ("+SCHEMA_VALIDATION_FEATURE_ID+")");
  532               }
  533               try {
  534                   parser.setFeature(SCHEMA_FULL_CHECKING_FEATURE_ID, schemaFullChecking);
  535               }
  536               catch (SAXNotRecognizedException e) {
  537                   System.err.println("warning: Parser does not recognize feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
  538   
  539               }
  540               catch (SAXNotSupportedException e) {
  541                   System.err.println("warning: Parser does not support feature ("+SCHEMA_FULL_CHECKING_FEATURE_ID+")");
  542               }
  543               try {
  544                   parser.setFeature(HONOUR_ALL_SCHEMA_LOCATIONS_ID, honourAllSchemaLocations);
  545               }
  546               catch (SAXNotRecognizedException e) {
  547                   System.err.println("warning: Parser does not recognize feature ("+HONOUR_ALL_SCHEMA_LOCATIONS_ID+")");
  548               }
  549               catch (SAXNotSupportedException e) {
  550                   System.err.println("warning: Parser does not support feature ("+HONOUR_ALL_SCHEMA_LOCATIONS_ID+")");
  551               }
  552               try {
  553                   parser.setFeature(VALIDATE_ANNOTATIONS_ID, validateAnnotations);
  554               }
  555               catch (SAXNotRecognizedException e) {
  556                   System.err.println("warning: Parser does not recognize feature ("+VALIDATE_ANNOTATIONS_ID+")");
  557   
  558               }
  559               catch (SAXNotSupportedException e) {
  560                   System.err.println("warning: Parser does not support feature ("+VALIDATE_ANNOTATIONS_ID+")");
  561               }
  562               try {
  563                   parser.setFeature(DYNAMIC_VALIDATION_FEATURE_ID, dynamicValidation);
  564               }
  565               catch (SAXNotRecognizedException e) {
  566                   System.err.println("warning: Parser does not recognize feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")");
  567   
  568               }
  569               catch (SAXNotSupportedException e) {
  570                   System.err.println("warning: Parser does not support feature ("+DYNAMIC_VALIDATION_FEATURE_ID+")");
  571               }
  572               try {
  573                   parser.setFeature(XINCLUDE_FEATURE_ID, xincludeProcessing);
  574               }
  575               catch (SAXNotRecognizedException e) {
  576                   System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FEATURE_ID+")");
  577   
  578               }
  579               catch (SAXNotSupportedException e) {
  580                   System.err.println("warning: Parser does not support feature ("+XINCLUDE_FEATURE_ID+")");
  581               }
  582               try {
  583                   parser.setFeature(XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID, xincludeFixupBaseURIs);
  584               }
  585               catch (SAXNotRecognizedException e) {
  586                   System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID+")");
  587   
  588               }
  589               catch (SAXNotSupportedException e) {
  590                   System.err.println("warning: Parser does not support feature ("+XINCLUDE_FIXUP_BASE_URIS_FEATURE_ID+")");
  591               }
  592               try {
  593                   parser.setFeature(XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID, xincludeFixupLanguage);
  594               }
  595               catch (SAXNotRecognizedException e) {
  596                   System.err.println("warning: Parser does not recognize feature ("+XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID+")");
  597   
  598               }
  599               catch (SAXNotSupportedException e) {
  600                   System.err.println("warning: Parser does not support feature ("+XINCLUDE_FIXUP_LANGUAGE_FEATURE_ID+")");
  601               }
  602   
  603               // parse file
  604               parser.setContentHandler(counter);
  605               parser.setErrorHandler(counter);
  606               try {
  607                   long timeBefore = System.currentTimeMillis();
  608                   long memoryBefore = Runtime.getRuntime().freeMemory();
  609                   for (int j = 0; j < repetition; j++) {
  610                       parser.parse(arg);
  611                   }
  612                   long memoryAfter = Runtime.getRuntime().freeMemory();
  613                   long timeAfter = System.currentTimeMillis();
  614   
  615                   long time = timeAfter - timeBefore;
  616                   long memory = memoryUsage
  617                               ? memoryBefore - memoryAfter : Long.MIN_VALUE;
  618                   counter.printResults(out, arg, time, memory, tagginess,
  619                                        repetition);
  620               }
  621               catch (SAXParseException e) {
  622                   // ignore
  623               }
  624               catch (Exception e) {
  625                   System.err.println("error: Parse error occurred - "+e.getMessage());
  626                   Exception se = e;
  627                   if (e instanceof SAXException) {
  628                       se = ((SAXException)e).getException();
  629                   }
  630                   if (se != null)
  631                     se.printStackTrace(System.err);
  632                   else
  633                     e.printStackTrace(System.err);
  634   
  635               }
  636           }
  637   
  638       } // main(String[])
  639   
  640       //
  641       // Private static methods
  642       //
  643   
  644       /** Prints the usage. */
  645       private static void printUsage() {
  646   
  647           System.err.println("usage: java sax.Counter (options) uri ...");
  648           System.err.println();
  649   
  650           System.err.println("options:");
  651           System.err.println("  -p name     Select parser by name.");
  652           System.err.println("  -x number   Select number of repetitions.");
  653           System.err.println("  -n  | -N    Turn on/off namespace processing.");
  654           System.err.println("  -np | -NP   Turn on/off namespace prefixes.");
  655           System.err.println("              NOTE: Requires use of -n.");
  656           System.err.println("  -v  | -V    Turn on/off validation.");
  657           System.err.println("  -s  | -S    Turn on/off Schema validation support.");
  658           System.err.println("              NOTE: Not supported by all parsers.");
  659           System.err.println("  -f  | -F    Turn on/off Schema full checking.");
  660           System.err.println("              NOTE: Requires use of -s and not supported by all parsers.");
  661           System.err.println("  -hs | -HS   Turn on/off honouring of all schema locations.");
  662           System.err.println("              NOTE: Requires use of -s and not supported by all parsers.");
  663           System.err.println("  -va | -VA   Turn on/off validation of schema annotations.");
  664           System.err.println("              NOTE: Requires use of -s and not supported by all parsers.");
  665           System.err.println("  -dv | -DV   Turn on/off dynamic validation.");
  666           System.err.println("              NOTE: Not supported by all parsers.");
  667           System.err.println("  -xi | -XI   Turn on/off XInclude processing.");
  668           System.err.println("              NOTE: Not supported by all parsers.");
  669           System.err.println("  -xb | -XB   Turn on/off base URI fixup during XInclude processing.");
  670           System.err.println("              NOTE: Requires use of -xi and not supported by all parsers.");
  671           System.err.println("  -xl | -XL   Turn on/off language fixup during XInclude processing.");
  672           System.err.println("              NOTE: Requires use of -xi and not supported by all parsers.");
  673           System.err.println("  -m  | -M    Turn on/off memory usage report");
  674           System.err.println("  -t  | -T    Turn on/off \"tagginess\" report.");
  675           System.err.println("  --rem text  Output user defined comment before next parse.");
  676           System.err.println("  -h          This help screen.");
  677   
  678           System.err.println();
  679           System.err.println("defaults:");
  680           System.err.println("  Parser:     "+DEFAULT_PARSER_NAME);
  681           System.err.println("  Repetition: "+DEFAULT_REPETITION);
  682           System.err.print("  Namespaces: ");
  683           System.err.println(DEFAULT_NAMESPACES ? "on" : "off");
  684           System.err.print("  Prefixes:   ");
  685           System.err.println(DEFAULT_NAMESPACE_PREFIXES ? "on" : "off");
  686           System.err.print("  Validation: ");
  687           System.err.println(DEFAULT_VALIDATION ? "on" : "off");
  688           System.err.print("  Schema:     ");
  689           System.err.println(DEFAULT_SCHEMA_VALIDATION ? "on" : "off");
  690           System.err.print("  Schema full checking:            ");
  691           System.err.println(DEFAULT_SCHEMA_FULL_CHECKING ? "on" : "off");
  692           System.err.print("  Honour all schema locations:     ");
  693           System.err.println(DEFAULT_HONOUR_ALL_SCHEMA_LOCATIONS ? "on" : "off");
  694           System.err.print("  Validate annotations:            ");
  695           System.err.println(DEFAULT_VALIDATE_ANNOTATIONS ? "on" : "off");
  696           System.err.print("  Dynamic:    ");
  697           System.err.println(DEFAULT_DYNAMIC_VALIDATION ? "on" : "off");
  698           System.err.print("  XInclude:   ");
  699           System.err.println(DEFAULT_XINCLUDE ? "on" : "off");
  700           System.err.print("  XInclude base URI fixup:  ");
  701           System.err.println(DEFAULT_XINCLUDE_FIXUP_BASE_URIS ? "on" : "off");
  702           System.err.print("  XInclude language fixup:  ");
  703           System.err.println(DEFAULT_XINCLUDE_FIXUP_LANGUAGE ? "on" : "off");
  704           System.err.print("  Memory:     ");
  705           System.err.println(DEFAULT_MEMORY_USAGE ? "on" : "off");
  706           System.err.print("  Tagginess:  ");
  707           System.err.println(DEFAULT_TAGGINESS ? "on" : "off");
  708   
  709           System.err.println();
  710           System.err.println("notes:");
  711           System.err.println("  The speed and memory results from this program should NOT be used as the");
  712           System.err.println("  basis of parser performance comparison! Real analytical methods should be");
  713           System.err.println("  used. For better results, perform multiple document parses within the same");
  714           System.err.println("  virtual machine to remove class loading from parse time and memory usage.");
  715           System.err.println();
  716           System.err.println("  The \"tagginess\" measurement gives a rough estimate of the percentage of");
  717           System.err.println("  markup versus content in the XML document. The percent tagginess of a ");
  718           System.err.println("  document is equal to the minimum amount of tag characters required for ");
  719           System.err.println("  elements, attributes, and processing instructions divided by the total");
  720           System.err.println("  amount of characters (characters, ignorable whitespace, and tag characters)");
  721           System.err.println("  in the document.");
  722           System.err.println();
  723           System.err.println("  Not all features are supported by different parsers.");
  724   
  725       } // printUsage()
  726   
  727   } // class Counter

Save This Page
Home » Xerces-J-src.2.9.1 » sax » [javadoc | source]