/**
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements.  See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache License, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License.  You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apache.solr.core;

import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.DOMUtil;
import org.w3c.dom.Node;
import org.w3c.dom.NamedNodeMap;
import org.w3c.dom.NodeList;

import javax.xml.xpath.XPathConstants;
import javax.xml.xpath.XPathExpressionException;
import java.util.*;
import static java.util.Collections.unmodifiableList;
import static java.util.Collections.unmodifiableMap;

/**
 * An Object which represents a Plugin of any type 
 * @version $Id$
 */
public class PluginInfo {
  public final String name, className, type;
  public final NamedList initArgs;
  public final Map<String, String> attributes;
  public final List<PluginInfo> children;

  public PluginInfo(String type, Map<String, String> attrs ,NamedList initArgs, List<PluginInfo> children) {
    this.type = type;
    this.name = attrs.get("name");
    this.className = attrs.get("class");
    this.initArgs = initArgs;
    attributes = unmodifiableMap(attrs);
    this.children = children == null ? Collections.<PluginInfo>emptyList(): unmodifiableList(children);
  }


  public PluginInfo(Node node, String err, boolean requireName, boolean requireClass) {
    type = node.getNodeName();
    name = DOMUtil.getAttr(node, "name", requireName ? err : null);
    className = DOMUtil.getAttr(node, "class", requireClass ? err : null);
    initArgs = DOMUtil.childNodesToNamedList(node);
    Map<String, String> m = new HashMap<String, String>();
    NamedNodeMap nnm = node.getAttributes();
    for (int i = 0; i < nnm.getLength(); i++) {
      String name = nnm.item(i).getNodeName();
      m.put(name, nnm.item(i).getNodeValue());
    }
    attributes = unmodifiableMap(m);
    children = loadSubPlugins(node);
  }

  private List<PluginInfo> loadSubPlugins(Node node) {
    List<PluginInfo> children = null;
    try {
      //if there is another sub tag with a 'class' attribute that has to be another plugin
      NodeList nodes = (NodeList) Config.xpathFactory.newXPath().evaluate("*[@class]",node, XPathConstants.NODESET);
      if(nodes.getLength() > 0){
        children = new ArrayList<PluginInfo>(nodes.getLength());
        for (int i=0; i<nodes.getLength(); i++) {
          PluginInfo pluginInfo = new PluginInfo(nodes.item(i), null, false, false);
          if (pluginInfo.isEnabled()) children.add(pluginInfo);
        }
      }
    } catch (XPathExpressionException e) { }
    return children == null ? Collections.<PluginInfo>emptyList(): unmodifiableList(children);
  }

  @Override
  public String toString() {
    StringBuilder sb = new StringBuilder("{");
    if (type != null) sb.append("type = " + type + ",");
    if (name != null) sb.append("name = " + name + ",");
    if (className != null) sb.append("class = " + className + ",");
    if (initArgs.size() > 0) sb.append("args = " + initArgs);
    sb.append("}");
    return sb.toString();
  }

  public boolean isEnabled(){
    String enable = attributes.get("enable");
    return enable == null || Boolean.parseBoolean(enable); 
  }

  public boolean isDefault() {
    return Boolean.parseBoolean(attributes.get("default"));
  }
}

@@ -967,42 +967,8 @@
 e;%0D%0A
-import org.w3c.dom.NamedNodeMap;%0D%0A
 impo
@@ -2225,296 +2225,72 @@
     
-Map%3CString, String%3E m = new HashMap%3CString, String%3E();%0D%0A    NamedNodeMap nnm = node.getAttributes();%0D%0A    for (int i = 0; i %3C nnm.getLength(); i++) %7B%0D%0A      String name = nnm.item(i).getNodeName();%0D%0A      m.put(name, nnm.item(i).getNodeValue());%0D%0A    %7D%0D%0A    attributes = unmodifiableMap(m
+attributes = unmodifiableMap(DOMUtil.toMap(node.getAttributes())
 );%0D%0A

use DOMUtil