Example usage for org.apache.commons.httpclient.util URIUtil encodePath

List of usage examples for org.apache.commons.httpclient.util URIUtil encodePath

Introduction

In this page you can find the example usage for org.apache.commons.httpclient.util URIUtil encodePath.

Prototype

public static String encodePath(String unescaped) throws URIException 

Source Link

Document

Escape and encode a string regarded as the path component of an URI with the default protocol charset.

Usage

From source file:de.dentrassi.pm.jenkins.UrlMaker.java

public static String make(final String serverUrl, final String channelId) {
    try {/*w w  w. ja  v a2  s  . co  m*/
        return serverUrl + "/channel/" + URIUtil.encodePath(channelId) + "/view";
    } catch (final URIException e) {
        throw new RuntimeException(e);
    }
}

From source file:de.dentrassi.pm.jenkins.UrlMaker.java

public static String make(final String serverUrl, final String channelId, final String artifactUrl) {
    try {//from  w w  w. ja  v a 2  s.  c  o m
        return serverUrl + "/channel/" + URIUtil.encodePath(channelId) + "/artifacts/"
                + URIUtil.encodePath(artifactUrl) + "/view";
    } catch (final URIException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.icloud.framework.http.URLUtil.java

public static String getRequestUrlString(HttpServletRequest request) {

    String fullURL = "";

    try {/*from   w  ww  .java2 s  .  co m*/

        String urlString = request.getRequestURL().toString();

        String encodedRequestURL = URIUtil.encodePath(urlString);

        String queryString = request.getQueryString();

        if (null == queryString) {
            fullURL = encodedRequestURL;
        } else {
            fullURL = encodedRequestURL + "?" + queryString;
        }

    } catch (URIException e1) {
        e1.printStackTrace();
    }
    // http://robinkin:8280/jproxy-feeder/urlset/add

    // request.getPathTranslated();
    // //
    // /home/liangwang/repo/mobile/workspace/.metadata/.plugins/org.eclipse.wst.server.core/tmp2/wtpwebapps/jproxy/jproxy-feeder/urlset/add
    //
    // request.getPathInfo();
    // // /jproxy-feeder/urlset/add
    //
    // request.getRequestURI();
    // // /jproxy-feeder/urlset/add
    //
    // request.getContextPath();
    // /

    // url=http%3A%2F%2Fnews.sohu.com%2F20040723%2Fn221153893.shtml&setname=test

    // HttpGet will translate a urlString into a URI, so , we should do the
    // check first,
    // if failed, call the encoder
    //      try {
    //         URI url = new URI(fullURL);
    //      } catch (URISyntaxException e) {
    //         try {
    //            fullURL = URIUtil.encodePathQuery(fullURL);
    //         } catch (URIException e1) {
    //            e1.printStackTrace();
    //         }
    //      }

    return fullURL;
}

From source file:edu.isi.karma.rep.metadata.WorksheetProperties.java

public static String createDefaultGraphName(String worksheetTitle) throws URIException {
    return DEFAULT_GRAPH_NAME_PREFIX + URIUtil.encodePath(worksheetTitle);
}

From source file:edu.mayo.cts2.framework.plugin.service.bioportal.transform.TransformUtils.java

/**
 * Url encode./*from w w  w .jav  a  2s  .c o  m*/
 *
 * @param url the url
 * @return the string
 */
public static String urlEncode(String url) {
    try {
        return URIUtil.encodePath(url);
    } catch (Exception e) {
        throw new Cts2RuntimeException(e);
    }
}

From source file:davmail.exchange.TestExchangePropfindMethod.java

public void testGetFolder() throws IOException, DavException {
    ExchangeSession.Folder folder = session.getFolder("INBOX");
    assertNotNull(folder);//from   www . j a v  a 2 s . com
    DavPropertyNameSet davPropertyNameSet = new DavPropertyNameSet();
    // davPropertyNameSet.add(Field.getPropertyName("displayname"));
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    //session.httpClient.executeMethod(propFindMethod);
    //propFindMethod.getResponseBodyAsMultiStatus();

    ExchangePropFindMethod exchangePropFindMethod = new ExchangePropFindMethod(
            URIUtil.encodePath(((DavExchangeSession) session).getFolderPath(folder.folderPath)),
            davPropertyNameSet, 0);
    //PropFindMethod propFindMethod = new PropFindMethod(URIUtil.encodePath(((DavExchangeSession)session).getFolderPath(folder.folderPath)));
    session.httpClient.executeMethod(exchangePropFindMethod);
    MultiStatusResponse response = exchangePropFindMethod.getResponse();
    DavPropertySet properties = response.getProperties(HttpStatus.SC_OK);
    System.out.println(properties);
}

From source file:com.github.terma.jenkins.githubprcoveragestatus.Message.java

private String shieldIoUrl(String icon, final int yellowThreshold, final int greenThreshold) {
    final String color = getColor(yellowThreshold, greenThreshold);
    // dash should be encoded as two dash
    icon = icon.replace("-", "--");
    try {// www  . j  a  v  a  2s . co  m
        return String.format(BADGE_TEMPLATE, URIUtil.encodePath(icon), color);
    } catch (URIException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.datos.vfs.provider.http.HttpFileObject.java

protected String encodePath(final String decodedPath) throws URIException {
    return URIUtil.encodePath(decodedPath);
}

From source file:ch.cyberduck.core.dav.DAVResource.java

@Override
protected void setWebdavProperties(final Enumeration responses) throws HttpException, IOException {

    super.setWebdavProperties(new Enumeration() {
        public boolean hasMoreElements() {
            return responses.hasMoreElements();
        }//  w  ww  . j  ava 2  s  .  c om

        public Object nextElement() {
            final ResponseEntity response = (ResponseEntity) responses.nextElement();
            return new ResponseEntity() {

                public int getStatusCode() {
                    return response.getStatusCode();
                }

                public Enumeration getProperties() {
                    return response.getProperties();
                }

                public Enumeration getHistories() {
                    return response.getHistories();
                }

                public Enumeration getWorkspaces() {
                    return response.getWorkspaces();
                }

                public String getHref() {
                    if (StringUtils.isNotBlank(response.getHref())) {
                        // http://trac.cyberduck.ch/ticket/2223
                        final String escaped = StringUtils.replace(response.getHref(), " ", "%20");
                        try {
                            new java.net.URI(escaped);
                        } catch (URISyntaxException e) {
                            log.warn("Href not escaped in respose:" + response.getHref());
                            try {
                                return URIUtil.encodePath(response.getHref());
                            } catch (URIException failure) {
                                log.error("Encoding path failed:" + failure.getMessage());
                            }
                        }
                        return escaped;
                    }
                    return response.getHref();
                }
            };
        }
    });
}

From source file:davmail.caldav.TestCaldav.java

public void testCreateCalendar() throws IOException {
    String folderName = "test & accentu";
    String encodedFolderpath = URIUtil
            .encodePath("/users/" + session.getEmail() + "/calendar/" + folderName + '/');
    // first delete calendar
    session.deleteFolder("calendar/" + folderName);
    String body = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n" + "   <C:mkcalendar xmlns:D=\"DAV:\"\n"
            + "                 xmlns:C=\"urn:ietf:params:xml:ns:caldav\">\n" + "     <D:set>\n"
            + "       <D:prop>\n" + "         <D:displayname>" + StringUtil.xmlEncode(folderName)
            + "</D:displayname>\n"
            + "         <C:calendar-description xml:lang=\"en\">Calendar description</C:calendar-description>\n"
            + "         <C:supported-calendar-component-set>\n" + "           <C:comp name=\"VEVENT\"/>\n"
            + "         </C:supported-calendar-component-set>\n" + "       </D:prop>\n" + "     </D:set>\n"
            + "   </C:mkcalendar>";

    SearchReportMethod method = new SearchReportMethod(encodedFolderpath, body) {
        @Override/*from   www.ja  va  2 s .c o  m*/
        public String getName() {
            return "MKCALENDAR";
        }
    };
    httpClient.executeMethod(method);
    assertEquals(HttpStatus.SC_CREATED, method.getStatusCode());

    GetMethod getMethod = new GetMethod(encodedFolderpath);
    httpClient.executeMethod(getMethod);
    assertEquals(HttpStatus.SC_OK, getMethod.getStatusCode());
}