Skip to content

Commit a1e8db3

Browse files
jirka.pinkas@gmail.comjirka.pinkas@gmail.com
authored andcommitted
fixed RssGenerator so that it correctly uses default dir & extension the same way as in SitemapGenerators
1 parent ee68572 commit a1e8db3

File tree

4 files changed

+86
-5
lines changed

4 files changed

+86
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ First add this library to classpath:
1212
<dependency>
1313
<groupId>cz.jiripinkas</groupId>
1414
<artifactId>jsitemapgenerator</artifactId>
15-
<version>3.13</version>
15+
<version>3.14</version>
1616
</dependency>
1717

1818
If you want to use "ping google / bing" functionality, also add this library to classpath:

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<modelVersion>4.0.0</modelVersion>
44
<groupId>cz.jiripinkas</groupId>
55
<artifactId>jsitemapgenerator</artifactId>
6-
<version>3.13</version>
6+
<version>3.14</version>
77
<packaging>jar</packaging>
88
<name>Java sitemap generator</name>
99
<description>This library generates a web sitemap and can ping Google that it has changed. This project has been inspired by sitemapgen4j, but is much more focused on traditional web sitemap and ease of use.</description>

src/main/java/cz/jiripinkas/jsitemapgenerator/WebPage.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public void setPriority(Double priority) {
120120
}
121121

122122
/**
123-
* Constructs name from dir and extension (if available)
123+
* Constructs name from dir and extension (if available), used in SitemapGenerators
124124
* @return Name
125125
*/
126126
public String constructName() {
@@ -134,6 +134,25 @@ public String constructName() {
134134
return result;
135135
}
136136

137+
/**
138+
* Constructs shortName from dir and extension (if available), used in RssGenerator
139+
* @return Name
140+
*/
141+
public String constructShortName() {
142+
String result = shortName;
143+
if(dir != null) {
144+
result = dir + "/" + result;
145+
}
146+
if(extension != null) {
147+
result = result + "." + extension;
148+
}
149+
return result;
150+
}
151+
152+
public String getName() {
153+
return name;
154+
}
155+
137156
public Map<String, String> getAlternateNames() {
138157
return alternateNames;
139158
}

src/main/java/cz/jiripinkas/jsitemapgenerator/generator/RssGenerator.java

Lines changed: 64 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,10 @@ public class RssGenerator extends AbstractGenerator<RssGenerator> {
1414

1515
private String webDescription;
1616

17+
private String defaultDir;
18+
19+
private String defaultExtension;
20+
1721
/**
1822
* Create RssGenerator
1923
*
@@ -164,7 +168,7 @@ public String toString() {
164168
builder.append("<item>" + "\n")
165169

166170
.append("<title>")
167-
.append(webPage.constructName())
171+
.append(webPage.getName())
168172
.append("</title>" + "\n")
169173

170174
.append("<description>")
@@ -173,7 +177,7 @@ public String toString() {
173177

174178
.append("<link>")
175179
.append(baseUrl)
176-
.append(webPage.getShortName())
180+
.append(webPage.constructShortName())
177181
.append("</link>" + "\n")
178182

179183
.append("<pubDate>")
@@ -188,4 +192,62 @@ public String toString() {
188192
return builder.toString();
189193
}
190194

195+
@Override
196+
protected void beforeAddPageEvent(WebPage webPage) {
197+
if(defaultDir != null && webPage.getDir() == null) {
198+
webPage.setShortName(defaultDir + "/" + webPage.getShortName());
199+
}
200+
if(defaultExtension != null && webPage.getExtension() == null) {
201+
webPage.setShortName(webPage.getShortName() + "." + defaultExtension);
202+
}
203+
}
204+
205+
/**
206+
* Sets default prefix dir to name for all subsequent WebPages. Final name will be "dirName/name"
207+
* @param dirName Dir name
208+
* @return this
209+
*/
210+
public RssGenerator defaultDir(String dirName) {
211+
defaultDir = dirName;
212+
return getThis();
213+
}
214+
215+
/**
216+
* Sets default prefix dirs to name for all subsequent WebPages. For dirs: ["a", "b", "c"], the final name will be "a/b/c/name"
217+
* @param dirNames Dir names
218+
* @return this
219+
*/
220+
public RssGenerator defaultDir(String ... dirNames) {
221+
defaultDir = String.join("/", dirNames);
222+
return getThis();
223+
}
224+
225+
/**
226+
* Reset default dir value
227+
* @return this
228+
*/
229+
public RssGenerator resetDefaultDir() {
230+
defaultDir = null;
231+
return getThis();
232+
}
233+
234+
/**
235+
* Sets default suffix extension for all subsequent WebPages. Final name will be "name.extension"
236+
* @param extension Extension
237+
* @return this
238+
*/
239+
public RssGenerator defaultExtension(String extension) {
240+
defaultExtension = extension;
241+
return getThis();
242+
}
243+
244+
/**
245+
* Reset default extension value
246+
* @return this
247+
*/
248+
public RssGenerator resetDefaultExtension() {
249+
defaultExtension = null;
250+
return getThis();
251+
}
252+
191253
}

0 commit comments

Comments
 (0)