1 /*
2 * Copyright (C) 2003-2007 eXo Platform SAS.
3 *
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Affero General Public License
6 * as published by the Free Software Foundation; either version 3
7 * of the License, or (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, see<http://www.gnu.org/licenses/>.
16 */
17 package org.exoplatform.services.cms.link;
18
19 import java.util.List;
20
21 import javax.jcr.Item;
22 import javax.jcr.ItemNotFoundException;
23 import javax.jcr.Node;
24 import javax.jcr.RepositoryException;
25
26 import org.exoplatform.services.jcr.ext.common.SessionProvider;
27
28 /**
29 * Supplies API to work with the linked node or the link included in a node.
30 *
31 * @LevelAPI Platform
32 */
33 public interface LinkManager {
34
35 /**
36 * Creates a new link with a given type.
37 *
38 * @param parent The parent node that contains the new link.
39 * @param linkType The primary nodetype of the link that must be sub-type of
40 * "exo:symlink". Its default value is "exo:symlink".
41 * @param target Target of the link.
42 * @return The created link.
43 * @throws RepositoryException if the link cannot be created for any reason.
44 */
45 public Node createLink(Node parent, String linkType, Node target) throws RepositoryException;
46
47 /**
48 * Creates a new link with "exo:symlink" type.
49 *
50 * @param parent The parent node that contains the new link.
51 * @param target Target of the link.
52 * @return The created link.
53 * @throws RepositoryException if the link cannot be created for any reason.
54 */
55 public Node createLink(Node parent, Node target) throws RepositoryException;
56
57 /**
58 * Creates a new link with given type and name.
59 *
60 * @param parent The parent node that contains the new link.
61 * @param linkType The primary nodetype of the link that must be sub-type of
62 * "exo:symlink". Its default value is "exo:symlink".
63 * @param target Target of the link.
64 * @param linkName Name of the link.
65 * @return The created link.
66 * @throws RepositoryException if the link cannot be created for any reason.
67 */
68 public Node createLink(Node parent, String linkType, Node target, String linkName)
69 throws RepositoryException;
70
71 /**
72 * Creates a new link with given type, name and title.
73 *
74 * @param parent The parent node that contains the new link.
75 * @param linkType The primary nodetype of the link that must be sub-type of
76 * "exo:symlink". Its default value is "exo:symlink".
77 * @param target Target of the link.
78 * @param linkName Name of the link.
79 * @param linkTitle Title of the link.
80 * @return The created link.
81 * @throws RepositoryException if the link cannot be created for any reason.
82 */
83 public Node createLink(Node parent, String linkType, Node target, String linkName, String linkTitle)
84 throws RepositoryException;
85
86 /**
87 * Updates a link node.
88 *
89 * @param link The link node to be updated.
90 * @param target Target of the link node.
91 * @return The updated link node.
92 * @throws RepositoryException if the link cannot be updated for any reason.
93 */
94 public Node updateLink(Node link, Node target) throws RepositoryException;
95
96 /**
97 * Gets the target node of a given link.
98 *
99 * @param link The node of "exo:symlink" type.
100 * @param system Indicates whether the target node must be retrieved using a
101 * system or user session. In case the target and the
102 * link are not in the same workspace, the system session will be used.
103 * @return The target node.
104 * @throws ItemNotFoundException if the target node cannot be found.
105 * @throws RepositoryException if an unexpected error occurs while retrieving
106 * the target node.
107 */
108 public Node getTarget(Node link, boolean system) throws ItemNotFoundException,
109 RepositoryException;
110
111 /**
112 * Gets the target node of a given link using the user session.
113 *
114 * @param link The node of "exo:symlink" type.
115 * @return The target node.
116 * @throws ItemNotFoundException if the target node cannot be found.
117 * @throws RepositoryException if an unexpected error occurs while retrieving
118 * the target node
119 */
120 public Node getTarget(Node link) throws ItemNotFoundException, RepositoryException;
121
122 /**
123 * Checks if the target node of a given link can be reached using the user session.
124 *
125 * @param link The node of "exo:symlink" type.
126 * @return "True" if the target node is reachable. Otherwise, it returns "false".
127 * @throws RepositoryException if an unexpected error occurs.
128 */
129 public boolean isTargetReachable(Node link) throws RepositoryException;
130
131 /**
132 * Checks if the target node of a given link can be reached using the user session.
133 *
134 * @param link The node of "exo:symlink" type.
135 * @param system The boolean value which indicates if the system session is needed.
136 * @return "True" if the target node is reachable. Otherwise, it returns "false".
137 * @throws RepositoryException if an unexpected error occurs.
138 */
139 public boolean isTargetReachable(Node link, boolean system) throws RepositoryException;
140
141 /**
142 * Checks if a given item is link.
143 *
144 * @param item The item to be checked.
145 * @return "True" if the given item is link. Otherwise, it returns "false".
146 *
147 * @throws RepositoryException if an unexpected error occurs
148 */
149 public boolean isLink(Item item) throws RepositoryException;
150
151 /**
152 * Gets the primary nodetype of a target node by a given link.
153 *
154 * @param link The given link.
155 * @return The primary nodetype of the target node.
156 * @throws RepositoryException if an unexpected error occurs.
157 */
158 public String getTargetPrimaryNodeType(Node link) throws RepositoryException;
159
160 /**
161 * Gets all links of a target node by a given link type.
162 *
163 * @param targetNode The target node.
164 * @param linkType The given link type.
165 * @return The list of links.
166 * @throws Exception
167 */
168 public List<Node> getAllLinks(Node targetNode, String linkType) throws Exception;
169
170 /**
171 * Gets all links of a target node by a given link type.
172 *
173 * @param targetNode The target node.
174 * @param linkType The given link type.
175 * @param sessionProvider The session provider.
176 * @return The list of links.
177 * @throws Exception
178 */
179 public List<Node> getAllLinks(Node targetNode, String linkType, SessionProvider sessionProvider) throws Exception;
180
181 /**
182 * Updates information for a symlink, including "exo:title", "exo:dateCreated", "exo:dateModified", "publication:liveDate" and "exo:index".
183 *
184 * @param link The link node.
185 * @throws Exception
186 */
187 public void updateSymlink(Node link) throws Exception;
188
189 }