001    /**
002     * Copyright (c) 2000-2012 Liferay, Inc. All rights reserved.
003     *
004     * This library is free software; you can redistribute it and/or modify it under
005     * the terms of the GNU Lesser General Public License as published by the Free
006     * Software Foundation; either version 2.1 of the License, or (at your option)
007     * any later version.
008     *
009     * This library is distributed in the hope that it will be useful, but WITHOUT
010     * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
011     * FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more
012     * details.
013     */
014    
015    package com.liferay.portal.sharepoint.methods;
016    
017    import com.liferay.portal.kernel.log.Log;
018    import com.liferay.portal.kernel.log.LogFactoryUtil;
019    import com.liferay.portal.kernel.util.Validator;
020    import com.liferay.portal.sharepoint.Property;
021    import com.liferay.portal.sharepoint.ResponseElement;
022    import com.liferay.portal.sharepoint.SharepointRequest;
023    import com.liferay.portal.sharepoint.SharepointUtil;
024    
025    import java.util.ArrayList;
026    import java.util.List;
027    
028    /**
029     * @author Bruno Farache
030     */
031    public class UrlToWebUrlMethodImpl extends BaseMethodImpl {
032    
033            public String getMethodName() {
034                    return _METHOD_NAME;
035            }
036    
037            @Override
038            protected List<ResponseElement> getElements(
039                    SharepointRequest sharepointRequest) {
040    
041                    List<ResponseElement> elements = new ArrayList<ResponseElement>();
042    
043                    String url = sharepointRequest.getParameterValue("url");
044    
045                    if (Validator.isNotNull(url)) {
046                            if (_log.isInfoEnabled()) {
047                                    _log.info("Original URL " + url);
048                            }
049    
050                            url = SharepointUtil.stripService(url, false);
051    
052                            if (_log.isInfoEnabled()) {
053                                    _log.info("Modified URL " + url);
054                            }
055    
056                            elements.add(new Property("fileUrl", url));
057                            elements.add(new Property("webUrl", "/sharepoint"));
058                    }
059                    else if (_log.isInfoEnabled()) {
060                            _log.info("URL is " + url);
061                    }
062    
063                    return elements;
064            }
065    
066            private static final String _METHOD_NAME = "url to web url";
067    
068            private static Log _log = LogFactoryUtil.getLog(
069                    UrlToWebUrlMethodImpl.class);
070    
071    }