Пример #1
0
  /**
   * This is a method that must be overwritten for the SAXParser. It is called for the charaters
   * that lie between tags. Since the parse doesn't guarantee delivery of all of the characters
   * between the start and end tags, the HistoryParser must be prepared to receive more than one
   * callout before receiving notification of the ending tag.
   *
   * <p>(non-Javadoc)
   *
   * @see org.xml.sax.ContentHandler#characters(char[], int, int)
   */
  @Override
  public void characters(char ch[], int start, int length) throws SAXException {
    String data = new String(ch, start, length);
    logger.trace(
        PC2LogCategory.Parser,
        subCat,
        curTag + " - CDATA: " + length + " characters. Data=[" + data + "].");

    logger.trace(PC2LogCategory.Parser, subCat, "Ignoring characters(" + data + ").");
  }
Пример #2
0
 /**
  * This is a method that must be overwritten for the SAXParser. It is called by the parser upon
  * initiating parsing allowing the application to create any variables or infrastructure it may
  * need. The HistoryParser simply logs that it is starting and creates the final History
  * container.
  */
 @Override
 public void startDocument() throws SAXException {
   logger.info(
       PC2LogCategory.UI, subCat, "HistoryParser - Starting to parse " + History.HISTORY_FILE);
 }
Пример #3
0
 public HistoryParser() {
   super();
   logger = LogAPI.getInstance();
 }
Пример #4
0
  @Override
  public void endElement(String uri, String name, String qName) throws SAXException {
    logger.trace(PC2LogCategory.UI, subCat, "ending element (" + qName + ")");

    curTag = null;
  }
Пример #5
0
  /**
   * This is a method that must be overwritten for the SAXParser. It is called at the start of each
   * element and is were the HistoryParser begins to separate the various tags into their respective
   * objects. Validation of each mandatory attribute and children elements begins in this method.
   *
   * <p>(non-Javadoc)
   *
   * @see org.xml.sax.ContentHandler#startElement(java.lang.String, java.lang.String,
   *     java.lang.String, org.xml.sax.Attributes)
   */
  @Override
  public void startElement(String uri, String name, String qName, Attributes atts)
      throws SAXException {

    logger.trace(PC2LogCategory.UI, subCat, "starting element (" + qName + ")");
    logger.trace(PC2LogCategory.UI, subCat, "   number of attributes: " + atts.getLength());
    curTag = qName;
    boolean unrecognizedTag = false;
    int count = atts.getLength();
    if (qName.equals(PCSIM2)) {
      for (int i = 0; i < count; i++) {
        String attr = atts.getLocalName(i);
        if (attr.equals(VERSION)) {
          // Add any versioning operations that might be needed in the future here
          // for this initial release though, there is no operation as the version
          // is assigned automatically to the History class.
        } else {
          logger.trace(
              PC2LogCategory.UI,
              subCat,
              "The attribute["
                  + attr
                  + "] is an unexpected attribute for the "
                  + PCSIM2
                  + " tag. It has been ignored.");
        }
      }
      if (history == null) history = History.getInstance();
      return;
    } else {

      switch (qName.charAt(0)) {
        case 'b':
          if (qName.equals(BATCH)) {
            for (int i = 0; i < count; i++) {
              String attr = atts.getLocalName(i);

              if (attr.equals(DIR)) {
                File f = new File(atts.getValue(i));
                if (f.isDirectory() && f.canRead()) history.lastBatchDirectory = f;
              } else {
                logger.trace(
                    PC2LogCategory.UI,
                    subCat,
                    "The attribute["
                        + attr
                        + "] is an unexpected attribute for the "
                        + BATCH
                        + " tag. It has been ignored.");
              }
            }
          } else unrecognizedTag = true;
          break;

        case 'd':
          if (qName.equals(DCF)) {
            for (int i = 0; i < count; i++) {
              String attr = atts.getLocalName(i);

              if (attr.equals(DIR)) {
                File f = new File(atts.getValue(i));
                if (f.isDirectory() && f.canRead()) history.lastDCFDirectory = f;
              } else {
                logger.trace(
                    PC2LogCategory.UI,
                    subCat,
                    "The attribute["
                        + attr
                        + "] is an unexpected attribute for the "
                        + DCF
                        + " tag. It has been ignored.");
              }
            }
          } else unrecognizedTag = true;
          break;
        case 'h':
          if (qName.equals(HISTORY)) {
            for (int i = 0; i < count; i++) {
              String attr = atts.getLocalName(i);

              if (attr.equals(FILE)) {
                String value = atts.getValue(i);
                File f = new File(value);
                if (f.isFile() && f.canRead()) history.addHistoryFile(f);
              } else {
                logger.trace(
                    PC2LogCategory.UI,
                    subCat,
                    "The attribute["
                        + attr
                        + "] is an unexpected attribute for the "
                        + DCF
                        + " tag. It has been ignored.");
              }
            }
          } else unrecognizedTag = true;
          break;
        case 'p':
          if (qName.equals(PCF)) {
            for (int i = 0; i < count; i++) {
              String attr = atts.getLocalName(i);

              if (attr.equals(DIR)) {
                File f = new File(atts.getValue(i));
                if (f.isDirectory() && f.canRead()) history.lastPCFDirectory = f;
              } else {
                logger.trace(
                    PC2LogCategory.UI,
                    subCat,
                    "The attribute["
                        + attr
                        + "] is an unexpected attribute for the "
                        + PCF
                        + " tag. It has been ignored.");
              }
            }
          } else unrecognizedTag = true;
          break;

        case 's':
          if (qName.equals(SCRIPTS)) {
            for (int i = 0; i < count; i++) {
              String attr = atts.getLocalName(i);

              if (attr.equals(DIR)) {
                File f = new File(atts.getValue(i));
                if (f.isDirectory() && f.canRead()) history.lastScriptsDirectory = f;
              } else {
                logger.trace(
                    PC2LogCategory.UI,
                    subCat,
                    "The attribute["
                        + attr
                        + "] is an unexpected attribute for the "
                        + SCRIPTS
                        + " tag. It has been ignored.");
              }
            }
          } else unrecognizedTag = true;
          break;
        default:
          throw new PC2XMLException(
              History.HISTORY_FILE.getName(),
              "Encountered unexpected tag(" + qName + ") element.",
              l);
      }
    }

    if (unrecognizedTag)
      throw new PC2XMLException(
          History.HISTORY_FILE.getName(), "Encountered unexpected tag(" + qName + ") element.", l);
  }