org.springframework.extensions.surf.util.URLEncoder Java Examples

The following examples show how to use org.springframework.extensions.surf.util.URLEncoder. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ApplicationScriptUtils.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @param  node the node to construct the download URL for
 * @return For a content document, this method returns the URL to the /api/node/content
 *         API for the default content property
 *         <p>
 *         For a container node, this method returns an empty string
 *         </p>
 */
public String getDownloadAPIUrl(ScriptNode node)
{
    if (node.getIsDocument())
    {
       return MessageFormat.format(CONTENT_DOWNLOAD_API_URL, new Object[]{
               node.nodeRef.getStoreRef().getProtocol(),
               node.nodeRef.getStoreRef().getIdentifier(),
               node.nodeRef.getId(),
               URLEncoder.encode(node.getName())});
    }
    else
    {
        return "";
    }
}
 
Example #2
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @return For a content document, this method returns the download URL to the content for
 *         the default content property (@see ContentModel.PROP_CONTENT)
 *         <p>
 *         For a container node, this method returns an empty string
 */
public String getDownloadUrl()
{
    if (getIsDocument() == true)
    {
       return MessageFormat.format(CONTENT_DOWNLOAD_URL, new Object[] {
                nodeRef.getStoreRef().getProtocol(),
                nodeRef.getStoreRef().getIdentifier(),
                nodeRef.getId(),
                URLEncoder.encode(getName()) });
    }
    else
    {
        return "";
    }
}
 
Example #3
Source File: GetMethod.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 6 votes vote down vote up
protected String getContentDispositionHeader(FileInfo nodeInfo)
{
    String filename = nodeInfo.getName();
    StringBuilder sb = new StringBuilder();
    sb.append("attachment; filename=\"");
    for(int i = 0; i < filename.length(); i++)
    {
        char c = filename.charAt(i);
        if(isValidQuotedStringHeaderParamChar(c))
        {
            sb.append(c);
        }
        else
        {
            sb.append(" ");
        }
    }
    sb.append("\"; filename*=UTF-8''");
    sb.append(URLEncoder.encode(filename));
    return sb.toString();
}
 
Example #4
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * @return download URL to the content for a document item only
 */
public String getDownloadUrl()
{
    if (getIsDocument() == true)
    {
        return MessageFormat.format(CONTENT_DOWNLOAD_PROP_URL, new Object[] {
                nodeRef.getStoreRef().getProtocol(),
                nodeRef.getStoreRef().getIdentifier(),
                nodeRef.getId(),
                URLEncoder.encode(getName()),
                URLEncoder.encode(property.toString()) });
    }
    else
    {
        return "";
    }
}
 
Example #5
Source File: NodeLocatorWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
public void testXPathNodeLocator() throws Exception
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    NodeRef first = makeChildFolderNode(companyHome);
    try
    {
        NodeRef second = makeChildFolderNode(first);
        NodeRef content = makeChildContentNode(second);
        
        // Check bad path returns null
        String badPath = URLEncoder.encode("cm:foo/cm:bar/cm:foobar");
        String badPathUrl = baseURL + XPathNodeLocator.NAME + "?query=" + badPath;
        checkNodeLocator(badPathUrl, null);
        
        String path  = nodeService.getPath(content).toPrefixString(namespaceService);
        String encodedPath = URLEncoder.encode(path);
        
        // Check default store ref works.
        String defaultStoreUrl = baseURL + XPathNodeLocator.NAME + "?query=" +encodedPath;
        checkNodeLocator(defaultStoreUrl, content);
        
        // Check specified store ref works.
        String storeIdUrl = defaultStoreUrl + "&store_type=workspace&store_id=SpacesStore";
        checkNodeLocator(storeIdUrl, content);
        
        // Check node store ref works.
        String nodePathUrl = makeUrl(companyHome, XPathNodeLocator.NAME) + "?query=" + encodedPath;
        checkNodeLocator(nodePathUrl, content);
    }
    finally
    {
        nodeService.deleteNode(first);
    }
}
 
Example #6
Source File: WebDavServiceImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Get the WebDavUrl for the specified nodeRef
 * 
 * @param nodeRef the node that the webdav URL (or null)
 * @return the URL of the node in webdav or "" if a URL cannot be built.
 */
