Examples of VanityUrl


Examples of org.jahia.services.seo.VanityUrl

                if (StringUtils.isNotEmpty(outboundUrl) && !URLGenerator.isLocalhost(hsRequest.getServerName())) {
                    String url = StringUtils.substringAfter(outboundUrl,hsRequest.getContextPath()+"/cms");
                    URLResolver urlResolver = urlResolverFactory.createURLResolver(url, hsRequest.getServerName() ,hsRequest);
                    if (urlResolver.isMapped()) {
                        try {
                            VanityUrl vanityUrl = vanityUrlService
                                    .getVanityUrlForWorkspaceAndLocale(
                                            urlResolver.getNode(),
                                            urlResolver.getWorkspace(),
                                            urlResolver.getLocale());
                            if (vanityUrl != null) {
                                outboundUrl = outboundUrl.replace("/" + urlResolver.getLocale()
                                        + urlResolver.getPath(), vanityUrl.getUrl());
                            }
                        } catch (RepositoryException e) {
                            logger.debug("Error when trying to obtain vanity url", e);
                        }
                    }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

            JCRSessionWrapper session) throws ItemNotFoundException, RepositoryException, ConstraintViolationException {
        String site = JCRContentUtils.getSiteKey(gwtNode.getPath());
        List<VanityUrl> vanityUrls = new LinkedList<VanityUrl>();
        for (GWTJahiaUrlMapping mapping : mappings) {
            if (StringUtils.isNotBlank(mapping.getUrl())) {
                VanityUrl url = new VanityUrl(mapping.getUrl(), site, mapping.getLanguage(), mapping.isDefault(),
                        mapping.isActive());
                url.setPath(mapping.getPath());
                vanityUrls.add(url);
            }
        }
        urlService.saveVanityUrlMappings(session.getNodeByIdentifier(gwtNode.getUUID()), vanityUrls, updatedLocales);
    }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

                                + JCRContentUtils.stringToQueryLiteral(url)
                                + "]", Query.XPATH).execute();
        List<VanityUrl> existingUrls = new ArrayList<VanityUrl>();
        for (NodeIterator it = result.getNodes(); it.hasNext();) {
            JCRNodeWrapper node = (JCRNodeWrapper) it.next();
            existingUrls.add(populateJCRData(node, new VanityUrl()));
        }

        return existingUrls;
    }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

     * @return the VanityUrl bean
     * @throws RepositoryException if there was an unexpected exception accessing the repository
     */
    public VanityUrl getVanityUrlForCurrentLocale(JCRNodeWrapper contentNode,
            JCRSessionWrapper session) throws RepositoryException {
        VanityUrl vanityUrl = null;
        if (contentNode.isNodeType(JAHIAMIX_VANITYURLMAPPED)) {
            String currentLanguage = session.getLocale().toString();
            contentNode = session.getNodeByUUID(contentNode.getIdentifier());
            for (NodeIterator it = contentNode.getNode(VANITYURLMAPPINGS_NODE).getNodes(); it
                    .hasNext();) {
                JCRNodeWrapper currentNode = (JCRNodeWrapper) it.next();
                if (currentNode.getPropertyAsString(JCR_LANGUAGE).equals(
                        currentLanguage)) {
                    if (vanityUrl == null
                            || currentNode.getProperty(PROPERTY_DEFAULT)
                                    .getBoolean()) {
                        vanityUrl = populateJCRData(currentNode,
                                new VanityUrl());
                    }
                    if (vanityUrl.isDefaultMapping()) {
                        break;
                    }
                }
            }
        }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

        if (contentNode.isNodeType(JAHIAMIX_VANITYURLMAPPED)) {
            for (NodeIterator it = contentNode.getNode(VANITYURLMAPPINGS_NODE).getNodes(); it
                    .hasNext();) {
                JCRNodeWrapper currentNode = (JCRNodeWrapper) it.next();
                if (currentNode.getPropertyAsString(JCR_LANGUAGE).equals(languageCode)) {
                    vanityUrls.add(populateJCRData(currentNode, new VanityUrl()));
                }
            }
        }
        return vanityUrls;
    }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

                            .get(language);
                    if (existingVanityUrls == null) {
                        existingMappings.put(language,
                                new HashMap<String, VanityUrl>());
                    }
                    VanityUrl vanityUrl = populateJCRData(currentNode,
                            new VanityUrl());
                    existingMappings.get(language).put(currentNode.getName(), vanityUrl);
                    if (currentNode.getProperty(PROPERTY_DEFAULT).getBoolean()) {
                        oldDefaultMappings.put(language, new DefaultKeyValue(
                                currentNode.getName(), vanityUrl));
                    }
                }
            }
        }
       
        // as next we need to find out, which mappings need to be updated or added and
        // get the collection of new default mappings.
        List<VanityUrl> toAdd = new ArrayList<VanityUrl>();
        Map<String, VanityUrl> toUpdate = new HashMap<String, VanityUrl>();
        Map<String, VanityUrl> newDefaultMappings = new HashMap<String, VanityUrl>();

        for (VanityUrl vanityUrl : vanityUrls) {
            if (vanityUrl.isDefaultMapping()) {
                VanityUrl otherDefaultMapping = newDefaultMappings.put(
                        vanityUrl.getLanguage(), vanityUrl);
                if (otherDefaultMapping != null) {

                    throw new ConstraintViolationException(
                            "Two mappings are set as default for the same language: "
                                    + vanityUrl.getUrl() + " and "
                                    + otherDefaultMapping.getUrl()
                                    + " for language: "
                                    + vanityUrl.getLanguage(), null);
                }
            }
            boolean found = false;
            Map<String, VanityUrl> mappings = existingMappings.get(vanityUrl
                    .getLanguage());
            if (mappings != null) {
                for (Map.Entry<String, VanityUrl> entry : mappings.entrySet()) {
                    if (entry.getValue().equals(vanityUrl)) {
                        mappings.remove(entry.getKey());
                        found = true;
                        if (entry.getValue().isActive() != vanityUrl.isActive()
                                || entry.getValue().isDefaultMapping() != vanityUrl
                                        .isDefaultMapping()) {
                            vanityUrl.setIdentifier(entry.getValue()
                                    .getIdentifier());
                            toUpdate.put(entry.getKey(), vanityUrl);
                        }
                        break;
                    }
                }
            }
            if (!found) {
                toAdd.add(vanityUrl);
            }
        }
        // Compare the new default settings with the old ones to see which mapping should
        // be default. Also consider the case, that in the new collection none is set to
        // default, then we take the previous default one or if there was also no default,
        // then the first found mapping for a language will be default.
        if (!newDefaultMappings.keySet().containsAll(updatedLocales)) {
            for (String locale : updatedLocales) {
                if (!newDefaultMappings.containsKey(locale)) {
                    boolean defaultWasSet = false;
                    VanityUrl oldDefaultVanityUrl = null;
                    if (oldDefaultMappings.get(locale) != null) {
                        oldDefaultVanityUrl = (VanityUrl) oldDefaultMappings
                                .get(locale).getValue();

                        for (Map.Entry<String, VanityUrl> entry : toUpdate
                                .entrySet()) {
                            VanityUrl vanityUrl = entry.getValue();
                            if (vanityUrl.equals(oldDefaultVanityUrl)) {
                                vanityUrl.setDefaultMapping(true);
                                newDefaultMappings.put(locale, vanityUrl);
                                defaultWasSet = true;
                            }
                        }
                    }
                    if (!defaultWasSet) {
                        for (VanityUrl vanityUrl : vanityUrls) {
                            if (locale.equals(vanityUrl.getLanguage())) {
                                vanityUrl.setDefaultMapping(true);
                                newDefaultMappings.put(locale, vanityUrl);
                                break;
                            }
                        }
                    }
                }
            }
        }
        // At last we need to see, which mappings are no longer existing in the new collection,
        // which means that they need to be completely removed
        List<Map.Entry<String, VanityUrl>> toDelete = new ArrayList<Map.Entry<String, VanityUrl>>();
        for (Map<String, VanityUrl> existingVanityUrls : existingMappings
                .values()) {
            toDelete.addAll(existingVanityUrls.entrySet());
        }
        // Compare the new default settings with the old ones to know if the default flag needs
        // to be set to false for the previous default.
        List<String> removeDefaultMapping = new ArrayList<String>();
        for (Map.Entry<String, KeyValue> oldDefaultMapping : oldDefaultMappings
                .entrySet()) {
            VanityUrl oldDefaultVanityUrl = (VanityUrl) oldDefaultMapping
                    .getValue().getValue();
            VanityUrl newDefaultVanityUrl = newDefaultMappings
                    .get(oldDefaultMapping.getKey());
            if (!oldDefaultVanityUrl.equals(newDefaultVanityUrl)) {
                boolean oldDefaultWillBeDeleted = false;
                for (Map.Entry<String, VanityUrl> entry : toDelete) {
                    if (oldDefaultVanityUrl.equals(entry.getValue())) {
                        oldDefaultWillBeDeleted = true;
                        break;
                    }
                }
                if (!(oldDefaultWillBeDeleted || toUpdate.entrySet().contains(
                        oldDefaultVanityUrl))) {
                    removeDefaultMapping.add((String) oldDefaultMapping
                            .getValue().getKey());
                }
            }
        }

        // Check if the added vanity URLs are really unique for the site
        for (VanityUrl vanityUrl : toAdd) {
            checkUniqueConstraint(contentNode, vanityUrl, toDelete, session);
        }
       
        // If there is no change do nothing otherwise do all the operations and
        // save the session
        if (toUpdate.isEmpty() && toAdd.isEmpty() && toDelete.isEmpty()) {
            return false;           
        } else {
            session.checkout(vanityUrlMappingsNode);
            for (Map.Entry<String, VanityUrl> entry : toUpdate.entrySet()) {
                JCRNodeWrapper vanityUrlNode = vanityUrlMappingsNode
                        .getNode(entry.getKey());
                VanityUrl vanityUrl = entry.getValue();
                session.checkout(vanityUrlNode);
                vanityUrlNode
                        .setProperty(PROPERTY_ACTIVE, vanityUrl.isActive());
                vanityUrlNode.setProperty(PROPERTY_DEFAULT, vanityUrl
                        .isDefaultMapping());
            }
            for (String index : removeDefaultMapping) {
                JCRNodeWrapper vanityUrlNode = vanityUrlMappingsNode
                        .getNode(index);
                session.checkout(vanityUrlNode);
                vanityUrlNode.setProperty(PROPERTY_DEFAULT, false);
            }
            for (Map.Entry<String, VanityUrl> entry : toDelete) {
                JCRNodeWrapper vanityUrlNode = vanityUrlMappingsNode
                        .getNode(entry.getKey());
                session.checkout(vanityUrlNode);
                vanityUrlNode.remove();
            }

            for (VanityUrl vanityUrl : toAdd) {
                JCRNodeWrapper vanityUrlNode = vanityUrlMappingsNode.addNode(
                        JCRContentUtils.escapeLocalNodeName(vanityUrl.getUrl()), JAHIANT_VANITYURL);
                session.checkout(vanityUrlNode);
                vanityUrlNode.setProperty(PROPERTY_URL, vanityUrl.getUrl());
                vanityUrlNode
                        .setProperty(JCR_LANGUAGE, vanityUrl.getLanguage());
                vanityUrlNode
                        .setProperty(PROPERTY_ACTIVE, vanityUrl.isActive());
                vanityUrlNode.setProperty(PROPERTY_DEFAULT, vanityUrl
                        .isDefaultMapping());
            }
            session.save();
        }
        return true;
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

        String value = attrValue;
        if (StringUtils.isNotEmpty(attrValue) && !URLGenerator.isLocalhost(context.getRequest().getServerName())) {
            URLResolver urlResolver = urlResolverFactory.createURLResolver(attrValue, context);
            if (urlResolver.isMapped()) {
                try {
                    VanityUrl vanityUrl = vanityUrlService
                            .getVanityUrlForWorkspaceAndLocale(
                                    urlResolver.getNode(),
                                    urlResolver.getWorkspace(),
                                    urlResolver.getLocale());
                    if (vanityUrl != null) {
                        value = attrValue.replace("/" + urlResolver.getLocale()
                                + urlResolver.getPath(), vanityUrl.getUrl());
                    }
                } catch (RepositoryException e) {
                    logger.debug("Error when trying to obtain vanity url", e);
                }
            }
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

            init();
            if (!URLGenerator.isLocalhost(serverName) && isMappable()
                    && SettingsBean.getInstance().isPermanentMoveForVanityURL()) {
                try {
                    if (siteKeyByServerName != null && siteKeyByServerName.equals(getNode().getResolveSite().getSiteKey()) ) {
                        VanityUrl defaultVanityUrl = getVanityUrlService()
                                .getVanityUrlForWorkspaceAndLocale(getNode(),
                                        workspace, locale);
                        if (defaultVanityUrl != null && defaultVanityUrl.isActive()) {
                            if (request == null || StringUtils.isEmpty(request.getQueryString())) {
                                setRedirectUrl(defaultVanityUrl.getUrl());
                            } else {
                                setRedirectUrl(defaultVanityUrl.getUrl() + "?" + request.getQueryString());
                            }
                        }
                    }
                } catch (PathNotFoundException e) {
                    logger.debug("Path not found : " + urlPathInfo);
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

                String tempWorkspace = verifyWorkspace(StringUtils.substringBefore(getPath(), "/"));
                tempPath = StringUtils.substringAfter(getPath(), "/");
                List<VanityUrl> vanityUrls = getVanityUrlService()
                        .findExistingVanityUrls("/" + tempPath,
                                StringUtils.EMPTY, tempWorkspace);
                VanityUrl resolvedVanityUrl = null;
                for (VanityUrl vanityUrl : vanityUrls) {
                    if (vanityUrl.isActive()
                            && (StringUtils.isEmpty(getSiteKey()) || getSiteKey().equals(
                            vanityUrl.getSite()))) {
                        resolvedVanityUrl = vanityUrl;
                        break;
                    }
                }
                if (resolvedVanityUrl != null) {
                    workspace = tempWorkspace;
                    locale = StringUtils.isEmpty(resolvedVanityUrl
                            .getLanguage()) ? DEFAULT_LOCALE
                            : LanguageCodeConverters
                            .languageCodeToLocale(resolvedVanityUrl
                                    .getLanguage());
                    path = StringUtils.substringBefore(resolvedVanityUrl
                            .getPath(), VANITY_URL_NODE_PATH_SEGMENT)
                            + ".html";
                    setVanityUrl(resolvedVanityUrl.getUrl());
                    if (SettingsBean.getInstance()
                            .isPermanentMoveForVanityURL()
                            && !resolvedVanityUrl.isDefaultMapping()) {
                        VanityUrl defaultVanityUrl = getVanityUrlService()
                                .getVanityUrlForWorkspaceAndLocale(getNode(),
                                        workspace, locale);
                        if (defaultVanityUrl != null
                                && defaultVanityUrl.isActive() && !resolvedVanityUrl.equals(defaultVanityUrl)) {
                            setRedirectUrl(defaultVanityUrl.getUrl());
                        }
                    }
                    mappingResolved = true;
                }
            } catch (RepositoryException e) {
View Full Code Here

Examples of org.jahia.services.seo.VanityUrl

        JCRNodeWrapper pageNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage");
        JCRNodeWrapper contentNode = session.getNode(SITECONTENT_ROOT_NODE
                + "/testPage/testContent");

        VanityUrl vanityUrl = new VanityUrl("/testpage", TESTSITE_NAME, "en");
        vanityUrl.setDefaultMapping(true);
        vanityUrl.setActive(true);
        assertTrue("URL mapping should not exist yet", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        getVanityUrlService().saveVanityUrlMapping(pageNode, vanityUrl);
        assertFalse("URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());
        try {
            getVanityUrlService().saveVanityUrlMapping(contentNode, vanityUrl);
            assertTrue("Exception should have been thrown", false);
        } catch (ConstraintViolationException ex) {
            // expected
        }

        VanityUrl newVanityUrl = new VanityUrl("/testcontent", TESTSITE_NAME,
                "en");
        newVanityUrl.setDefaultMapping(true);
        newVanityUrl.setActive(true);
        getVanityUrlService().saveVanityUrlMapping(contentNode, newVanityUrl);
        assertFalse("New URL mapping should exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
                        vanityUrl.getSite(), Constants.EDIT_WORKSPACE)
                .isEmpty());

        VanityUrl savedVanityUrl = getVanityUrlService()
                .getVanityUrlForWorkspaceAndLocale(pageNode,
                        session.getWorkspace().getName(), session.getLocale());
        assertTrue("Wrong page vanity URL returned", vanityUrl.getUrl().equals(
                savedVanityUrl.getUrl()));

        VanityUrl savedNewVanityUrl = getVanityUrlService()
                .getVanityUrlsForCurrentLocale(contentNode, session).get(0);
        assertTrue("Wrong container vanity URL returned", newVanityUrl.getUrl()
                .equals(savedNewVanityUrl.getUrl()));

        getVanityUrlService().removeVanityUrlMapping(pageNode, vanityUrl);
        getVanityUrlService().removeVanityUrlMapping(contentNode, newVanityUrl);
        assertTrue("URL mapping should no longer exist", getVanityUrlService()
                .findExistingVanityUrls(vanityUrl.getUrl(),
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.