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); attributes = unmodifiableMap(DOMUtil.toMap(node.getAttributes())); children = loadSubPlugins(node); }
/** * Replaces ${system.property[:default value]} references in all attributes * and text nodes of supplied node. If the system property is not defined and no * default value is provided, a runtime exception is thrown. * * @param node DOM node to walk for substitutions */ public static void substituteSystemProperties(Node node) { substituteProperties(node, null); }
public static Map<String,String> toMap(NamedNodeMap attrs) { return toMapExcept(attrs); }
String name = DOMUtil.getAttr(attrs,"name","field definition"); log.trace("reading field def "+name); String type = DOMUtil.getAttr(attrs,"type","field " + name); Map<String,String> args = DOMUtil.toMapExcept(attrs, "name", "type"); if( args.get( "required" ) != null ) { explicitRequiredProp.put( name, Boolean.valueOf( args.get( "required" ) ) ); if (obj instanceof SimilarityFactory) { SolrParams params = SolrParams.toSolrParams(DOMUtil.childNodesToNamedList(node)); similarityFactory = (SimilarityFactory)obj; similarityFactory.init(params); NamedNodeMap attrs = node.getAttributes(); String source = DOMUtil.getAttr(attrs,"source","copyField definition"); String dest = DOMUtil.getAttr(attrs,"dest", "copyField definition"); String maxChars = DOMUtil.getAttr(attrs, "maxChars"); int maxCharsInt = CopyField.UNLIMITED; if (maxChars != null) {
public static String getAttr(NamedNodeMap attrs, String name) { return getAttr(attrs,name,null); }
val = getText(nd); } else if ("int".equals(type)) { val = Integer.valueOf(getText(nd)); } else if ("long".equals(type)) { val = Long.valueOf(getText(nd)); } else if ("float".equals(type)) { val = Float.valueOf(getText(nd)); } else if ("double".equals(type)) { val = Double.valueOf(getText(nd)); } else if ("bool".equals(type)) { val = Boolean.valueOf(getText(nd)); } else if ("lst".equals(type)) { val = childNodesToNamedList(nd); } else if ("arr".equals(type)) { val = childNodesToList(nd);
/** * Replaces ${property[:default value]} references in all attributes * and text nodes of supplied node. If the property is not defined neither in the * given Properties instance nor in System.getProperty and no * default value is provided, a runtime exception is thrown. * * @param node DOM node to walk for substitutions * @param properties the Properties instance from which a value can be looked up */ public static void substituteProperties(Node node, Properties properties) { // loop through child nodes Node child; Node next = node.getFirstChild(); while ((child = next) != null) { // set next before we change anything next = child.getNextSibling(); // handle child by node type if (child.getNodeType() == Node.TEXT_NODE) { child.setNodeValue(substituteProperty(child.getNodeValue(), properties)); } else if (child.getNodeType() == Node.ELEMENT_NODE) { // handle child elements with recursive call NamedNodeMap attributes = child.getAttributes(); for (int i = 0; i < attributes.getLength(); i++) { Node attribute = attributes.item(i); attribute.setNodeValue(substituteProperty(attribute.getNodeValue(), properties)); } substituteProperties(child, properties); } } }
public String getVal(String path, boolean errIfMissing) { Node nd = getNode(path,errIfMissing); if (nd==null) return null; String txt = DOMUtil.getText(nd); log.debug(name + ' '+path+'='+txt); return txt; /****** short typ = nd.getNodeType(); if (typ==Node.ATTRIBUTE_NODE || typ==Node.TEXT_NODE) { return nd.getNodeValue(); } return nd.getTextContent(); ******/ }
@Override protected void init(T plugin,Node node) throws Exception { plugin.init( DOMUtil.childNodesToNamedList(node) ); }
public static List nodesToList(NodeList nlst) { List lst = new ArrayList(); for (int i=0; i<nlst.getLength(); i++) { addToNamedList(nlst.item(i), null, lst); } return lst; }
public static NamedList<Object> childNodesToNamedList(Node nd) { return nodesToNamedList(nd.getChildNodes()); }
public static List childNodesToList(Node nd) { return nodesToList(nd.getChildNodes()); }
parsePropertyString(value, fragments, propertyRefs);
public static String getAttr(Node node, String name, String missing_err) { return getAttr(node.getAttributes(), name, missing_err); }
/** * Drop in replacement for Node.getTextContent(). * * <p> * This method is provided to support the same functionality as * Node.getTextContent() but in a way that is DOM Level 2 compatible. * </p> * * @see <a href="http://www.w3.org/TR/DOM-Level-3-Core/core.html#Node3-textContent">DOM Object Model Core</a> */ public static String getText(Node nd) { short type = nd.getNodeType(); // for most node types, we can defer to the recursive helper method, // but when asked for the text of these types, we must return null // (Not the empty string) switch (type) { case Node.DOCUMENT_NODE: /* fall through */ case Node.DOCUMENT_TYPE_NODE: /* fall through */ case Node.NOTATION_NODE: /* fall through */ return null; } StringBuilder sb = new StringBuilder(); getText(nd, sb); return sb.toString(); }
public static NamedList<Object> nodesToNamedList(NodeList nlst) { NamedList<Object> clst = new NamedList<Object>(); for (int i=0; i<nlst.getLength(); i++) { addToNamedList(nlst.item(i), clst, null); } return clst; }
public static String getAttr(Node nd, String name) { return getAttr(nd.getAttributes(), name); }
@Override protected void init(FieldType plugin, Node node) throws Exception { Map<String,String> params = DOMUtil.toMapExcept( node.getAttributes(), "name","class" ); plugin.setArgs(schema, params ); }
if (childType != Node.COMMENT_NODE && childType != Node.PROCESSING_INSTRUCTION_NODE) { getText(child, buf);
DOMUtil.substituteProperties(doc, loader.getCoreProperties()); } catch (ParserConfigurationException e) { SolrException.log(log, "Exception during parsing file: " + name, e);