List of usage examples for org.apache.commons.lang StringUtils splitPreserveAllTokens
public static String[] splitPreserveAllTokens(String str, String separatorChars)
Splits the provided text into an array, separators specified, preserving all tokens, including empty tokens created by adjacent separators.
From source file:org.apache.directory.fortress.core.model.UserAdminRole.java
/** * This method loads UserAdminRole entity temporal and ARBAC constraint instance variables with data that was retrieved from the * 'ftARC' attribute on the 'ftUserAttrs' object class. This is the raw format that Fortress uses to condense the temporal and ARBAC data into * a compact String for efficient storage and retrieval and is not intended to be called by external programs. * * @param szRawData contains a raw formatted String that maps to 'ftARC' attribute on 'ftUserAttrs' object class * @param contextId contains the tenant id. * @param parentUtil provides method to getParents. *//*from w ww.j a va 2 s.com*/ public void load(String szRawData, String contextId, ParentUtil parentUtil) { if ((szRawData != null) && (szRawData.length() > 0)) { String[] tokens = StringUtils.splitPreserveAllTokens(szRawData, GlobalIds.DELIMITER); for (int i = 0; i < tokens.length; i++) { if (StringUtils.isNotEmpty(tokens[i])) { switch (i) { case 0: name = tokens[i]; parents = parentUtil.getParentsCB(name.toUpperCase(), contextId); break; case 1: this.setTimeout(Integer.parseInt(tokens[i])); break; case 2: this.setBeginTime(tokens[i]); break; case 3: this.setEndTime(tokens[i]); break; case 4: this.setBeginDate(tokens[i]); break; case 5: this.setEndDate(tokens[i]); break; case 6: this.setBeginLockDate(tokens[i]); break; case 7: this.setEndLockDate(tokens[i]); break; case 8: this.setDayMask(tokens[i]); break; default: String szValue = tokens[i]; int indx = szValue.indexOf(P + GlobalIds.PROP_SEP); if (indx >= 0) { String szOsP = szValue.substring(indx + 2); this.setOsP(szOsP); } indx = szValue.indexOf(U + GlobalIds.PROP_SEP); if (indx >= 0) { String szOsU = szValue.substring(indx + 2); this.setOsU(szOsU); } indx = szValue.indexOf(R + GlobalIds.PROP_SEP); if (indx >= 0) { String szRangeRaw = szValue.substring(indx + 2); this.setRoleRangeRaw(szRangeRaw); } break; } } } } }
From source file:org.apache.directory.fortress.core.model.UserRole.java
/** * This method loads UserRole entity temporal constraint instance variables with data that was retrieved from the * 'ftRC' attribute on the 'ftUserAttrs' object class. This is the raw format that Fortress uses to condense the * temporal data into/* w ww . ja v a 2 s . c o m*/ * a compact String for efficient storage and retrieval and is not intended to be called by external programs. * * @param szRawData contains a raw formatted String that maps to 'ftRC' attribute on 'ftUserAttrs' object class * @param contextId contains the tenant id. * @param parentUtil provides method to getParents. */ public void load(String szRawData, String contextId, ParentUtil parentUtil) { if ((szRawData != null) && (szRawData.length() > 0)) { String[] tokens = StringUtils.splitPreserveAllTokens(szRawData, GlobalIds.DELIMITER); for (int i = 0; i < tokens.length; i++) { if (StringUtils.isNotEmpty(tokens[i])) { switch (i) { case 0: name = tokens[i]; parents = parentUtil.getParentsCB(name.toUpperCase(), contextId); break; case 1: timeout = Integer.parseInt(tokens[i]); break; case 2: beginTime = tokens[i]; break; case 3: endTime = tokens[i]; break; case 4: beginDate = tokens[i]; break; case 5: endDate = tokens[i]; break; case 6: beginLockDate = tokens[i]; break; case 7: endLockDate = tokens[i]; break; case 8: dayMask = tokens[i]; break; } } } } }
From source file:org.apache.jetspeed.portlets.prm.LanguageBean.java
public void setLocaleString(String localeString) { String language = null;//from w w w . j a va 2s . co m String country = null; String[] tokens = StringUtils.splitPreserveAllTokens(localeString, '_'); if (tokens.length > 0) { language = tokens[0]; } if (tokens.length > 1) { country = tokens[1]; } locale = (country == null ? new Locale(language) : new Locale(language, country)); }
From source file:org.apache.jetspeed.portlets.prm.LocalizedFieldBean.java
public void setLocaleString(String localeString) { String language = null;// w ww .ja v a2s . c o m String country = null; String[] tokens = StringUtils.splitPreserveAllTokens(localeString, '_'); if (tokens.length > 0) { language = tokens[0]; } if (tokens.length > 1) { country = tokens[1]; } Locale locale = (country == null ? new Locale(language) : new Locale(language, country)); field.setLocale(locale); }
From source file:org.apache.lens.cube.metadata.ExprColumn.java
public ExprColumn(String name, Map<String, String> props) { super(name, props); String serializedExpressions = props.get(MetastoreUtil.getExprColumnKey(getName())); String[] expressions = StringUtils.split(serializedExpressions, EXPRESSION_DELIMITER); if (expressions.length == 0) { throw new IllegalArgumentException( "No expressions found for column " + name + " property val=" + serializedExpressions); }//w ww . jav a 2 s. c om boolean isExpressionBase64Encoded = EXPRESSION_ENCODED .equals(props.get(MetastoreUtil.getExprEncodingPropertyKey(getName()))); for (String e : expressions) { String[] exprSpecStrs = StringUtils.splitPreserveAllTokens(e, EXPRESSION_SPEC_DELIMITER); try { String decodedExpr = isExpressionBase64Encoded ? new String(Base64.decodeBase64(exprSpecStrs[0]), "UTF-8") : exprSpecStrs[0]; ExprSpec exprSpec = new ExprSpec(); exprSpec.expr = decodedExpr; if (exprSpecStrs.length > 1) { // start time and end time serialized if (StringUtils.isNotBlank(exprSpecStrs[1])) { // start time available exprSpec.startTime = getDate(exprSpecStrs[1]); } if (exprSpecStrs.length > 2) { if (StringUtils.isNotBlank(exprSpecStrs[2])) { // end time available exprSpec.endTime = getDate(exprSpecStrs[2]); } } } expressionSet.add(exprSpec); } catch (UnsupportedEncodingException e1) { throw new IllegalArgumentException( "Error decoding expression for expression column " + name + " encoded value=" + e); } } this.type = props.get(MetastoreUtil.getExprTypePropertyKey(getName())); }
From source file:org.apache.nutch.util.TableUtil.java
public static String unreverseUrl(String reversedUrl) { StringBuilder buf = new StringBuilder(reversedUrl.length() + 2); int pathBegin = reversedUrl.indexOf('/'); if (pathBegin == -1) pathBegin = reversedUrl.length(); String sub = reversedUrl.substring(0, pathBegin); String[] splits = StringUtils.splitPreserveAllTokens(sub, ':'); // {<reversed // host>, // <port>, // <protocol>} buf.append(splits[1]); // add protocol buf.append("://"); reverseAppendSplits(splits[0], buf); // splits[0] is reversed // host/* w w w.j ava 2 s.c o m*/ if (splits.length == 3) { // has a port buf.append(':'); buf.append(splits[2]); } buf.append(reversedUrl.substring(pathBegin)); return buf.toString(); }
From source file:org.apache.shindig.common.crypto.BasicBlobCrypter.java
private Map<String, String> deserialize(byte[] plain) throws UnsupportedEncodingException { String base = new String(plain, UTF8); // replaces [&=] regex String[] items = StringUtils.splitPreserveAllTokens(base, "&="); Map<String, String> map = Maps.newHashMapWithExpectedSize(items.length); for (int i = 0; i < items.length;) { String key = URLDecoder.decode(items[i++], UTF8); String val = URLDecoder.decode(items[i++], UTF8); map.put(key, val); }//from w ww .j a v a 2 s. c o m return map; }
From source file:org.apache.shindig.common.util.JsonConversionUtil.java
@SuppressWarnings("unchecked") public static JSONObject fromRequest(HttpServletRequest request) throws JSONException { Map<String, String[]> params = request.getParameterMap(); if (!params.containsKey("method")) { return null; }/* ww w . j av a 2 s . c o m*/ JSONObject root = new JSONObject(); root.put("method", params.get("method")[0]); if (params.containsKey("id")) { root.put("id", params.get("id")[0]); } JSONObject paramsRoot = new JSONObject(); for (Map.Entry<String, String[]> entry : params.entrySet()) { if (!RESERVED_PARAMS.contains(entry.getKey().toLowerCase())) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(paramsRoot, path, 0); holder.put(path[path.length - 1], convertToJsonValue(entry.getValue()[0])); } } if (paramsRoot.length() > 0) { root.put("params", paramsRoot); } return root; }
From source file:org.apache.shindig.common.util.JsonConversionUtil.java
static JSONObject parametersToJsonObject(Map<String, String> params) throws JSONException { JSONObject root = new JSONObject(); for (Map.Entry<String, String> entry : params.entrySet()) { String[] path = StringUtils.splitPreserveAllTokens(entry.getKey(), '.'); JSONObject holder = buildHolder(root, path, 0); if (path.length > 1) { holder.put(path[path.length - 1], convertToJsonValue(entry.getValue())); } else {//w w w . j ava 2 s .c om holder.put(path[0], convertToJsonValue(entry.getValue())); } } return root; }
From source file:org.apache.shindig.gadgets.http.BasicHttpFetcher.java
public HttpResponse fetch(org.apache.shindig.gadgets.http.HttpRequest request) throws GadgetException { HttpUriRequest httpMethod = null;//from w w w . j av a2 s.co m Preconditions.checkNotNull(request); final String methodType = request.getMethod(); final org.apache.http.HttpResponse response; final long started = System.currentTimeMillis(); // Break the request Uri to its components: Uri uri = request.getUri(); if (StringUtils.isEmpty(uri.getAuthority())) { throw new GadgetException(GadgetException.Code.INVALID_USER_DATA, "Missing domain name for request: " + uri, HttpServletResponse.SC_BAD_REQUEST); } if (StringUtils.isEmpty(uri.getScheme())) { throw new GadgetException(GadgetException.Code.INVALID_USER_DATA, "Missing schema for request: " + uri, HttpServletResponse.SC_BAD_REQUEST); } String[] hostparts = StringUtils.splitPreserveAllTokens(uri.getAuthority(), ':'); int port = -1; // default port if (hostparts.length > 2) { throw new GadgetException(GadgetException.Code.INVALID_USER_DATA, "Bad host name in request: " + uri.getAuthority(), HttpServletResponse.SC_BAD_REQUEST); } if (hostparts.length == 2) { try { port = Integer.parseInt(hostparts[1]); } catch (NumberFormatException e) { throw new GadgetException(GadgetException.Code.INVALID_USER_DATA, "Bad port number in request: " + uri.getAuthority(), HttpServletResponse.SC_BAD_REQUEST); } } String requestUri = uri.getPath(); // Treat path as / if set as null. if (uri.getPath() == null) { requestUri = "/"; } if (uri.getQuery() != null) { requestUri += '?' + uri.getQuery(); } // Get the http host to connect to. HttpHost host = new HttpHost(hostparts[0], port, uri.getScheme()); try { if ("POST".equals(methodType) || "PUT".equals(methodType)) { HttpEntityEnclosingRequestBase enclosingMethod = ("POST".equals(methodType)) ? new HttpPost(requestUri) : new HttpPut(requestUri); if (request.getPostBodyLength() > 0) { enclosingMethod .setEntity(new InputStreamEntity(request.getPostBody(), request.getPostBodyLength())); } httpMethod = enclosingMethod; } else if ("GET".equals(methodType)) { httpMethod = new HttpGet(requestUri); } else if ("HEAD".equals(methodType)) { httpMethod = new HttpHead(requestUri); } else if ("DELETE".equals(methodType)) { httpMethod = new HttpDelete(requestUri); } for (Map.Entry<String, List<String>> entry : request.getHeaders().entrySet()) { httpMethod.addHeader(entry.getKey(), StringUtils.join(entry.getValue(), ',')); } // Disable following redirects. if (!request.getFollowRedirects()) { httpMethod.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, false); } // HttpClient doesn't handle all cases when breaking url (specifically '_' in domain) // So lets pass it the url parsed: response = FETCHER.execute(host, httpMethod); if (response == null) { throw new IOException("Unknown problem with request"); } long now = System.currentTimeMillis(); if (now - started > slowResponseWarning) { slowResponseWarning(request, started, now); } return makeResponse(response); } catch (Exception e) { long now = System.currentTimeMillis(); // Find timeout exceptions, respond accordingly if (TIMEOUT_EXCEPTIONS.contains(e.getClass())) { LOG.info("Timeout for " + request.getUri() + " Exception: " + e.getClass().getName() + " - " + e.getMessage() + " - " + (now - started) + "ms"); return HttpResponse.timeout(); } LOG.log(Level.INFO, "Got Exception fetching " + request.getUri() + " - " + (now - started) + "ms", e); // Separate shindig error from external error throw new GadgetException(GadgetException.Code.INTERNAL_SERVER_ERROR, e, HttpServletResponse.SC_INTERNAL_SERVER_ERROR); } finally { // cleanup any outstanding resources.. if (httpMethod != null) try { httpMethod.abort(); } catch (UnsupportedOperationException e) { // ignore } } }