List of usage examples for javax.xml.xpath XPathConstants STRING
QName STRING
To view the source code for javax.xml.xpath XPathConstants STRING.
Click Source Link
The XPath 1.0 string data type.
Maps to Java String .
From source file:com.mnxfst.testing.client.TSClientPlanExecCallable.java
/** * Parses the result identifier from the returned result * @param rootNode/*from w w w. ja va 2 s .co m*/ * @return * @throws TSClientExecutionException */ protected String parseResultIdentifier(Node rootNode, XPath xpath) throws TSClientExecutionException { String resultIdentifier = null; try { resultIdentifier = (String) xpath.evaluate(TEST_EXEC_RESULT_IDENTIFIER, rootNode, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new TSClientExecutionException( "Failed to parse out result identifier from document received from " + httpHost.getHostName()); } if (resultIdentifier == null || resultIdentifier.isEmpty()) throw new TSClientExecutionException( "Failed to parse out result identifier from document received from " + httpHost.getHostName()); return resultIdentifier; }
From source file:de.bayern.gdi.services.CatalogService.java
/** * parses the services.//from www .j a v a2 s. co m * @param servicesNL node list of service entries * @return list of services * @throws MalformedURLException if url is wrong */ public List<Service> parseServices(NodeList servicesNL) throws MalformedURLException { List<Service> services = new ArrayList<>(); for (int i = 0; i < servicesNL.getLength(); i++) { Node serviceN = servicesNL.item(i); String nameExpr = GMD_IDENTIFICATION_INFO + SRV_SV_SERVICE_IDENTIFICATION + "/gmd:citation" + "/gmd:CI_Citation" + "/gmd:title" + GCO_CHARACTER_STRING; String serviceName = (String) XML.xpath(serviceN, nameExpr, XPathConstants.STRING, context); String restrictionExpr = GMD_IDENTIFICATION_INFO + SRV_SV_SERVICE_IDENTIFICATION + "/gmd:resourceConstraints" + "/gmd:MD_SecurityConstraints" + "/gmd:classification" + "/gmd:MD_ClassificationCode"; String restriction = (String) XML.xpath(serviceN, restrictionExpr, XPathConstants.STRING, context); boolean restricted = false; if ("restricted".equals(restriction)) { restricted = true; } String serviceTypeVersionExpr = GMD_IDENTIFICATION_INFO + SRV_SV_SERVICE_IDENTIFICATION + "/srv:serviceTypeVersion" + GCO_CHARACTER_STRING; String serviceTypeVersion = (String) XML.xpath(serviceN, serviceTypeVersionExpr, XPathConstants.STRING, context); String serviceURL = getServiceURL(serviceN); if (serviceTypeVersion.isEmpty()) { serviceTypeVersion = "ATOM"; } if (!serviceName.isEmpty() && serviceURL != null) { serviceURL = makeCapabiltiesURL(serviceURL, serviceTypeVersion); Service service = new Service(new URL(serviceURL), serviceName, restricted, ServiceType.guess(serviceTypeVersion)); services.add(service); } } return services; }
From source file:com.baracuda.piepet.nexusrelease.nexus.StageClient.java
/** * Completion of the stage action is asynchronous - so poll until the action completed. * // www .j a v a 2s .c om * @param stage the stage to wait until the previous action is completed. * @throws StageException */ protected void waitForActionToComplete(Stage stage) throws StageException { log.debug("Waiting for {} to finish transitioning.", stage); int i = 0; boolean transitioning = false; try { final URL activityUrl = getRepositoryURL(stage); do { Document doc = getDocument(activityUrl); String status = (String) evaluateXPath("/stagingProfileRepository/transitioning", doc, XPathConstants.STRING); transitioning = Boolean.valueOf(status).booleanValue(); if (transitioning) { i++; Thread.sleep(500L); if (i % 100 == 0) { log.debug("Still waiting for {} to finish transitioning.", stage); } // TODO should we ever time out? } } while (transitioning); } catch (InterruptedException ex) { throw new StageException(ex); } }
From source file:com.espertech.esper.client.TestConfigurationParser.java
protected static void assertFileConfig(Configuration config) throws Exception { // assert name for class assertEquals(2, config.getEventTypeAutoNamePackages().size()); assertEquals("com.mycompany.eventsone", config.getEventTypeAutoNamePackages().toArray()[0]); assertEquals("com.mycompany.eventstwo", config.getEventTypeAutoNamePackages().toArray()[1]); // assert name for class assertEquals(3, config.getEventTypeNames().size()); assertEquals("com.mycompany.myapp.MySampleEventOne", config.getEventTypeNames().get("MySampleEventOne")); assertEquals("com.mycompany.myapp.MySampleEventTwo", config.getEventTypeNames().get("MySampleEventTwo")); assertEquals("com.mycompany.package.MyLegacyTypeEvent", config.getEventTypeNames().get("MyLegacyTypeEvent")); // assert auto imports assertEquals(8, config.getImports().size()); assertEquals("java.lang.*", config.getImports().get(0)); assertEquals("java.math.*", config.getImports().get(1)); assertEquals("java.text.*", config.getImports().get(2)); assertEquals("java.util.*", config.getImports().get(3)); assertEquals("com.espertech.esper.client.annotation.*", config.getImports().get(4)); assertEquals("com.espertech.esper.dataflow.ops.*", config.getImports().get(5)); assertEquals("com.mycompany.myapp.*", config.getImports().get(6)); assertEquals("com.mycompany.myapp.ClassOne", config.getImports().get(7)); // assert XML DOM - no schema assertEquals(2, config.getEventTypesXMLDOM().size()); ConfigurationEventTypeXMLDOM noSchemaDesc = config.getEventTypesXMLDOM().get("MyNoSchemaXMLEventName"); assertEquals("MyNoSchemaEvent", noSchemaDesc.getRootElementName()); assertEquals("/myevent/element1", noSchemaDesc.getXPathProperties().get("element1").getXpath()); assertEquals(XPathConstants.NUMBER, noSchemaDesc.getXPathProperties().get("element1").getType()); assertEquals(null, noSchemaDesc.getXPathProperties().get("element1").getOptionalCastToType()); assertNull(noSchemaDesc.getXPathFunctionResolver()); assertNull(noSchemaDesc.getXPathVariableResolver()); assertFalse(noSchemaDesc.isXPathPropertyExpr()); // assert XML DOM - with schema ConfigurationEventTypeXMLDOM schemaDesc = config.getEventTypesXMLDOM().get("MySchemaXMLEventName"); assertEquals("MySchemaEvent", schemaDesc.getRootElementName()); assertEquals("MySchemaXMLEvent.xsd", schemaDesc.getSchemaResource()); assertEquals("actual-xsd-text-here", schemaDesc.getSchemaText()); assertEquals("samples:schemas:simpleSchema", schemaDesc.getRootElementNamespace()); assertEquals("default-name-space", schemaDesc.getDefaultNamespace()); assertEquals("/myevent/element2", schemaDesc.getXPathProperties().get("element2").getXpath()); assertEquals(XPathConstants.STRING, schemaDesc.getXPathProperties().get("element2").getType()); assertEquals(Long.class, schemaDesc.getXPathProperties().get("element2").getOptionalCastToType()); assertEquals("/bookstore/book", schemaDesc.getXPathProperties().get("element3").getXpath()); assertEquals(XPathConstants.NODESET, schemaDesc.getXPathProperties().get("element3").getType()); assertEquals(null, schemaDesc.getXPathProperties().get("element3").getOptionalCastToType()); assertEquals("MyOtherXMLNodeEvent", schemaDesc.getXPathProperties().get("element3").getOptionaleventTypeName()); assertEquals(1, schemaDesc.getNamespacePrefixes().size()); assertEquals("samples:schemas:simpleSchema", schemaDesc.getNamespacePrefixes().get("ss")); assertFalse(schemaDesc.isXPathResolvePropertiesAbsolute()); assertEquals("com.mycompany.OptionalFunctionResolver", schemaDesc.getXPathFunctionResolver()); assertEquals("com.mycompany.OptionalVariableResolver", schemaDesc.getXPathVariableResolver()); assertTrue(schemaDesc.isXPathPropertyExpr()); assertFalse(schemaDesc.isEventSenderValidatesRoot()); assertFalse(schemaDesc.isAutoFragment()); assertEquals("startts", schemaDesc.getStartTimestampPropertyName()); assertEquals("endts", schemaDesc.getEndTimestampPropertyName()); // assert mapped events assertEquals(1, config.getEventTypesMapEvents().size()); assertTrue(config.getEventTypesMapEvents().keySet().contains("MyMapEvent")); Map<String, String> expectedProps = new HashMap<String, String>(); expectedProps.put("myInt", "int"); expectedProps.put("myString", "string"); assertEquals(expectedProps, config.getEventTypesMapEvents().get("MyMapEvent")); assertEquals(1, config.getMapTypeConfigurations().size()); Set<String> superTypes = config.getMapTypeConfigurations().get("MyMapEvent").getSuperTypes(); EPAssertionUtil.assertEqualsExactOrder(new Object[] { "MyMapSuperType1", "MyMapSuperType2" }, superTypes.toArray());//from w w w. ja v a 2 s . c o m assertEquals("startts", config.getMapTypeConfigurations().get("MyMapEvent").getStartTimestampPropertyName()); assertEquals("endts", config.getMapTypeConfigurations().get("MyMapEvent").getEndTimestampPropertyName()); // assert objectarray events assertEquals(1, config.getEventTypesNestableObjectArrayEvents().size()); assertTrue(config.getEventTypesNestableObjectArrayEvents().containsKey("MyObjectArrayEvent")); Map<String, String> expectedPropsObjectArray = new HashMap<String, String>(); expectedPropsObjectArray.put("myInt", "int"); expectedPropsObjectArray.put("myString", "string"); assertEquals(expectedPropsObjectArray, config.getEventTypesNestableObjectArrayEvents().get("MyObjectArrayEvent")); assertEquals(1, config.getObjectArrayTypeConfigurations().size()); Set<String> superTypesOA = config.getObjectArrayTypeConfigurations().get("MyObjectArrayEvent") .getSuperTypes(); EPAssertionUtil.assertEqualsExactOrder( new Object[] { "MyObjectArraySuperType1", "MyObjectArraySuperType2" }, superTypesOA.toArray()); assertEquals("startts", config.getObjectArrayTypeConfigurations().get("MyObjectArrayEvent") .getStartTimestampPropertyName()); assertEquals("endts", config.getObjectArrayTypeConfigurations().get("MyObjectArrayEvent").getEndTimestampPropertyName()); // assert legacy type declaration assertEquals(1, config.getEventTypesLegacy().size()); ConfigurationEventTypeLegacy legacy = config.getEventTypesLegacy().get("MyLegacyTypeEvent"); assertEquals(ConfigurationEventTypeLegacy.CodeGeneration.ENABLED, legacy.getCodeGeneration()); assertEquals(ConfigurationEventTypeLegacy.AccessorStyle.PUBLIC, legacy.getAccessorStyle()); assertEquals(1, legacy.getFieldProperties().size()); assertEquals("myFieldName", legacy.getFieldProperties().get(0).getAccessorFieldName()); assertEquals("myfieldprop", legacy.getFieldProperties().get(0).getName()); assertEquals(1, legacy.getMethodProperties().size()); assertEquals("myAccessorMethod", legacy.getMethodProperties().get(0).getAccessorMethodName()); assertEquals("mymethodprop", legacy.getMethodProperties().get(0).getName()); assertEquals(Configuration.PropertyResolutionStyle.CASE_INSENSITIVE, legacy.getPropertyResolutionStyle()); assertEquals("com.mycompany.myapp.MySampleEventFactory.createMyLegacyTypeEvent", legacy.getFactoryMethod()); assertEquals("myCopyMethod", legacy.getCopyMethod()); assertEquals("startts", legacy.getStartTimestampPropertyName()); assertEquals("endts", legacy.getEndTimestampPropertyName()); // assert database reference - data source config assertEquals(3, config.getDatabaseReferences().size()); ConfigurationDBRef configDBRef = config.getDatabaseReferences().get("mydb1"); ConfigurationDBRef.DataSourceConnection dsDef = (ConfigurationDBRef.DataSourceConnection) configDBRef .getConnectionFactoryDesc(); assertEquals("java:comp/env/jdbc/mydb", dsDef.getContextLookupName()); assertEquals( "{java.naming.provider.url=iiop://localhost:1050, java.naming.factory.initial=com.myclass.CtxFactory}", dsDef.getEnvProperties().toString()); assertEquals(ConfigurationDBRef.ConnectionLifecycleEnum.POOLED, configDBRef.getConnectionLifecycleEnum()); assertNull(configDBRef.getConnectionSettings().getAutoCommit()); assertNull(configDBRef.getConnectionSettings().getCatalog()); assertNull(configDBRef.getConnectionSettings().getReadOnly()); assertNull(configDBRef.getConnectionSettings().getTransactionIsolation()); ConfigurationLRUCache lruCache = (ConfigurationLRUCache) configDBRef.getDataCacheDesc(); assertEquals(10, lruCache.getSize()); assertEquals(ConfigurationDBRef.ColumnChangeCaseEnum.LOWERCASE, configDBRef.getColumnChangeCase()); assertEquals(ConfigurationDBRef.MetadataOriginEnum.SAMPLE, configDBRef.getMetadataRetrievalEnum()); assertEquals(2, configDBRef.getSqlTypesMapping().size()); assertEquals("int", configDBRef.getSqlTypesMapping().get(2)); assertEquals("float", configDBRef.getSqlTypesMapping().get(6)); // assert database reference - driver manager config configDBRef = config.getDatabaseReferences().get("mydb2"); ConfigurationDBRef.DriverManagerConnection dmDef = (ConfigurationDBRef.DriverManagerConnection) configDBRef .getConnectionFactoryDesc(); assertEquals("my.sql.Driver", dmDef.getClassName()); assertEquals("jdbc:mysql://localhost", dmDef.getUrl()); assertEquals("myuser1", dmDef.getOptionalUserName()); assertEquals("mypassword1", dmDef.getOptionalPassword()); assertEquals("{user=myuser2, password=mypassword2, somearg=someargvalue}", dmDef.getOptionalProperties().toString()); assertEquals(ConfigurationDBRef.ConnectionLifecycleEnum.RETAIN, configDBRef.getConnectionLifecycleEnum()); assertEquals((Boolean) false, configDBRef.getConnectionSettings().getAutoCommit()); assertEquals("test", configDBRef.getConnectionSettings().getCatalog()); assertEquals(Boolean.TRUE, configDBRef.getConnectionSettings().getReadOnly()); assertEquals(new Integer(3), configDBRef.getConnectionSettings().getTransactionIsolation()); ConfigurationExpiryTimeCache expCache = (ConfigurationExpiryTimeCache) configDBRef.getDataCacheDesc(); assertEquals(60.5, expCache.getMaxAgeSeconds()); assertEquals(120.1, expCache.getPurgeIntervalSeconds()); assertEquals(ConfigurationCacheReferenceType.HARD, expCache.getCacheReferenceType()); assertEquals(ConfigurationDBRef.ColumnChangeCaseEnum.UPPERCASE, configDBRef.getColumnChangeCase()); assertEquals(ConfigurationDBRef.MetadataOriginEnum.METADATA, configDBRef.getMetadataRetrievalEnum()); assertEquals(1, configDBRef.getSqlTypesMapping().size()); assertEquals("java.lang.String", configDBRef.getSqlTypesMapping().get(99)); // assert database reference - data source factory and DBCP config configDBRef = config.getDatabaseReferences().get("mydb3"); ConfigurationDBRef.DataSourceFactory dsFactory = (ConfigurationDBRef.DataSourceFactory) configDBRef .getConnectionFactoryDesc(); assertEquals("org.apache.commons.dbcp.BasicDataSourceFactory", dsFactory.getFactoryClassname()); assertEquals("jdbc:mysql://localhost/test", dsFactory.getProperties().getProperty("url")); assertEquals("myusername", dsFactory.getProperties().getProperty("username")); assertEquals("mypassword", dsFactory.getProperties().getProperty("password")); assertEquals("com.mysql.jdbc.Driver", dsFactory.getProperties().getProperty("driverClassName")); assertEquals("2", dsFactory.getProperties().getProperty("initialSize")); // assert custom view implementations List<ConfigurationPlugInView> configViews = config.getPlugInViews(); assertEquals(2, configViews.size()); for (int i = 0; i < configViews.size(); i++) { ConfigurationPlugInView entry = configViews.get(i); assertEquals("ext" + i, entry.getNamespace()); assertEquals("myview" + i, entry.getName()); assertEquals("com.mycompany.MyViewFactory" + i, entry.getFactoryClassName()); } // assert custom virtual data window implementations List<ConfigurationPlugInVirtualDataWindow> configVDW = config.getPlugInVirtualDataWindows(); assertEquals(2, configVDW.size()); for (int i = 0; i < configVDW.size(); i++) { ConfigurationPlugInVirtualDataWindow entry = configVDW.get(i); assertEquals("vdw" + i, entry.getNamespace()); assertEquals("myvdw" + i, entry.getName()); assertEquals("com.mycompany.MyVdwFactory" + i, entry.getFactoryClassName()); if (i == 1) { assertEquals("abc", entry.getConfig()); } } // assert adapter loaders parsed List<ConfigurationPluginLoader> plugins = config.getPluginLoaders(); assertEquals(2, plugins.size()); ConfigurationPluginLoader pluginOne = plugins.get(0); assertEquals("Loader1", pluginOne.getLoaderName()); assertEquals("com.espertech.esper.support.plugin.SupportLoaderOne", pluginOne.getClassName()); assertEquals(2, pluginOne.getConfigProperties().size()); assertEquals("val1", pluginOne.getConfigProperties().get("name1")); assertEquals("val2", pluginOne.getConfigProperties().get("name2")); assertEquals( "<?xml version=\"1.0\" encoding=\"UTF-8\"?><sample-initializer><some-any-xml-can-be-here>This section for use by a plugin loader.</some-any-xml-can-be-here></sample-initializer>", pluginOne.getConfigurationXML()); ConfigurationPluginLoader pluginTwo = plugins.get(1); assertEquals("Loader2", pluginTwo.getLoaderName()); assertEquals("com.espertech.esper.support.plugin.SupportLoaderTwo", pluginTwo.getClassName()); assertEquals(0, pluginTwo.getConfigProperties().size()); // assert plug-in aggregation function loaded assertEquals(4, config.getPlugInAggregationFunctions().size()); ConfigurationPlugInAggregationFunction pluginAgg = config.getPlugInAggregationFunctions().get(0); assertEquals("com.mycompany.MyMatrixAggregationMethod0DEPRECATED", pluginAgg.getFunctionClassName()); assertEquals("func1", pluginAgg.getName()); assertEquals(null, pluginAgg.getFactoryClassName()); pluginAgg = config.getPlugInAggregationFunctions().get(1); assertEquals("com.mycompany.MyMatrixAggregationMethod1DEPRECATED", pluginAgg.getFunctionClassName()); assertEquals("func2", pluginAgg.getName()); assertEquals(null, pluginAgg.getFactoryClassName()); pluginAgg = config.getPlugInAggregationFunctions().get(2); assertEquals(null, pluginAgg.getFunctionClassName()); assertEquals("func1a", pluginAgg.getName()); assertEquals("com.mycompany.MyMatrixAggregationMethod0Factory", pluginAgg.getFactoryClassName()); pluginAgg = config.getPlugInAggregationFunctions().get(3); assertEquals(null, pluginAgg.getFunctionClassName()); assertEquals("func2a", pluginAgg.getName()); assertEquals("com.mycompany.MyMatrixAggregationMethod1Factory", pluginAgg.getFactoryClassName()); // assert plug-in aggregation multi-function loaded assertEquals(1, config.getPlugInAggregationMultiFunctions().size()); ConfigurationPlugInAggregationMultiFunction pluginMultiAgg = config.getPlugInAggregationMultiFunctions() .get(0); EPAssertionUtil.assertEqualsExactOrder(new String[] { "func1", "func2" }, pluginMultiAgg.getFunctionNames()); assertEquals("com.mycompany.MyAggregationMultiFunctionFactory", pluginMultiAgg.getMultiFunctionFactoryClassName()); assertEquals(1, pluginMultiAgg.getAdditionalConfiguredProperties().size()); assertEquals("value1", pluginMultiAgg.getAdditionalConfiguredProperties().get("prop1")); // assert plug-in singlerow function loaded assertEquals(2, config.getPlugInSingleRowFunctions().size()); ConfigurationPlugInSingleRowFunction pluginSingleRow = config.getPlugInSingleRowFunctions().get(0); assertEquals("com.mycompany.MyMatrixSingleRowMethod0", pluginSingleRow.getFunctionClassName()); assertEquals("method1", pluginSingleRow.getFunctionMethodName()); assertEquals("func3", pluginSingleRow.getName()); assertEquals(ConfigurationPlugInSingleRowFunction.ValueCache.DISABLED, pluginSingleRow.getValueCache()); assertEquals(ConfigurationPlugInSingleRowFunction.FilterOptimizable.ENABLED, pluginSingleRow.getFilterOptimizable()); assertFalse(pluginSingleRow.isRethrowExceptions()); pluginSingleRow = config.getPlugInSingleRowFunctions().get(1); assertEquals("com.mycompany.MyMatrixSingleRowMethod1", pluginSingleRow.getFunctionClassName()); assertEquals("func4", pluginSingleRow.getName()); assertEquals("method2", pluginSingleRow.getFunctionMethodName()); assertEquals(ConfigurationPlugInSingleRowFunction.ValueCache.ENABLED, pluginSingleRow.getValueCache()); assertEquals(ConfigurationPlugInSingleRowFunction.FilterOptimizable.DISABLED, pluginSingleRow.getFilterOptimizable()); assertTrue(pluginSingleRow.isRethrowExceptions()); // assert plug-in guard objects loaded assertEquals(4, config.getPlugInPatternObjects().size()); ConfigurationPlugInPatternObject pluginPattern = config.getPlugInPatternObjects().get(0); assertEquals("com.mycompany.MyGuardFactory0", pluginPattern.getFactoryClassName()); assertEquals("ext0", pluginPattern.getNamespace()); assertEquals("guard1", pluginPattern.getName()); assertEquals(ConfigurationPlugInPatternObject.PatternObjectType.GUARD, pluginPattern.getPatternObjectType()); pluginPattern = config.getPlugInPatternObjects().get(1); assertEquals("com.mycompany.MyGuardFactory1", pluginPattern.getFactoryClassName()); assertEquals("ext1", pluginPattern.getNamespace()); assertEquals("guard2", pluginPattern.getName()); assertEquals(ConfigurationPlugInPatternObject.PatternObjectType.GUARD, pluginPattern.getPatternObjectType()); pluginPattern = config.getPlugInPatternObjects().get(2); assertEquals("com.mycompany.MyObserverFactory0", pluginPattern.getFactoryClassName()); assertEquals("ext0", pluginPattern.getNamespace()); assertEquals("observer1", pluginPattern.getName()); assertEquals(ConfigurationPlugInPatternObject.PatternObjectType.OBSERVER, pluginPattern.getPatternObjectType()); pluginPattern = config.getPlugInPatternObjects().get(3); assertEquals("com.mycompany.MyObserverFactory1", pluginPattern.getFactoryClassName()); assertEquals("ext1", pluginPattern.getNamespace()); assertEquals("observer2", pluginPattern.getName()); assertEquals(ConfigurationPlugInPatternObject.PatternObjectType.OBSERVER, pluginPattern.getPatternObjectType()); // assert engine defaults assertFalse(config.getEngineDefaults().getThreading().isInsertIntoDispatchPreserveOrder()); assertEquals(3000, config.getEngineDefaults().getThreading().getInsertIntoDispatchTimeout()); assertEquals(ConfigurationEngineDefaults.Threading.Locking.SUSPEND, config.getEngineDefaults().getThreading().getInsertIntoDispatchLocking()); assertFalse(config.getEngineDefaults().getThreading().isListenerDispatchPreserveOrder()); assertEquals(2000, config.getEngineDefaults().getThreading().getListenerDispatchTimeout()); assertEquals(ConfigurationEngineDefaults.Threading.Locking.SUSPEND, config.getEngineDefaults().getThreading().getListenerDispatchLocking()); assertTrue(config.getEngineDefaults().getThreading().isThreadPoolInbound()); assertTrue(config.getEngineDefaults().getThreading().isThreadPoolOutbound()); assertTrue(config.getEngineDefaults().getThreading().isThreadPoolRouteExec()); assertTrue(config.getEngineDefaults().getThreading().isThreadPoolTimerExec()); assertEquals(1, config.getEngineDefaults().getThreading().getThreadPoolInboundNumThreads()); assertEquals(2, config.getEngineDefaults().getThreading().getThreadPoolOutboundNumThreads()); assertEquals(3, config.getEngineDefaults().getThreading().getThreadPoolTimerExecNumThreads()); assertEquals(4, config.getEngineDefaults().getThreading().getThreadPoolRouteExecNumThreads()); assertEquals(1000, (int) config.getEngineDefaults().getThreading().getThreadPoolInboundCapacity()); assertEquals(1500, (int) config.getEngineDefaults().getThreading().getThreadPoolOutboundCapacity()); assertEquals(null, config.getEngineDefaults().getThreading().getThreadPoolTimerExecCapacity()); assertEquals(2000, (int) config.getEngineDefaults().getThreading().getThreadPoolRouteExecCapacity()); assertFalse(config.getEngineDefaults().getThreading().isInternalTimerEnabled()); assertEquals(1234567, config.getEngineDefaults().getThreading().getInternalTimerMsecResolution()); assertFalse(config.getEngineDefaults().getViewResources().isShareViews()); assertTrue(config.getEngineDefaults().getViewResources().isAllowMultipleExpiryPolicies()); assertEquals(Configuration.PropertyResolutionStyle.DISTINCT_CASE_INSENSITIVE, config.getEngineDefaults().getEventMeta().getClassPropertyResolutionStyle()); assertEquals(ConfigurationEventTypeLegacy.AccessorStyle.PUBLIC, config.getEngineDefaults().getEventMeta().getDefaultAccessorStyle()); assertEquals(Configuration.EventRepresentation.MAP, config.getEngineDefaults().getEventMeta().getDefaultEventRepresentation()); assertEquals(100, config.getEngineDefaults().getEventMeta().getAnonymousCacheSize()); assertTrue(config.getEngineDefaults().getLogging().isEnableExecutionDebug()); assertFalse(config.getEngineDefaults().getLogging().isEnableTimerDebug()); assertTrue(config.getEngineDefaults().getLogging().isEnableQueryPlan()); assertTrue(config.getEngineDefaults().getLogging().isEnableJDBC()); assertEquals("[%u] %m", config.getEngineDefaults().getLogging().getAuditPattern()); assertEquals(30000, config.getEngineDefaults().getVariables().getMsecVersionRelease()); assertEquals(3L, (long) config.getEngineDefaults().getPatterns().getMaxSubexpressions()); assertEquals(false, config.getEngineDefaults().getPatterns().isMaxSubexpressionPreventStart()); assertEquals(StreamSelector.RSTREAM_ISTREAM_BOTH, config.getEngineDefaults().getStreamSelection().getDefaultStreamSelector()); assertEquals(ConfigurationEngineDefaults.TimeSourceType.NANO, config.getEngineDefaults().getTimeSource().getTimeSourceType()); assertTrue(config.getEngineDefaults().getExecution().isPrioritized()); assertTrue(config.getEngineDefaults().getExecution().isFairlock()); assertTrue(config.getEngineDefaults().getExecution().isDisableLocking()); assertEquals(ConfigurationEngineDefaults.ThreadingProfile.LARGE, config.getEngineDefaults().getExecution().getThreadingProfile()); ConfigurationMetricsReporting metrics = config.getEngineDefaults().getMetricsReporting(); assertTrue(metrics.isEnableMetricsReporting()); assertEquals(4000L, metrics.getEngineInterval()); assertEquals(500L, metrics.getStatementInterval()); assertFalse(metrics.isThreading()); assertEquals(2, metrics.getStatementGroups().size()); assertTrue(metrics.isJmxEngineMetrics()); ConfigurationMetricsReporting.StmtGroupMetrics def = metrics.getStatementGroups().get("MyStmtGroup"); assertEquals(5000, def.getInterval()); assertTrue(def.isDefaultInclude()); assertEquals(50, def.getNumStatements()); assertTrue(def.isReportInactive()); assertEquals(5, def.getPatterns().size()); assertEquals(def.getPatterns().get(0), new Pair<StringPatternSet, Boolean>(new StringPatternSetRegex(".*"), true)); assertEquals(def.getPatterns().get(1), new Pair<StringPatternSet, Boolean>(new StringPatternSetRegex(".*test.*"), false)); assertEquals(def.getPatterns().get(2), new Pair<StringPatternSet, Boolean>(new StringPatternSetLike("%MyMetricsStatement%"), false)); assertEquals(def.getPatterns().get(3), new Pair<StringPatternSet, Boolean>(new StringPatternSetLike("%MyFraudAnalysisStatement%"), true)); assertEquals(def.getPatterns().get(4), new Pair<StringPatternSet, Boolean>(new StringPatternSetLike("%SomerOtherStatement%"), true)); def = metrics.getStatementGroups().get("MyStmtGroupTwo"); assertEquals(200, def.getInterval()); assertFalse(def.isDefaultInclude()); assertEquals(100, def.getNumStatements()); assertFalse(def.isReportInactive()); assertEquals(0, def.getPatterns().size()); assertTrue(config.getEngineDefaults().getLanguage().isSortUsingCollator()); assertTrue(config.getEngineDefaults().getExpression().isIntegerDivision()); assertTrue(config.getEngineDefaults().getExpression().isDivisionByZeroReturnsNull()); assertFalse(config.getEngineDefaults().getExpression().isSelfSubselectPreeval()); assertFalse(config.getEngineDefaults().getExpression().isUdfCache()); assertFalse(config.getEngineDefaults().getExpression().isExtendedAggregation()); assertTrue(config.getEngineDefaults().getExpression().isDuckTyping()); assertEquals(2, config.getEngineDefaults().getExpression().getMathContext().getPrecision()); assertEquals(RoundingMode.CEILING, config.getEngineDefaults().getExpression().getMathContext().getRoundingMode()); assertEquals(2, config.getEngineDefaults().getExceptionHandling().getHandlerFactories().size()); assertEquals("my.company.cep.LoggingExceptionHandlerFactory", config.getEngineDefaults().getExceptionHandling().getHandlerFactories().get(0)); assertEquals("my.company.cep.AlertExceptionHandlerFactory", config.getEngineDefaults().getExceptionHandling().getHandlerFactories().get(1)); assertEquals(2, config.getEngineDefaults().getConditionHandling().getHandlerFactories().size()); assertEquals("my.company.cep.LoggingConditionHandlerFactory", config.getEngineDefaults().getConditionHandling().getHandlerFactories().get(0)); assertEquals("my.company.cep.AlertConditionHandlerFactory", config.getEngineDefaults().getConditionHandling().getHandlerFactories().get(1)); assertEquals("abc", config.getEngineDefaults().getScripts().getDefaultDialect()); // variables assertEquals(3, config.getVariables().size()); ConfigurationVariable variable = config.getVariables().get("var1"); assertEquals(Integer.class.getName(), variable.getType()); assertEquals("1", variable.getInitializationValue()); assertFalse(variable.isConstant()); variable = config.getVariables().get("var2"); assertEquals(String.class.getName(), variable.getType()); assertEquals(null, variable.getInitializationValue()); assertFalse(variable.isConstant()); variable = config.getVariables().get("var3"); assertTrue(variable.isConstant()); // method references assertEquals(2, config.getMethodInvocationReferences().size()); ConfigurationMethodRef methodRef = config.getMethodInvocationReferences().get("abc"); expCache = (ConfigurationExpiryTimeCache) methodRef.getDataCacheDesc(); assertEquals(91.0, expCache.getMaxAgeSeconds()); assertEquals(92.2, expCache.getPurgeIntervalSeconds()); assertEquals(ConfigurationCacheReferenceType.WEAK, expCache.getCacheReferenceType()); methodRef = config.getMethodInvocationReferences().get("def"); lruCache = (ConfigurationLRUCache) methodRef.getDataCacheDesc(); assertEquals(20, lruCache.getSize()); // plug-in event representations assertEquals(2, config.getPlugInEventRepresentation().size()); ConfigurationPlugInEventRepresentation rep = config.getPlugInEventRepresentation() .get(new URI("type://format/rep/name")); assertEquals("com.mycompany.MyPlugInEventRepresentation", rep.getEventRepresentationClassName()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><anyxml>test string event rep init</anyxml>", rep.getInitializer()); rep = config.getPlugInEventRepresentation().get(new URI("type://format/rep/name2")); assertEquals("com.mycompany.MyPlugInEventRepresentation2", rep.getEventRepresentationClassName()); assertEquals(null, rep.getInitializer()); // plug-in event types assertEquals(2, config.getPlugInEventTypes().size()); ConfigurationPlugInEventType type = config.getPlugInEventTypes().get("MyEvent"); assertEquals(2, type.getEventRepresentationResolutionURIs().length); assertEquals("type://format/rep", type.getEventRepresentationResolutionURIs()[0].toString()); assertEquals("type://format/rep2", type.getEventRepresentationResolutionURIs()[1].toString()); assertEquals("<?xml version=\"1.0\" encoding=\"UTF-8\"?><anyxml>test string event type init</anyxml>", type.getInitializer()); type = config.getPlugInEventTypes().get("MyEvent2"); assertEquals(1, type.getEventRepresentationResolutionURIs().length); assertEquals("type://format/rep2", type.getEventRepresentationResolutionURIs()[0].toString()); assertEquals(null, type.getInitializer()); // plug-in event representation resolution URIs when using a new name in a statement assertEquals(2, config.getPlugInEventTypeResolutionURIs().length); assertEquals("type://format/rep", config.getPlugInEventTypeResolutionURIs()[0].toString()); assertEquals("type://format/rep2", config.getPlugInEventTypeResolutionURIs()[1].toString()); // revision types assertEquals(1, config.getRevisionEventTypes().size()); ConfigurationRevisionEventType configRev = config.getRevisionEventTypes().get("MyRevisionEvent"); assertEquals(1, configRev.getNameBaseEventTypes().size()); assertTrue(configRev.getNameBaseEventTypes().contains("MyBaseEventName")); assertTrue(configRev.getNameDeltaEventTypes().contains("MyDeltaEventNameOne")); assertTrue(configRev.getNameDeltaEventTypes().contains("MyDeltaEventNameTwo")); EPAssertionUtil.assertEqualsAnyOrder(new String[] { "id", "id2" }, configRev.getKeyPropertyNames()); assertEquals(ConfigurationRevisionEventType.PropertyRevision.MERGE_NON_NULL, configRev.getPropertyRevision()); // variance types assertEquals(1, config.getVariantStreams().size()); ConfigurationVariantStream configVStream = config.getVariantStreams().get("MyVariantStream"); assertEquals(2, configVStream.getVariantTypeNames().size()); assertTrue(configVStream.getVariantTypeNames().contains("MyEvenTypetNameOne")); assertTrue(configVStream.getVariantTypeNames().contains("MyEvenTypetNameTwo")); assertEquals(ConfigurationVariantStream.TypeVariance.ANY, configVStream.getTypeVariance()); }
From source file:org.ala.harvester.MorphbankHarvester.java
/** * Process a single image, do the document mapping etc * //from w w w . j a v a2 s . c om * @param infosourceId * @param imageIndex * @param currentResDom * @throws Exception */ private void processSingleImage(int infosourceId, int imageIndex, Document currentResDom) throws Exception { XPathFactory factory = XPathFactory.newInstance(); XPath xpath = factory.newXPath(); ParsedDocument pd = new ParsedDocument(); ParsedDocument imageDoc = new ParsedDocument(); String subject = MappingUtils.getSubject(); String xPathToIdentifier = "/response/object[" + imageIndex + "]/detailPageUrl/text()"; String xPathToScientificName = "/response/object[" + imageIndex + "]/ScientificName/text()"; String xPathToLatitude = "/response/object[" + imageIndex + "]/DecimalLatitude/text()"; String xPathToLongitude = "/response/object[" + imageIndex + "]/DecimalLongitude/text()"; String xPathToImageUrl = "/response/object[" + imageIndex + "]/thumbUrl/text()"; String xPathToLicense = "/response/object[" + imageIndex + "]/copyrightText/text()"; String xPathToKingdom = "/response/object[" + imageIndex + "]/Kingdom/text()"; String xPathToPhylum = "/response/object[" + imageIndex + "]/Phylum/text()"; String xPathToClass = "/response/object[" + imageIndex + "]/Class/text()"; String xPathToOrder = "/response/object[" + imageIndex + "]/Order/text()"; String xPathToFamily = "/response/object[" + imageIndex + "]/Family/text()"; String xPathToGenus = "/response/object[" + imageIndex + "]/Genus/text()"; String xPathToSpecificEpithet = "/response/object[" + imageIndex + "]/SpecificEpithet/text()"; String xPathToCountry = "/response/object[" + imageIndex + "]/Country/text()"; String xPathToLocality = "/response/object[" + imageIndex + "]/Locality/text()"; String identifier = null; String scientificName = null; String latitude = null; String longitude = null; String imageUrl = null; String license = null; String kingdom = null; String phylum = null; String klass = null; String order = null; String family = null; String genus = null; String specificEpithet = null; String country = null; String locality = null; try { identifier = (String) xpath.evaluate(xPathToIdentifier, currentResDom, XPathConstants.STRING); scientificName = (String) xpath.evaluate(xPathToScientificName, currentResDom, XPathConstants.STRING); latitude = (String) xpath.evaluate(xPathToLatitude, currentResDom, XPathConstants.STRING); longitude = (String) xpath.evaluate(xPathToLongitude, currentResDom, XPathConstants.STRING); imageUrl = (String) xpath.evaluate(xPathToImageUrl, currentResDom, XPathConstants.STRING); license = (String) xpath.evaluate(xPathToLicense, currentResDom, XPathConstants.STRING); kingdom = (String) xpath.evaluate(xPathToKingdom, currentResDom, XPathConstants.STRING); phylum = (String) xpath.evaluate(xPathToPhylum, currentResDom, XPathConstants.STRING); klass = (String) xpath.evaluate(xPathToClass, currentResDom, XPathConstants.STRING); order = (String) xpath.evaluate(xPathToOrder, currentResDom, XPathConstants.STRING); family = (String) xpath.evaluate(xPathToFamily, currentResDom, XPathConstants.STRING); genus = (String) xpath.evaluate(xPathToGenus, currentResDom, XPathConstants.STRING); specificEpithet = (String) xpath.evaluate(xPathToSpecificEpithet, currentResDom, XPathConstants.STRING); country = (String) xpath.evaluate(xPathToCountry, currentResDom, XPathConstants.STRING); locality = (String) xpath.evaluate(xPathToLocality, currentResDom, XPathConstants.STRING); } catch (XPathExpressionException getPageFragmentationError) { String errMsg = "Failed to obtain Morphbank's Detail Page Url"; logger.error(errMsg); throw new Exception(errMsg, getPageFragmentationError); } // System.out.println("Index: " + imageIndex); identifier = identifier.replaceAll("\\-svc", ""); System.out.println(imageIndex + ", PHOTO URL:" + identifier); List<Triple<String, String, String>> triples = pd.getTriples(); Map<String, String> dcs = pd.getDublinCore(); pd.setGuid(identifier); pd.setContent(getContent(identifier)); pd.setContentType(contentType); dcs.put(Predicates.DC_TITLE.toString(), scientificName); dcs.put(Predicates.DC_IDENTIFIER.toString(), identifier); dcs.put(Predicates.LATITUDE.toString(), latitude); dcs.put(Predicates.LONGITUDE.toString(), longitude); dcs.put(Predicates.DC_LICENSE.toString(), "Creative Commons Attribution-Non Commercial 3.0 Australia License, http://creativecommons.org/licenses/by-nc/3.0/au/deed.en"); dcs.put(Predicates.DC_CREATOR.toString(), license); if (isCoral) { dcs.put(Predicates.DC_RIGHTS.toString(), "J. Veron Coral Reef Research"); } else { if (license != null && !"".equals(license)) { dcs.put(Predicates.DC_RIGHTS.toString(), license); } else { dcs.put(Predicates.DC_RIGHTS.toString(), "Copyright by Morphbank"); } } dcs.put(Predicates.COUNTRY.toString(), country); dcs.put(Predicates.LOCALITY.toString(), locality); triples.add(new Triple(subject, Predicates.SCIENTIFIC_NAME.toString(), scientificName)); triples.add(new Triple(subject, Predicates.KINGDOM.toString(), kingdom)); triples.add(new Triple(subject, Predicates.PHYLUM.toString(), phylum)); triples.add(new Triple(subject, Predicates.CLASS.toString(), klass)); triples.add(new Triple(subject, Predicates.ORDER.toString(), order)); triples.add(new Triple(subject, Predicates.FAMILY.toString(), family)); triples.add(new Triple(subject, Predicates.GENUS.toString(), genus)); triples.add(new Triple(subject, Predicates.SPECIFIC_EPITHET.toString(), specificEpithet)); if (imageUrl != null && !"".equals(imageUrl)) { imageUrl = imageUrl.replaceAll("thumb", "jpg"); imageUrl = imageUrl.replaceAll("images\\.morphbank\\.net", "morphbank-images.ala.org.au"); imageDoc = MappingUtils.retrieveImageDocument(pd, imageUrl); // debugParsedDoc(imageDoc); } // debugParsedDoc(pd); if (pd != null) { this.repository.storeDocument(infosourceId, pd); } if (imageDoc != null) { this.repository.storeDocument(infosourceId, imageDoc); } }
From source file:de.bitzeche.video.transcoding.zencoder.ZencoderClient.java
public ZencoderNotificationJobState getJobState(int id) { Document response = getJobProgress(id); if (response == null) { return null; }//from ww w . j ava 2 s. c om String stateString = null; try { stateString = (String) xPath.evaluate("/api-response/state", response, XPathConstants.STRING); return ZencoderNotificationJobState.getJobState(stateString); } catch (IllegalArgumentException ex) { LOGGER.error("Unable to find state for string '{}'", stateString); } catch (XPathExpressionException e) { LOGGER.error("XPath threw Exception", e); } return null; }
From source file:com.mnxfst.testing.client.TSClientPlanResultCollectCallable.java
/** * Parses the int value referenced by the given query * @param rootNode/*from w w w. j a v a 2 s .c om*/ * @param query * @param xpath * @return * @throws TSClientExecutionException */ protected int parseIntValue(Node rootNode, String query, XPath xpath) throws TSClientExecutionException { String tmp = null; try { tmp = (String) xpath.evaluate(query, rootNode, XPathConstants.STRING); } catch (XPathExpressionException e) { throw new TSClientExecutionException("Failed to parse out value for '" + query + "' from document received from " + httpHost.getHostName()); } if (tmp != null && !tmp.isEmpty()) { try { return Integer.parseInt(tmp); } catch (NumberFormatException e) { throw new TSClientExecutionException("Failed to parse the string '" + tmp + "' into a valid numerical value received through query '" + query + "'. Returning host: " + httpHost.getHostName()); } } throw new TSClientExecutionException( "No valid value found for '" + query + "' from document received from " + httpHost.getHostName()); }
From source file:org.opencastproject.remotetest.server.ComposerRestEndpointTest.java
/** * Gets the mediapackage element from a job polling response * // w w w .j av a 2 s. c o m * @param jobXml * the job as xml * @return the mediapackage elemet as an xml string */ protected long getDurationFromJob(String jobXml) throws Exception { DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); factory.setNamespaceAware(true); DocumentBuilder builder = factory.newDocumentBuilder(); Document doc = builder.parse(IOUtils.toInputStream(jobXml, "UTF-8")); String payload = (String) XPathFactory.newInstance().newXPath().compile("//*[local-name() = 'payload']") .evaluate(doc, XPathConstants.STRING); Document payloadDoc = builder.parse(IOUtils.toInputStream(payload, "UTF-8")); Element element = ((Element) XPathFactory.newInstance().newXPath() .compile("//*[local-name() = 'duration'][1]").evaluate(payloadDoc, XPathConstants.NODE)); if (element == null) throw new IllegalStateException("Track doesn't contain a duration"); return Long.parseLong(element.getFirstChild().getNodeValue()); }
From source file:com.mnxfst.testing.server.cfg.PTestServerConfigurationParser.java
/** * Evaluates the given expression on the referenced document into a result object of type string * @param expression/*from w w w. j a va2 s.c o m*/ * @param document * @return * @throws XPathExpressionException */ protected String evaluateString(XPathExpression expression, Object document) throws XPathExpressionException { if (expression == null) throw new XPathExpressionException("Null is not a valid expression"); if (document == null) throw new XPathExpressionException("An xpath expression must not be applied to a NULL document"); return (String) expression.evaluate(document, XPathConstants.STRING); }
From source file:eu.planets_project.tb.impl.services.EvaluationTestbedServiceTemplateImpl.java
/** * @param node a Node obtained by getAllEvalResultsRootNodes() * @return LinkedHashMap<MetricName,MetricResult> * @throws XPathExpressionException/* w w w. j a va 2 s. c o m*/ */ public Map<String, String> getEvalResultMetricNamesAndValues(Node node) throws XPathExpressionException { //get all metric nodes for this property NodeList metrics = getEvalResultMetricNodes(node); Map<String, String> ret = new LinkedHashMap<String, String>(); if ((metrics != null) && (metrics.getLength() > 0)) { for (int i = 0; i < metrics.getLength(); i++) { //metric node Node n = metrics.item(i); //query the name XPath xpathName = XPathFactory.newInstance().newXPath(); String name = (String) xpathName.evaluate(sMetricName, n, XPathConstants.STRING); //query the result XPath xpathResult = XPathFactory.newInstance().newXPath(); String value = (String) xpathResult.evaluate(sMetricResult, n, XPathConstants.STRING); ret.put(name, value); } } return ret; }