DamManagerImpl.java
3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
/*
* Decompiled with CFR 0_118.
*
* Could not load the following classes:
* com.day.cq.dam.api.Asset
* com.day.cq.dam.api.AssetManager
* com.day.cq.dam.api.DamManager
* com.day.cq.dam.commons.util.DamUtil
* javax.jcr.AccessDeniedException
* javax.jcr.Node
* javax.jcr.PathNotFoundException
* javax.jcr.RepositoryException
* javax.jcr.Session
* javax.jcr.lock.LockException
* javax.jcr.nodetype.ConstraintViolationException
* javax.jcr.version.VersionException
* org.apache.felix.scr.annotations.Component
* org.apache.felix.scr.annotations.Reference
* org.apache.felix.scr.annotations.Service
* org.apache.sling.api.resource.ResourceResolver
* org.apache.sling.jcr.resource.JcrResourceResolverFactory
* org.slf4j.Logger
* org.slf4j.LoggerFactory
*/
package com.day.cq.dam.core.impl;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.api.AssetManager;
import com.day.cq.dam.api.DamManager;
import com.day.cq.dam.commons.util.DamUtil;
import java.io.File;
import java.io.IOException;
import javax.jcr.AccessDeniedException;
import javax.jcr.Node;
import javax.jcr.PathNotFoundException;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.lock.LockException;
import javax.jcr.nodetype.ConstraintViolationException;
import javax.jcr.version.VersionException;
import org.apache.felix.scr.annotations.Component;
import org.apache.felix.scr.annotations.Reference;
import org.apache.felix.scr.annotations.Service;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.jcr.resource.JcrResourceResolverFactory;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@Component(immediate=0, metatype=0, label="DamManager", description="The Dam Manager...")
@Service
public class DamManagerImpl
implements DamManager {
private static final Logger log = LoggerFactory.getLogger(DamManagerImpl.class);
@Reference
private JcrResourceResolverFactory jcrResolverFactory;
public File createTempFile(String prefix, String suffix) throws IOException {
throw new RuntimeException("operation no longer supported");
}
public Session getSession() throws RepositoryException {
throw new RuntimeException("operation no longer supported");
}
public String createMetadataPath(String binaryNodePath) {
return DamUtil.binaryToAssetPath((String)binaryNodePath);
}
public String createBinaryUploadLocationPath(String metadataNodePath) {
return DamUtil.assetToBinaryPath((String)metadataNodePath);
}
public Node getAssetNode(String assetPath, Session session) {
try {
return session.getNode(DamUtil.binaryToAssetPath((String)assetPath));
}
catch (PathNotFoundException e) {
}
catch (RepositoryException e) {
// empty catch block
}
return null;
}
public void removeAssetNode(String assetPath, Session session) {
try {
session.removeItem(DamUtil.binaryToAssetPath((String)assetPath));
}
catch (AccessDeniedException e) {
e.printStackTrace();
}
catch (VersionException e) {
}
catch (LockException e) {
e.printStackTrace();
}
catch (ConstraintViolationException e) {
}
catch (RepositoryException e) {
// empty catch block
}
}
public Asset createAssetStructure(String binaryPath, Session session, boolean doSave) {
return ((AssetManager)this.jcrResolverFactory.getResourceResolver(session).adaptTo(AssetManager.class)).createAssetForBinary(binaryPath, doSave);
}
protected void bindJcrResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
this.jcrResolverFactory = jcrResourceResolverFactory;
}
protected void unbindJcrResolverFactory(JcrResourceResolverFactory jcrResourceResolverFactory) {
if (this.jcrResolverFactory == jcrResourceResolverFactory) {
this.jcrResolverFactory = null;
}
}
}