@Override public Option<T> unmarshal(T o) throws Exception { return Option.option(o); }
@Override public Option<A> apply(A a) { return option(a); } };
@Override public Option<A> apply(EntityManager em) { return option(em.find(clazz, primaryKey)); } };
@Override public Option<A> apply(EntityManager em) { return option(em.find(clazz, primaryKey)); } };
@Override public Option<B> apply(A a) { return option(map.get(a)); } };
/** * Open a classpath resource using the class loader of the given class. * * @return an input stream to the resource wrapped in a Some or none if the resource cannot be found */ public static Option<InputStream> openClassPathResource(String resource, Class<?> clazz) { return option(clazz.getResourceAsStream(resource)); }
/** Extract the build number of a bundle. */ public static Option<String> getBuildNumber(Bundle bundle) { return option(bundle.getHeaders().get(MANIFEST_BUILD_NUMBER)); } }
/** Evaluate the xpath expression against the contained document. The expression must return a nodelist. */ // todo replace return type with Valid once it is implemented public Option<NodeList> nodeSet(String expr) { try { return option(((NodeList) xpath.evaluate(expr, node, XPathConstants.NODESET))); } catch (XPathExpressionException e) { return none(); } }
/** * Get an optional, non-blank value from the <em>bundle</em> context. * * @throws RuntimeException * key does not exist or its value is blank */ public static Option<String> getOptContextProperty(ComponentContext cc, String key) { return option(cc.getBundleContext().getProperty(key)).bind(Strings.trimToNone); }
@Override public Option<Date> apply(DublinCoreValue dublinCoreValue) { return option(decodeDate(dublinCoreValue)); } };
/** Evaluate the xpath expression against the contained document. The expression must return a node. */ // todo replace return type with Valid once it is implemented public Option<Node> node(String expr) { try { return option((Node) xpath.evaluate(expr, node, XPathConstants.NODE)); } catch (XPathExpressionException e) { return none(); } }
/** Evaluate the xpath expression against the contained document. The expression must return a string (text). */ // todo replace return type with Valid once it is implemented public Option<String> string(String expr) { try { return option(((String) xpath.evaluate(expr, node, XPathConstants.STRING)).trim()); } catch (XPathExpressionException e) { return none(); } }
@Override public String getMountPoint() { for (HttpResponse r : option(getResponse(get("mountpoint"), HttpStatus.SC_OK))) { try { return EntityUtils.toString(r.getEntity()); } catch (IOException e) { logger.error("Cannot contact remote service", e); return chuck(e); } } throw new RuntimeException("Cannot contact remote service"); } }
/** Get the OAI-PMH server URL of the current organization. */ public static Option<String> oaiPmhServerUrlOfCurrentOrganization(SecurityService secSvc) { return option(secSvc.getOrganization().getProperties().get(ORG_CFG_OAIPMH_SERVER_HOSTURL)); } }
/** * Get a configuration option. * * @deprecated use {@link #getConfig(WorkflowInstance, String)} or {@link #getOptConfig(org.opencastproject.workflow.api.WorkflowInstance, String)} */ protected Option<String> getCfg(WorkflowInstance wi, String key) { return option(wi.getCurrentOperation().getConfiguration(key)); }
@Override public Option<String> apply(MediaPackageElement mpe) { return option(mpe.getChecksum().getValue()); } };
@Override public String getPrefix(final String uri) { return option(b.getPrefix(uri)).getOrElse(new Function0<String>() { @Override public String apply() { return a.getPrefix(uri); } }); }
/** OSGi callback */ public void activate(ComponentContext cc) { host = option(getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY)).bind(Strings.trimToNone).getOrElse( UrlSupport.DEFAULT_BASE_URL); for (BundleInfoDb a : db) a.clear(host); cc.getBundleContext().addBundleListener(this); for (Bundle b : cc.getBundleContext().getBundles()) { logBundle(b); } }
/** * Get an optional boolean from a dictionary. */ public static Option<Boolean> getOptCfgAsBoolean(Dictionary d, String key) { return option(d.get(key)).bind(Strings.asString()).map(Strings.toBool); }
@Override public Option<Date[]> getTemporalPeriod() { if (temporalOpt.isSome()) { if (temporalOpt.get() instanceof DCMIPeriod) { DCMIPeriod p = (DCMIPeriod) temporalOpt.get(); return option(new Date[] { p.getStart(), p.getEnd() }); } } return Option.none(); }