Woonsan Ko pushed to branch feature/HSTTWO-3623 at cms-community / 
hippo-site-toolkit


Commits:
9b1ca067 by Woonsan Ko at 2016-03-21T21:47:36-04:00
HSTTWO-3623: package renaming; simplifying cache registry

- - - - -


11 changed files:

- 
api/src/main/java/org/hippoecm/hst/content/service/HippoTranslationBeanService.java
 → 
api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationBeanService.java
- + 
api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationContentRegistry.java
- api/src/main/java/org/hippoecm/hst/content/service/package-info.java → 
api/src/main/java/org/hippoecm/hst/content/service/translation/package-info.java
- 
components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml
- 
components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-observation.xml
- 
content-beans/src/main/java/org/hippoecm/hst/content/beans/standard/AvailableTranslations.java
- 
content-beans/src/main/java/org/hippoecm/hst/content/service/CachingHippoTranslationBeanServiceImpl.java
 → 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationBeanServiceImpl.java
- + 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationEventListener.java
- 
content-beans/src/main/java/org/hippoecm/hst/content/service/DefaultHippoTranslationBeanServiceImpl.java
 → 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationBeanServiceImpl.java
- + 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationContentRegistry.java
- + 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslatedContentUtils.java


Changes:

=====================================
api/src/main/java/org/hippoecm/hst/content/service/HippoTranslationBeanService.java
 → 
api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationBeanService.java
=====================================
--- 
a/api/src/main/java/org/hippoecm/hst/content/service/HippoTranslationBeanService.java
+++ 
b/api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationBeanService.java
@@ -13,7 +13,7 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.hippoecm.hst.content.service;
+package org.hippoecm.hst.content.service.translation;
 
 import java.util.List;
 import java.util.Map;


=====================================
api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationContentRegistry.java
=====================================
--- /dev/null
+++ 
b/api/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslationContentRegistry.java
@@ -0,0 +1,30 @@
+/**
+ * Copyright 2016-2016 Hippo B.V. (http://www.onehippo.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.content.service.translation;
+
+import java.util.Set;
+
+public interface HippoTranslationContentRegistry {
+
+    public Set<String> getDocumentHandleIdsByTranslationId(String 
translationId);
+
+    public void putDocumentHandleIdsForTranslationId(String translationId, 
Set<String> documentHandleIds);
+
+    public boolean removeDocumentHandleIdsByTranslationId(String 
translationId);
+
+    public boolean removeDocumentHandleId(String documentHandleId);
+
+}


=====================================
api/src/main/java/org/hippoecm/hst/content/service/package-info.java → 
api/src/main/java/org/hippoecm/hst/content/service/translation/package-info.java
=====================================
--- a/api/src/main/java/org/hippoecm/hst/content/service/package-info.java
+++ 
b/api/src/main/java/org/hippoecm/hst/content/service/translation/package-info.java
@@ -15,6 +15,6 @@
  */
 
 /**
- * The org.hippoecm.hst.content.service package defines the content related 
services.
+ * The org.hippoecm.hst.content.service.translation package defines the Hippo 
Translation related services.
  */
-package org.hippoecm.hst.content.service;
+package org.hippoecm.hst.content.service.translation;


=====================================
components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml
=====================================
--- 
a/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml
+++ 
b/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-content-beans.xml
@@ -32,8 +32,19 @@
     <property name="defaultContentRewriterClassName" 
value="${default.hst.contentrewriter.class}" />
   </bean>
 
+  <!--
   <bean id="org.hippoecm.hst.content.service.HippoTranslationBeanService"
         
class="org.hippoecm.hst.content.service.DefaultHippoTranslationBeanServiceImpl">
   </bean>
