List of usage examples for org.apache.commons.lang StringUtils substringBefore
public static String substringBefore(String str, String separator)
Gets the substring before the first occurrence of a separator.
From source file:org.hippoecm.repository.LoggingServlet.java
protected void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException { if (!isAuthorized(req)) { BasicAuth.setRequestAuthorizationHeaders(res, "LoggingServlet"); return;// w w w.j a va 2 s. co m } String[] logLevelParams = req.getParameterValues(LOG_LEVEL_PARAM_NAME); if (logLevelParams != null) { Map<String, LoggerLevelInfo> loggerLevelInfosMap = getLoggerLevelInfosMap(); String loggerName = null; String loggerLevel = null; for (String logLevelParam : logLevelParams) { loggerName = StringUtils.substringBefore(logLevelParam, ":"); loggerLevel = StringUtils.substringAfter(logLevelParam, ":"); if (StringUtils.isNotEmpty(loggerName) && StringUtils.isNotEmpty(loggerLevel)) { LoggerLevelInfo loggerLevelInfo = loggerLevelInfosMap.get(loggerName); if (loggerLevelInfo != null && !StringUtils.equals(loggerLevel, loggerLevelInfo.getEffectiveLogLevel())) { setLoggerLevel(loggerName, loggerLevel); } } } } doGet(req, res); }
From source file:org.hydracache.server.httpd.handler.BaseHttpMethodHandler.java
protected String extractRequestString(final String requestUri) { String cleanUri = StringUtils.trim(requestUri); if (cleanUri.endsWith(SLASH)) { cleanUri = StringUtils.chop(cleanUri); }// www . j a v a 2s. c om cleanUri = StringUtils.removeStart(cleanUri, SLASH); String requestString = cleanUri; if (StringUtils.contains(requestString, SLASH)) { requestString = StringUtils.substringAfter(requestString, SLASH); } if (StringUtils.contains(requestString, QUESTION_MARK)) { requestString = StringUtils.substringBefore(requestString, QUESTION_MARK); } return requestString; }
From source file:org.hydracache.server.httpd.handler.BaseHttpMethodHandler.java
protected String extractRequestContext(final String requestUri) { String requestString = StringUtils.trim(requestUri); requestString = StringUtils.removeStart(requestString, SLASH); requestString = StringUtils.removeEnd(requestString, SLASH); if (StringUtils.contains(requestString, SLASH)) { requestString = StringUtils.substringBefore(requestString, SLASH); } else {/*from w w w . j a v a2 s . c om*/ requestString = ""; } return requestString; }
From source file:org.intermine.api.mines.HttpRequester.java
@Override public BufferedReader requestURL(final String urlString, final ContentType contentType) { BufferedReader reader = null; OutputStreamWriter writer = null; // TODO: when all friendly mines support mimetype formats then we can remove this. String suffix = "?format=" + contentType.getFormat(); try {/* ww w . ja v a 2 s.c o m*/ URL url = new URL(StringUtils.substringBefore(urlString, "?") + suffix); URLConnection conn = url.openConnection(); conn.addRequestProperty("Accept", contentType.getMimeType()); conn.setConnectTimeout(timeout * 1000); // conn accepts millisecond timeout. if (urlString.contains("?")) { // POST String queryString = StringUtils.substringAfter(urlString, "?"); conn.setDoOutput(true); writer = new OutputStreamWriter(conn.getOutputStream()); writer.write(queryString); writer.flush(); LOG.info("FriendlyMine URL (POST) " + urlString); } reader = new BufferedReader(new InputStreamReader(conn.getInputStream())); } catch (Exception e) { throw new RuntimeException("Unable to access " + urlString + " exception: " + e.getMessage()); } finally { if (writer != null) { try { writer.close(); } catch (IOException e) { LOG.error("Error sending POST request", e); } } } return reader; }
From source file:org.intermine.bio.dataconversion.ModEncodeMetaDataProcessor.java
/** * method to clean a wiki reference (url to a named page) in chado * used also for experiment names//from ww w .j ava 2s . c o m * @param w the wiki reference */ private String cleanWikiLinks(String w) { String url = "http://wiki.modencode.org/project/index.php?title="; // we are stripping from first ':', maybe we want to include project suffix // e.g.: // original "http://...?title=Gene Model Prediction:SC:1&oldid=12356" // now: Gene Model Prediction // maybe? Gene Model Prediction:SC:1 // (:->&) String w1 = StringUtils.replace(w, url, ""); String s1 = null; if (w1.contains(":")) { s1 = StringUtils.substringBefore(w1, ":"); } else { // for links missing the : char, e.g. // MacAlpine Early Origin of Replication Identification&oldid=10464 s1 = StringUtils.substringBefore(w1, "&"); } String s = s1.replace('"', ' ').trim(); if (s.contains("%E2%80%99")) { // prime: for the Piano experiment String s2 = s.replace("%E2%80%99", "'"); return s2; } if (s.contains("%28A%29%2B")) { // this is (A)+, in // Stranded Cell Line Transcriptional Profiling Using Illumina poly%28A%29%2B RNA-seq String s2 = s.replace("%28A%29%2B", "(A)+"); return s2; } if (s.contains("%2B")) { // +: for Celniker experiment "Tissue-specific Transcriptional Profiling..." String s2 = s.replace("%2B", "+"); return s2; } return s; }
From source file:org.jahia.ajax.gwt.helper.ContentManagerHelper.java
public void clearAllLocks(String path, boolean processChildNodes, JCRSessionWrapper currentUserSession, Locale uiLocale) throws GWTJahiaServiceException { try {//from w ww . j a v a 2 s .c om if (currentUserSession.getUserNode().isRoot()) { JCRContentUtils.clearAllLocks(path, processChildNodes, currentUserSession.getWorkspace().getName()); } else { JCRNodeWrapper node = currentUserSession.getNode(path); Map<String, List<String>> lockInfos = node.getLockInfos(); List<String> locks = lockInfos.get(null); if (locks != null) { for (String lock : locks) { if (StringUtils.substringBefore(lock, ":").equals(currentUserSession.getUserID())) { node.unlock(StringUtils.substringAfter(lock, ":")); } } } } } catch (RepositoryException e) { logger.error("Repository error when clearing all locks on node " + path, e); throw new GWTJahiaServiceException( Messages.getInternalWithArguments("label.gwt.error.when.clearing.all.locks.on.node", uiLocale, path, currentUserSession.getUser().getUserKey())); } }
From source file:org.jahia.ajax.gwt.helper.NodeHelper.java
/** * Get list of version that have been published as GWT bean list * * @param node//from w w w . j a v a 2 s. com * @return */ List<GWTJahiaNodeVersion> getVersions(JCRNodeWrapper node, boolean publishedOnly) throws RepositoryException { List<GWTJahiaNodeVersion> versions = new ArrayList<GWTJahiaNodeVersion>(); List<VersionInfo> versionInfos = jcrVersionService.getVersionInfos(node.getSession(), node); for (VersionInfo versionInfo : versionInfos) { if (!publishedOnly || versionInfo.getLabel().startsWith("live_")) { Version v = versionInfo.getVersion(); GWTJahiaNode n = getGWTJahiaNode(node); final String workspace = StringUtils.substringBefore(versionInfo.getLabel(), "_"); GWTJahiaNodeVersion jahiaNodeVersion = new GWTJahiaNodeVersion(v.getIdentifier(), v.getName(), v.getCreated().getTime(), versionInfo.getLabel(), workspace, n); String url = getNodeURL(null, node, versionInfo.getVersion().getCreated().getTime(), versionInfo.getLabel(), workspace, node.getSession().getLocale(), false); jahiaNodeVersion.setUrl(url); versions.add(jahiaNodeVersion); } } return versions; }
From source file:org.jahia.ajax.gwt.helper.NodeHelper.java
private void populateLocksInfo(GWTJahiaNode n, JCRNodeWrapper node) { n.setLockable(node.isLockable());/*from w w w . ja va 2s . c o m*/ try { String username = node.getSession().getUser().getName(); n.setLocked(JCRContentUtils.isLockedAndCannotBeEdited(node)); Map<String, List<String>> infos = node.getLockInfos(); Map<String, List<String>> results = new HashMap<String, List<String>>(infos.size()); if (!infos.isEmpty()) { for (Map.Entry<String, List<String>> entry : infos.entrySet()) { for (String s : entry.getValue()) { JCRNodeLockType type = JCRContentUtils.getLockType(s); if (!results.containsKey(entry.getKey())) { results.put(entry.getKey(), new LinkedList<String>()); } results.get(entry.getKey()) .add(JCRNodeLockType.USER.equals(type) && StringUtils.isNotBlank(s) ? StringUtils.substringBefore(s, ":") : ("label.locked.by." + type.toString().toLowerCase())); } } } n.setLockInfos(results); if (node.getSession().getLocale() != null) { String l = node.getSession().getLocale().toString(); n.setCanLock(infos.isEmpty() || (!infos.containsKey(l) && infos.size() > 1)); n.setCanUnlock(infos.containsKey(null) && infos.get(null).contains(username + ":user") && (infos.size() == 1 || infos.containsKey(l) && infos.get(l).contains(username + ":user"))); } else { n.setCanLock(infos.isEmpty()); n.setCanUnlock(infos.containsKey(null) && infos.get(null).contains(username + ":user")); } } catch (RepositoryException e) { logger.error("Error when getting lock", e); } }
From source file:org.jahia.ajax.gwt.helper.PublicationHelper.java
public Map<PublicationWorkflow, WorkflowDefinition> createPublicationWorkflows( List<GWTJahiaPublicationInfo> all) { final TreeMap<String, List<GWTJahiaPublicationInfo>> infosListByWorflowGroup = new TreeMap<String, List<GWTJahiaPublicationInfo>>(); Map<String, String> workflowGroupToKey = new HashMap<String, String>(); List<String> keys = new ArrayList<String>(); for (GWTJahiaPublicationInfo info : all) { String workflowGroup = info.getWorkflowGroup(); if (!infosListByWorflowGroup.containsKey(workflowGroup)) { infosListByWorflowGroup.put(workflowGroup, new ArrayList<GWTJahiaPublicationInfo>()); }/*w w w . ja v a 2s. c om*/ infosListByWorflowGroup.get(workflowGroup).add(info); if (info.getWorkflowDefinition() != null) { workflowGroupToKey.put(info.getWorkflowGroup(), info.getWorkflowDefinition()); if (!keys.contains(info.getWorkflowDefinition())) { keys.add(info.getWorkflowDefinition()); } } } Map<PublicationWorkflow, WorkflowDefinition> result = new LinkedHashMap<PublicationWorkflow, WorkflowDefinition>(); Map<String, WorkflowDefinition> workflows = new HashMap<String, WorkflowDefinition>(); for (String wf : keys) { WorkflowDefinition w = workflowService.getWorkflowDefinition(StringUtils.substringBefore(wf, ":"), StringUtils.substringAfter(wf, ":"), null); workflows.put(wf, w); } for (Map.Entry<String, List<GWTJahiaPublicationInfo>> entry : infosListByWorflowGroup.entrySet()) { result.put(new PublicationWorkflow(entry.getValue()), workflows.get(workflowGroupToKey.get(entry.getKey()))); } return result; }
From source file:org.jahia.ajax.gwt.helper.UIConfigHelper.java
/** * Get resources/*from ww w . java2 s.c o m*/ * * @param key * @param locale * @param site * @param jahiaUser * @return */ private String getResources(String key, Locale locale, JCRSiteNode site, JahiaUser jahiaUser) { if (key == null || key.length() == 0) { return key; } if (logger.isDebugEnabled()) { logger.debug("Resources key: " + key); } String baseName = null; String value = null; if (key.contains("@")) { baseName = StringUtils.substringAfter(key, "@"); key = StringUtils.substringBefore(key, "@"); } value = Messages.get(baseName, site != null ? site.getTemplatePackage() : null, key, locale, null); if (value == null || value.length() == 0) { value = Messages.getInternal(key, locale); } if (logger.isDebugEnabled()) { logger.debug("Resources value: " + value); } if (value.contains("${")) { try { ScriptEngine scriptEngine = scriptEngineUtils.getEngineByName("velocity"); ScriptContext scriptContext = new SimpleScriptContext(); final Bindings bindings = new SimpleBindings(); bindings.put("currentSite", site); bindings.put("currentUser", jahiaUser); bindings.put("currentLocale", locale); bindings.put("PrincipalViewHelper", PrincipalViewHelper.class); scriptContext.setBindings(bindings, ScriptContext.ENGINE_SCOPE); scriptContext.setBindings(scriptEngine.getContext().getBindings(ScriptContext.GLOBAL_SCOPE), ScriptContext.GLOBAL_SCOPE); scriptContext.setWriter(new StringWriter()); scriptContext.setErrorWriter(new StringWriter()); scriptEngine.eval(value, scriptContext); //String error = scriptContext.getErrorWriter().toString(); return scriptContext.getWriter().toString().trim(); } catch (ScriptException e) { logger.error("Error while executing script [" + value + "]", e); } } return value; }