/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */
package org.xwiki.url.internal.standard;

import javax.inject.Inject;
import javax.inject.Named;
import javax.inject.Singleton;

import org.apache.commons.lang.StringUtils;
import org.xwiki.component.annotation.Component;
import org.xwiki.configuration.ConfigurationSource;

/**
 * Replaces {@link DefaultStandardURLConfiguration} with fallbacks to configuration properties defined in the
 * {@code xwiki.cfg} configuration file.
 * 
 * @version $Id$
 * @since 5.1M1
 */
@Component
@Singleton
public class LegacyStandardURLConfiguration extends DefaultStandardURLConfiguration
{
    @Inject
    @Named("xwikicfg")
    private ConfigurationSource configuration;

    @Override
    public boolean isPathBasedMultiWiki()
    {
        return super.isPathBasedMultiWiki("1".equals(this.configuration.getProperty("xwiki.virtual.usepath", "1")));
    }

    @Override
    public String getWikiPathPrefix()
    {
        return super.getWikiPathPrefix(this.configuration.getProperty("xwiki.virtual.usepath.servletpath", "wiki"));
    }

    @Override
    public String getEntityPathPrefix()
    {
        String prefix = super.getWikiPathPrefix(this.configuration.getProperty("xwiki.defaultservletpath", "bin"));

        // Remove potential trailing "/" since the documentation in xwiki.cfg says it should contain a trailing "/" but
        // getEntityPathPrefix should return the prefix without "/"...
        prefix = StringUtils.removeEnd(prefix, "/");

        return prefix;
    }

    @Override
    public WikiNotFoundBehavior getWikiNotFoundBehavior()
    {
        WikiNotFoundBehavior legacyBehavior = WikiNotFoundBehavior.DISPLAY_ERROR;

        String legacyValue = this.configuration.getProperty("xwiki.virtual.failOnWikiDoesNotExist", "0");

        if (!"1".equals(legacyValue)) {
            legacyBehavior = WikiNotFoundBehavior.REDIRECT_TO_MAIN_WIKI;
        }

        return super.getWikiNotFoundBehavior(legacyBehavior);
    }
}

@@ -1533,29 +1533,24 @@
 nSource 
-configuration
+xwikicfg
 ;%0A%0A    @
@@ -1660,37 +1660,32 @@
 equals(this.
-configuration
+xwikicfg
 .getProperty
@@ -1823,37 +1823,32 @@
 Prefix(this.
-configuration
+xwikicfg
 .getProperty
@@ -2011,37 +2011,32 @@
 Prefix(this.
-configuration
+xwikicfg
 .getProperty
@@ -2544,29 +2544,24 @@
  = this.
-configuration
+xwikicfg
 .getProp

Make xwiki.cfg accessible without XWiki instance * fix regression