/** * DOCUMENT ME! * * @return DOCUMENT ME! * @throws CloneNotSupportedException DOCUMENT ME! */ @Override protected Object clone() throws CloneNotSupportedException { final MagicMatcher clone = new MagicMatcher(); clone.setMatch((MagicMatch) this.match.clone()); final Iterator<MagicMatcher> i = this.subMatchers.iterator(); final ArrayList<MagicMatcher> sub = new ArrayList<MagicMatcher>(); while (i.hasNext()) { final MagicMatcher m = i.next(); sub.add((MagicMatcher) m.clone()); } clone.setSubMatchers(sub); return clone; }
/** * DOCUMENT ME! * * @param uri DOCUMENT ME! * @param localName DOCUMENT ME! * @param qname DOCUMENT ME! * @param attributes DOCUMENT ME! * @throws SAXException DOCUMENT ME! */ public void startElement(String uri, String localName, String qname, Attributes attributes) throws SAXException { log.debug("startElement()"); log.debug("startElement(): localName is '" + localName + "'"); // create a new matcher if (localName.equals("match")) { log.debug("startElement(): creating new matcher"); // match to hold data match = new MagicMatch(); // our matcher matcher = new MagicMatcher(); matcher.setMatch(match); } // these are subelements of matcher, but also occur elsewhere if (matcher != null) { if (localName.equals("mimetype")) { isMimeType = true; } else if (localName.equals("extension")) { isExtension = true; } else if (localName.equals("description")) { isDescription = true; } else if (localName.equals("test")) { isTest = true; int length = attributes.getLength(); for (int i = 0; i < length; i++) { String attrLocalName = attributes.getLocalName(i); String attrValue = attributes.getValue(i); if (attrLocalName.equals("offset")) { if (!attrValue.equals("")) { match.setOffset(new Integer(attrValue).intValue()); log.debug("startElement(): setting offset to '" + attrValue + "'"); } } else if (attrLocalName.equals("length")) { if (!attrValue.equals("")) { match.setLength(new Integer(attrValue).intValue()); log.debug("startElement(): setting length to '" + attrValue + "'"); } } else if (attrLocalName.equals("type")) { match.setType(attrValue); log.debug("startElement(): setting type to '" + attrValue + "'"); } else if (attrLocalName.equals("bitmask")) { if (!attrValue.equals("")) { match.setBitmask(attrValue); log.debug("startElement(): setting bitmask to '" + attrValue + "'"); } } else if (attrLocalName.equals("comparator")) { match.setComparator(attrValue); log.debug("startElement(): setting comparator to '" + attrValue + "'"); } } } else if (localName.equals("property")) { int length = attributes.getLength(); String name = null; String value = null; for (int i = 0; i < length; i++) { String attrLocalName = attributes.getLocalName(i); String attrValue = attributes.getValue(i); if (attrLocalName.equals("name")) { if (!attrValue.equals("")) { name = attrValue; } } else if (attrLocalName.equals("value")) { if (!attrValue.equals("")) { value = attrValue; } } } // save the property to our map if ((name != null) && (value != null)) { if (properties == null) { properties = new HashMap(); } if (!properties.containsKey(name)) { properties.put(name, value); log.debug("startElement(): setting property '" + name + "'='" + value + "'"); } else { log.debug("startElement(): not setting property '" + name + "', duplicate key"); } } } else if (localName.equals("match-list")) { log.debug("startElement(): found submatcher list"); // this means we are processing a child match, so we need to push // the existing match on the stack log.debug("startElement(): pushing current matcher to stack"); stack.add(matcher); } else { // we don't care about this type } } }