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

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

Introduction

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

Prototype

public static String getPath(String uri) 

Source Link

Document

Get the path of an URI.

Usage

From source file:org.alfresco.module.vti.web.fp.GetDocsMetaInfoMethod.java

/**
 * Provides the meta-information for the files in the current Web site
 *
 * @param request Vti Frontpage request ({@link VtiFpRequest})
 * @param response Vti Frontpage response ({@link VtiFpResponse}) 
 *///w  w  w  . j ava 2  s. com
protected void doExecute(VtiFpRequest request, VtiFpResponse response) throws VtiMethodException, IOException {
    if (logger.isDebugEnabled()) {
        logger.debug("Start method execution. Method name: " + getName());
    }

    String serviceName = request.getParameter("service_name", "");
    boolean listHiddenDocs = request.getParameter("listHiddenDocs", false);
    boolean listLinkInfo = request.getParameter("listLinkInfo", false);
    boolean validateWelcomeNames = request.getParameter("validateWelcomeNames", false);
    List<String> urlList = request.getParameter("url_list", new LinkedList<String>());
    String context = request.getAlfrescoContextName();

    String uri = request.getRequestURI();
    int pos = uri.indexOf("/_vti_bin");
    if (pos != -1 && (context.length() + 1) < pos) {
        serviceName = uri.substring(context.length() + 1, pos);
    } else {
        serviceName = "";
    }

    for (int i = 0; i < urlList.size(); ++i) {
        String url = urlList.get(i);
        String path = URIUtil.getPath(url);
        if (urlIsAbsolute(url)) {
            // Remove context path
            path = path.substring(context.length());

            if (path.length() > 1 && path.startsWith("/")) {
                // Remove preceding slash if one exists.
                path = path.substring(1);
            }
            if (path.startsWith(serviceName)) {
                path = path.substring(serviceName.length());
            }
            if (path.length() > 1 && path.startsWith("/")) {
                // ALF-19851 fix, remove preceding slash if one exists after removing serviceName.
                path = path.substring(1);
            }
            urlList.set(i, path);
        }
    }
    DocsMetaInfo docsMetaInfoList;
    try {
        docsMetaInfoList = vtiHandler.getDocsMetaInfo(serviceName, listLinkInfo, validateWelcomeNames,
                listHiddenDocs, urlList);
    } catch (VtiHandlerException e) {
        throw new VtiMethodException(e);
    }

    response.beginVtiAnswer(getName(), ServerVersionMethod.version);

    List<DocMetaInfo> fileMetaInfoList = docsMetaInfoList.getFileMetaInfoList();
    response.beginList("document_list");
    for (DocMetaInfo docMetaInfo : fileMetaInfoList) {
        response.beginList();
        response.addParameter("document_name", VtiEncodingUtils.encode(docMetaInfo.getPath()));
        response.beginList("meta_info");
        processDocMetaInfo(docMetaInfo, request, response);
        response.endList();
        response.endList();
    }
    response.endList();

    List<DocMetaInfo> folderMetaInfoList = docsMetaInfoList.getFolderMetaInfoList();
    response.beginList("urldirs");
    for (DocMetaInfo docMetaInfo : folderMetaInfoList) {
        response.beginList();
        response.addParameter("url", VtiEncodingUtils.encode(docMetaInfo.getPath()));
        response.beginList("meta_info");
        processDocMetaInfo(docMetaInfo, request, response);
        response.endList();
        response.endList();
    }
    response.endList();

    List<DocMetaInfo> failedUrls = docsMetaInfoList.getFailedUrls();
    if (!failedUrls.isEmpty()) {
        response.beginList("failedUrls");
        for (DocMetaInfo docMetaInfo : failedUrls) {
            response.addParameter(VtiEncodingUtils.encode(docMetaInfo.getPath()));
        }
        response.endList();
    }
    response.endVtiAnswer();

    if (logger.isDebugEnabled()) {
        logger.debug("End of method execution. Method name: " + getName());
    }
}

From source file:org.alfresco.module.vti.web.ws.CheckInFileEndpoint.java

/**
 * Check in file//from  w  w w . ja v  a 2  s .  c  o  m
 * 
 * @param soapRequest Vti soap request ({@link VtiSoapRequest})
 * @param soapResponse Vti soap response ({@link VtiSoapResponse}) 
 */
