/** Convert list of URL-form name/value pairs into a Map representation * TODO: backport vector values code * @param extraparams url parameters * @param target map * @return map */ public static Map paramsToMap(String extraparams, Map target) { if (Logger.log.isDebugEnabled()) { Logger.log .debug("Action link requires extra parameters from " + extraparams); } StringTokenizer st = new StringTokenizer(extraparams, "&"); while (st.hasMoreTokens()) { String token = st.nextToken(); int eqpos = token.indexOf("="); String key = decodeURL(token.substring(0, eqpos)); String value = decodeURL(token.substring(eqpos + 1)); target.put(key, value); } return target; }
public void adjustAttributes(String tag, Map attributes) { String attrname = (String) tagToAttrName.get(tag); if (attrname == null) return; if (attributes.get(XMLLump.ID_ATTRIBUTE) != null) return; String url = (String) attributes.get(attrname); if (url == null || URLUtil.isAbsolute(url) || url.equals("") || url.charAt(0) == '/' || url.charAt(0) == '#') return; attributes.put(XMLLump.ID_ATTRIBUTE, XMLLump.SCR_PREFIX + URLRewriteSCR.NAME); }
/** Parse a "reduced URL" (as often seen in serialized component trees and * the like) into a full ViewParameters object. */ public static ViewParameters parse(ViewParametersParser parser, String reducedURL) { int qpos = reducedURL.indexOf('?'); String pathinfo = qpos == -1? reducedURL : reducedURL.substring(0, qpos); HashMap params = new HashMap(); if (qpos != -1) { URLUtil.paramsToMap(reducedURL.substring(qpos + 1), params); } String[] paths = URLUtil.splitPathInfo(pathinfo); return parser.parse(paths, params); }
togo.append(URLUtil.toPathInfo(rawstate.pathinfo)); boolean isfirst = true; for (Iterator keyit = rawstate.params.keySet().iterator(); keyit.hasNext();) { Object attrval = rawstate.params.get(attrname); if (attrval instanceof String) { URLUtil.appendAttribute(togo, isfirst, attrname, (String) attrval); isfirst = false; String[] vals = (String[]) attrval; for (int j = 0; j < vals.length; ++j) { URLUtil.appendAttribute(togo, isfirst, attrname, vals[j]); isfirst = false;
public boolean handle() { String viewID = viewParameters.viewID; Logger.log.info("Handling view: " + viewID); String pathBeyondViewID = ""; if (pathInfo.length > 1) { pathBeyondViewID = URLUtil.toPathInfo((String[]) ArrayUtil.subArray(pathInfo, 1, pathInfo.length)); } if (Logger.log.isInfoEnabled()) { Logger.log.info("pathInfo: " + pathInfo + " pathBeyondViewID: " + pathBeyondViewID); } if (pathBeyondViewID.startsWith(HELPER_FINISHED_PATH)) { return handleHelperDone(); } if (pathBeyondViewID.startsWith(IN_HELPER_PATH)) { return handleHelperHelper(pathBeyondViewID); } return handleHelperStart(); }
: URLUtil.deSpace(sitepage.getUrl());
/** Append the supplied name/value pair to the end of the supplied URL, * after URLencoding name and value. * @param url the url to append * @param name the name of the parameter to append * @param value the value to append * @return the encoded url */ public static String appendAttribute(String url, String name, String value) { CharWrap togo = new CharWrap(url); int qpos = url.indexOf('?'); appendAttribute(togo, qpos == -1, name, value); return togo.toString(); }
/** * An array of pathinfo segments as returned from the request */ public String[] getPathInfo() { String pathinfo = request.getPathInfo(); if (pathinfo == null) pathinfo = "/"; return URLUtil.splitPathInfo(pathinfo); }
/** Converts the portion of ViewParameters that will be rendered into URL * attributes into name/value pairs as a Map. * @param vsh The ViewStateHandler encoding URL information * @param viewparams The ViewParameters object to be encoded * @return A map of String to String holding the key/value pairs. */ public static Map viewParamsToMap(ViewStateHandler vsh, ViewParameters viewparams) { String fullURL = vsh.getFullURL(viewparams); int qpos = fullURL.indexOf('?'); HashMap togo = new HashMap(); return URLUtil.paramsToMap(fullURL.substring(qpos + 1), togo); }
public boolean handle() { String viewID = viewParameters.viewID; Logger.log.info("Handling view: " + viewID); String pathBeyondViewID = ""; if (pathInfo.length > 1) { pathBeyondViewID = URLUtil.toPathInfo( (String[]) ArrayUtil.subArray(pathInfo, 1, pathInfo.length)); } if (Logger.log.isInfoEnabled()) { Logger.log.info("pathInfo: " + pathInfo + " pathBeyondViewID: " + pathBeyondViewID); } if (pathBeyondViewID.startsWith(HELPER_FINISHED_PATH)) { return handleHelperDone(); } if (pathBeyondViewID.startsWith(IN_HELPER_PATH)) { return handleHelperHelper(pathBeyondViewID); } return handleHelperStart(); }
consumerinfo.consumertype = "sakai"; consumerinfo.externalURL = sitepage == null ? consumerinfo.urlbase : URLUtil.deSpace(sitepage.getUrl());
/** * "Unpacks" the supplied command link "name" (as encoded using the * HTMLRenderSystem for submission controls) by treating it as a section of * URL attribute stanzas. The key/value pairs encoded in it will be added to * the supplied (modifiable) map. */ public static void unpackCommandLink(String longvalue, Map requestparams) { String[] split = longvalue.split("[&=]"); // start at 1 since string will begin with & if ((split.length % 2) == 0) { Logger.log .warn("Erroneous submission - odd number of parameters/values in " + longvalue); return; } for (int i = 1; i < split.length; i += 2) { String key = URLUtil.decodeURL(split[i]); String value = URLUtil.decodeURL(split[i + 1]); Logger.log.info("Unpacked command link key " + key + " value " + value); String[] existing = (String[]) requestparams.get(key); if (existing == null) { requestparams.put(key, new String[] { value }); } else { String[] fused = (String[]) ArrayUtil.append(existing, value); requestparams.put(key, fused); } } }
public String encodeResourceURL(String resourcepath) { if (URLUtil.isAbsolute(resourcepath) || resourcepath.charAt(0) == '/') { return resourcepath; } else { return cup.getContextBaseURL() + resourcepath; } }
/** * Computes the "Base URL" of this servlet, defined as the complete request * path, with any trailing string agreeing with the "PathInfo" removed. With * the exception that the trailing slash IS reappended. */ public static String getBaseURL2(HttpServletRequest hsr) { String requestURL = hsr.getRequestURL().toString(); // In some totally unspecced way, javax implementation provides the URL // ENCODED, whereas the PathInfo UNENCODED. requestURL = URLUtil.decodeURL(requestURL); String extrapath = hsr.getPathInfo(); String togo; if (extrapath == null || extrapath.equals("") || extrapath.equals("/")) { togo = requestURL; } else { int embedpoint = requestURL.lastIndexOf(extrapath); if (embedpoint == -1) { throw new UniversalRuntimeException("Cannot locate path info of " + extrapath + " within request URL of " + requestURL); } togo = requestURL.substring(0, embedpoint); } // I don't trust the Servlet API further than I can throw it. if (togo.charAt(togo.length() - 1) != '/') { togo += '/'; } return togo; }
/** * relpath has leading slash removed. */ public String rewriteResourceURL(String path, String resourcebase) { String resourceURL = null; if (!URLUtil.isAbsolute(path) && (path.length() == 0 || path.charAt(0) != '/')) { if (isContextURL(path)) { resourceURL = rewriteContextURL(path); } else { resourceURL = viewstatehandler.encodeResourceURL(resourcebase + path); } resourceURL = StringUtils.cleanPath(resourceURL); } if (Logger.log.isDebugEnabled()) { Logger.log.debug("getResourceURL returning " + resourceURL + " for path " + path); } return resourceURL; } }