List of usage examples for org.apache.commons.lang StringUtils stripEnd
public static String stripEnd(String str, String stripChars)
Strips any of a set of characters from the end of a String.
From source file:org.ebayopensource.turmeric.eclipse.typelibrary.ui.wst.WTPCopyUtil.java
public static void transformQNamePrefix(XSDSchema dstSchema, XSDSchema srcSchema, boolean typeFolding) throws SOABadParameterException { String targetNameSpace = dstSchema.getTargetNamespace(); String targetNameSpaceprefix = ""; Map<String, String> srcPrefixes = srcSchema.getQNamePrefixToNamespaceMap(); Map<String, String> dstPrefixes = dstSchema.getQNamePrefixToNamespaceMap(); Map<String, String> srcToDstPrefixMap = new TreeMap<String, String>(); Map<String, String> additionalSrcPrefixes = new TreeMap<String, String>(); // finding the targetNameSpacePrefix in the destination schema for (Entry<String, String> entry : dstPrefixes.entrySet()) { if (StringUtils.equals(entry.getValue(), targetNameSpace)) { targetNameSpaceprefix = entry.getKey(); break; }/*w w w. j av a2 s .co m*/ } // if the destination schema does not have a name space prefix for // its own target name space if (StringUtils.isEmpty(targetNameSpaceprefix)) targetNameSpaceprefix = StringUtils .stripEnd(TypeLibraryUIActivator.getPrefix(dstSchema, targetNameSpace), ":"); for (Entry<String, String> srcEntry : srcPrefixes.entrySet()) { if (!XSDConstants.isSchemaForSchemaNamespace(srcEntry.getValue())) { if (typeFolding) { srcToDstPrefixMap.put(srcEntry.getKey(), targetNameSpaceprefix); } else { boolean foundCorrespondingPrefix = false; for (Entry<String, String> dstEntry : dstPrefixes.entrySet()) { if (StringUtils.equals(dstEntry.getValue(), srcEntry.getValue())) { srcToDstPrefixMap.put(srcEntry.getKey(), dstEntry.getKey()); foundCorrespondingPrefix = true; } } // if there is no corresponding prefix add one to // the destination schema and replace it in the src // schema if (!foundCorrespondingPrefix) { String newPrefix = StringUtils .stripEnd(TypeLibraryUIActivator.getPrefix(dstSchema, srcEntry.getValue()), ":"); // we add this to the src schema also to make sure // that the prefix changes does not make it invalid additionalSrcPrefixes.put(newPrefix, srcEntry.getValue()); srcToDstPrefixMap.put(srcEntry.getKey(), newPrefix); } } } } srcPrefixes.putAll(additionalSrcPrefixes); Element srcElement = srcSchema.getTypeDefinitions().get(0).getElement(); Element dstElement = (Element) dstSchema.getElement(); // setting the Schema for Schema prefix for eg: xs to xsd or // whatever. srcSchema.setSchemaForSchemaQNamePrefix(dstSchema.getSchemaForSchemaQNamePrefix()); updatePrefixes(srcElement, srcToDstPrefixMap); DOMUtil.copyInto(srcElement, dstElement); }
From source file:org.eclipse.wb.core.eval.AstEvaluationEngine.java
/** * @return stack trace for exception in user code. *///w ww. ja v a 2 s . co m public static String getUserStackTrace(Throwable e) { e = DesignerExceptionUtils.getRootCause(e); String stackTrace = ExceptionUtils.getStackTrace(e); stackTrace = StringUtils.substringBefore(stackTrace, "at org.eclipse.wb."); stackTrace = StringUtils.substringBefore(stackTrace, "at sun.reflect."); stackTrace = StringUtils.stripEnd(stackTrace, null); return stackTrace; }
From source file:org.eclipse.wb.internal.core.eval.evaluators.DoubleEvaluator.java
public Object evaluate(EvaluationContext context, Expression expression, ITypeBinding typeBinding, String typeQualifiedName) throws Exception { // double expression if ("double".equals(typeQualifiedName)) { // single number literal if (expression instanceof NumberLiteral) { NumberLiteral numberLiteral = (NumberLiteral) expression; String token = numberLiteral.getToken(); // remove trailing 'D'/'d' token = StringUtils.stripEnd(token, "Dd"); // parse return Double.valueOf(token); }/* www . ja v a 2 s . c o m*/ // prefix expression (+, -) if (expression instanceof PrefixExpression) { PrefixExpression prefixExpression = (PrefixExpression) expression; PrefixExpression.Operator operator = prefixExpression.getOperator(); // Expression operand = prefixExpression.getOperand(); double operandValue = getDoubleValue(context, operand); // + if (operator == PrefixExpression.Operator.PLUS) { return new Double(operandValue); } // - if (operator == PrefixExpression.Operator.MINUS) { return new Double(-operandValue); } } // infix expression (+, -, *, /, %) if (expression instanceof InfixExpression) { InfixExpression infixExpression = (InfixExpression) expression; // prepare operands double operands[]; { List<Expression> extendedOperands = DomGenerics.extendedOperands(infixExpression); operands = new double[2 + extendedOperands.size()]; // evaluate usual operands operands[0] = getDoubleValue(context, infixExpression.getLeftOperand()); operands[1] = getDoubleValue(context, infixExpression.getRightOperand()); // evaluate extended operands for (int i = 0; i < extendedOperands.size(); i++) { Expression operandExpression = extendedOperands.get(i); operands[2 + i] = getDoubleValue(context, operandExpression); } } // process each operand double value = operands[0]; Operator operator = infixExpression.getOperator(); for (int i = 1; i < operands.length; i++) { double operand = operands[i]; if (operator == InfixExpression.Operator.PLUS) { value += operand; } else if (operator == InfixExpression.Operator.MINUS) { value -= operand; } else if (operator == InfixExpression.Operator.TIMES) { value *= operand; } else if (operator == InfixExpression.Operator.DIVIDE) { value /= operand; } else if (operator == InfixExpression.Operator.REMAINDER) { value %= operand; } } // return final value as object return new Double(value); } } // we don't understand given expression return AstEvaluationEngine.UNKNOWN; }
From source file:org.eclipse.wb.internal.core.eval.evaluators.FloatEvaluator.java
public Object evaluate(EvaluationContext context, Expression expression, ITypeBinding typeBinding, String typeQualifiedName) throws Exception { // float expression if ("float".equals(typeQualifiedName)) { // single number literal if (expression instanceof NumberLiteral) { NumberLiteral numberLiteral = (NumberLiteral) expression; String token = numberLiteral.getToken(); // remove trailing 'F'/'f' token = StringUtils.stripEnd(token, "Ff"); // parse return Float.valueOf(token); }// www.ja va 2s. c o m // prefix expression (+, -) if (expression instanceof PrefixExpression) { PrefixExpression prefixExpression = (PrefixExpression) expression; PrefixExpression.Operator operator = prefixExpression.getOperator(); // Expression operand = prefixExpression.getOperand(); float operandValue = getFloatValue(context, operand); // + if (operator == PrefixExpression.Operator.PLUS) { return +operandValue; } // - if (operator == PrefixExpression.Operator.MINUS) { return -operandValue; } } // infix expression (+, -, *, /, %) if (expression instanceof InfixExpression) { InfixExpression infixExpression = (InfixExpression) expression; // prepare operands float operands[]; { List<Expression> extendedOperands = DomGenerics.extendedOperands(infixExpression); operands = new float[2 + extendedOperands.size()]; // evaluate usual operands operands[0] = getFloatValue(context, infixExpression.getLeftOperand()); operands[1] = getFloatValue(context, infixExpression.getRightOperand()); // evaluate extended operands for (int i = 0; i < extendedOperands.size(); i++) { Expression operandExpression = extendedOperands.get(i); operands[2 + i] = getFloatValue(context, operandExpression); } } // process each operand float value = operands[0]; Operator operator = infixExpression.getOperator(); for (int i = 1; i < operands.length; i++) { float operand = operands[i]; if (operator == InfixExpression.Operator.PLUS) { value += operand; } else if (operator == InfixExpression.Operator.MINUS) { value -= operand; } else if (operator == InfixExpression.Operator.TIMES) { value *= operand; } else if (operator == InfixExpression.Operator.DIVIDE) { value /= operand; } else if (operator == InfixExpression.Operator.REMAINDER) { value %= operand; } } // return final value as object return value; } } // we don't understand given expression return AstEvaluationEngine.UNKNOWN; }
From source file:org.eclipse.wb.internal.core.eval.evaluators.LongEvaluator.java
public Object evaluate(EvaluationContext context, Expression expression, ITypeBinding typeBinding, String typeQualifiedName) throws Exception { // long expression if ("long".equals(typeQualifiedName)) { // single number literal if (expression instanceof NumberLiteral) { NumberLiteral numberLiteral = (NumberLiteral) expression; String token = numberLiteral.getToken(); // remove trailing 'L'/'l' token = StringUtils.stripEnd(token, "Ll"); // hex if (token.startsWith("0x")) { return Long.valueOf(token.substring(2), 16); }/*from w w w . ja v a 2 s .co m*/ // oct if (token.startsWith("0")) { return Long.valueOf(token, 8); } // decimal return Long.valueOf(token); } // prefix expression (+, -) if (expression instanceof PrefixExpression) { PrefixExpression prefixExpression = (PrefixExpression) expression; PrefixExpression.Operator operator = prefixExpression.getOperator(); // Expression operand = prefixExpression.getOperand(); long operandValue = getLongValue(context, operand); // + if (operator == PrefixExpression.Operator.PLUS) { return operandValue; } // - if (operator == PrefixExpression.Operator.MINUS) { return -operandValue; } } // infix expression (+, -, *, /, %, |, &) if (expression instanceof InfixExpression) { InfixExpression infixExpression = (InfixExpression) expression; // prepare operands long operands[]; { List<Expression> extendedOperands = DomGenerics.extendedOperands(infixExpression); operands = new long[2 + extendedOperands.size()]; // evaluate usual operands operands[0] = getLongValue(context, infixExpression.getLeftOperand()); operands[1] = getLongValue(context, infixExpression.getRightOperand()); // evaluate extended operands for (int i = 0; i < extendedOperands.size(); i++) { Expression operandExpression = extendedOperands.get(i); operands[2 + i] = getLongValue(context, operandExpression); } } // process each operand long value = operands[0]; Operator operator = infixExpression.getOperator(); for (int i = 1; i < operands.length; i++) { long operand = operands[i]; if (operator == InfixExpression.Operator.PLUS) { value += operand; } else if (operator == InfixExpression.Operator.MINUS) { value -= operand; } else if (operator == InfixExpression.Operator.TIMES) { value *= operand; } else if (operator == InfixExpression.Operator.DIVIDE) { value /= operand; } else if (operator == InfixExpression.Operator.REMAINDER) { value %= operand; } else if (operator == InfixExpression.Operator.OR) { value |= operand; } else if (operator == InfixExpression.Operator.AND) { value &= operand; } } // return final value as object return value; } } // we don't understand given expression return AstEvaluationEngine.UNKNOWN; }
From source file:org.eclipse.wb.internal.core.utils.ast.AstNodeUtils.java
/** * For {@link AnonymousClassDeclaration} we can not get full name using only {@link ITypeBinding}, * so we use AST to find necessary <code>$1</code>, <code>$2</code>, etc suffixes. * //from ww w.j av a 2 s . c om * @return the fully qualified name with anonymous suffix. */ private static String getFullyQualifiedName_appendAnonymous(Expression expression, final boolean runtime, String fullyQualifiedName) { final AnonymousClassDeclaration acd = ((ClassInstanceCreation) expression).getAnonymousClassDeclaration(); final String[] suffix = new String[1]; expression.getRoot().accept(new ASTVisitor() { private final int[] m_counts = new int[32]; private int m_level = 0; @Override public boolean visit(AnonymousClassDeclaration node) { m_counts[m_level]++; if (node == acd) { StringBuilder sb = new StringBuilder(); String separator = runtime ? "$" : "."; for (int i = 0; i <= m_level; i++) { sb.append(separator); sb.append(m_counts[i]); } suffix[0] = sb.toString(); } m_counts[++m_level] = 0; return suffix[0] == null; } @Override public void endVisit(AnonymousClassDeclaration node) { m_level--; } }); fullyQualifiedName = StringUtils.stripEnd(fullyQualifiedName, "$."); fullyQualifiedName += suffix[0]; return fullyQualifiedName; }
From source file:org.geoserver.jdbc.metrics.RequestMetricsController.java
@Override protected ModelAndView handleRequestInternal(HttpServletRequest req, HttpServletResponse rsp) throws Exception { String[] split = req.getPathInfo().split("/"); String reqId = StringUtils.stripEnd(StringUtils.stripStart(split[split.length - 1], "/"), "/"); JSONObject obj = new JSONObject(); obj.put("request", reqId); Map<String, Object> m = METRICS.getIfPresent(reqId); if (m != null) { obj.put("metrics", m); rsp.setStatus(HttpServletResponse.SC_OK); } else {//from www . j a v a 2 s. c o m rsp.setStatus(HttpServletResponse.SC_NOT_FOUND); obj.put("message", "metrics unavailable"); } rsp.setContentType(MediaType.APPLICATION_JSON_VALUE); try (OutputStreamWriter w = new OutputStreamWriter(rsp.getOutputStream(), Charsets.UTF_8)) { obj.write(w); w.flush(); } return null; }
From source file:org.jahia.services.seo.VanityUrl.java
/** * Initializes an instance of this class. * @param url mapping URL/* w w w .j a va 2s . c o m*/ * @param site virtual site of the mapped content object * @param language the mapping language */ public VanityUrl(String url, String site, String language) { super(); this.url = StringUtils.stripEnd(StringUtils.startsWith(url, "/") ? url : '/' + url, "/"); this.site = site; this.language = language; }
From source file:org.jamwiki.parser.jflex.JFlexLexer.java
/** * Pop the most recent HTML tag from the lexer stack. *//*from ww w .java2 s . co m*/ protected JFlexTagItem popTag(String tagType) { if (this.tagStack.size() <= 1) { logger.warning( "popTag called on an empty tag stack or on the root stack element. Please report this error on jamwiki.org, and provide the wiki syntax for the topic being parsed."); } // verify that the tag being closed is the tag that is currently open. if not // there are two options - first is that the user entered unbalanced HTML such // as "<u><strong>text</u></strong>" and it should be re-balanced, and second // is that this is just a random close tag such as "<div>text</div></div>" and // it should be escaped without modifying the tag stack. if (!this.peekTag().getTagType().equals(tagType)) { // check to see if a close tag override was previously set, which happens // from the inner tag of unbalanced HTML. Example: "<u><strong>text</u></strong>" // would set a close tag override when the "</u>" is parsed to indicate that // the "</strong>" should actually be parsed as a "</u>". if (StringUtils.equals(this.peekTag().getTagType(), this.peekTag().getCloseTagOverride())) { return this.popTag(this.peekTag().getCloseTagOverride()); } // check to see if the parent tag matches the current close tag. if so then // this is unbalanced HTML of the form "<u><strong>text</u></strong>" and // it should be parsed as "<u><strong>text</strong></u>". JFlexTagItem parent = null; if (this.tagStack.size() > 2) { parent = this.tagStack.get(this.tagStack.size() - 2); } if (parent != null && parent.getTagType().equals(tagType)) { parent.setCloseTagOverride(tagType); return this.popTag(this.peekTag().getTagType()); } // if the above checks fail then this is an attempt to pop a tag that is not // currently open, so append the escaped close tag to the current tag // content without modifying the tag stack. JFlexTagItem currentTag = this.tagStack.peek(); currentTag.getTagContent().append("</" + tagType + ">"); return null; } JFlexTagItem currentTag = this.tagStack.peek(); if (this.tagStack.size() > 1) { // only pop if not the root tag currentTag = this.tagStack.pop(); } JFlexTagItem previousTag = this.tagStack.peek(); if (!JFlexParserUtil.isInlineTag(currentTag.getTagType()) || currentTag.getTagType().equals("pre")) { // if the current tag is not an inline tag, make sure it is on its own lines String trimmedContent = StringUtils.stripEnd(previousTag.getTagContent().toString(), null); previousTag.getTagContent().replace(0, previousTag.getTagContent().length(), trimmedContent); previousTag.getTagContent().append('\n'); previousTag.getTagContent().append(currentTag.toHtml()); previousTag.getTagContent().append('\n'); } else { previousTag.getTagContent().append(currentTag.toHtml()); } return currentTag; }
From source file:org.jboss.as.test.integration.security.common.Utils.java
/** * Creates request against SPNEGO protected web-app with FORM fallback. It tries to login using SPNEGO first - if it fails, * FORM is used.//from w w w . j a v a2 s. co m * * @param contextUrl * @param page * @param user * @param pass * @param expectedStatusCode * @return * @throws IOException * @throws URISyntaxException * @throws PrivilegedActionException * @throws LoginException */ public static String makeHttpCallWithFallback(final String contextUrl, final String page, final String user, final String pass, final int expectedStatusCode) throws IOException, URISyntaxException, PrivilegedActionException, LoginException { final String strippedContextUrl = StringUtils.stripEnd(contextUrl, "/"); final String url = strippedContextUrl + page; LOGGER.trace("Requesting URL: " + url); String unauthorizedPageBody = null; final Krb5LoginConfiguration krb5Configuration = new Krb5LoginConfiguration(getLoginConfiguration()); Registry<AuthSchemeProvider> authSchemeRegistry = RegistryBuilder.<AuthSchemeProvider>create() .register(AuthSchemes.SPNEGO, new JBossNegotiateSchemeFactory(true)).build(); CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); credentialsProvider.setCredentials(new AuthScope(null, -1, null), new NullHCCredentials()); final CloseableHttpClient httpClient = HttpClientBuilder.create() .setDefaultAuthSchemeRegistry(authSchemeRegistry).setDefaultCredentialsProvider(credentialsProvider) .setRedirectStrategy(REDIRECT_STRATEGY).setConnectionManager(new BasicHttpClientConnectionManager()) .build(); try { final HttpGet httpGet = new HttpGet(url); final HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); if (HttpServletResponse.SC_UNAUTHORIZED != statusCode || StringUtils.isEmpty(user)) { assertEquals("Unexpected HTTP response status code.", expectedStatusCode, statusCode); return EntityUtils.toString(response.getEntity()); } final Header[] authnHeaders = response.getHeaders("WWW-Authenticate"); assertTrue("WWW-Authenticate header is present", authnHeaders != null && authnHeaders.length > 0); final Set<String> authnHeaderValues = new HashSet<String>(); for (final Header header : authnHeaders) { authnHeaderValues.add(header.getValue()); } assertTrue("WWW-Authenticate: Negotiate header is missing", authnHeaderValues.contains("Negotiate")); LOGGER.debug("HTTP response was SC_UNAUTHORIZED, let's authenticate the user " + user); unauthorizedPageBody = EntityUtils.toString(response.getEntity()); // Use our custom configuration to avoid reliance on external config Configuration.setConfiguration(krb5Configuration); // 1. Authenticate to Kerberos. final LoginContext lc = loginWithKerberos(krb5Configuration, user, pass); // 2. Perform the work as authenticated Subject. final String responseBody = Subject.doAs(lc.getSubject(), new PrivilegedExceptionAction<String>() { public String run() throws Exception { final HttpResponse response = httpClient.execute(httpGet); int statusCode = response.getStatusLine().getStatusCode(); assertEquals("Unexpected status code returned after the authentication.", expectedStatusCode, statusCode); return EntityUtils.toString(response.getEntity()); } }); lc.logout(); return responseBody; } catch (LoginException e) { assertNotNull(unauthorizedPageBody); assertTrue(unauthorizedPageBody.contains("j_security_check")); HttpPost httpPost = new HttpPost(strippedContextUrl + "/j_security_check"); List<NameValuePair> nameValuePairs = new ArrayList<NameValuePair>(); nameValuePairs.add(new BasicNameValuePair("j_username", user)); nameValuePairs.add(new BasicNameValuePair("j_password", pass)); httpPost.setEntity(new UrlEncodedFormEntity(nameValuePairs)); final HttpResponse response = httpClient.execute(httpPost); int statusCode = response.getStatusLine().getStatusCode(); assertEquals("Unexpected status code returned after the authentication.", expectedStatusCode, statusCode); return EntityUtils.toString(response.getEntity()); } finally { // When HttpClient instance is no longer needed, // shut down the connection manager to ensure // immediate deallocation of all system resources httpClient.close(); // reset login configuration krb5Configuration.resetConfiguration(); } }