public String getWebdavUrl(NodeRef nodeRef)
{
    String url = "";
    
    if (!enabled)
    {
        return url;
    }
    
    try
    {
        QName typeName = nodeService.getType(nodeRef);
        
        if (getIsContainer(typeName) || getIsDocument(typeName))
        {
            List<String> paths = fileFolderService.getNameOnlyPath(getRootNode().getNodeForCurrentTenant(), nodeRef);
            
            // build up the webdav url
            StringBuilder path = new StringBuilder(128);
            path.append("/" + WEBDAV_PREFIX);
            
            for (int i=0; i<paths.size(); i++)
            {
                path.append("/")
                    .append(URLEncoder.encode(paths.get(i)));
            }
            url = path.toString();
        }
    }
    catch (InvalidTypeException typeErr)
    {
        // cannot build path if file is a type such as a rendition
    }
    catch (FileNotFoundException nodeErr)
    {
        // cannot build path if file no longer exists, return default
    }
    return url;
}
 
Example #7
Source File: KeywordSearch.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public String getUrl()
{
    return MessageFormat.format(URL, new Object[] {
        getNodeRef().getStoreRef().getProtocol(),
        getNodeRef().getStoreRef().getIdentifier(),
        getNodeRef().getId(),
        URLEncoder.encode(getName()) } );
}
 
Example #8
Source File: ContentStreamer.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Set attachment header
 * 
 * @param req WebScriptRequest
 * @param res WebScriptResponse
 * @param attach boolean
 * @param attachFileName String
 */
public void setAttachment(WebScriptRequest req, WebScriptResponse res, boolean attach, String attachFileName)
{
    if (attach == true)
    {
        String headerValue = "attachment";
        if (attachFileName != null && attachFileName.length() > 0)
        {
            if (logger.isDebugEnabled())
                logger.debug("Attaching content using filename: " + attachFileName);

            if (req == null)
            {
                headerValue += "; filename*=UTF-8''" + URLEncoder.encode(attachFileName)
                        + "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"";
            }
            else
            {
                String userAgent = req.getHeader(HEADER_USER_AGENT);
                boolean isLegacy = (null != userAgent) && (userAgent.contains("MSIE 8") || userAgent.contains("MSIE 7"));
                if (isLegacy)
                {
                    headerValue += "; filename=\"" + URLEncoder.encode(attachFileName);
                }
                else
                {
                    headerValue += "; filename=\"" + filterNameForQuotedString(attachFileName) + "\"; filename*=UTF-8''"
                            + URLEncoder.encode(attachFileName);
                }
            }
        }
        
        // set header based on filename - will force a Save As from the browse if it doesn't recognize it
        // this is better than the default response of the browser trying to display the contents
        res.setHeader("Content-Disposition", headerValue);
    }
}
 
Example #9
Source File: NodeBrowserPost.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
private static String buildUrl(WebScriptRequest req, Map<String, String> params, String hash)
{
    StringBuilder url = new StringBuilder(256);
    
    url.append(req.getServicePath());
    if (!params.isEmpty())
    {
        boolean first = true;
        for (String key: params.keySet())
        {
            String val = params.get(key);
            if (val != null && val.length() != 0)
            {
                url.append(first ? '?' : '&');
                url.append(key);
                url.append('=');
                url.append(URLEncoder.encode(val));
                first = false;
            }
        }
    }
    if (hash != null && hash.length() != 0)
    {
        url.append('#').append(hash);
    }
    
    return url.toString();
}
 
Example #10
Source File: HTTPProxyServlet.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @see javax.servlet.http.HttpServlet#doGet(javax.servlet.http.HttpServletRequest, javax.servlet.http.HttpServletResponse)
 */
protected void doGet(HttpServletRequest req, HttpServletResponse res)
        throws ServletException, IOException
{
    String endpoint = null;
    StringBuilder args = new StringBuilder(32);
    
    Map<String, String[]> parameters = req.getParameterMap();
    for (Map.Entry<String, String[]> parameter : parameters.entrySet())
    {
        String[] values = parameter.getValue();
        int startIdx = 0;
        
        if (parameter.getKey().equals(PARAM_ENDPOINT) && values.length != 0)
        {
            endpoint = values[0];
            startIdx++;
        }
        
        for (int i = startIdx; i < values.length; i++)
        {
            if (args.length() != 0)
            {
                args.append("&");
            }
            args.append(parameter.getKey()).append('=').append(URLEncoder.encode(values[i]));
        }
    }
    
    if (endpoint == null || endpoint.length() == 0)
    {
        throw new IllegalArgumentException("endpoint argument not specified");
    }
    
    String url = endpoint + ((args.length() == 0) ? "" : "?" + args.toString());
    HTTPProxy proxy = new HTTPProxy(url, res);
    proxy.service();
}
 