public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Soap Method with name " + getName() + " is started.");

    // mapping xml namespace to prefix
    SimpleNamespaceContext nc = new SimpleNamespaceContext();
    nc.addNamespace(prefix, namespace);
    nc.addNamespace(soapUriPrefix, soapUri);

    // getting pageUrl parameter from request
    XPath xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/pageUrl"));
    xpath.setNamespaceContext(nc);
    Element docE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement());
    if (docE == null || docE.getTextTrim().length() == 0) {
        throw new VtiSoapException("pageUrl must be supplied", 0x82000001l);
    }

    String docPath = URLDecoder.decode(docE.getTextTrim());
    String context = soapRequest.getAlfrescoContextName();
    docPath = URIUtil.getPath(docPath).substring(context.length());

    // Get the comment
    xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/comment"));
    xpath.setNamespaceContext(nc);
    String comment = ((Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement()))
            .getTextTrim();

    // Get the checkin type
    xpath = new Dom4jXPath(buildXPath(prefix, "/CheckInFile/CheckinType"));
    xpath.setNamespaceContext(nc);
    Element typeE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement());

    VersionType type = VersionType.MAJOR;
    if (typeE != null && typeE.getTextTrim().length() > 0) {
        String typeS = typeE.getTextTrim();
        if ("0".equals(typeS)) {
            type = VersionType.MINOR;
        } else if ("1".equals(typeS)) {
            type = VersionType.MAJOR;
        } else if ("2".equals(typeS)) {
            type = VersionType.MAJOR;
        } else {
            throw new VtiSoapException("Invalid Checkin Type '" + typeS + "' received", -1);
        }
    }

    // Good to go
    if (logger.isDebugEnabled()) {
        logger.debug("item parameter for this request: " + docPath);
    }

    NodeRef originalNode;
    boolean lockAfterSucess = true;

    // Do not lock original node if we work with Office 2008/2011 for Mac
    if (VtiUtils.isMacClientRequest(soapRequest)) {
        lockAfterSucess = false;
    }

    try {
        originalNode = handler.checkInDocument(docPath, type, comment, lockAfterSucess);
    } catch (FileNotFoundException fnfe) {
        throw new VtiSoapException("File not found", -1, fnfe);
    }

    // creating soap response
    Element responseElement = soapResponse.getDocument().addElement("CheckInFileResponse", namespace);
    Element result = responseElement.addElement("CheckInFileResult");
    result.setText(originalNode != null ? "true" : "false");

    soapResponse.setContentType("text/xml");
    if (logger.isDebugEnabled()) {
        logger.debug("Soap Method with name " + getName() + " is finished.");
    }

}

From source file:org.alfresco.module.vti.web.ws.CheckOutFileEndpoint.java

/**
 * Check out file/* w w  w .  ja  v a  2s.c om*/
 * 
 * @param soapRequest Vti soap request ({@link VtiSoapRequest})
 * @param soapResponse Vti soap response ({@link VtiSoapResponse}) 
 */
public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Soap Method with name " + getName() + " is started.");

    // mapping xml namespace to prefix
    SimpleNamespaceContext nc = new SimpleNamespaceContext();
    nc.addNamespace(prefix, namespace);
    nc.addNamespace(soapUriPrefix, soapUri);

    // Get the pageUrl parameter from the request
    XPath xpath = new Dom4jXPath(buildXPath(prefix, "/CheckOutFile/pageUrl"));
    xpath.setNamespaceContext(nc);
    Element docE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement());
    if (docE == null || docE.getTextTrim().length() == 0) {
        throw new VtiSoapException("pageUrl must be supplied", 0x82000001l);
    }
    String docPath = URLDecoder.decode(docE.getTextTrim(), "UTF-8");
    String context = soapRequest.getAlfrescoContextName();

    docPath = URIUtil.getPath(docPath).substring(context.length());

    // Did they want to work on it locally?
    xpath = new Dom4jXPath(buildXPath(prefix, "/CheckOutFile/checkoutToLocal"));
    xpath.setNamespaceContext(nc);
    Element localE = (Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement());
    if (localE != null) {
        // If given, must be one of True or False
        String local = localE.getTextTrim().toLowerCase();
        if ("true".equals(local) || "false".equals(local)) {
            // Good
        } else {
            throw new VtiSoapException("Invalid CheckOutToLocal Parameter", -1);
        }
    }

    // Report what we're about to do
    if (logger.isDebugEnabled()) {
        logger.debug("About to check out " + docPath);
    }

    NodeRef workingCopy;
    boolean lockAfterSucess = true;

    // Do not lock working copy node if we work with Office 2008/2011 for Mac
    // this clients don't send UNLOCK method after SOAP CheckOutFile request, so no need to lock working copy
    if (VtiUtils.isMacClientRequest(soapRequest)) {
        lockAfterSucess = false;
    }

    try {
        workingCopy = handler.checkOutDocument(docPath, lockAfterSucess);

        // creating soap response
        Element responseElement = soapResponse.getDocument().addElement("CheckOutFileResponse", namespace);
        Element result = responseElement.addElement("CheckOutFileResult");
        result.setText(workingCopy != null ? "true" : "false");

        soapResponse.setContentType("text/xml");
        if (logger.isDebugEnabled()) {
            logger.debug("Soap Method with name " + getName() + " is finished.");
        }
    } catch (AccessDeniedException e) {
        soapResponse.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
    } catch (FileNotFoundException fnfe) {
        throw new VtiSoapException("File not found", -1, fnfe);
    }

}