+  -->
+
+  <bean 
id="org.hippoecm.hst.content.service.translation.HippoTranslationContentRegistry"
+        
class="org.hippoecm.hst.content.service.translation.DefaultHippoTranslationContentRegistry">
+  </bean>
+
+  <bean id="org.hippoecm.hst.content.service.HippoTranslationBeanService"
+        
class="org.hippoecm.hst.content.service.translation.CachingHippoTranslationBeanServiceImpl">
+    <constructor-arg 
ref="org.hippoecm.hst.content.service.translation.HippoTranslationContentRegistry"
 />
+  </bean>
 
 </beans>


=====================================
components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-observation.xml
=====================================
--- 
a/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-observation.xml
+++ 
b/components/core/src/main/resources/org/hippoecm/hst/site/container/SpringComponentManager-observation.xml
@@ -397,6 +397,33 @@
           </property>
         </bean>
 
+        <!-- Changes in the hippotranslation:translated documents to update 
hippo translation cache. -->
+        <bean class="org.hippoecm.hst.core.jcr.EventListenerItemImpl">
+          <property name="nodeAddedEnabled" value="true"/>
+          <property name="nodeRemovedEnabled" value="true"/>
+          <property name="propertyAddedEnabled" value="false"/>
+          <property name="propertyChangedEnabled" value="false"/>
+          <property name="propertyRemovedEnabled" value="false"/>
+          <property name="absolutePath" value="/content"/>
+          <property name="deep" value="true"/>
+          <property name="uuids">
+            <null/>
+          </property>
+          <property name="nodeTypeNames">
+            <list>
+              <value>hippostd:folder</value>
+            </list>
+          </property>
+          <property name="noLocal" value="false"/>
+          <property name="eventListener">
+            <bean parent="baseEventListener" 
class="org.hippoecm.hst.content.service.translation.CachingHippoTranslationEventListener">
+              <constructor-arg ref="javax.jcr.Repository" />
+              <constructor-arg ref="javax.jcr.Credentials.hstconfigreader" />
+              <constructor-arg 
ref="org.hippoecm.hst.content.service.translation.HippoTranslationContentRegistry"
 />
+            </bean>
+          </property>
+        </bean>
+
       </list>
     </property> 
   </bean>


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/beans/standard/AvailableTranslations.java
=====================================
--- 
a/content-beans/src/main/java/org/hippoecm/hst/content/beans/standard/AvailableTranslations.java
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/beans/standard/AvailableTranslations.java
@@ -23,7 +23,7 @@ import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 
 import org.hippoecm.hst.content.beans.manager.ObjectConverter;
-import org.hippoecm.hst.content.service.HippoTranslationBeanService;
+import 
org.hippoecm.hst.content.service.translation.HippoTranslationBeanService;
 import org.hippoecm.hst.site.HstServices;
 import org.hippoecm.repository.translation.HippoTranslationNodeType;
 import org.slf4j.Logger;


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/service/CachingHippoTranslationBeanServiceImpl.java
 → 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationBeanServiceImpl.java
=====================================
--- 
a/content-beans/src/main/java/org/hippoecm/hst/content/service/CachingHippoTranslationBeanServiceImpl.java
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationBeanServiceImpl.java
@@ -13,19 +13,20 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.hippoecm.hst.content.service;
+package org.hippoecm.hst.content.service.translation;
 
 import java.util.ArrayList;
 import java.util.Collections;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 
 import javax.jcr.Node;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
 
 import org.apache.commons.lang.StringUtils;
-import org.hippoecm.hst.cache.CacheElement;
-import org.hippoecm.hst.cache.HstCache;
+import org.hippoecm.repository.api.HippoNodeType;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -37,10 +38,11 @@ public class CachingHippoTranslationBeanServiceImpl extends 
DefaultHippoTranslat
 
     private static Logger log = 
LoggerFactory.getLogger(CachingHippoTranslationBeanServiceImpl.class);
 
-    private final HstCache handleIdsOfTranslationIdCache;
+    private final HippoTranslationContentRegistry 
hippoTranslationContentRegistry;
 