Example #11
Source File: InviteSenderTest.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
public Person(String name)
{
    this.name = name;
    String encName = URLEncoder.encode(name);
    this.email = encName + "@test.com";
    this.node = new NodeRef(testStore, encName);
}
 
Example #12
Source File: BaseContentNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String buildPropUrl(String pformat)
{
    return MessageFormat.format(pformat, new Object[] {
             getNodeRef().getStoreRef().getProtocol(),
             getNodeRef().getStoreRef().getIdentifier(),
             getNodeRef().getId(),
             URLEncoder.encode(getName()),
             URLEncoder.encode(property.toString()) } );
}
 
Example #13
Source File: BaseContentNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String buildUrl(String format)
{
   return MessageFormat.format(format, new Object[] {
             getNodeRef().getStoreRef().getProtocol(),
             getNodeRef().getStoreRef().getIdentifier(),
             getNodeRef().getId(),
             URLEncoder.encode(getName()) } );
}
 
Example #14
Source File: VersionHistoryNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return Returns the URL to the content stream for the frozen state of the node from
 *         the default content property (@see ContentModel.PROP_CONTENT)
 */
@Override
public String getUrl()
{
    NodeRef nodeRef = this.version.getFrozenStateNodeRef();
    return MessageFormat.format(parent.CONTENT_GET_URL, new Object[] {
            nodeRef.getStoreRef().getProtocol(),
            nodeRef.getStoreRef().getIdentifier(),
            nodeRef.getId(),
            URLEncoder.encode(getName()) } );
}
 
Example #15
Source File: InviteNominatedSender.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
private String buildUrlParamString(Map<String, String> properties)
{
    StringBuilder params = new StringBuilder("?inviteId=");
    params.append(properties.get(WF_INSTANCE_ID));
    params.append("&inviteeUserName=");
    params.append(URLEncoder.encode(properties.get(wfVarInviteeUserName)));
    params.append("&siteShortName=");
    params.append(properties.get(wfVarResourceName));
    params.append("&inviteTicket=");
    params.append(properties.get(wfVarInviteTicket));
    return params.toString();
}
 
Example #16
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return download URL to the content
 */
public String getUrl()
{
    return MessageFormat.format(CONTENT_PROP_URL, new Object[] { nodeRef.getStoreRef().getProtocol(),
            nodeRef.getStoreRef().getIdentifier(), nodeRef.getId(),
            URLEncoder.encode(getName()),
            URLEncoder.encode(property.toString()) });
}
 
Example #17
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return The WebDav cm:name based path to the content for the default content property
 *         (@see ContentModel.PROP_CONTENT)
 */
public String getWebdavUrl()
{
    String url = "";
    try
    {
        if (getIsContainer() || getIsDocument())
        {
            List<String> paths = this.services.getFileFolderService().getNameOnlyPath(null, getNodeRef());
            
            // build up the webdav url
            StringBuilder path = new StringBuilder(128);
            path.append("/webdav");
            
            // build up the path skipping the first path as it is the root folder
            for (int i=1; i<paths.size(); i++)
            {
                path.append("/")
                    .append(URLEncoder.encode(paths.get(i)));
            }
            url = path.toString();
        }
    }
    catch (InvalidTypeException typeErr)
    {
        // cannot build path if file is a type such as a rendition
    }
    catch (FileNotFoundException nodeErr)
    {
        // cannot build path if file no longer exists
    }
    return url;
}
 
Example #18
Source File: ScriptNode.java    From alfresco-repository with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * @return For a content document, this method returns the URL to the content stream for the default content
 *         property (@see ContentModel.PROP_CONTENT)
 *         <p>
 *         For a container node, this method return the URL to browse to the folder in the web-client
 */
