Exemplo n.º 1
0
  /**
   * DOCUMENT ME!
   *
   * @param uri DOCUMENT ME!
   * @param localName DOCUMENT ME!
   * @param qname DOCUMENT ME!
   * @throws SAXException DOCUMENT ME!
   */
  public void endElement(String uri, String localName, String qname) throws SAXException {
    log.debug("endElement()");
    log.debug("endElement(): localName is '" + localName + "'");

    // determine which tag these chars are for and save them
    if (isMimeType) {
      isMimeType = false;
      match.setMimeType(finalValue);
      log.debug("characters(): setting mimetype to '" + finalValue + "'");
    } else if (isExtension) {
      isExtension = false;
      match.setExtension(finalValue);
      log.debug("characters(): setting extension to '" + finalValue + "'");
    } else if (isDescription) {
      isDescription = false;
      match.setDescription(finalValue);
      log.debug("characters(): setting description to '" + finalValue + "'");
    } else if (isTest) {
      isTest = false;
      match.setTest(convertOctals(finalValue));
      log.debug("characters(): setting test to '" + convertOctals(finalValue) + "'");
    } else {
      // do nothing
    }

    finalValue = "";

    // need to save the current matcher here if it is filled out enough and
    // we have an /matcher
    if (localName.equals("match")) {
      // FIXME - make sure the MagicMatcher isValid() test works
      if (matcher.isValid()) {
        // set the collected properties on this matcher
        match.setProperties(properties);

        // add root match
        if (stack.size() == 0) {
          log.debug("endElement(): adding root matcher");
          matchers.add(matcher);
        } else {
          // we need to add the match to it's parent which is on the
          // stack
          log.debug("endElement(): adding sub matcher");

          MagicMatcher m = (MagicMatcher) stack.get(stack.size() - 1);
          m.addSubMatcher(matcher);
        }
      } else {
        // don't add invalid matchers
        log.info("endElement(): not adding invalid matcher '" + match.getDescription() + "'");
      }

      matcher = null;
      properties = null;

      // restore matcher from the stack if we have an /matcher-list
    } else if (localName.equals("match-list")) {
      if (stack.size() > 0) {
        log.debug("endElement(): popping from the stack");
        matcher = (MagicMatcher) stack.get(stack.size() - 1);
        // pop from the stack
        stack.remove(matcher);
      }
    } else if (localName.equals("mimetype")) {
      isMimeType = false;
    } else if (localName.equals("extension")) {
      isExtension = false;
    } else if (localName.equals("description")) {
      isDescription = false;
    } else if (localName.equals("test")) {
      isTest = false;
    }
  }