From source file:org.alfresco.module.vti.web.ws.WebUrlFromPageUrlEndpoint.java

/**
 * Retrieves url of the document workspace site from the document url
 * /*w  w w.  ja  va2s.  c om*/
 * @param soapRequest Vti soap request ({@link VtiSoapRequest})
 * @param soapResponse Vti soap response ({@link VtiSoapResponse}) 
 */
public void execute(VtiSoapRequest soapRequest, VtiSoapResponse soapResponse) throws Exception {
    if (logger.isDebugEnabled())
        logger.debug("Soap Method with name " + getName() + " is started.");

    // mapping xml namespace to prefix
    SimpleNamespaceContext nc = new SimpleNamespaceContext();
    nc.addNamespace(prefix, namespace);
    nc.addNamespace(soapUriPrefix, soapUri);

    // getting pageUrl parameter from request
    XPath xpath = new Dom4jXPath(buildXPath(prefix, "/WebUrlFromPageUrl/pageUrl"));
    xpath.setNamespaceContext(nc);
    String pageUrl = URLDecoder.decode(
            ((Element) xpath.selectSingleNode(soapRequest.getDocument().getRootElement())).getTextTrim(),
            "UTF-8");

    if (logger.isDebugEnabled())
        logger.debug("pageUrl parameter for this request: " + pageUrl);
    String server = getHost(soapRequest);
    String context = soapRequest.getAlfrescoContextName();

    String[] uris = handler.decomposeURL(URIUtil.getPath(pageUrl), context);

    // creating soap response
    Element responseElement = soapResponse.getDocument().addElement("WebUrlFromPageUrlResponse", namespace);
    Element result = responseElement.addElement("WebUrlFromPageUrlResult");
    result.setText(server + uris[0]);

    if (logger.isDebugEnabled()) {
        logger.debug("Soap Method with name " + getName() + " is finished.");
    }
}

From source file:org.apache.webdav.lib.WebdavResource.java

/**
 * Set WebDAV properties following to the given http URL.
 * This method is fundamental for getting information of a collection.
 *
 * @param responses An enumeration over {@link ResponseEntity} items, one
 * for each resource for which information was returned via PROPFIND.
 *
 * @exception HttpException//w  ww.  j  a  v a 2 s  . com
 * @exception IOException The socket error with a server.
 */
protected void setWebdavProperties(Enumeration responses) throws HttpException, IOException {

    // Make the resources in the collection empty.
    childResources.removeAll();
    while (responses.hasMoreElements()) {

        ResponseEntity response = (ResponseEntity) responses.nextElement();

        boolean itself = false;
        String href = response.getHref();
        if (!href.startsWith("/"))
            href = URIUtil.getPath(href);
        href = decodeMarks(href);

        /*
         * Decode URIs to common (unescaped) format for comparison 
         * as HttpClient.URI.setPath() doesn't escape $ and : chars.
         */
        String httpURLPath = httpURL.getPath();
        String escapedHref = URIUtil.decode(href);

        // Normalize them to both have trailing slashes if they differ by one in length.
        int lenDiff = escapedHref.length() - httpURLPath.length();
        int compareLen = 0;

        if (lenDiff == -1 && !escapedHref.endsWith("/")) {
            compareLen = escapedHref.length();
            lenDiff = 0;
        } else if (lenDiff == 1 && !httpURLPath.endsWith("/")) {
            compareLen = httpURLPath.length();
            lenDiff = 0;
        }

        // if they are the same length then compare them.
        if (lenDiff == 0) {
            if ((compareLen == 0 && httpURLPath.equals(escapedHref))
                    || httpURLPath.regionMatches(0, escapedHref, 0, compareLen)) {
                // escaped href and http path are the same
                // Set the status code for this resource.
                if (response.getStatusCode() > 0)
                    setStatusCode(response.getStatusCode());
                setExistence(true);
                itself = true;
            }
        }

        // Get to know each resource.
        WebdavResource workingResource = null;
        if (itself) {
            workingResource = this;
        } else {
            workingResource = createWebdavResource(client);
            workingResource.setDebug(debug);
        }

        // clear the current lock set
        workingResource.setLockDiscovery(null);

        // Process the resource's properties
        Enumeration properties = response.getProperties();
        while (properties.hasMoreElements()) {

            Property property = (Property) properties.nextElement();

            // ------------------------------  Checking WebDAV properties
            workingResource.processProperty(property);
        }

        String displayName = workingResource.getDisplayName();

        if (displayName == null || displayName.trim().equals("")) {
            displayName = getName(href, true);
        }
        if (!itself) {
            String myURI = httpURL.getEscapedURI();
            char[] childURI = (myURI + (myURI.endsWith("/") ? "" : "/") + getName(href, false)).toCharArray();
            HttpURL childURL = httpURL instanceof HttpsURL ? new HttpsURL(childURI) : new HttpURL(childURI);
            childURL.setRawAuthority(httpURL.getRawAuthority());
            workingResource.setHttpURL(childURL, NOACTION, defaultDepth);
            workingResource.setExistence(true);
            workingResource.setOverwrite(getOverwrite());
        }
        workingResource.setDisplayName(displayName);

        if (!itself)
            childResources.addResource(workingResource);
    }
}

