List of usage examples for java.net URL getQuery
public String getQuery()
From source file:com.xpn.xwiki.XWiki.java
public String getRefererText(String referer, XWikiContext context) { try {//from ww w.j a v a2 s .c om URL url = new URL(referer); Map<String, SearchEngineRule> searchengines = getSearchEngineRules(context); if (searchengines != null) { for (SearchEngineRule senginerule : searchengines.values()) { String host = url.getHost(); int i1 = host.indexOf(senginerule.getHost()); if (i1 != -1) { String query = context.getUtil().substitute(senginerule.getRegEx(), url.getQuery()); if ((query != null) && (!query.equals(""))) { // We return the query text instead of the full referer return host.substring(i1) + ":" + query; } } } } } catch (Exception e) { } String result = referer.substring(referer.indexOf("://") + 3); if (result.endsWith("/")) { return result.substring(0, result.length() - 1); } else { return result; } }
From source file:org.sakaiproject.content.tool.ResourcesAction.java
public static List<ContentResource> createUrls(SessionState state, ResourceToolActionPipe pipe) { logger.debug("ResourcesAction.createUrls()"); boolean item_added = false; String collectionId = null;//from www . ja v a 2 s. c o m List<ContentResource> new_resources = new ArrayList<ContentResource>(); MultiFileUploadPipe mfp = (MultiFileUploadPipe) pipe; Iterator<ResourceToolActionPipe> pipeIt = mfp.getPipes().iterator(); while (pipeIt.hasNext()) { ResourceToolActionPipe fp = pipeIt.next(); collectionId = pipe.getContentEntity().getId(); String name = fp.getFileName(); if (name == null || name.trim().equals("")) { continue; } String basename = name.trim(); String extension = ".URL"; try { ContentResourceEdit resource = ContentHostingService.addResource(collectionId, Validator.escapeResourceName(basename), Validator.escapeResourceName(extension), MAXIMUM_ATTEMPTS_FOR_UNIQUENESS); extractContent(fp, resource); // SAK-23171 - cleanup the URL spaces String originalUrl = new String(resource.getContent()); String cleanedURL = StringUtils.trim(originalUrl); //cleanedURL = StringUtils.replace(cleanedURL, " ", "%20"); // SAK-23587 - properly escape the URL where required try { URL url = new URL(cleanedURL); URI uri = new URI(url.getProtocol(), url.getUserInfo(), url.getHost(), url.getPort(), url.getPath(), url.getQuery(), url.getRef()); cleanedURL = uri.toString(); } catch (Exception e) { //ok to ignore, just use the original url logger.debug("URL can not be encoded: " + e.getClass() + ":" + e.getCause()); } if (!StringUtils.equals(originalUrl, cleanedURL)) { // the url was cleaned up, log it and update it logger.info( "Resources URL cleanup changed url to '" + cleanedURL + "' from '" + originalUrl + "'"); resource.setContent(cleanedURL.getBytes()); } resource.setContentType(fp.getRevisedMimeType()); resource.setResourceType(pipe.getAction().getTypeId()); int notification = NotificationService.NOTI_NONE; Object obj = fp.getRevisedListItem(); if (obj != null && obj instanceof ListItem) { ((ListItem) obj).updateContentResourceEdit(resource); notification = ((ListItem) obj).getNotification(); } ResourcePropertiesEdit resourceProperties = resource.getPropertiesEdit(); String displayName = null; if (obj != null && obj instanceof ListItem) { displayName = ((ListItem) obj).getName(); List<String> alerts = ((ListItem) obj).checkRequiredProperties(); for (String alert : alerts) { addAlert(state, alert); } } if (displayName == null || displayName.trim().equals("")) { displayName = name; } if (displayName != null) { resourceProperties.addProperty(ResourceProperties.PROP_DISPLAY_NAME, displayName); } Map values = pipe.getRevisedResourceProperties(); for (Iterator<Entry<String, String>> mapIter = values.entrySet().iterator(); mapIter.hasNext();) { Entry<String, String> entry = mapIter.next(); resourceProperties.addProperty(entry.getKey(), entry.getValue()); } try { ContentHostingService.commitResource(resource, notification); conditionsHelper.notifyCondition(resource); item_added = true; new_resources.add(resource); } catch (OverQuotaException e) { addAlert(state, trb.getFormattedMessage("alert.overquota", new String[] { name })); logger.debug("OverQuotaException " + e); try { ContentHostingService.removeResource(resource.getId()); } catch (Exception e1) { logger.debug( "Unable to remove partially completed resource: " + resource.getId() + "\n" + e); } } catch (ServerOverloadException e) { addAlert(state, trb.getFormattedMessage("alert.unable1", new String[] { name })); logger.debug("ServerOverloadException " + e); try { ContentHostingService.removeResource(resource.getId()); } catch (Exception e1) { logger.debug( "Unable to remove partially completed resource: " + resource.getId() + "\n" + e); } } } catch (PermissionException e) { addAlert(state, trb.getString("alert.perm")); logger.warn("PermissionException ", e); } catch (IdUnusedException e) { logger.warn("IdUsedException ", e); } catch (IdInvalidException e) { logger.warn("IdInvalidException ", e); } catch (IdUniquenessException e) { logger.warn("IdUniquenessException ", e); } catch (IdLengthException e) { addAlert(state, trb.getFormattedMessage("alert.toolong", new String[] { e.getMessage() })); // TODO Auto-generated catch block logger.warn("IdLengthException ", e); } catch (OverQuotaException e) { addAlert(state, trb.getFormattedMessage("alert.overquota", new String[] { name })); logger.warn("OverQuotaException ", e); } catch (ServerOverloadException e) { addAlert(state, trb.getFormattedMessage("alert.unable1", new String[] { name })); logger.warn("ServerOverloadException ", e); } } return (item_added ? new_resources : null); }