-    public CachingHippoTranslationBeanServiceImpl(final HstCache 
handleIdsOfTranslationIdCache) {
-        this.handleIdsOfTranslationIdCache = handleIdsOfTranslationIdCache;
+    public CachingHippoTranslationBeanServiceImpl(
+            final HippoTranslationContentRegistry 
hippoTranslationContentRegistry) {
+        this.hippoTranslationContentRegistry = hippoTranslationContentRegistry;
     }
 
     @Override
@@ -52,17 +54,16 @@ public class CachingHippoTranslationBeanServiceImpl extends 
DefaultHippoTranslat
 
         List<Node> translationNodes = null;
 
-        CacheElement cacheElem = 
handleIdsOfTranslationIdCache.get(translationId);
+        Set<String> documentHandleIds = hippoTranslationContentRegistry
+                .getDocumentHandleIdsByTranslationId(translationId);
 
-        if (cacheElem != null) {
-            List<String> handleNodeIds = (List<String>) cacheElem.getContent();
-
-            if (handleNodeIds != null) {
+        if (documentHandleIds != null) {
+            if (documentHandleIds != null) {
                 translationNodes = new ArrayList<>();
                 Node handleNode;
 
-                for (String handleNodeId : handleNodeIds) {
-                    handleNode = session.getNodeByIdentifier(handleNodeId);
+                for (String documentHandleId : documentHandleIds) {
+                    handleNode = session.getNodeByIdentifier(documentHandleId);
 
                     if (handleNode.hasNode(handleNode.getName())) {
                         
translationNodes.add(handleNode.getNode(handleNode.getName()));
@@ -70,17 +71,20 @@ public class CachingHippoTranslationBeanServiceImpl extends 
DefaultHippoTranslat
                 }
             }
         } else {
-            translationNodes = super.getTranslationNodes(session, 
translationId);
+            translationNodes = 
HippoTranslatedContentUtils.findTranslationNodes(session, translationId);
 
-            List<String> handleNodeIds = new ArrayList<String>();
+            documentHandleIds = new HashSet<>();
             Node handleNode;
+
             for (Node translationNode : translationNodes) {
                 handleNode = translationNode.getParent();
-                handleNodeIds.add(handleNode.getIdentifier());
+
+                if (handleNode.isNodeType(HippoNodeType.NT_HANDLE)) {
+                    documentHandleIds.add(handleNode.getIdentifier());
+                }
             }
 
-            cacheElem = 
handleIdsOfTranslationIdCache.createElement(translationId, handleNodeIds);
-            handleIdsOfTranslationIdCache.put(cacheElem);
+            
hippoTranslationContentRegistry.putDocumentHandleIdsForTranslationId(translationId,
 documentHandleIds);
         }
 
         return translationNodes == null ? Collections.emptyList() : 
translationNodes;


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationEventListener.java
=====================================
--- /dev/null
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/service/translation/CachingHippoTranslationEventListener.java
@@ -0,0 +1,169 @@
+/*
+ *  Copyright 2012-2015 Hippo B.V. (http://www.onehippo.com)
+ * 
+ *  Licensed under the Apache License, Version 2.0 (the "License");
+ *  you may not use this file except in compliance with the License.
+ *  You may obtain a copy of the License at
+ * 
+ *       http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ *  Unless required by applicable law or agreed to in writing, software
+ *  distributed under the License is distributed on an "AS IS" BASIS,
+ *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ *  See the License for the specific language governing permissions and
+ *  limitations under the License.
+ */
+package org.hippoecm.hst.content.service.translation;
+
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+import javax.jcr.Credentials;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Repository;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.observation.Event;
+import javax.jcr.observation.EventIterator;
+
+import org.apache.commons.lang.StringUtils;
+import org.hippoecm.hst.core.jcr.EventListenersContainerListener;
+import org.hippoecm.hst.core.jcr.GenericEventListener;
+import org.hippoecm.repository.api.HippoNodeType;
+import org.hippoecm.repository.translation.HippoTranslationNodeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class CachingHippoTranslationEventListener extends GenericEventListener
+        implements EventListenersContainerListener {
+
+    private static final Logger log = 
LoggerFactory.getLogger(CachingHippoTranslationEventListener.class);
+
+    private final Repository repository;
+
+    private final Credentials credentials;
+
+    private final HippoTranslationContentRegistry 
hippoTranslationContentRegistry;
+
+    public CachingHippoTranslationEventListener(final Repository repository, 
final Credentials credentials,
+            final HippoTranslationContentRegistry 
hippoTranslationContentRegistry) {
+        this.repository = repository;
+        this.credentials = credentials;
+        this.hippoTranslationContentRegistry = hippoTranslationContentRegistry;
+    }
+
+    @Override
+    public void onEvent(EventIterator events) {
+        Event event;
+
+        while (events.hasNext()) {
+            try {
+                event = events.nextEvent();
+
+                if (eventIgnorable(event)) {
+                    continue;
+                }
+
+                switch (event.getType()) {
+                case Event.NODE_ADDED:
+                    handleNodeAdded(event);
+                    break;
+                case Event.NODE_REMOVED:
+                    handleNodeRemoved(event);
+                    break;
+                }
+            } catch (RepositoryException e) {
+                log.error("Error processing event");
+            }
+        }
+    }
+
+    @Override
+    public void onEventListenersContainerStarted() {
+        // do nothing
+    }
+
+    @Override
+    public void onEventListenersContainerRefreshed() {
+        // do nothing
+    }
+
+    @Override
+    public void onEventListenersContainerStopped() {
+    }
+
+    private void handleNodeAdded(final Event event) throws RepositoryException 
{
+        Session session = null;
+
+        try {
+            session = repository.login(credentials);
+            Node node = session.getNodeByIdentifier(event.getIdentifier());
+
+            if (node.isNodeType(HippoNodeType.NT_HANDLE)) {
+                String translationId = findTranslationIdFromHandleNode(node);
+
+                if (translationId != null) {
+                    List<Node> translationNodes = 
HippoTranslatedContentUtils.findTranslationNodes(session,
+                            translationId);
+                    Set<String> documentHandleIds = new HashSet<>();
+                    Node handleNode;
+
+                    for (Node translationNode : translationNodes) {
+                        handleNode = translationNode.getParent();
+
+                        if (handleNode.isNodeType(HippoNodeType.NT_HANDLE)) {
+                            documentHandleIds.add(handleNode.getIdentifier());
+                        }
+                    }
+
+                    
hippoTranslationContentRegistry.putDocumentHandleIdsForTranslationId(translationId,
+                            documentHandleIds);
+                }
+            }
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+    }
+
+    private void handleNodeRemoved(final Event event) throws 
RepositoryException {
+        Session session = null;
+
+        try {
+            session = repository.login(credentials);
+            String nodeId = event.getIdentifier();
+            hippoTranslationContentRegistry.removeDocumentHandleId(nodeId);
+        } finally {
+            if (session != null) {
+                session.logout();
+            }
+        }
+    }
+
+    private String findTranslationIdFromHandleNode(final Node handle) throws 
RepositoryException {
+        String translationId = null;
+
+        if (handle.hasNode(handle.getName())) {
+            Node variant;
+
+            for (NodeIterator nodeIt = handle.getNodes(handle.getName()); 
nodeIt.hasNext();) {
+                variant = nodeIt.nextNode();
+
+                if (variant.isNodeType(HippoTranslationNodeType.NT_TRANSLATED)
+                        && variant.hasProperty(HippoTranslationNodeType.ID)) {
+                    translationId = StringUtils
+                            
.trimToNull(variant.getProperty(HippoTranslationNodeType.ID).getString());
+
+                    if (translationId != null) {
+                        break;
+                    }
+                }
+            }
+        }
+
+        return translationId;
+    }
+}


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/service/DefaultHippoTranslationBeanServiceImpl.java
 → 
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationBeanServiceImpl.java
=====================================
--- 
a/content-beans/src/main/java/org/hippoecm/hst/content/service/DefaultHippoTranslationBeanServiceImpl.java
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationBeanServiceImpl.java
@@ -13,19 +13,15 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.hippoecm.hst.content.service;
+package org.hippoecm.hst.content.service.translation;
 
-import java.util.ArrayList;
 import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import javax.jcr.Node;
-import javax.jcr.NodeIterator;
 import javax.jcr.RepositoryException;
 import javax.jcr.Session;
-import javax.jcr.query.Query;
-import javax.jcr.query.QueryResult;
 
 import org.apache.commons.lang.StringUtils;
 import org.hippoecm.hst.container.RequestContextProvider;
@@ -90,31 +86,7 @@ public class DefaultHippoTranslationBeanServiceImpl 
implements HippoTranslationB
             throw new IllegalArgumentException("Blank translation ID.");
         }
 
-        List<Node> translationNodes = new ArrayList<>();
-
-        String xpath = "//element(*," + HippoTranslationNodeType.NT_TRANSLATED 
+ ")[" + HippoTranslationNodeType.ID
-                + " = '" + translationId + "']";
-
-        @SuppressWarnings("deprecation")
-        Query query = 
session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
-        final QueryResult result = query.execute();
-
-        Node translationNode;
-        for (NodeIterator nodeIt = result.getNodes(); nodeIt.hasNext();) {
-            translationNode = nodeIt.nextNode();
-
-            if (translationNode != null) {
-                if 
(!translationNode.hasProperty(HippoTranslationNodeType.LOCALE)) {
-                    log.debug("Skipping node '{}' because does not contain 
property '{}'", translationNode.getPath(),
-                            HippoTranslationNodeType.LOCALE);
-                    continue;
-                }
-
-                translationNodes.add(translationNode);
-            }
-        }
-
-        return translationNodes;
+        return HippoTranslatedContentUtils.findTranslationNodes(session, 
translationId);
     }
 
 }


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationContentRegistry.java
=====================================
--- /dev/null
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/service/translation/DefaultHippoTranslationContentRegistry.java
@@ -0,0 +1,104 @@
+/**
+ * Copyright 2016-2016 Hippo B.V. (http://www.onehippo.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.content.service.translation;
+
+import java.util.Map;
+import java.util.Set;
+import java.util.concurrent.ConcurrentHashMap;
+
+import org.apache.commons.lang.StringUtils;
+
+public class DefaultHippoTranslationContentRegistry implements 
HippoTranslationContentRegistry {
+
+    private Object lock = new Object();
+
+    private Map<String, Set<String>> documentHandleIdsByTranslationIdCache = 
new ConcurrentHashMap<>();
+
+    private Map<String, String> translationIdByDocumentHandleIdCache = new 
ConcurrentHashMap<>();
+
+    @Override
+    public Set<String> getDocumentHandleIdsByTranslationId(String 
translationId) {
+        if (StringUtils.isBlank(translationId)) {
+            throw new IllegalArgumentException("Invalid translation ID.");
+        }
+
+        Set<String> handleIds = 
documentHandleIdsByTranslationIdCache.get(translationId);
+        return handleIds;
+    }
+
+    @Override
+    public void putDocumentHandleIdsForTranslationId(String translationId, 
Set<String> documentHandleIds) {
+        if (StringUtils.isBlank(translationId)) {
+            throw new IllegalArgumentException("Invalid translation ID.");
+        }
+
+        if (documentHandleIds == null) {
+            throw new IllegalArgumentException("Invalid documentHandleIds.");
+        }
+
+        synchronized (lock) {
+            documentHandleIdsByTranslationIdCache.put(translationId, 
documentHandleIds);
+
+            for (String documentHandleId : documentHandleIds) {
+                translationIdByDocumentHandleIdCache.put(documentHandleId, 
translationId);
+            }
+        }
+    }
+
+    @Override
+    public boolean removeDocumentHandleIdsByTranslationId(String 
translationId) {
+        if (StringUtils.isBlank(translationId)) {
+            throw new IllegalArgumentException("Invalid translation ID.");
+        }
+
+        boolean removed = false;
+
+        synchronized (lock) {
+            Set<String> documentHandleIds = 
documentHandleIdsByTranslationIdCache.remove(translationId);
+            removed = documentHandleIds != null;
+
+            for (String documentHandleId : documentHandleIds) {
+                translationIdByDocumentHandleIdCache.remove(documentHandleId);
+            }
+        }
+
+        return removed;
+    }
+
+    @Override
+    public boolean removeDocumentHandleId(String documentHandleId) {
+        boolean removed = false;
+
+        synchronized (lock) {
+            String translationId = 
translationIdByDocumentHandleIdCache.remove(documentHandleId);
+            removed = translationId != null;
+
+            if (removed) {
+                Set<String> documentHandleIds = 
documentHandleIdsByTranslationIdCache.get(translationId);
+
+                if (documentHandleIds != null) {
+                    if (documentHandleIds.isEmpty()
+                            || (documentHandleIds.size() == 1 && 
documentHandleIds.contains(documentHandleId))) {
+                        
documentHandleIdsByTranslationIdCache.remove(translationId);
+                    }
+                }
+            }
+        }
+
+        return removed;
+    }
+
+}


=====================================
content-beans/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslatedContentUtils.java
=====================================
--- /dev/null
+++ 
b/content-beans/src/main/java/org/hippoecm/hst/content/service/translation/HippoTranslatedContentUtils.java
@@ -0,0 +1,67 @@
+/**
+ * Copyright 2016-2016 Hippo B.V. (http://www.onehippo.com)
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *         http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.hippoecm.hst.content.service.translation;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.RepositoryException;
+import javax.jcr.Session;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+
+import org.hippoecm.repository.translation.HippoTranslationNodeType;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class HippoTranslatedContentUtils {
+
+    private static Logger log = 
LoggerFactory.getLogger(HippoTranslatedContentUtils.class);
+
+    private HippoTranslatedContentUtils() {
+    }
+
+    public static List<Node> findTranslationNodes(final Session session, final 
String translationId)
+            throws RepositoryException {
+        List<Node> translationNodes = new ArrayList<>();
+
+        String xpath = "//element(*," + HippoTranslationNodeType.NT_TRANSLATED 
+ ")[" + HippoTranslationNodeType.ID
+                + " = '" + translationId + "']";
+
+        @SuppressWarnings("deprecation")
+        Query query = 
session.getWorkspace().getQueryManager().createQuery(xpath, Query.XPATH);
+        final QueryResult result = query.execute();
+
+        Node translationNode;
+        for (NodeIterator nodeIt = result.getNodes(); nodeIt.hasNext();) {
+            translationNode = nodeIt.nextNode();
+
+            if (translationNode != null) {
+                if 
(!translationNode.hasProperty(HippoTranslationNodeType.LOCALE)) {
+                    log.debug("Skipping node '{}' because does not contain 
property '{}'", translationNode.getPath(),
+                            HippoTranslationNodeType.LOCALE);
+                    continue;
+                }
+
+                translationNodes.add(translationNode);
+            }
+        }
+
+        return translationNodes;
+    }
+}



View it on GitLab: 
https://code.onehippo.org/cms-community/hippo-site-toolkit/commit/9b1ca067dca8f816504202593aa25061a7b4862e
_______________________________________________
Hippocms-svn mailing list
Hippocms-svn@lists.onehippo.org
https://lists.onehippo.org/mailman/listinfo/hippocms-svn

Reply via email to