@Override public Option<A> apply(A a) { return option(a); } };
/** 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(); } }
/** 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); } }
/** * Return the endpoint's server URL and the service path by extracting the relevant parameters from the * ComponentContext. * * @param cc * ComponentContext to get configuration from * @param serverUrlKey * Configuration key for the server URL * @param servicePathKey * Configuration key for the service path * @return (serverUrl, servicePath) * @throws Error * if the service path is not configured for this component */ public static Tuple<String, String> getEndpointUrl(ComponentContext cc, String serverUrlKey, String servicePathKey) { final String serverUrl = option(cc.getBundleContext().getProperty(serverUrlKey)).getOrElse( UrlSupport.DEFAULT_BASE_URL); final String servicePath = option((String) cc.getProperties().get(servicePathKey)).getOrElse( Option.<String> error(RestConstants.SERVICE_PATH_PROPERTY + " property not configured")); return tuple(serverUrl, servicePath); }
/** * 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); }
/** * OSGI callback for activating this component * * @param cc * the osgi component context */ public void activate(ComponentContext cc) throws ConfigurationException { logger.info("Static File REST Service started."); serverUrl = OsgiUtil.getContextProperty(cc, OpencastConstants.SERVER_URL_PROPERTY); useWebserver = BooleanUtils.toBoolean(OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_ENABLED_KEY) .getOrElse("false")); webserverURL = OsgiUtil.getOptCfg(cc.getProperties(), STATICFILES_WEBSERVER_URL_KEY); Option<String> cfgMaxUploadSize = OsgiUtil.getOptContextProperty(cc, STATICFILES_UPLOAD_MAX_SIZE_KEY); if (cfgMaxUploadSize.isSome()) maxUploadSize = Long.parseLong(cfgMaxUploadSize.get()); }
/** * {@inheritDoc} * * @see org.opencastproject.workingfilerepository.api.WorkingFileRepository#getTotalSpace() */ public Option<Long> getTotalSpace() { File f = new File(rootDirectory); return Option.some(f.getTotalSpace()); }
/** * Basic sanity checking for media packages. * * <pre> * // media package is ok * sanityCheck(mp).isNone() * </pre> * * @return none if the media package is a healthy condition, some([error_msgs]) otherwise */ public static Option<List<String>> sanityCheck(MediaPackage mp) { final Option<List<String>> errors = sequenceOpt(list(toOption(mp.getIdentifier() != null, "no ID"), toOption(mp.getIdentifier() != null && isNotBlank(mp.getIdentifier().toString()), "blank ID"))); return errors.getOrElse(NIL).size() == 0 ? Option.<List<String>> none() : errors; }
@Override public A apply(Option<A> ao) { return ao.getOrElse(a); } };