]>
git.argeo.org Git - gpl/argeo-slc.git/blob - org.argeo.slc.core/src/org/argeo/slc/jcr/JcrMetadataWriter.java
2 * Copyright (C) 2007-2012 Argeo GmbH
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
16 package org
.argeo
.slc
.jcr
;
18 import java
.util
.HashMap
;
21 import javax
.jcr
.Node
;
22 import javax
.jcr
.RepositoryException
;
24 import org
.apache
.commons
.logging
.Log
;
25 import org
.apache
.commons
.logging
.LogFactory
;
26 import org
.argeo
.jcr
.JcrUtils
;
27 import org
.argeo
.slc
.SlcException
;
28 import org
.argeo
.slc
.SlcNames
;
31 * Writes arbitrary metadata into a child node of a given node (or the node
32 * itself if metadata node name is set to null)
34 public class JcrMetadataWriter
implements Runnable
{
35 private final static Log log
= LogFactory
.getLog(JcrMetadataWriter
.class);
37 private Node baseNode
;
38 private String metadataNodeName
= SlcNames
.SLC_METADATA
;
40 private Map
<String
, String
> metadata
= new HashMap
<String
, String
>();
45 if (metadataNodeName
!= null)
46 metadataNode
= baseNode
.hasNode(metadataNodeName
) ? baseNode
47 .getNode(metadataNodeName
) : baseNode
48 .addNode(metadataNodeName
);
50 metadataNode
= baseNode
;
52 for (String key
: metadata
.keySet())
53 metadataNode
.setProperty(key
, metadata
.get(key
));
55 baseNode
.getSession().save();
57 if (log
.isDebugEnabled())
58 log
.debug("Wrote " + metadata
.size() + " metadata entries to "
60 } catch (RepositoryException e
) {
61 throw new SlcException("Cannot write metadata to " + baseNode
, e
);
63 JcrUtils
.discardUnderlyingSessionQuietly(baseNode
);
68 public void setBaseNode(Node baseNode
) {
69 this.baseNode
= baseNode
;
72 public void setMetadataNodeName(String metadataNodeName
) {
73 this.metadataNodeName
= metadataNodeName
;
76 public void setMetadata(Map
<String
, String
> metadata
) {
77 this.metadata
= metadata
;