[
https://issues.apache.org/jira/browse/SLING-4512?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=14384754#comment-14384754
]
Alexander Klimetschek edited comment on SLING-4512 at 3/27/15 9:56 PM:
-----------------------------------------------------------------------
Here is a new patch on top of trunk (since SLING-4543 has been fixed):
[^SLING-4512-alex.patch]
It's a lot simpler - just uses {{javax.jcr.util.TraversingItemVisitor.Default}}
and a straightforward node type check, see below.
[~amitgupt] Yes, the node type check can be simplified since the JCR API
naturally has support for this: {{node.isNodeType("sling:Message")}} (this
covers node type inheritance). Also, checking just for the {{sling:Message}}
(mixin) type, since the primary node type {{sling:MessageEntry}} inherits from
the mixin.
{code:java}
private void loadSlingMessageDictionary(Resource dictionaryResource, final
Map<String, Object> targetDictionary) {
log.info("Loading sling:Message dictionary: {}",
dictionaryResource.getPath());
TraversingItemVisitor.Default visitor = new
TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int level) throws
RepositoryException {
if (node.isNodeType(NT_MESSAGE) &&
node.hasProperty(PROP_VALUE)) {
String key;
if (node.hasProperty(PROP_KEY)) {
key = node.getProperty(PROP_KEY).getString();
} else {
key = node.getName();
}
String value = node.getProperty(PROP_VALUE).getString();
targetDictionary.put(key, value);
}
}
};
try {
Node node = dictionaryResource.adaptTo(Node.class);
visitor.visit(node);
} catch (RepositoryException e) {
log.error("Could not read sling:Message dictionary: " +
dictionaryResource.getPath(), e);
}
}
{code}
was (Author: alexander.klimetschek):
Here is a new patch on top of trunk (since SLING-4543 has been fixed):
[^SLING-4512-alex.patch]
It's a lot simpler - just uses {{javax.jcr.util.TraversingItemVisitor.Default}}
and a straightforward node type check.
[~amitgupt] Yes, the node type check can be simplified since the JCR API
naturally has support for this: {{node.isNodeType("sling:Message")}} (this
covers node type inheritance). Also, checking just for the {{sling:Message}}
(mixin) type, since the primary node type {{sling:MessageEntry}} inherits from
the mixin.
{code:java}
private void loadSlingMessageDictionary(Resource dictionaryResource, final
Map<String, Object> targetDictionary) {
log.info("Loading sling:Message dictionary: {}",
dictionaryResource.getPath());
TraversingItemVisitor.Default visitor = new
TraversingItemVisitor.Default() {
@Override
protected void entering(Node node, int level) throws
RepositoryException {
if (node.isNodeType(NT_MESSAGE) &&
node.hasProperty(PROP_VALUE)) {
String key;
if (node.hasProperty(PROP_KEY)) {
key = node.getProperty(PROP_KEY).getString();
} else {
key = node.getName();
}
String value = node.getProperty(PROP_VALUE).getString();
targetDictionary.put(key, value);
}
}
};
try {
Node node = dictionaryResource.adaptTo(Node.class);
visitor.visit(node);
} catch (RepositoryException e) {
log.error("Could not read sling:Message dictionary: " +
dictionaryResource.getPath(), e);
}
}
{code}
> Traversal Warnings in OAK while creating i18n JcrResourceBundle
> ---------------------------------------------------------------
>
> Key: SLING-4512
> URL: https://issues.apache.org/jira/browse/SLING-4512
> Project: Sling
> Issue Type: Improvement
> Components: Extensions
> Reporter: Srijan Bhatnagar
> Assignee: Amit Gupta
> Attachments: SLING-4512-alex.patch, SLING-4512.diff
>
>
> org.apache.sling.i18n.impl.JcrResourceBundle#loadFully uses an XPath query to
> load [sling:Message] nodes under given paths. If the subtree under the path
> is too big (>1000), we receive traversal warnings in Oak. The following
> warning is generated if the path is /libs/wcm/core/i18n/de :
> {code}
> GET /content/geometrixx/de.html HTTP/1.1]
> org.apache.jackrabbit.oak.spi.query.Cursors$TraversingCursor Traversed 1000
> nodes with filter Filter(query=select [jcr:path], [jcr:score], * from
> [sling:Message] as a where isdescendantnode(a, '/libs/wcm/core/i18n/de') /*
> xpath: /jcr:root/libs/wcm/core/i18n/de//element(*,sling:Message) */,
> path=/libs/wcm/core/i18n/de//*); consider creating an index or changing the
> query
> {code}
> A suggestion would be to use
> [TreeTraverser|http://jackrabbit.apache.org/api/2.4/org/apache/jackrabbit/commons/flat/TreeTraverser.html]
> instead of XPath query since the subtree is mostly a flat list.
--
This message was sent by Atlassian JIRA
(v6.3.4#6332)