List of usage examples for org.apache.commons.lang3 StringUtils substring
public static String substring(final String str, int start)
Gets a substring from the specified String avoiding exceptions.
A negative start position can be used to start n characters from the end of the String.
A null String will return null .
From source file:de.jcup.egradle.codeassist.dsl.MethodUtils.java
public static boolean hasSignature(Method method, String dataMethodName, String[] dataParameters, boolean shrinkToSimpleTypes) { /* validate parameters */ if (method == null) { return false; }/*from w w w . ja v a 2s. co m*/ if (dataMethodName == null) { return false; } if (dataParameters == null) { dataParameters = new String[] {}; } /* check */ String methodNameOfType = method.getName(); if (!methodNameOfType.equals(dataMethodName)) { return false; } List<Parameter> mParams = method.getParameters(); if (mParams.size() != dataParameters.length) { return false; } int i = 0; for (Parameter mParam : mParams) { String mParamType = mParam.getTypeAsString(); String dataParamType = dataParameters[i++]; if (mParamType == null) { return false; } if (!mParamType.equals(dataParamType)) { if (!shrinkToSimpleTypes) { return false; } /* try shorting names */ int index = mParamType.lastIndexOf("."); if (index == -1 || index == mParamType.length() - 1) { return false; } String shortendMParamType = StringUtils.substring(mParamType, index + 1); if (!shortendMParamType.equals(dataParamType)) { return false; } } } return true; }
From source file:eu.openanalytics.rsb.component.JobsResource.java
private Map<String, Serializable> getJobMeta(final HttpHeaders httpHeaders) { final Map<String, Serializable> meta = new HashMap<String, Serializable>(); for (final Entry<String, List<String>> multiValues : httpHeaders.getRequestHeaders().entrySet()) { if (!StringUtils.startsWithIgnoreCase(multiValues.getKey(), Constants.RSB_META_HEADER_HTTP_PREFIX)) { continue; }/*from ww w . j av a2 s . co m*/ if (multiValues.getValue().size() > 1) { throw new IllegalArgumentException("Multiple values found for header: " + multiValues.getKey()); } meta.put(StringUtils.substring(multiValues.getKey(), Constants.RSB_META_HEADER_HTTP_PREFIX.length()), multiValues.getValue().get(0)); } return Util.normalizeJobMeta(meta); }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.java
/** * Returns the specified event handler./* w w w . jav a 2 s . com*/ * @param eventName the event name (e.g. "onclick") * @return the handler function, or {@code null} if the property is null or not a function */ public Function getEventHandler(final String eventName) { if (eventListenersContainer_ == null) { return null; } return eventListenersContainer_.getEventHandler(StringUtils.substring(eventName, 2)); }
From source file:fusion.FuseLinkServlet.java
private void metadataKeepFlatLeft(int idx) throws SQLException { Connection virt_conn = vSet.getConnection(); StringBuilder concat_str = new StringBuilder(); for (String s : fs.predsA) { String[] pres = StringUtils.split(s, ","); StringBuilder q = new StringBuilder(); q.append("sparql SELECT * "); String prev_s = "<" + nodeA + ">"; q.append(" WHERE {\n GRAPH <" + tGraph + "metadataA> {"); if (pres.length == 1) { StringBuilder sq = new StringBuilder(); sq.append("INSERT { GRAPH <" + tGraph + "> { "); sq.append(prev_s + " <" + pres[0] + "> ?o" + 0 + " . } "); sq.append(" } WHERE {\n GRAPH <" + tGraph + "metadataA> { " + prev_s + " <" + pres[0] + "> ?o" + 0 + " . } }"); //System.out.println(sq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(sq.toString(), vSet); vur.exec();// w ww.jav a 2 s . c o m return; } for (int i = 0; i < pres.length; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } q.append("} }"); //System.out.println(q.toString()); PreparedStatement stmt; stmt = virt_conn.prepareStatement(q.toString()); ResultSet rs = stmt.executeQuery(); while (rs.next()) { StringBuilder insq = new StringBuilder(); insq.append("INSERT { GRAPH <" + tGraph + "> { "); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length - 2; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } String o = rs.getString(pres.length); String simplified = StringUtils.substringAfter(pres[pres.length - 1], "#"); if (simplified.equals("")) { simplified = StringUtils.substring(pres[pres.length - 1], StringUtils.lastIndexOf(pres[pres.length - 1], "/") + 1); } String o2 = rs.getString(pres.length - 1); insq.append(prev_s + " <" + o2 + "_" + simplified + "> \"" + o + "\""); insq.append("} } WHERE {\n GRAPH <" + tGraph + "metadataA> {"); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } insq.append("} }"); //System.out.println(insq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(insq.toString(), vSet); vur.exec(); } //System.out.println(q.toString()); } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.java
/** * Gets the property defined as event handler (not necessary a Function if something else has been set). * @param eventName the event name (e.g. "onclick") * @return the property/* w w w.j a v a 2 s . co m*/ */ protected Object getEventHandlerProp(final String eventName) { if (eventListenersContainer_ == null) { return null; } final String name = StringUtils.substring(eventName.toLowerCase(Locale.ROOT), 2); return eventListenersContainer_.getEventHandlerProp(name); }
From source file:io.wcm.devops.conga.generator.FileGenerator.java
private String getFilenameForLog(FileContext fileItem) { return StringUtils.substring(FileUtil.getCanonicalPath(fileItem), FileUtil.getCanonicalPath(nodeDir).length() + 1); }
From source file:de.adorsys.forge.gwt.GWTFacet.java
public String getSaveProjectName() { final JavaSourceFacet javaSourceFacet = project.getFacet(JavaSourceFacet.class); String basePackage = javaSourceFacet.getBasePackage(); return StringUtils.substring(basePackage, StringUtils.lastIndexOf(basePackage, ".") + 1); }
From source file:com.gargoylesoftware.htmlunit.html.HtmlScript.java
/** * Executes this script node as inline script if necessary and/or possible. *//* www. j a va 2 s. co m*/ private void executeInlineScriptIfNeeded() { if (!isExecutionNeeded()) { return; } final String src = getSrcAttribute(); if (src != ATTRIBUTE_NOT_DEFINED) { return; } final String forr = getHtmlForAttribute(); String event = getEventAttribute(); // The event name can be like "onload" or "onload()". if (event.endsWith("()")) { event = event.substring(0, event.length() - 2); } final String scriptCode = getScriptCode(); if (event != ATTRIBUTE_NOT_DEFINED && forr != ATTRIBUTE_NOT_DEFINED) { if (hasFeature(JS_SCRIPT_SUPPORTS_FOR_AND_EVENT_WINDOW) && "window".equals(forr)) { final Window window = (Window) getPage().getEnclosingWindow().getScriptableObject(); final BaseFunction function = new EventHandler(this, event, scriptCode); window.getEventListenersContainer().addEventListener(StringUtils.substring(event, 2), function, false); return; } } if (forr == ATTRIBUTE_NOT_DEFINED || "onload".equals(event)) { final String url = getPage().getUrl().toExternalForm(); final int line1 = getStartLineNumber(); final int line2 = getEndLineNumber(); final int col1 = getStartColumnNumber(); final int col2 = getEndColumnNumber(); final String desc = "script in " + url + " from (" + line1 + ", " + col1 + ") to (" + line2 + ", " + col2 + ")"; executed_ = true; ((HtmlPage) getPage()).executeJavaScriptIfPossible(scriptCode, desc, line1); } }
From source file:com.gargoylesoftware.htmlunit.javascript.host.event.EventTarget.java
/** * Defines an event handler (or maybe any other object). * @param eventName the event name (e.g. "onclick") * @param value the property ({@code null} to reset it) *//* w w w . ja va 2 s . co m*/ protected void setEventHandlerProp(final String eventName, final Object value) { getEventListenersContainer() .setEventHandlerProp(StringUtils.substring(eventName.toLowerCase(Locale.ROOT), 2), value); }
From source file:fusion.FuseLinkServlet.java
private void metadataKeepFlatRight(int idx) throws SQLException { Connection virt_conn = vSet.getConnection(); StringBuilder concat_str = new StringBuilder(); for (String s : fs.predsB) { String[] pres = StringUtils.split(s, ","); StringBuilder q = new StringBuilder(); q.append("sparql SELECT * "); String prev_s = "<" + nodeA + ">"; q.append(" WHERE {\n GRAPH <" + tGraph + "metadataB> {"); if (pres.length == 1) { StringBuilder sq = new StringBuilder(); sq.append("INSERT { GRAPH <" + tGraph + "> { "); sq.append(prev_s + " <" + pres[0] + "> ?o" + 0 + " . } "); sq.append(" } WHERE {\n GRAPH <" + tGraph + "metadataB> { " + prev_s + " <" + pres[0] + "> ?o" + 0 + " . } }"); //System.out.println(sq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(sq.toString(), vSet); vur.exec();/*from w w w . j a v a 2 s . c o m*/ return; } for (int i = 0; i < pres.length; i++) { q.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } q.append("} }"); //System.out.println(q.toString()); PreparedStatement stmt; stmt = virt_conn.prepareStatement(q.toString()); ResultSet rs = stmt.executeQuery(); while (rs.next()) { StringBuilder insq = new StringBuilder(); insq.append("INSERT { GRAPH <" + tGraph + "> { "); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length - 2; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } String o = rs.getString(pres.length); String simplified = StringUtils.substringAfter(pres[pres.length - 1], "#"); if (simplified.equals("")) { simplified = StringUtils.substring(pres[pres.length - 1], StringUtils.lastIndexOf(pres[pres.length - 1], "/") + 1); } String o2 = rs.getString(pres.length - 1); insq.append(prev_s + " <" + o2 + "_" + simplified + "> \"" + o + "\""); insq.append("} } WHERE {\n GRAPH <" + tGraph + "metadataB> {"); prev_s = "<" + nodeA + ">"; for (int i = 0; i < pres.length; i++) { insq.append(prev_s + " <" + pres[i] + "> ?o" + i + " . "); prev_s = "?o" + i; } insq.append("} }"); //System.out.println(insq.toString()); VirtuosoUpdateRequest vur = VirtuosoUpdateFactory.create(insq.toString(), vSet); vur.exec(); } //System.out.println(q.toString()); } }