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 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
48
49 public class SiteMapNodeTypes {
50
51
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
65
66 public static String getType(Node node) throws RepositoryException {
67 return node.hasProperty(TYPE) ? node.getProperty(TYPE).getString() : null;
68 }
69
70
71
72
73 public static String getDisplayName(Node node) throws RepositoryException {
74 return node.hasProperty(DISPLAY_NAME) ? node.getProperty(DISPLAY_NAME).getString() : null;
75 }
76
77
78
79
80 public static boolean isVirtualUriMappingIncluded(Node node) throws RepositoryException {
81 return node.hasProperty(INCLUDE_VIRTUAL_URI) ? node.getProperty(INCLUDE_VIRTUAL_URI).getBoolean() : Boolean.FALSE;
82 }
83
84
85
86
87 public static String getUrl(Node node) throws RepositoryException {
88 return node.hasProperty(URL) ? node.getProperty(URL).getString() : null;
89 }
90
91
92
93
94 public static String getDefaultChangeFreq(Node node) throws RepositoryException {
95 return node.hasProperty(DEFAULT_CHANGEFREQ) ? node.getProperty(DEFAULT_CHANGEFREQ).getString() : null;
96 }
97
98
99
100
101 public static Double getDefaultPriority(Node node) throws RepositoryException {
102 return node.hasProperty(DEFAULT_PRIORITY) ? node.getProperty(DEFAULT_PRIORITY).getDouble() : null;
103 }
104
105
106
107
108 public static List<String> getPages(Node node) throws RepositoryException {
109 if (!node.hasProperty(PAGES)) {
110 return new ArrayList<String>();
111 }
112
113 Value[] values = node.getProperty(PAGES).getValues();
114 List<String> res = new LinkedList<String>();
115 for (Value value : values) {
116 res.add(value.getString());
117 }
118 return res;
119 }
120
121 public static void update(Node node, String type, String url, String displayName, boolean includeVirtualUri, String defaultChangeFrq, Double defaultPriority, List<String> pages) throws RepositoryException {
122 NodeTypes.checkNodeType(node, NAME, TYPE, URL, DISPLAY_NAME, INCLUDE_VIRTUAL_URI, PAGES);
123 node.setProperty(TYPE, type);
124 node.setProperty(URL, url);
125 node.setProperty(DISPLAY_NAME, displayName);
126 node.setProperty(INCLUDE_VIRTUAL_URI, includeVirtualUri);
127 node.setProperty(DEFAULT_CHANGEFREQ, defaultChangeFrq);
128 node.setProperty(DEFAULT_PRIORITY, defaultPriority);
129 if (pages != null) {
130 node.setProperty(PAGES, pages.toArray(new String[pages.size()]));
131 }
132 }
133
134 }
135
136
137
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
148
149 public static String getChangeFreq(Node node) throws RepositoryException {
150 return node.hasProperty(SITEMAP_CHANGEFREQ) ? node.getProperty(SITEMAP_CHANGEFREQ).getString() : null;
151 }
152
153
154
155
156 public static Double getPriority(Node node) throws RepositoryException {
157 return node.hasProperty(SITEMAP_PRIORITY) ? node.getProperty(SITEMAP_PRIORITY).getDouble() : null;
158 }
159
160
161
162
163 public static boolean isHide(Node node) throws RepositoryException {
164 return node.hasProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP) ? node.getProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP).getBoolean() : Boolean.FALSE;
165 }
166
167
168
169
170 public static boolean isHideChildren(Node node) throws RepositoryException {
171 return node.hasProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN) ? node.getProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN).getBoolean() : Boolean.FALSE;
172 }
173
174 public static void update(Node node, String changeFrq, Double priority, boolean hide, boolean hideChildren) throws RepositoryException {
175 NodeTypes.checkNodeType(node, NAME, SITEMAP_CHANGEFREQ, SITEMAP_PRIORITY, SITEMAP_HIDE_IN_GOOGLESITEMAP, SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN);
176 node.setProperty(SITEMAP_CHANGEFREQ, changeFrq);
177 node.setProperty(SITEMAP_PRIORITY, priority);
178 node.setProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP, hide);
179 node.setProperty(SITEMAP_HIDE_IN_GOOGLESITEMAP_CHILDREN, hideChildren);
180 }
181 }
182 }