View Javadoc
1   /**
2    * This file Copyright (c) 2009-2018 Magnolia International
3    * Ltd.  (http://www.magnolia-cms.com). All rights reserved.
4    *
5    *
6    * This file is dual-licensed under both the Magnolia
7    * Network Agreement and the GNU General Public License.
8    * You may elect to use one or the other of these licenses.
9    *
10   * This file is distributed in the hope that it will be
11   * useful, but AS-IS and WITHOUT ANY WARRANTY; without even the
12   * implied warranty of MERCHANTABILITY or FITNESS FOR A
13   * PARTICULAR PURPOSE, TITLE, or NONINFRINGEMENT.
14   * Redistribution, except as permitted by whichever of the GPL
15   * or MNA you select, is prohibited.
16   *
17   * 1. For the GPL license (GPL), you can redistribute and/or
18   * modify this file under the terms of the GNU General
19   * Public License, Version 3, as published by the Free Software
20   * Foundation.  You should have received a copy of the GNU
21   * General Public License, Version 3 along with this program;
22   * if not, write to the Free Software Foundation, Inc., 51
23   * Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
24   *
25   * 2. For the Magnolia Network Agreement (MNA), this file
26   * and the accompanying materials are made available under the
27   * terms of the MNA which accompanies this distribution, and
28   * is available at http://www.magnolia-cms.com/mna.html
29   *
30   * Any modifications to this file must keep this entire header
31   * intact.
32   *
33   */
34  package info.magnolia.link;
35  
36  import info.magnolia.cms.core.Content;
37  import info.magnolia.cms.core.NodeData;
38  
39  import java.util.regex.Pattern;
40  
41  /**
42   * Factory processing various input into the Link objects and back.
43   * For parsing html and converting multiple link instances on the fly use {@link LinkUtil}.
44   *
45   * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil}.
46   */
47  @Deprecated
48  public class LinkFactory {
49      private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(LinkFactory.class);
50  
51      /**
52       * Creates new link from the content node.
53       *
54       * @param node Target content for the link.
55       * @return Link pointing to the provided content
56       * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#createLinkInstance(Content)} instead.
57       */
58      public static Link createLink(Content node) {
59          return LinkUtil.createLinkInstance(node);
60      }
61  
62      /**
63       * Creates new link from the node data.
64       *
65       * @param nodeData Target node data for the link.
66       * @return Link pointing to the provided node data.
67       * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#createLinkInstance(NodeData)} instead.
68       */
69      public static Link createLink(NodeData nodeData) throws LinkException {
70          return LinkUtil.createLinkInstance(nodeData);
71      }
72  
73      /**
74       * Creates link to the content denoted by repository and uuid.
75       *
76       * @param repository Parent repository of the content of interest.
77       * @param uuid UUID of the content to create link to.
78       * @return link to the content with provided UUID.
79       * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#createLinkInstance(String, String)} instead.
80       */
81      public static Link createLink(String repository, String uuid) throws LinkException {
82          return LinkUtil.createLinkInstance(repository, uuid);
83      }
84  
85      /**
86       * Creates link to the content identified by the repository and path. Link will use specified extension and will also contain the anchor and parameters if specified.
87       *
88       * @param repository Source repository for the content.
89       * @param path Path to the content of interest.
90       * @param extension Optional extension to be used in the link
91       * @param anchor Optional link anchor.
92       * @param parameters Optional link parameters.
93       * @return Link pointing to the content denoted by repository and path including extension, anchor and parameters if such were provided.
94       * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#createLinkInstance(String, String, String, String, String)} instead.
95       */
96      public static Link createLink(String repository, String path, String extension, String anchor, String parameters) throws LinkException {
97          return LinkUtil.createLinkInstance(repository, path, extension, anchor, parameters);
98      }
99  
100     /**
101      * Creates link based on provided parameters. Should the uuid be non existent or the fallback handle invalid, creates nonetheless an <em>"undefined"</em> {@link Link} object,
102      * pointing to the non existing uuid so that broken link detection tools can find it.
103      *
104      * @param uuid UUID of the content
105      * @param repository Content repository name.
106      * @param fallbackHandle Optional fallback content handle.
107      * @param nodeDataName Content node data name for binary data.
108      * @param extension Optional link extension.
109      * @param anchor Optional link anchor.
110      * @param parameters Optional link parameters.
111      * @return Link pointing to the content denoted by uuid and repository. Link is created using all provided optional values if present.
112      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#createLinkInstance(String, String, String, String, String, String, String)} instead.
113      */
114     public static Link createLink(String uuid, String repository, String fallbackHandle, String nodeDataName, String extension, String anchor, String parameters) throws LinkException {
115         return LinkUtil.createLinkInstance(uuid, repository, fallbackHandle, nodeDataName, extension, anchor, parameters);
116     }
117 
118     /**
119      * Parses UUID link pattern string and converts it into a Link object.
120      *
121      * @param uuidLink String containing reference to content as a UUID link pattern.
122      * @return Link to content referenced in the provided text.
123      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#parseUUIDLink(String)} instead.
124      */
125     public static Link parseUUIDLink(String uuidLink) throws LinkException {
126         return LinkUtil.parseUUIDLink(uuidLink);
127     }
128 
129     /**
130      * Parses provided URI to the link.
131      *
132      * @param link URI representing path to piece of content
133      * @return Link pointing to the content represented by provided URI
134      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#parseLink(String)} instead.
135      */
136     public static Link parseLink(String link) throws LinkException {
137         return LinkUtil.parseLink(link);
138     }
139 
140     /**
141      * Converts provided Link to an UUID link pattern.
142      *
143      * @param link Link to convert.
144      * @return UUID link pattern representation of provided link.
145      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#toPattern(Link)} instead.
146      */
147     public static String toPattern(Link link) {
148         return LinkUtil.toPattern(link);
149     }
150 
151     /**
152      * Pattern to find a magnolia formatted uuid link.
153      *
154      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#UUID_PATTERN} instead.
155      */
156     public static Pattern UUID_PATTERN = LinkUtil.UUID_PATTERN;
157 
158     /**
159      * Pattern to find a link.
160      *
161      * @deprecated since 5.0 use {@link info.magnolia.link.LinkUtil#LINK_PATTERN} instead.
162      */
163     public static final Pattern LINK_PATTERN = LinkUtil.LINK_PATTERN;
164 }