Clover icon

Google Sitemap Module 2.4.3

  1. Project Clover database Thu May 11 2017 16:52:32 CEST
  2. Package info.magnolia.module.googlesitemap

File SiteMapNodeTypes.java

 

Coverage histogram

../../../../img/srcFileCovDistChart10.png
0% of files have more coverage

Code metrics

24
31
13
3
182
87
25
0.81
2.38
4.33
1.92

Classes

Class Line # Actions
SiteMapNodeTypes 49 0 - 0 0
-1.0 -
SiteMapNodeTypes.SiteMap 53 22 0% 16 1
0.978260997.8%
SiteMapNodeTypes.GoogleSiteMap 139 9 0% 9 0
1.0100%
 

Contributing tests

This file is covered by 40 tests. .

Source view

1    /**
2    * This file Copyright (c) 2013-2017 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.module.googlesitemap;
35   
36    import info.magnolia.jcr.util.NodeTypes;
37   
38    import java.util.ArrayList;
39    import java.util.LinkedList;
40    import java.util.List;
41   
42    import javax.jcr.Node;
43    import javax.jcr.RepositoryException;
44    import javax.jcr.Value;
45   
46    /**
47    * Constants and convenience methods for node types introduced by Google Site Map module.
48    */
 
49    public class SiteMapNodeTypes {
50    /**
51    * Represents the node type mgnl:siteMap.
52    */
 
53    public static class SiteMap {
54    public static final String NAME = NodeTypes.MGNL_PREFIX + "siteMap";
55    public static final String TYPE = NodeTypes.MGNL_PREFIX + "googleSiteMapType";
56    public static final String DISPLAY_NAME = NodeTypes.MGNL_PREFIX + "googleSiteMapDisplayName";
57    public static final String INCLUDE_VIRTUAL_URI = NodeTypes.MGNL_PREFIX + "googleSiteMapIncludeVirtualUri";
58    public static final String URL = NodeTypes.MGNL_PREFIX + "googleSiteMapURL";
59    public static final String PAGES = NodeTypes.MGNL_PREFIX + "googleSiteMapPages";
60    public static final String DEFAULT_CHANGEFREQ = NodeTypes.MGNL_PREFIX + "googleSiteMapDefaultChangeFreq";
61    public static final String DEFAULT_PRIORITY = NodeTypes.MGNL_PREFIX + "googleSiteMapDefaultPriority";
62   
63    /**
64    * Returns the type of the site map or null if no type has been stored on the node.
65    */
 
66  9 toggle public static String getType(Node node) throws RepositoryException {
67  9 return node.hasProperty(TYPE) ? node.getProperty(TYPE).getString() : null;
68    }
69   
70    /**
71    * Returns the displayName of the site map or null if no displayName has been stored on the node.
72    */
 
73  2 toggle public static String getDisplayName(Node node) throws RepositoryException {
74  2 return node.hasProperty(DISPLAY_NAME) ? node.getProperty(DISPLAY_NAME).getString() : null;
75    }
76   
77    /**
78    * Returns the value of {@link #INCLUDE_VIRTUAL_URI} stored or false in the property is empty.
79    */
 
80  9 toggle public static boolean isVirtualUriMappingIncluded(Node node) throws RepositoryException {
81  9 return node.hasProperty(INCLUDE_VIRTUAL_URI) ? node.getProperty(INCLUDE_VIRTUAL_URI).getBoolean() : Boolean.FALSE;
82    }
83   
84    /**
85    * Returns the URL of the site map or null if no URL has been stored on the node.
86    */
 
87  32 toggle public static String getUrl(Node node) throws RepositoryException {
88  32 return node.hasProperty(URL) ? node.getProperty(URL).getString() : null;
89    }
90   
91    /**
92    * Returns the change frequency of the site map page or null if no change frequency has been stored on the node.
93    */
 
94  38 toggle public static String getDefaultChangeFreq(Node node) throws RepositoryException {
95  38 return node.hasProperty(DEFAULT_CHANGEFREQ) ? node.getProperty(DEFAULT_CHANGEFREQ).getString() : null;
96    }
97   
98    /**
99    * Returns the priority of the site map page or null if no priority has been stored on the node.
100    */
 
101  38 toggle public static Double getDefaultPriority(Node node) throws RepositoryException {
102  38 return node.hasProperty(DEFAULT_PRIORITY) ? node.getProperty(DEFAULT_PRIORITY).getDouble() : null;
103    }
104   
105    /**
106    * Returns the pages linked to the site map or null if no pages has been stored on the node.
107    */
 
108  13 toggle public static List<String> getPages(Node node) throws RepositoryException {
109  13 if (!node.hasProperty(PAGES)) {
110  1 return new ArrayList<String>();
111    }
112   
113  12 Value[] values = node.getProperty(PAGES).getValues();
114  12 List<String> res = new LinkedList<String>();
115  12 for (Value value : values) {
116  15 res.add(value.getString());
117    }
118  12 return res;
119    }
120   
 
121  1 toggle public static void update(Node node, String type, String url, String displayName, boolean includeVirtualUri, String defaultChangeFrq, Double defaultPriority, List<String> pages) throws RepositoryException {
122  1 NodeTypes.checkNodeType(node, NAME, TYPE, URL, DISPLAY_NAME, INCLUDE_VIRTUAL_URI, PAGES);
123  1 node.setProperty(TYPE, type);
124  1 node.setProperty(URL, url);
125  1 node.setProperty(DISPLAY_NAME, displayName);
126  1 node.setProperty(INCLUDE_VIRTUAL_URI, includeVirtualUri);
127  1 node.setProperty(DEFAULT_CHANGEFREQ, defaultChangeFrq);
128  1 node.setProperty(DEFAULT_PRIORITY, defaultPriority);
129  1 if (pages != null) {
130  1 node.setProperty(PAGES, pages.toArray(new String[pages.size()]));
131    }
132    }
133   
134    }
135   
136    /**
137    * Represents the mixIn node type mgnl:googleSiteMap.
138    */
 
139    public static class GoogleSiteMap {
140    public static final String NAME = NodeTypes.MGNL_PREFIX + "googleSiteMap";
141    public static final String SITEMAP_CHANGEFREQ = NodeTypes.MGNL_PREFIX + "googleSiteMapChangeFreq";
142    public static final String SITEMAP_PRIORITY = NodeTypes.MGNL_PREFIX + "googleSiteMapPriority";
143    public static final String SITEMAP_HIDE_IN_GOOGLESITEMAP = NodeTypes.MGNL_PREFIX + "googleSiteMapHide";
144    public static final String SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN = NodeTypes.MGNL_PREFIX + "googleSiteMapHideChildren";
145   
146    /**
147    * Returns the change frequency of the site map page or null if no change frequency has been stored on the node.
148    */
 
149  138 toggle public static String getChangeFreq(Node node) throws RepositoryException {
150  138 return node.hasProperty(SITEMAP_CHANGEFREQ) ? node.getProperty(SITEMAP_CHANGEFREQ).getString() : null;
151    }
152   
153    /**
154    * Returns the priority of the site map page or null if no priority has been stored on the node.
155    */
 
156  138 toggle public static Double getPriority(Node node) throws RepositoryException {
157  138 return node.hasProperty(SITEMAP_PRIORITY) ? node.getProperty(SITEMAP_PRIORITY).getDouble() : null;
158    }
159   
160    /**
161    * Returns the hide value of the site map page or false if no value is stored on the node.
162    */
 
163  236 toggle public static boolean isHide(Node node) throws RepositoryException {
164  236 return node.hasProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP) ? node.getProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean() : Boolean.FALSE;
165    }
166   
167    /**
168    * Returns the hide children value of the site map page or false if no value is stored on the node.
169    */
 
170  144 toggle public static boolean isHideChildren(Node node) throws RepositoryException {
171  144 return node.hasProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN) ? node.getProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean() : Boolean.FALSE;
172    }
173   
 
174  5 toggle public static void update(Node node, String changeFrq, Double priority, boolean hide, boolean hideChildren) throws RepositoryException {
175  5 NodeTypes.checkNodeType(node, NAME, SITEMAP_CHANGEFREQ, SITEMAP_PRIORITY, SITEMAP_HIDE_IN_GOOGLESITEMAP, SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN);
176  5 node.setProperty(SITEMAP_CHANGEFREQ, changeFrq);
177  5 node.setProperty(SITEMAP_PRIORITY, priority);
178  5 node.setProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP, hide);
179  5 node.setProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, hideChildren);
180    }
181    }
182    }