From source file:org.elasticsearch.hadoop.rest.URIUtils.java

public static String addPath(String uri, String... path) {
    String p = URIUtil.getPath(uri);
    String fixedP = p.endsWith("/") ? p : p.concat("/");
    return uri.replace(p, fixedP + StringUtils.concatenate(path, "/"));
}

From source file:org.opencms.frontend.templateone.CmsTemplateForm.java

/**
 * Returns the (not substituted) URI to the page that called the form.<p>
 * // w w w .jav  a  2 s  . c  o m
 * Removes all request parameters from the page URI, if specified.<p>
 * 
 * @param removeParams if true, all request parameters will be removed from the URI
 * @return the (not substituted) URI to the page that called the form
 */
public String getPageUri(boolean removeParams) {

    if (removeParams) {
        // remove eventual request parameters
        String uri = m_pageUri;
        if (CmsStringUtil.isNotEmpty(uri)) {
            uri = URIUtil.getPath(uri);
        }
        return uri;
    } else {
        return m_pageUri;
    }
}

From source file:org.pengyou.client.lib.DavResource.java

/**
* Set WebDAV properties following to the given http URL.
* This method is fundamental for getting information of a collection.
*
* @param responses An enumeration over {@link ResponseEntity} items, one
* for each resource for which information was returned via PROPFIND.
*
* @exception HttpException/*ww  w .  ja  v a2 s  .  c o  m*/
* @exception IOException The socket error with a server.
*/
protected void setWebdavProperties(Enumeration responses) throws HttpException, IOException {

    // Make the resources in the collection empty.
    childResources.removeAll();
    while (responses.hasMoreElements()) {

        ResponseEntity response = (ResponseEntity) responses.nextElement();

        boolean itself = false;
        String href = response.getHref();
        if (!href.startsWith("/"))
            href = URIUtil.getPath(href);
        href = decodeMarks(href);

        /*
         * Decode URIs to common (unescaped) format for comparison
         * as HttpClient.URI.setPath() doesn't escape $ and : chars.
         */
        //String httpURLPath = httpURL.getPath();
        String httpURLPath = context.getBaseUrl() + getPath();
        String escapedHref = URIUtil.decode(href);

        // Normalize them to both have trailing slashes if they differ by one in length.
        int lenDiff = escapedHref.length() - httpURLPath.length();
        int compareLen = 0;

        if (lenDiff == -1 && !escapedHref.endsWith("/")) {
            compareLen = escapedHref.length();
            lenDiff = 0;
        } else if (lenDiff == 1 && !httpURLPath.endsWith("/")) {
            compareLen = httpURLPath.length();
            lenDiff = 0;
        }

        // if they are the same length then compare them.
        if (lenDiff == 0) {
            if ((compareLen == 0 && httpURLPath.equals(escapedHref))
                    || httpURLPath.regionMatches(0, escapedHref, 0, compareLen)) {
                // escaped href and http path are the same
                // Set the status code for this resource.
                if (response.getStatusCode() > 0)
                    this.statusCode = response.getStatusCode();
                this.exist = true;
                itself = true;
            }
        }

        // Get to know each resource.
        DavResource workingResource = null;
        if (itself) {
            workingResource = this;
        } else {
            workingResource = createWebdavResource(client);
        }

        // clear the current lock set
        workingResource.setLockDiscovery(null);

        // Process the resource's properties
        Enumeration properties = response.getProperties();
        while (properties.hasMoreElements()) {

            Property property = (Property) properties.nextElement();

            // ------------------------------  Checking WebDAV properties
            workingResource.processProperty(property);
        }

        String displayName = workingResource.displayName;

        if (displayName == null || displayName.trim().equals("")) {
            displayName = getName(href);
        }
        if (!itself) {
            String myPath = getPath();
            String childPath = myPath + (myPath.endsWith("/") ? "" : "/") + DavResource.getName(href); //(myPath.endsWith("/") ? "" : "/") + URIUtil.getName(href);
            workingResource.setEncodedPath(childPath);
            workingResource.setExistence(true);
        }

        if (!itself)
            childResources.addResource(workingResource);
    }
}