public String getUrl()
{
    if (getIsDocument() == true)
    {
        return MessageFormat.format(CONTENT_DEFAULT_URL, new Object[] { nodeRef.getStoreRef().getProtocol(),
                nodeRef.getStoreRef().getIdentifier(), nodeRef.getId(),
                URLEncoder.encode(getName())});
    }
    else
    {
        return MessageFormat.format(FOLDER_BROWSE_URL, new Object[] { nodeRef.getStoreRef().getProtocol(),
                nodeRef.getStoreRef().getIdentifier(), nodeRef.getId() });
    }
}
 
Example #19
Source File: SOLRAPIClient.java    From SearchServices with GNU Lesser General Public License v3.0 4 votes vote down vote up
public GetTextContentResponse getTextContent(Long nodeId, QName propertyQName, Long modifiedSince) throws AuthenticationException, IOException {
    StringBuilder url = new StringBuilder(128);
    url.append(GET_CONTENT);
    
    StringBuilder args = new StringBuilder(128);
    if(nodeId != null)
    {
        args.append("?");
        args.append("nodeId");
        args.append("=");
        args.append(nodeId);            
    }
    else
    {
        throw new NullPointerException("getTextContent(): nodeId cannot be null.");
    }
    if(propertyQName != null)
    {
        if(args.length() == 0)
        {
            args.append("?");
        }
        else
        {
            args.append("&");
        }
        args.append("propertyQName");
        args.append("=");
        args.append(URLEncoder.encode(propertyQName.toString()));
    }
    
    url.append(args);
    
    GetRequest req = new GetRequest(url.toString());
    
    Map<String, String> headers = new HashMap<>();
    if(modifiedSince != null)
    {
        headers.put("If-Modified-Since", String.valueOf(DateUtil.formatDate(new Date(modifiedSince))));
    }
    if (compression)
    {
        headers.put("Accept-Encoding", "gzip");
    }
    req.setHeaders(headers);
    
    Response response = repositoryHttpClient.sendRequest(req);
    
    if(response.getStatus() != Status.STATUS_NOT_MODIFIED && response.getStatus() != Status.STATUS_NO_CONTENT && response.getStatus() != Status.STATUS_OK)
    {
        int status = response.getStatus();
        response.release();
        throw new AlfrescoRuntimeException("GetTextContentResponse return status is " + status);
    }

    return new GetTextContentResponse(response);
}
 
Example #20
Source File: JSONConversionComponent.java    From alfresco-repository with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * 
 * @param nodeInfo FileInfo
 * @param rootJSONObject JSONObject
 * @param useShortQNames boolean
 */
@SuppressWarnings("unchecked")
protected void setRootValues(final FileInfo nodeInfo, final JSONObject rootJSONObject, final boolean useShortQNames)
{
    final NodeRef nodeRef = nodeInfo.getNodeRef();
    
    rootJSONObject.put("nodeRef", nodeInfo.getNodeRef().toString());
    rootJSONObject.put("type", nameToString(nodeInfo.getType(), useShortQNames));                   
    rootJSONObject.put("isContainer", nodeInfo.isFolder()); //node.getIsContainer() || node.getIsLinkToContainer());
    rootJSONObject.put("isLocked", isLocked(nodeInfo.getNodeRef()));
    
    rootJSONObject.put("isLink", nodeInfo.isLink());
    if (nodeInfo.isLink())
    {
        NodeRef targetNodeRef = nodeInfo.getLinkNodeRef();
        if (targetNodeRef != null)
        {
            rootJSONObject.put("linkedNode", toJSONObject(targetNodeRef, useShortQNames));
        }
    }    
    
    // TODO should this be moved to the property output since we may have more than one content property
    //      or a non-standard content property 
    
    if (nodeInfo.isFolder() == false)
    {
        final ContentData cdata = nodeInfo.getContentData();
        if (cdata != null)
        {
            String contentURL = MessageFormat.format(
                    CONTENT_DOWNLOAD_API_URL, new Object[]{
                            nodeRef.getStoreRef().getProtocol(),
                            nodeRef.getStoreRef().getIdentifier(),
                            nodeRef.getId(),
                            URLEncoder.encode(nodeInfo.getName())});
            
            rootJSONObject.put("contentURL", contentURL);
            rootJSONObject.put("mimetype", cdata.getMimetype());
            Map<String, String> mimetypeDescriptions;
            mimetypeDescriptions = mimetypeService.getDisplaysByMimetype();

            if (mimetypeDescriptions.containsKey(cdata.getMimetype()))
            {
                rootJSONObject.put("mimetypeDisplayName", mimetypeDescriptions.get(cdata.getMimetype()));
            }
            rootJSONObject.put("encoding", cdata.getEncoding());
            rootJSONObject.put("size", cdata.getSize());
        }
    }
}
 
