List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
From source file:com.opera.core.systems.scope.services.ums.WindowManager.java
public void findDriverWindow() { JXPathContext pathContext = JXPathContext.newContext(windows.values()); WindowInfo window = windows.peek();/* w w w . ja va 2 s . com*/ if (window == null || !window.getWindowType().equals("normal")) { // we dont deal with anything else, at least for now // select a window that is normal and return first // Fix for Windows OS, we dont encounter this problem on linux at all /* if(windowsStack.isEmpty()) throw new WebDriverException("List of windows is empty"); */ Integer windowId = (Integer) windowFinder.getValue(pathContext); if (windowId != null) { setActiveWindowId(windowId); } else { throw new WindowNotFoundException("No window is available for driving"); } filterActiveWindow(); } }
From source file:blueprint.sdk.util.JXPathHelper.java
/** * @param xpath XPath to evaluate/*from w w w . ja v a 2 s . c o m*/ * @param target target node * @return Iterator or null(not found) */ public static Iterator<Pointer> evaluateIteratorPointers(String xpath, Node target) { return evaluateIteratorPointers(xpath, JXPathContext.newContext(target)); }
From source file:de.innovationgate.webgate.api.templates.BeanWrapper.java
/** * Constructor. Not to be used outside WGAPI. * @param db//w ww . j av a 2 s .c om * @param key * @param bean * @param saved * @param temporary */ public BeanWrapper(SimpleContentSource db, BeanKey key, Object bean, boolean saved, boolean temporary) { _key = key; _bean = bean; _db = db; _fakeLanguage = db.getFakeLanguage(); _context = JXPathContext.newContext(_bean); _saved = saved; _temporary = temporary; _lowerCaseItems = db.getSpecs().isLowerCaseItems(); }
From source file:de.tudarmstadt.ukp.dkpro.core.dictionaryannotator.semantictagging.SemanticFieldAnnotator.java
@Override public void process(JCas aJCas) throws AnalysisEngineProcessException { CAS cas = aJCas.getCas();// w ww. j a v a 2 s .c om for (AnnotationFS cover : CasUtil.select(cas, CasUtil.getAnnotationType(cas, annotationType))) { // If there is a constraint, check if it matches if (constraint != null) { JXPathContext ctx = JXPathContext.newContext(cover); boolean match = ctx.iterate(constraint).hasNext(); if (!match) { continue; } } // If the target type is a token, use it directly, otherwise select the covered tokens Collection<Token> tokens; if (cover instanceof Token) { tokens = Collections.singleton((Token) cover); } else { tokens = JCasUtil.selectCovered(aJCas, Token.class, cover); } for (Token token : tokens) { try { String semanticField = semanticFieldResource.getSemanticTag(token); SemanticField semanticFieldAnnotation = new SemanticField(aJCas, token.getBegin(), token.getEnd()); semanticFieldAnnotation.setValue(semanticField); semanticFieldAnnotation.addToIndexes(); } catch (ResourceAccessException e) { throw new AnalysisEngineProcessException(e); } } } }
From source file:com.netspective.sparx.console.form.InspectObject.java
public void execute(Writer writer, DialogContext dc) throws IOException, DialogExecuteException { JXPathContext jxPathContext = null;//from w w w. j a v a2s .c o m DialogFieldStates fieldStates = dc.getFieldStates(); String contextValue = fieldStates.getState("context").getValue().getTextValue(); String jxPathExprValue = fieldStates.getState("jxpath-expr").getValue().getTextValue(); String action = fieldStates.getState("action").getValue().getTextValue(); if (contextValue.equalsIgnoreCase("Project")) jxPathContext = JXPathContext.newContext(dc.getProject()); else if (contextValue.equalsIgnoreCase("Servlet")) jxPathContext = JXPathContext.newContext(dc.getServlet()); else if (contextValue.equalsIgnoreCase("Application")) jxPathContext = JXPathServletContexts .getApplicationContext(dc.getServlet().getServletConfig().getServletContext()); else if (contextValue.equalsIgnoreCase("Request")) jxPathContext = JXPathServletContexts.getRequestContext(dc.getRequest(), dc.getServlet().getServletConfig().getServletContext()); else if (contextValue.equalsIgnoreCase("Session")) jxPathContext = JXPathServletContexts.getSessionContext(dc.getHttpRequest().getSession(), dc.getServlet().getServletConfig().getServletContext()); Object jxPathValue = null; if (action.equalsIgnoreCase("getValue")) jxPathValue = jxPathContext.getValue(jxPathExprValue); else jxPathValue = jxPathContext.iterate(jxPathExprValue); if (jxPathValue != null) { Map vars = new HashMap(); vars.put("jxPathValue", jxPathValue); vars.put("jxPathExpr", jxPathExprValue); inspectJxPathValueTemplate.process(writer, dc, vars); } else writer.write("JXPath expression '" + jxPathExprValue + "' evaluated to NULL."); }
From source file:com.opera.core.systems.scope.AbstractService.java
/** * Query a collection JXPath and return a pointer FIXME: This does not belong * here!/*from ww w. ja v a2s.c o m*/ * * @param collection * @param query * @return Pointer to node */ public Iterator<?> xpathIterator(Collection<?> collection, String query) { JXPathContext pathContext = JXPathContext.newContext(collection); Iterator<?> result = null; try { result = pathContext.iteratePointers(query); } catch (JXPathNotFoundException e) { logger.log(Level.WARNING, "JXPath exception: {0}", e.getMessage()); } return result; }
From source file:jp.co.opentone.bsol.framework.test.AbstractTestCase.java
/** * ???Excel????.// w w w .j av a 2 s. co m * <p> * ???? * <ul> * <li>Excel?</li> * <li>Excel????</li> * <li>Excel?</li> * <li>?????</li> * </ul> * </p> * @param sheetCount Excel? * @param sheetName Excel???? * @param sheetRow Excel????? * @param expected * @param actual Excel * @throws Exception ?? */ @SuppressWarnings("unchecked") protected void assertExcel(int sheetCount, String sheetName, int sheetRow, List<Object> expected, byte[] actual) throws Exception { // JXPathContext? DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); DocumentBuilder builder = factory.newDocumentBuilder(); Document document = builder.parse(new ByteArrayInputStream(actual)); JXPathContext context = JXPathContext.newContext(document); // ???? context.registerNamespace("NS", "urn:schemas-microsoft-com:office:spreadsheet"); // ?TEST assertEquals(sheetCount, ((Double) context.getValue("count(/NS:Workbook/NS:Worksheet)")).intValue()); // ?TEST?? assertEquals(sheetName, context.getValue("/NS:Workbook/NS:Worksheet/@ss:Name")); // ?TEST assertEquals(sheetRow + 1, Integer .parseInt((String) context.getValue("/NS:Workbook/NS:Worksheet/NS:Table/@ss:ExpandedRowCount"))); // Row?? int rows = ((Double) context.getValue("count(/NS:Workbook/NS:Worksheet/NS:Table/NS:Row)")).intValue(); assertEquals(sheetRow + 1, rows); // ???? for (int i = 1; i <= rows; i++) { // XPath?? context.getVariables().declareVariable("index", i); // Pointer?????JXPathContext? Pointer pointer = context.getPointer("/NS:Workbook/NS:Worksheet/NS:Table/NS:Row[$index]"); JXPathContext contextRow = context.getRelativeContext(pointer); contextRow.registerNamespace("NS", "urn:schemas-microsoft-com:office:spreadsheet"); List<Object> expectedRow = (List<Object>) expected.get(i - 1); // Column?? int columns = ((Double) contextRow.getValue("count(NS:Cell)")).intValue(); // ???? for (int j = 1; j <= columns; j++) { // Pointer?????JXPathContext? contextRow.getVariables().declareVariable("index", j); Pointer pointerColumn = contextRow.getPointer("NS:Cell[$index]"); JXPathContext contextColumn = contextRow.getRelativeContext(pointerColumn); // String actualColumn = (String) contextColumn.getValue("NS:Data"); // actualColumn?String?????String?? String expectedColumn; Object o = expectedRow.get(j - 1); if (o == null) { expectedColumn = ""; } else if (o instanceof Date) { SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS"); expectedColumn = dateFormat.format(o); } else { expectedColumn = o.toString(); } // ?TEST? assertEquals(expectedColumn, actualColumn); } } }
From source file:com.betfair.testing.utils.cougar.assertions.AssertionUtils.java
private static void doJsonSorting(JSONObject doc, String x) throws XPathExpressionException, IOException, JSONException { JXPathContext ctx = JXPathContext.newContext(doc); String parentX = x.substring(0, x.lastIndexOf("/")); if ("".equals(parentX)) { parentX = "/"; }//from w ww.j a v a 2s . c o m String childName = x.substring(x.lastIndexOf("/") + 1); Iterator it = ctx.iterate(parentX); while (it.hasNext()) { JSONObject p = (JSONObject) it.next(); JSONArray n = p.getJSONArray(childName); List allKids = new ArrayList<>(n.length()); for (int j = 0; j < n.length(); j++) { allKids.add(n.get(j)); } Collections.sort(allKids, new Comparator<Object>() { @Override public int compare(Object o1, Object o2) { return o1.toString().compareTo(o2.toString()); } }); JSONArray newArray = new JSONArray(allKids); p.put(childName, newArray); } }
From source file:blueprint.sdk.util.JXPathHelper.java
/** * @param expr XPath to evaluate/*from ww w .j a v a 2 s .c om*/ * @param target target node * @return Iterator or null(not found) */ public static Iterator<Pointer> evaluateIteratorPointers(CompiledExpression expr, Node target) { return evaluateIteratorPointers(expr, JXPathContext.newContext(target)); }
From source file:com.opera.core.systems.scope.stp.services.ScopeWindowManager.java
public void findDriverWindow() { JXPathContext pathContext = JXPathContext.newContext(windows.values()); WindowInfo window = windows.peek();//from ww w.j a v a 2s. c o m if (window == null || !window.getWindowType().equals("normal")) { Integer windowId = (Integer) WINDOW_FINDER_EXPRESSION.getValue(pathContext); if (windowId != null) { setActiveWindowId(windowId); } else { throw new WindowNotFoundException("No window is available for driving"); } filterActiveWindow(); } }