public static String getAttributeOrFail(Element e, String name) throws ParserException { String v = e.getAttribute(name); if (null == v) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" attribute"); } return v; }
public static String getAttributeOrFail(Element e, String name) throws ParserException { String v = e.getAttribute(name); if (null == v) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" attribute"); } return v; }
private static Document parseXML(InputStream pXmlFile) throws ParserException { DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); DocumentBuilder db = null; try { db = dbf.newDocumentBuilder(); } catch (Exception se) { throw new ParserException("XML Parser configuration error", se); } org.w3c.dom.Document doc = null; try { doc = db.parse(pXmlFile); } catch (Exception se) { throw new ParserException("Error parsing XML stream:" + se, se); } return doc; }
static BooleanClause.Occur getOccursValue(Element clauseElem) throws ParserException { String occs = clauseElem.getAttribute("occurs"); if (occs == null || "should".equalsIgnoreCase(occs)) { return BooleanClause.Occur.SHOULD; } else if ("must".equalsIgnoreCase(occs)) { return BooleanClause.Occur.MUST; } else if ("mustNot".equalsIgnoreCase(occs)) { return BooleanClause.Occur.MUST_NOT; } else if ("filter".equals(occs)) { return BooleanClause.Occur.FILTER; } throw new ParserException("Invalid value for \"occurs\" attribute of clause:" + occs); }
static BooleanClause.Occur getOccursValue(Element clauseElem) throws ParserException { String occs = clauseElem.getAttribute("occurs"); if (occs == null || "should".equalsIgnoreCase(occs)) { return BooleanClause.Occur.SHOULD; } else if ("must".equalsIgnoreCase(occs)) { return BooleanClause.Occur.MUST; } else if ("mustNot".equalsIgnoreCase(occs)) { return BooleanClause.Occur.MUST_NOT; } else if ("filter".equals(occs)) { return BooleanClause.Occur.FILTER; } throw new ParserException("Invalid value for \"occurs\" attribute of clause:" + occs); }
public static String getAttributeWithInheritanceOrFail(Element e, String name) throws ParserException { String v = getAttributeWithInheritance(e, name); if (null == v) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" attribute"); } return v; }
public static String getNonBlankTextOrFail(Element e) throws ParserException { String v = getText(e); if (null != v) v = v.trim(); if (null == v || 0 == v.length()) { throw new ParserException(e.getTagName() + " has no text"); } return v; }
public static Element getChildByTagOrFail(Element e, String name) throws ParserException { Element kid = getChildByTagName(e, name); if (null == kid) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" child element"); } return kid; }
public static Element getFirstChildOrFail(Element e) throws ParserException { Element kid = getFirstChildElement(e); if (null == kid) { throw new ParserException(e.getTagName() + " does not contain a child element"); } return kid; }
@Override public Query getQuery(Element n) throws ParserException { QueryBuilder builder = builders.get(n.getNodeName()); if (builder == null) { throw new ParserException("No QueryObjectBuilder defined for node " + n.getNodeName()); } return builder.getQuery(n); }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { SpanQueryBuilder builder = builders.get(e.getNodeName()); if (builder == null) { throw new ParserException("No SpanQueryObjectBuilder defined for node " + e.getNodeName()); } return builder.getSpanQuery(e); }
@Override public SpanQuery getSpanQuery(Element e) throws ParserException { SpanQueryBuilder builder = builders.get(e.getNodeName()); if (builder == null) { throw new ParserException("No SpanQueryObjectBuilder defined for node " + e.getNodeName()); } return builder.getSpanQuery(e); }
@Override public Filter getFilter(Element n) throws ParserException { FilterBuilder builder = builders.get(n.getNodeName()); if (builder == null) { throw new ParserException("No FilterBuilder defined for node " + n.getNodeName()); } return builder.getFilter(n); }
public static Element getChildByTagOrFail(Element e, String name) throws ParserException { Element kid = getChildByTagName(e, name); if (null == kid) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" child element"); } return kid; }
public static String getAttributeWithInheritanceOrFail(Element e, String name) throws ParserException { String v = getAttributeWithInheritance(e, name); if (null == v) { throw new ParserException(e.getTagName() + " missing \"" + name + "\" attribute"); } return v; }
@Override public Filter getFilter(Element n) throws ParserException { FilterBuilder builder = builders.get(n.getNodeName()); if (builder == null) { throw new ParserException("No FilterBuilder defined for node " + n.getNodeName()); } return builder.getFilter(n); }
@Override public Query getQuery(Element n) throws ParserException { QueryBuilder builder = builders.get(n.getNodeName()); if (builder == null) { throw new ParserException("No QueryObjectBuilder defined for node " + n.getNodeName()); } return builder.getQuery(n); }
public static Element getFirstChildOrFail(Element e) throws ParserException { Element kid = getFirstChildElement(e); if (null == kid) { throw new ParserException(e.getTagName() + " does not contain a child element"); } return kid; }
public static String getNonBlankTextOrFail(Element e) throws ParserException { String v = getText(e); if (null != v) v = v.trim(); if (null == v || 0 == v.length()) { throw new ParserException(e.getTagName() + " has no text"); } return v; }
@Override public Query getQuery(Element e) throws ParserException { String text = DOMUtils.getText(e); try { Query q = null; if (unSafeParser != null) { //synchronize on unsafe parser synchronized (unSafeParser) { q = unSafeParser.parse(text); } } else { String fieldName = DOMUtils.getAttribute(e, "fieldName", defaultField); //Create new parser QueryParser parser = createQueryParser(fieldName, analyzer); q = parser.parse(text); } float boost = DOMUtils.getAttribute(e, "boost", 1.0f); return new BoostQuery(q, boost); } catch (ParseException e1) { throw new ParserException(e1.getMessage()); } }