Example #21
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public final static String encodeURL(String s, String userAgent)
{
      return URLEncoder.encode(s);
}
 
Example #22
Source File: WebDAVHelper.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * ALF-5333: Microsoft clients use ISO-8859-1 to decode WebDAV responses
 * so this method should only be used for Microsoft user agents.
 * 
 * @param string String
 * @return The encoded string for Microsoft clients
 * @throws UnsupportedEncodingException
 */
public final static String encodeUrlReservedSymbols(String string) throws UnsupportedEncodingException
{
    if (string == null)
    {
        return "";
    }
    
    StringBuilder sb = null;      // create on demand
    String enc;
    char c;
    for (int i = 0; i < string.length(); i++)
    {
        enc = null;
        c = string.charAt(i);
        switch (c)
        {
            // reserved
            case ';': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '/': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '?': enc = URLEncoder.encode(String.valueOf(c)); break;
            case ':': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '@': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '&': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '=': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '+': enc = URLEncoder.encode(String.valueOf(c)); break;
            
            // unsafe
            case '\"': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '#': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '%': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '>': enc = URLEncoder.encode(String.valueOf(c)); break;
            case '<': enc = URLEncoder.encode(String.valueOf(c)); break;
            default: break;
        }
        
        if (enc != null)
        {
            if (sb == null)
            {
                String soFar = string.substring(0, i);
                sb = new StringBuilder(i + 8);
                sb.append(soFar);
            }
            sb.append(enc);
        }
        else
        {
            if (sb != null)
            {
                sb.append(c);
            }
        }
    }
    
    if (sb == null)
    {
        return string;
    }
    else
    {
        return sb.toString();
    }
}
 
Example #23
Source File: ReplicationRestApiTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
/**
 * Test that when creating and working with replication
 *  definitions with a name that includes "nasty"
 *  characters, things still work.
 * Related to ALF-4610.
 */
public void testReplicationDefinitionsNastyNames() throws Exception
{
   AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
   Response response;
   String jsonStr;
   
   String nastyName = "~!@#$%^&()_+-={}[];";
   String nastyNameURL = URLEncoder.encodeUriComponent(nastyName);
   
   
   // Create
   JSONObject json = new JSONObject();
   json.put("name", nastyName);
   json.put("description", "Nasty Characters");
   response = sendRequest(new PostRequest(URL_DEFINITIONS, json.toString(), JSON), Status.STATUS_OK);
   assertEquals(Status.STATUS_OK, response.getStatus());
   
   jsonStr = response.getContentAsString();
   json = new JSONObject(jsonStr).getJSONObject("data");
   assertNotNull(json);
   
   assertEquals(nastyName, json.get("name"));
   assertEquals("Nasty Characters", json.get("description"));
   assertEquals("New", json.get("status"));
   assertEquals(JSONObject.NULL, json.get("startedAt"));
   assertEquals(JSONObject.NULL, json.get("endedAt"));
   assertEquals(JSONObject.NULL, json.get("failureMessage"));
   assertEquals(JSONObject.NULL, json.get("executionDetails"));
   assertEquals(JSONObject.NULL, json.get("transferLocalReport"));
   assertEquals(JSONObject.NULL, json.get("transferRemoteReport"));
   assertEquals(true, json.get("enabled"));
   assertEquals(JSONObject.NULL, json.get("targetName"));
   assertEquals(0, json.getJSONArray("payload").length());
   
   
   // Check it turned up
   assertEquals(1, replicationService.loadReplicationDefinitions().size());
   assertEquals(nastyName, replicationService.loadReplicationDefinitions().get(0).getReplicationName());
   
   
   // Fetch the details
   response = sendRequest(new GetRequest(URL_DEFINITION + nastyNameURL), 200);
   assertEquals(Status.STATUS_OK, response.getStatus());
   
   jsonStr = response.getContentAsString();
   json = new JSONObject(jsonStr).getJSONObject("data");
   assertNotNull(json);
   
   assertEquals(nastyName, json.get("name"));
   assertEquals("Nasty Characters", json.get("description"));
   assertEquals("New", json.get("status"));
   
   
   // Delete
   // Because some of the delete operations happen post-commit, and
   //  because we don't have real transactions, fake it
   UserTransaction txn = transactionService.getUserTransaction();
   txn.begin();
   
   // Call the delete webscript
   response = sendRequest(new DeleteRequest(URL_DEFINITION + nastyNameURL), Status.STATUS_NO_CONTENT);
   assertEquals(Status.STATUS_NO_CONTENT, response.getStatus());
   
   // Let the node service do its work
   txn.commit();
   Thread.sleep(50);
   
   // Check the details webscript to ensure it went
   response = sendRequest(new GetRequest(URL_DEFINITION + nastyNameURL), Status.STATUS_NOT_FOUND);
   assertEquals(Status.STATUS_NOT_FOUND, response.getStatus());
   
   // And check the service too
   assertEquals(0, replicationService.loadReplicationDefinitions().size());
}
 
