bugCategoryMap = new HashMap<String, String>(); List bugCategoryList = messageCollection.selectNodes("/MessageCollection/BugCategory"); for (Iterator i = bugCategoryList.iterator(); i.hasNext(); ) { Node bugCategoryNode = (Node) i.next(); String category = bugCategoryNode.valueOf("@category"); if (category.equals("")) throw new PluginException("BugCategory element with missing category attribute"); String description = bugCategoryNode.getText(); bugCategoryMap.put(category, description); }
	private void init() throws PluginException {		Document pluginDescriptor; // a.k.a, "findbugs.xml"		Document messageCollection; // a.k.a., "messages.xml" or localization thereof		try {			URL descriptorURL = findResource("findbugs.xml");			if (descriptorURL == null)				throw new PluginException("Couldn't find \"findbugs.xml\" in plugin");			SAXReader reader = new SAXReader();			pluginDescriptor = reader.read(descriptorURL);		} catch (DocumentException e) {			throw new PluginException("Couldn't parse \"findbugs.xml\"", e);		}		try {			URL messageURL = null;			Locale locale = Locale.getDefault();			String language = locale.getLanguage();			String country = locale.getCountry();			if (!country.equals(""))				messageURL = findResource("messages_" + language + "_" + country + ".xml");			if (messageURL == null)				messageURL = findResource("messages_" + language + ".xml");			if (messageURL == null)				messageURL = findResource("messages.xml");			if (messageURL == null)				throw new PluginException("Couldn't find messages.xml");			SAXReader reader = new SAXReader();			messageCollection = reader.read(messageURL);		} catch (DocumentException e) {			e.printStackTrace();			throw new PluginException("Couldn't parse \"messages.xml\"", e);		}		// Create a DetectorFactory for all Detector nodes		HashMap<String, DetectorFactory> detectorFactoryMap = new HashMap<String, DetectorFactory>();		try {			detectorFactoryList = new ArrayList<DetectorFactory>();			List detectorNodeList = pluginDescriptor.selectNodes("/FindbugsPlugin/Detector");			for (Iterator i = detectorNodeList.iterator(); i.hasNext(); ) {				Node detectorNode = (Node) i.next();				String className = detectorNode.valueOf("@class");				String speed = detectorNode.valueOf("@speed");				String disabled = detectorNode.valueOf("@disabled");				String reports = detectorNode.valueOf("@reports");					//System.out.println("Found detector: class="+className+", disabled="+disabled);					Class detectorClass = loadClass(className);				DetectorFactory factory = new DetectorFactory(detectorClass, !disabled.equals("true"), speed, reports);				detectorFactoryList.add(factory);				detectorFactoryMap.put(className, factory);			}		} catch (ClassNotFoundException e) {			throw new PluginException("Could not instantiate detector class", e);		}		// Get detail HTML for Detectors		List detectorMessageList = messageCollection.selectNodes("/MessageCollection/Detector");		for (Iterator i = detectorMessageList.iterator(); i.hasNext(); ) {			Element detector = (Element) i.next();			Element details = detector.element("Details");			String className = detector.valueOf("@class");			DetectorFactory factory = detectorFactoryMap.get(className);			if (factory == null)				throw new PluginException("In \"messages.xml\": unknown detector \"" + className + "\"");			if (details != null) {				String detailHTML = details.getText();				StringBuffer buf = new StringBuffer();				buf.append("<!DOCTYPE HTML PUBLIC \"-//W3C//DTD HTML 4.01 Transitional//EN\">\n");				buf.append("<HTML><HEAD><TITLE>Detector Description</TITLE></HEAD><BODY>\n");				buf.append(detailHTML);				buf.append("</BODY></HTML>\n");				factory.setDetailHTML(buf.toString());			}		}		// Create BugPatterns		bugPatternList = new ArrayList<BugPattern>();		List bugPatternNodeList = pluginDescriptor.selectNodes("/FindbugsPlugin/BugPattern");		for (Iterator i = bugPatternNodeList.iterator(); i.hasNext(); ) {			Node bugPatternNode = (Node) i.next();			String type = bugPatternNode.valueOf("@type");			String abbrev = bugPatternNode.valueOf("@abbrev");			String category = bugPatternNode.valueOf("@category");			String experimental = bugPatternNode.valueOf("@experimental");			// Find the matching element in messages.xml			String query = "/MessageCollection/BugPattern[@type='" + type + "']";			Node messageNode = (Node) messageCollection.selectSingleNode(query);			if (messageNode == null)				throw new PluginException("messages.xml missing BugPattern element for type " + type);			String shortDesc = getChildText(messageNode, "ShortDescription");			String longDesc = getChildText(messageNode, "LongDescription");			String detailText = getChildText(messageNode, "Details");			BugPattern bugPattern = new BugPattern(type, abbrev, category,				Boolean.valueOf(experimental).booleanValue(),				shortDesc, longDesc, detailText);			bugPatternList.add(bugPattern);		}		// Create BugCodes		bugCodeList = new ArrayList<BugCode>();		List bugCodeNodeList = messageCollection.selectNodes("/MessageCollection/BugCode");		for (Iterator i = bugCodeNodeList.iterator(); i.hasNext(); ) {			Node bugCodeNode = (Node) i.next();			String abbrev = bugCodeNode.valueOf("@abbrev");			if (abbrev.equals(""))				throw new PluginException("BugCode element with missing abbrev attribute");			String description = bugCodeNode.getText();			BugCode bugCode = new BugCode(abbrev, description);			bugCodeList.add(bugCode);		}		// Create BugCategory map		bugCategoryMap = new HashMap<String, String>();		List bugCategoryList = messageCollection.selectNodes("/MessageCollection/BugCategory");		for (Iterator i = bugCategoryList.iterator(); i.hasNext(); ) {			Node bugCategoryNode = (Node) i.next();			String category = bugCategoryNode.valueOf("@category");			if (category.equals(""))				throw new PluginException("BugCategory element with missing category attribute");			String description = bugCategoryNode.getText();			bugCategoryMap.put(category, description);		}	}