List of usage examples for org.apache.commons.jxpath JXPathContext newContext
public static JXPathContext newContext(Object contextBean)
From source file:jp.terasoluna.fw.beans.JXPathIndexedBeanWrapperImpl.java
/** * /*from w ww . j ava 2 s .c o m*/ * @param target ? */ public JXPathIndexedBeanWrapperImpl(Object target) { // ??JavaBean?Null??? if (target == null) { log.error("TargetBean is null!"); throw new IllegalArgumentException("TargetBean is null!"); } context = JXPathContext.newContext(target); }
From source file:jsondb.JsonDBTemplate.java
@Override public <T> void createCollection(String collectionName) { CollectionMetaData cmd = cmdMap.get(collectionName); if (null == cmd) { throw new InvalidJsonDbApiUsageException( "No class found with @Document Annotation and attribute collectionName as: " + collectionName); }// w w w .ja v a 2s . c om @SuppressWarnings("unchecked") Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName); if (null != collection) { throw new InvalidJsonDbApiUsageException("Collection by name '" + collectionName + "' already exists."); } cmd.getCollectionLock().writeLock().lock(); // Some other thread might have created same collection when this thread reached this point if (collectionsRef.get().get(collectionName) != null) { return; } try { String collectionFileName = dbConfig.getDBPrefix() + collectionName + ".json"; File fileObject = new File(dbConfig.getDbFilesLocation(), collectionFileName); try { fileObject.createNewFile(); } catch (IOException e) { Logger.error("IO Exception creating the collection file {}", collectionFileName, e); throw new InvalidJsonDbApiUsageException( "Unable to create a collection file for collection: " + collectionName); } if (Util.stampVersion(dbConfig, fileObject, cmd.getSchemaVersion())) { collection = new LinkedHashMap<Object, T>(); collectionsRef.get().put(collectionName, collection); contextsRef.get().put(collectionName, JXPathContext.newContext(collection.values())); fileObjectsRef.get().put(collectionName, fileObject); cmd.setActualSchemaVersion(cmd.getSchemaVersion()); } else { fileObject.delete(); throw new JsonDBException("Failed to stamp version for collection: " + collectionName); } } finally { cmd.getCollectionLock().writeLock().unlock(); } }
From source file:io.jsondb.JsonDBTemplate.java
@Override public <T> void createCollection(String collectionName) { CollectionMetaData cmd = cmdMap.get(collectionName); if (null == cmd) { throw new InvalidJsonDbApiUsageException( "No class found with @Document Annotation and attribute collectionName as: " + collectionName); }//from w w w.ja v a 2 s.c o m @SuppressWarnings("unchecked") Map<Object, T> collection = (Map<Object, T>) collectionsRef.get().get(collectionName); if (null != collection) { throw new InvalidJsonDbApiUsageException("Collection by name '" + collectionName + "' already exists."); } cmd.getCollectionLock().writeLock().lock(); // Some other thread might have created same collection when this thread reached this point if (collectionsRef.get().get(collectionName) != null) { return; } try { String collectionFileName = collectionName + ".json"; File fileObject = new File(dbConfig.getDbFilesLocation(), collectionFileName); try { fileObject.createNewFile(); } catch (IOException e) { logger.error("IO Exception creating the collection file {}", collectionFileName, e); throw new InvalidJsonDbApiUsageException( "Unable to create a collection file for collection: " + collectionName); } if (Util.stampVersion(dbConfig, fileObject, cmd.getSchemaVersion())) { collection = new LinkedHashMap<Object, T>(); collectionsRef.get().put(collectionName, collection); contextsRef.get().put(collectionName, JXPathContext.newContext(collection.values())); fileObjectsRef.get().put(collectionName, fileObject); cmd.setActualSchemaVersion(cmd.getSchemaVersion()); } else { fileObject.delete(); throw new JsonDBException("Failed to stamp version for collection: " + collectionName); } } finally { cmd.getCollectionLock().writeLock().unlock(); } }
From source file:com.lrodriguez.SVNBrowser.java
private void doXpathQuery(HttpServletRequest request, HttpServletResponse response, HttpSession session) throws ServletException, IOException { //example/*from w w w . j av a 2 s . com*/ //?xpathQuery=.[revision < 9315 and revision>9000 and author='echow' or author ='lrodrigu' and type='A'] logDebug("dispatching xpath query: " + request.getParameter(XPATH_QUERY)); SVNRepository repository = ((SVNHttpSession) request.getSession().getAttribute(SVNSESSION)).getRepository(); Collection svnLogEntries = null; try { svnLogEntries = getSVNLogEntries(request, 0, repository.getDatedRevision(new Date())); } catch (SVNException e) { e.printStackTrace(); request.setAttribute(ERROR, e.getErrorMessage()); request.getRequestDispatcher(INDEX_JSP).forward(request, response); return; } List entriesList = new ArrayList(); if (svnLogEntries != null && svnLogEntries.size() > 0) { List entryFacadeList = getAllEntries(svnLogEntries); JXPathContext context = JXPathContext.newContext(entryFacadeList); context.setLenient(true); for (Iterator iter = context.iterate(request.getParameter(XPATH_QUERY)); iter.hasNext();) { Object currEntryFacade = iter.next(); entriesList.add(currEntryFacade); } } session.setAttribute(UNIQUE_ENTRIES, entriesList); request.getRequestDispatcher(INDEX_JSP).forward(request, response); return; }
From source file:com.photon.maven.plugins.android.AbstractAndroidMojo.java
protected String extractPackageNameFromAndroidManifest(File androidManifestFile) throws MojoExecutionException { final URL xmlURL; try {//from ww w .j a va2 s . c o m xmlURL = androidManifestFile.toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Error while trying to figure out package name from inside AndroidManifest.xml file " + androidManifestFile, e); } final DocumentContainer documentContainer = new DocumentContainer(xmlURL); final Object packageName = JXPathContext.newContext(documentContainer).getValue("manifest/@package", String.class); return (String) packageName; }
From source file:com.photon.maven.plugins.android.AbstractAndroidMojo.java
/** * Attempts to find the instrumentation test runner from inside the * AndroidManifest.xml file.//from w w w .jav a 2 s . co m * * @param androidManifestFile * the AndroidManifest.xml file to inspect. * @return the instrumentation test runner declared in AndroidManifest.xml, * or {@code null} if it is not declared. * @throws MojoExecutionException */ protected String extractInstrumentationRunnerFromAndroidManifest(File androidManifestFile) throws MojoExecutionException { final URL xmlURL; try { xmlURL = androidManifestFile.toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Error while trying to figure out instrumentation runner from inside AndroidManifest.xml file " + androidManifestFile, e); } final DocumentContainer documentContainer = new DocumentContainer(xmlURL); final Object instrumentationRunner; try { instrumentationRunner = JXPathContext.newContext(documentContainer) .getValue("manifest//instrumentation/@android:name", String.class); } catch (JXPathNotFoundException e) { return null; } return (String) instrumentationRunner; }
From source file:com.ebay.jetstream.epl.EPLUtilities.java
/** * transformToObject - This method converts incoming JsonString to HashMap. Need/use of this method is, in EPL we need * to use pass Objects through window. But EPL allows primitives type alone. For that we 'll convert Obejct to * JsonString and pass it to the stream. After that we need to convert back the Json String to original Object type. * //w w w . j a v a 2s. co m */ @SuppressWarnings("unchecked") public static HashMap<String, Object> transformToObjectAndRemoveKey(String jsonStr, String key) throws Exception { if (jsonStr != null) { ObjectMapper mapper = new ObjectMapper(); HashMap<String, Object> event = mapper.readValue(jsonStr, HashMap.class); if (key != null && !key.equals("")) { JXPathContext context = JXPathContext.newContext(event); context.setLenient(true); context.removePath(key); } return event; } return null; }
From source file:de.innovationgate.wgpublisher.hdb.HDBModel.java
/** * Returns all model definitions for the given content class * @param contentClass The content class *///from w w w . j a v a 2s .c om @SuppressWarnings("unchecked") @CodeCompletion public List<Content> getModelsForContentClass(String contentClass) { JXPathContext jxPath = JXPathContext.newContext(_definition); return jxPath.selectNodes("/rootStorages//childContents[@contentClass='" + contentClass + "']"); }
From source file:com.jayway.maven.plugins.android.AbstractAndroidMojo.java
/** * Attempts to find the instrumentation test runner from inside the AndroidManifest.xml file. * * @param manifestFile the AndroidManifest.xml file to inspect. * @return the instrumentation test runner declared in AndroidManifest.xml, or {@code null} if it is not declared. * @throws MojoExecutionException// w ww .j a v a 2 s . c om */ protected String extractInstrumentationRunnerFromAndroidManifest(File manifestFile) throws MojoExecutionException { final URL xmlURL; try { xmlURL = manifestFile.toURI().toURL(); } catch (MalformedURLException e) { throw new MojoExecutionException( "Error while trying to figure out instrumentation runner from inside AndroidManifest.xml file " + manifestFile, e); } final DocumentContainer documentContainer = new DocumentContainer(xmlURL); final Object instrumentationRunner; try { instrumentationRunner = JXPathContext.newContext(documentContainer) .getValue("manifest//instrumentation/@android:name", String.class); } catch (JXPathNotFoundException e) { return null; } return (String) instrumentationRunner; }
From source file:de.innovationgate.wgpublisher.webtml.Input.java
private List<String> getHdbmodelRelationOptions(String titleExpression) { try {//www. j a v a2 s . c o m // Prerequisites: Contentclass-based form, HDB model object, relation TMLForm form = getTMLContext().gettmlform(); if (form == null || form.getforminfo().getContentClass() == null) { return null; } HDBModel model = (HDBModel) getTMLContext().gettmlform().gettargetcontext().db() .getAttribute(WGACore.DBATTRIB_HDBMODEL); if (model == null) { return null; } Relation relation = null; for (Content contentModel : model.getModelsForContentClass(form.getforminfo().getContentClass(), getTMLContext().content(), false)) { relation = (Relation) JXPathContext.newContext(contentModel) .selectSingleNode("/relations[name='" + getName() + "']"); if (relation != null) { break; } } if (relation == null) { return null; } WGAbstractResultSet relationTargets = model.getRelationTargets(getTMLContext().content(), form.getforminfo().getContentClass(), getName()); String emptyTitle = relation.isOptional() ? getTMLContext().systemLabel("tmlform", "input.emptytitle") : null; return getTMLContext().buildOptions(relationTargets, titleExpression, emptyTitle); } catch (Throwable e) { getTMLContext().getlog().error("Exception determining input option defaults", e); return null; } }