Example #24
Source File: NodeLocatorWebScriptTest.java    From alfresco-remote-api with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void testAncestorOfTypeNodeLocator() throws Exception
{
    AuthenticationUtil.setFullyAuthenticatedUser(AuthenticationUtil.getAdminUserName());
    NodeRef folder= makeChildFolderNode(companyHome);
    try
    {
        NodeRef sysFolder = makeChildSystemFolderNode(folder);
        NodeRef subFolder = makeChildFolderNode(sysFolder);
        NodeRef source = makeChildContentNode(subFolder);
        
        // No params so should find first parent.
        String ancestorUrl = makeUrl(source, AncestorNodeLocator.NAME);
        checkNodeLocator(ancestorUrl, subFolder);
        
        // Set type to cm:content. Should not match any node.
        String encodedContentType = URLEncoder.encode(ContentModel.TYPE_CONTENT.toPrefixString(namespaceService));
        String contentAncestorUrl = ancestorUrl + "?type=" + encodedContentType;
        checkNodeLocator(contentAncestorUrl, null);
        
        // Set type to cm:systemfolder. Should find the sysFolder node.
        String encodedSysFolderType = URLEncoder.encode(ContentModel.TYPE_SYSTEM_FOLDER.toPrefixString(namespaceService));
        String sysFolderAncestorUrl = ancestorUrl + "?type=" + encodedSysFolderType;
        checkNodeLocator(sysFolderAncestorUrl, sysFolder);
        
        // Set aspect to cm:ownable. Should not match any node.
        String encodedOwnableAspect= URLEncoder.encode(ContentModel.ASPECT_OWNABLE.toPrefixString(namespaceService));
        String ownableAncestorUrl = ancestorUrl + "?aspect=" + encodedOwnableAspect;
        checkNodeLocator(ownableAncestorUrl, null);
        
        // Add ownable aspect to folder node. Now that node should be found.
        nodeService.addAspect(folder, ContentModel.ASPECT_OWNABLE, null);
        checkNodeLocator(ownableAncestorUrl, folder);

        // Set aspect to cm:ownable and type to cm:systemfolder. Should not match any node.
        String ownableSysFolderAncestorUrl = sysFolderAncestorUrl + "&aspect=" + encodedOwnableAspect;
        checkNodeLocator(ownableSysFolderAncestorUrl, null);
        
        // Set aspect to cm:ownable and type to cm:folder. Should find folder node.
        String encodedFOlderType = URLEncoder.encode(ContentModel.TYPE_FOLDER.toPrefixString(namespaceService));
        String ownableFolderAncestorUrl = ownableAncestorUrl + "&type=" + encodedFOlderType;
        checkNodeLocator(ownableFolderAncestorUrl, folder);
    }
    finally
    {
        nodeService.deleteNode(folder);
    }
}
 
Example #25
Source File: AbstractRemoteAlfrescoTicketImpl.java    From alfresco-repository with GNU Lesser General Public License v3.0 2 votes vote down vote up
/**
 * Returns the Ticket as a URL Escaped Parameter fragment, such as 
 *  "ticket=12%20xx&sig=2". Special characters in the URL are escaped 
 *  suitable for using as full URL, but any ampersands are not escaped 
 *  (it's not HTML escaped)  
 */
public String getAsEscapedUrlParameters()
{
    String unescaped = getAsUrlParameters();
    return URLEncoder.encodeUri(unescaped);
}