]>
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
;
30 * Writes arbitrary metadata into a child node of a given node (or the node
31 * itself if metadata node name is set to null)
33 public class JcrMetadataWriter
implements Runnable
{
34 private final static Log log
= LogFactory
.getLog(JcrMetadataWriter
.class);
36 private Node baseNode
;
37 private String metadataNodeName
= SlcNames
.SLC_METADATA
;
39 private Map
<String
, String
> metadata
= new HashMap
<String
, String
>();
44 if (metadataNodeName
!= null)
45 metadataNode
= baseNode
.hasNode(metadataNodeName
) ? baseNode
46 .getNode(metadataNodeName
) : baseNode
47 .addNode(metadataNodeName
);
49 metadataNode
= baseNode
;
51 for (String key
: metadata
.keySet())
52 metadataNode
.setProperty(key
, metadata
.get(key
));
54 baseNode
.getSession().save();
56 if (log
.isDebugEnabled())
57 log
.debug("Wrote " + metadata
.size() + " metadata entries to "
59 } catch (RepositoryException e
) {
60 throw new SlcException("Cannot write metadata to " + baseNode
, e
);
62 JcrUtils
.discardUnderlyingSessionQuietly(baseNode
);
67 public void setBaseNode(Node baseNode
) {
68 this.baseNode
= baseNode
;
71 public void setMetadataNodeName(String metadataNodeName
) {
72 this.metadataNodeName
= metadataNodeName
;
75 public void setMetadata(Map
<String
, String
> metadata
) {
76 this.metadata
= metadata
;