List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
From source file:org.jbpm.formModeler.service.bb.mvc.taglib.formatter.ForFormatter.java
public void service(HttpServletRequest request, HttpServletResponse response) throws FormatterException { log.debug("Servicing ForFormatter."); Object array = getParameter("array"); if (array == null) { Object componentName = getParameter("bean"); Object propertyName = getParameter("property"); if (componentName != null) { Object component = CDIBeanLocator.getBeanByNameOrType((String) componentName); array = component;/*from w w w.j a v a 2 s .c o m*/ if (propertyName != null) { JXPathContext ctx = JXPathContext.newContext(component); try { array = ctx.getValue((String) propertyName); } catch (Exception e) { log.debug("Error:", e); } } } } String sortProperties = (String) getParameter("sortProperties"); Iterator iterator = null; if (array == null) { renderFragment("empty"); return; } if (array instanceof Collection) { iterator = ((Collection) array).iterator(); } else if (array.getClass().isArray()) { final Object theArray = array; iterator = new Iterator() { int index = 0; public void remove() { throw new UnsupportedOperationException(); } public boolean hasNext() { return Array.getLength(theArray) > index; } public Object next() { return Array.get(theArray, index++); } }; } else if (array instanceof Iterator) { iterator = (Iterator) array; } else if (array instanceof Enumeration) { List l = new ArrayList(); while (((Enumeration) array).hasMoreElements()) { l.add(((Enumeration) array).nextElement()); } iterator = l.iterator(); } if (sortProperties != null) { iterator = getSortedIterator(iterator, sortProperties); } if (iterator != null && iterator.hasNext()) { renderFragment("outputStart"); int i = 0; while (iterator.hasNext()) { Object o = iterator.next(); setAttribute("index", new Integer(i)); setAttribute("count", new Integer(++i)); if (o != null) setAttribute("element", o); else setAttribute("element", getParameter("nullValue")); renderFragment("output"); } renderFragment("outputEnd"); } else { renderFragment("empty"); } }
From source file:org.jkcsoft.java.xml.XMLUtil.java
/** * Get Child Element Text. Good when you have the following: * <Object>/*from w ww . j ava 2 s. c om*/ * <Property1>value1</Property1> * <Property2>value2</Property2> * </Object> * In effect, obj is the node for an object or row of data and * property is the name of the property. */ public static String getCET(Node obj, String property, String ifnull) throws Exception { String retVal = null; JXPathContext jxp = JXPathContext.newContext(obj); Text text = (org.w3c.dom.Text) jxp.getValue(property); if (text == null) { // throw new Exception("Property not found: " + property); retVal = ifnull; } else { retVal = text.getData(); } if (retVal == null) retVal = ifnull; return retVal; }
From source file:org.kuali.ole.docstore.discovery.solr.work.instance.oleml.WorkInstanceOlemlDocBuilder_UT.java
@Test public void testPerformanceFromJxPathModified() { WorkInstanceOlemlDocBuilder docBuilder = new WorkInstanceOlemlDocBuilder(); List<SolrInputDocument> jxSolrDocs = new ArrayList<SolrInputDocument>(); List<SolrInputDocument> custSolrDocs = new ArrayList<SolrInputDocument>(); RequestDocument rd = new RequestDocument(); rd.setCategory(DocCategory.WORK.getCode()); rd.setType(DocType.INSTANCE.getCode()); rd.getContent().setContentObject(instance); Long timeJxPath = System.currentTimeMillis(); JXPathContext instance1 = JXPathContext.newContext(instance); for (int i = 0; i < 1; i++) { docBuilder.buildSolrInputDocumentsForInstanceByJXPathTest(instance1, instance, jxSolrDocs); docBuilder.buildSolrInputDocumentsForHoldingByJXPathTest(instance1, instance, jxSolrDocs); docBuilder.buildSolrInputDocumentsForItemsByJXPathTest(instance1, instance, jxSolrDocs); // if (i == 0) // System.out.println("Modified JS SOLR DOCS: \n" + jxSolrDocs); }/*from w w w . j av a2 s . c o m*/ timeJxPath = System.currentTimeMillis() - timeJxPath; System.out.println("testPerformanceFromJxPathModified " + timeJxPath); }
From source file:org.kuali.ole.docstore.discovery.solr.work.license.onixpl.WorkLicenseOnixplDocBuilder.java
public SolrInputDocument buildSolrInputDocument(ONIXPublicationsLicenseMessage license, AdditionalAttributes addAtrbts, String content) { SolrInputDocument solrDoc = new SolrInputDocument(); solrDoc.addField(DOC_TYPE, DocType.LICENSE.getDescription()); solrDoc.addField(DOC_FORMAT, DocFormat.ONIXPL.getCode()); solrDoc.setField(DOC_CATEGORY, DocCategory.WORK.getCode()); JXPathContext message = JXPathContext.newContext(license); for (Field field : onixPlMetaData.getFields()) { String xp = field.get("xpath"); if (xp != null && xp.trim().length() != 0) { boolean hasValues = false; if (!xp.startsWith("/request/requestDocuments/ingestDocument/additionalAttributes/")) { Iterator values = message.iterate(xp); while (values.hasNext()) { hasValues = true;// ww w. j a va2 s . c om Object value = values.next(); solrDoc.addField(field.getName(), value); } } else if (addAtrbts != null) { solrDoc.addField(field.getName(), addAtrbts.getAttribute(xp.substring(xp.lastIndexOf('/') + 1))); hasValues = true; } if (!hasValues) solrDoc.addField(field.getName(), null); } } if (content != null) allText.append(xmlUtility.getAllContentText(content)); if (addAtrbts != null) allText.append(getAllTextForAdditionalAttributes(addAtrbts)); solrDoc.addField(ALL_TEXT, allText.toString()); return solrDoc; }
From source file:org.kuali.ole.docstore.engine.service.index.solr.LicenseOnixplIndexer.java
protected void buildSolrInputDocument(Object object, List<SolrInputDocument> solrInputDocuments) { License license = (License) object;/*from w ww. ja va 2 s . c o m*/ LicenseOnixplRecordConverter licenseOnixplRecordConverter = new LicenseOnixplRecordConverter(); String content = license.getContent(); ONIXPublicationsLicenseMessage onixPublicationsLicenseMessage = licenseOnixplRecordConverter .unmarshal(content); SolrInputDocument solrDoc = new SolrInputDocument(); solrDoc.addField(DOC_TYPE, DocType.LICENSE.getDescription()); solrDoc.addField(DOC_FORMAT, DocFormat.ONIXPL.getCode()); solrDoc.setField(DOC_CATEGORY, DocCategory.WORK.getCode()); JXPathContext message = JXPathContext.newContext(onixPublicationsLicenseMessage); for (Field field : onixPlMetaData.getFields()) { String xp = field.get("xpath"); if (xp != null && xp.trim().length() != 0) { Iterator values = message.iterate(xp); while (values.hasNext()) { Object value = values.next(); solrDoc.addField(field.getName(), value); } } } //TODO:set additional attributes if (content != null) { allText.append(xmlUtility.getAllContentText(content)); } solrDoc.addField(ALL_TEXT, allText.toString()); solrDoc.addField("dateEntered", new Date()); solrDoc.addField("createdBy", license.getCreatedBy()); solrDoc.setField("id", license.getId()); solrDoc.setField("uniqueId", license.getId()); solrDoc.setField("LocalId_search", DocumentLocalId.getDocumentId(license.getId())); solrDoc.setField("LocalId_display", DocumentLocalId.getDocumentIdDisplay(license.getId())); solrInputDocuments.add(solrDoc); }
From source file:org.langera.freud.optional.css.CssJdom.java
@SuppressWarnings("unchecked") public List<CssRule> getCssRuleList() { List<CssRule> cssRuleList = new ArrayList<CssRule>(); JXPathContext context = JXPathContext.newContext(root.getRootElement()); List<Element> cssRuleElementList = (List<Element>) context.selectNodes("/RULE"); for (Element element : cssRuleElementList) { final CssRuleJdom cssRuleJdom = new CssRuleJdom(element, 0); cssRuleList.add(cssRuleJdom);/*from ww w . j av a 2s . c o m*/ for (int i = 1; i < cssRuleJdom.getNumberOfCommaSeparatedSelectorLists(); i++) { cssRuleList.add(new CssRuleJdom(element, i)); } } return cssRuleList; }
From source file:org.langera.freud.optional.css.cssrule.CssRuleJdomTest.java
@Before public void setUp() throws Exception { final SAXBuilder saxBuilder = new SAXBuilder(false); Document document = saxBuilder.build(ClassLoader.getSystemResourceAsStream("parsed_css_example.xml")); JXPathContext context = JXPathContext.newContext(document.getRootElement()); cssRuleJdom = new CssRuleJdom((Element) context.selectSingleNode("//RULE[3]"), 0); cssRuleJdomSeparatedByCommas0 = new CssRuleJdom((Element) context.selectSingleNode("//RULE[2]"), 0); cssRuleJdomSeparatedByCommas1 = new CssRuleJdom((Element) context.selectSingleNode("//RULE[2]"), 1); }
From source file:org.langera.freud.optional.css.cssrule.declaration.CssDeclarationJdomTest.java
@Before public void setUp() throws Exception { final SAXBuilder saxBuilder = new SAXBuilder(false); Document document = saxBuilder.build(ClassLoader.getSystemResourceAsStream("parsed_css_example.xml")); JXPathContext context = JXPathContext.newContext(document.getRootElement()); cssDeclarationJdom = new CssDeclarationJdom(null, (Element) context.selectSingleNode("//PROPERTY")); }
From source file:org.langera.freud.optional.css.cssrule.selector.CssSelectorJdomTest.java
@Before public void setUp() throws Exception { final SAXBuilder saxBuilder = new SAXBuilder(false); Document document = saxBuilder.build(ClassLoader.getSystemResourceAsStream("parsed_css_example.xml")); JXPathContext context = JXPathContext.newContext(document.getRootElement()); cssSelectorJdom = new CssSelectorJdom(null, (Element) context.selectSingleNode("//CLASS"), CssSelector.Combinator.DESCENDANT); }
From source file:org.langera.freud.optional.javasource.block.CodeBlockJdom.java
@SuppressWarnings("unchecked") public List<MethodCall> getMethodCallListByMethodName(String methodName) { if (methodCallByMethodNameMap == null) { methodCallByMethodNameMap = new HashMap<String, List<MethodCall>>(); JXPathContext context = JXPathContext.newContext(codeBlockElement); List<Element> methodCallElementList = context .selectNodes("//" + JavaSourceTokenType.METHOD_CALL.getName()); for (Element methodCallElement : methodCallElementList) { final MethodCall methodCall = new MethodCallJdom(methodCallElement); List<MethodCall> methodCallList = methodCallByMethodNameMap.get(methodCall.getMethodName()); if (methodCallList == null) { methodCallList = new LinkedList<MethodCall>(); methodCallByMethodNameMap.put(methodCall.getMethodName(), methodCallList); }/*from w w w. j a va 2 s . c o m*/ methodCallList.add(methodCall); } } return methodCallByMethodNameMap.get(methodName); }