Changeset 1699

Show
Ignore:
Timestamp:
2008-03-15 17:23:28 (8 months ago)
Author:
mosipov
Message:

CLOSED - #2007: Rework response url handling

Location:
FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/connector/ConnectorServlet.java

    r1697 r1699  
    129129                                        .getDefaultResourceType(typeStr); 
    130130 
    131                         String typePath = constructResourceTypeUrl(resourceType, request); 
     131                        String typePath = Utils.constructResponseUrl(request, resourceType,  
     132                                        currentFolderStr, false, false); 
    132133                        String typeDirPath = getServletContext().getRealPath(typePath); 
    133                         String currentPath = typePath + currentFolderStr; 
    134134 
    135135                        File typeDir = new File(typeDirPath); 
     
    143143 
    144144                                xr = new XmlResponse(command, resourceType, currentFolderStr, 
    145                                                 currentPath, request); 
     145                                                Utils.constructResponseUrl(request, resourceType,  
     146                                                                currentFolderStr, true,  
     147                                                                ConnectorHandler.isFullUrl())); 
    146148 
    147149                                if (command.equals(CommandHandler.GET_FOLDERS)) 
     
    228230                        ResourceTypeHandler resourceType = ResourceTypeHandler.getDefaultResourceType(typeStr); 
    229231                         
    230                         String typePath = constructResourceTypeUrl(resourceType, request); 
     232                        String typePath = Utils.constructResponseUrl(request, resourceType,  
     233                                        currentFolderStr, false, false); 
    231234                        String typeDirPath = getServletContext().getRealPath(typePath); 
    232                         String currentPath = typePath + currentFolderStr; 
    233235 
    234236                        File typeDir = new File(typeDirPath); 
     
    273275                                                if (Utils.isEmpty(newFilename)) 
    274276                                                        ur = new UploadResponse(UploadResponse.EN_OK, Utils 
    275                                                                         .constructServerAddress(request, 
    276                                                                                         currentPath).concat(filename)); 
     277                                                                        .constructResponseUrl(request, 
     278                                                                                        resourceType, currentFolderStr, 
     279                                                                                        true, ConnectorHandler.isFullUrl()) 
     280                                                                        .concat(filename)); 
    277281                                                else 
    278282                                                        ur = new UploadResponse(UploadResponse.EN_RENAMED, 
    279                                                                         Utils.constructServerAddress(request, 
    280                                                                                         currentPath).concat(newFilename), 
    281                                                                         newFilename); 
     283                                                                        Utils.constructResponseUrl(request, 
     284                                                                                        resourceType, currentFolderStr, 
     285                                                                                        true, ConnectorHandler.isFullUrl()) 
     286                                                                                        .concat(newFilename), newFilename); 
    282287 
    283288                                                // secure image check 
     
    309314        } 
    310315 
    311         private String constructResponseUrl(final ResourceTypeHandler fileType, 
    312                 final String currentFolderString, final HttpServletRequest request) { 
    313                 StringBuffer sb = new StringBuffer(); 
    314                 sb.append(ConnectorHandler.getUserFilesPath(request)); 
    315                 sb.append(fileType.getPath()); 
    316                 if (Utils.isNotEmpty(currentFolderString)) 
    317                         sb.append(currentFolderString); 
    318                 return Utils.replaceAll(sb.toString(), "//", "/"); 
    319         } 
    320          
    321         /** 
    322          * TODO document me! 
    323          * @param resourceType 
    324          * @param request 
    325          * @return 
    326          */ 
    327         private String constructResourceTypeUrl(final ResourceTypeHandler resourceType, 
    328                         final HttpServletRequest request) { 
    329                 return constructResponseUrl(resourceType, null, request); 
    330         } 
    331  
    332316} 
  • FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/response/XmlResponse.java

    r1690 r1699  
    2525import java.io.StringWriter; 
    2626 
    27 import javax.servlet.http.HttpServletRequest; 
    2827import javax.xml.parsers.DocumentBuilder; 
    2928import javax.xml.parsers.DocumentBuilderFactory; 
     
    7877 
    7978        /** 
     79         *  
    8080         * @param command 
    81          *            file browser 
     81         * @param resourceType 
     82         * @param currentFolder 
    8283         * @param constructedUrl 
    83          *            TODO 
    8484         */ 
    85         public XmlResponse(CommandHandler command, ResourceTypeHandler type, String currentFolder, 
    86                         String constructedUrl, HttpServletRequest request) { 
     85        public XmlResponse(CommandHandler command, ResourceTypeHandler resourceType,  
     86                        String currentFolder, String constructedUrl) { 
    8787 
    8888                try { 
     
    9898                document.appendChild(root); 
    9999                root.setAttribute("command", command.toString()); 
    100                 root.setAttribute("resourceType", type.toString()); 
     100                root.setAttribute("resourceType", resourceType.toString()); 
    101101 
    102102                Element currentFolderElement = document.createElement("CurrentFolder"); 
    103103                currentFolderElement.setAttribute("path", currentFolder); 
    104104 
    105                 currentFolderElement.setAttribute("url", Utils.constructServerAddress( 
    106                                 request, constructedUrl)); 
     105                currentFolderElement.setAttribute("url", constructedUrl); 
    107106                root.appendChild(currentFolderElement); 
    108107 
  • FCKeditor.Java/branches/2.4/src/main/java/net/fckeditor/tool/Utils.java

    r1644 r1699  
    2828 
    2929import net.fckeditor.handlers.ConnectorHandler; 
     30import net.fckeditor.handlers.ResourceTypeHandler; 
    3031 
    3132 
     
    146147                else 
    147148                        return request.getContextPath() + url; 
    148         }        
     149        } 
     150         
     151        /** 
     152         *  
     153         * @param request 
     154         * @param resourceType 
     155         * @param urlPath TODO 
     156         * @param prependContextPath 
     157         * @param fullUrl 
     158         * @return 
     159         */ 
     160        public static String constructResponseUrl(HttpServletRequest request, 
     161                        ResourceTypeHandler resourceType, String urlPath, 
     162                        boolean prependContextPath, boolean fullUrl) { 
     163                         
     164                StringBuffer sb = new StringBuffer(); 
     165                 
     166                if (fullUrl) { 
     167                        String address = request.getRequestURL().toString(); 
     168                        sb.append(address.substring(0, address.indexOf('/', 8)) 
     169                                        + request.getContextPath()); 
     170                } 
     171                 
     172                if (prependContextPath && !fullUrl) 
     173                        sb.append(request.getContextPath()); 
     174                 
     175                sb.append(ConnectorHandler.getUserFilesPath(request)); 
     176                sb.append(resourceType.getPath()); 
     177                 
     178                if (isNotEmpty(urlPath)) 
     179                        sb.append(urlPath); 
     180                 
     181                return sb.toString(); 
     182        } 
     183         
     184        public static String constructResponseUrl(HttpServletRequest request, 
     185                        ResourceTypeHandler resourceType, boolean prependContextPath,  
     186                        boolean fullUrl) { 
     187                return constructResponseUrl(request, resourceType, null,  
     188                                prependContextPath, fullUrl); 
     189        } 
    149190}