protected void parseNameAndNamespace()

in core/src/main/java/org/apache/struts2/dispatcher/mapper/DefaultActionMapper.java [347:399]


    protected void parseNameAndNamespace(String uri, ActionMapping mapping, ConfigurationManager configManager) {
        String actionNamespace, actionName;
        int lastSlash = uri.lastIndexOf('/');
        if (lastSlash == -1) {
            actionNamespace = "";
            actionName = uri;
        } else if (lastSlash == 0) {
            // ww-1046, assume it is the root namespace, it will fallback to
            // default
            // namespace anyway if not found in root namespace.
            actionNamespace = "/";
            actionName = uri.substring(lastSlash + 1);
        } else if (alwaysSelectFullNamespace) {
            // Simply select the namespace as everything before the last slash
            actionNamespace = uri.substring(0, lastSlash);
            actionName = uri.substring(lastSlash + 1);
        } else {
            // Try to find the namespace in those defined, defaulting to ""
            Configuration config = configManager.getConfiguration();
            String prefix = uri.substring(0, lastSlash);
            actionNamespace = "";
            boolean rootAvailable = false;
            // Find the longest matching namespace, defaulting to the default
            for (PackageConfig cfg : config.getPackageConfigs().values()) {
                String ns = cfg.getNamespace();
                if (ns != null && prefix.startsWith(ns) && (prefix.length() == ns.length() || prefix.charAt(ns.length()) == '/')) {
                    if (ns.length() > actionNamespace.length()) {
                        actionNamespace = ns;
                    }
                }
                if ("/".equals(ns)) {
                    rootAvailable = true;
                }
            }

            actionName = uri.substring(actionNamespace.length() + 1);

            // Still none found, use root namespace if found
            if (rootAvailable && actionNamespace.isEmpty()) {
                actionNamespace = "/";
            }
        }

        if (!allowSlashesInActionNames) {
            int pos = actionName.lastIndexOf('/');
            if (pos > -1 && pos < actionName.length() - 1) {
                actionName = actionName.substring(pos + 1);
            }
        }

        mapping.setNamespace(cleanupNamespaceName(actionNamespace));
        mapping.setName(cleanupActionName(actionName));
    }