HTMLPage page = htmlAPI.loadLivePageById(
st.getPagedetail(), systemUser, true);
Logger.debug(this, " Creating Site Map for Structure "
+ stVelocityVarName);
Identifier pageIdentifier = identAPI.find(page
.getIdentifier());
Logger.debug(this,
" Performing Host Parameter validation Page Identifider Host ["
+ pageIdentifier.getHostId()
+ "], Host Identifider ["
+ host.getIdentifier() + "], Deleted ["
+ page.isDeleted() + "], Live ["
+ page.isLive() + "]");
if (!(host.getIdentifier().equals(
pageIdentifier.getHostId()) && (!page.isDeleted() && page
.isLive()))) {
Logger.debug(this,
"Host Parameter validation failed for structure ["
+ stVelocityVarName + "]");
continue;
}
String query = "+structureName:" + st.getVelocityVarName()
+ " +deleted:false +live:true";
List<Contentlet> hits = conAPI.search(query, -1, 0, "",
systemUser, true);
String structureURLMap = st.getUrlMapPattern();
List<RegExMatch> matches = null;
if (useStructureURLMap
&& UtilMethods.isSet(structureURLMap)) {
matches = RegEX.find(st.getUrlMapPattern(),
"({[^{}]+})");
}
for (Contentlet contenlet : hits) {
try {
if (usePermalinks) {
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape("http://"
+ host.getHostname()
+ "/permalink/"
+ contenlet.getIdentifier()
+ "/" + st.getPagedetail()
+ "/")
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
} else if (useStructureURLMap
&& UtilMethods.isSet(structureURLMap)
&& (matches != null)) {
String uri = structureURLMap;
Logger.debug(this,
" Found the URL String for validation ["
+ uri + "]");
for (RegExMatch match : matches) {
String urlMapField = match.getMatch();
String urlMapFieldValue = contenlet
.getStringProperty(urlMapField
.substring(1, (urlMapField
.length() - 1)));
urlMapField = urlMapField.replaceFirst(
"\\{", "\\\\{");
urlMapField = urlMapField.replaceFirst(
"\\}", "\\\\}");
if (urlMapFieldValue != null) {
uri = uri.replaceAll(urlMapField,
urlMapFieldValue);
}
Logger.debug(this,
"Performing Variable replacement - urlMapField ["
+ match.getMatch()
+ "], urlMapField [ "
+ urlMapField
+ "], urlMapFieldValue ["
+ urlMapFieldValue
+ "], uri [" + uri + "]");
}
if (uri == null
&& UtilMethods
.isSet(st.getDetailPage())) {
if (page != null
&& UtilMethods.isSet(page
.getIdentifier())) {
uri = page.getURI() + "?id="
+ contenlet.getInode();
}
}
String urlRelacementText = getUrlPatternReplacementText(
host, stVelocityVarName);
uri = uri.replaceAll(urlRelacementText, "");
Logger.debug(this,
"Performing URL replacement - urlRelacementText ["
+ urlRelacementText
+ "], uri [" + uri + "]");
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape("http://"
+ host.getHostname() + uri)
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
} else {
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape("http://"
+ host.getHostname()
+ pageIdentifier.getURI()
+ "?id="
+ contenlet.getIdentifier())
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
}
writeFile(stringbuf);
addRegistryProcessed();
} catch (Exception e) {
Logger.error(this, e.getMessage(), e);
}
}
}
/**
* This part add the show on menu pages. similar as we do in
* navigationwebapi to generate sitemap
* */
java.util.List<Folder> itemsList = new ArrayList<Folder>();
itemsList = folderAPI.findSubFolders(host, true);
//Logger.warn(this, "Finding Subfolders for referebce [" + itemsList.size() + "]");
Comparator<Folder> comparator = new AssetsComparator(
orderDirection);
Collections.sort(itemsList, comparator);
List<Inode> itemsList2 = new ArrayList<Inode>();
for (Folder f : itemsList) {
if (f instanceof Folder) {
//Logger.warn(this, "Folder Iteration in progress Name [" + f.getName() + "], show on Menu Indicator [" + f.isShowOnMenu() + "]");
itemsList2.addAll(folderAPI.findMenuItems(f,
systemUser, true));
}
}
//Logger.warn(this, "List Size [" + itemsList2 + "]");
if (itemsList2.size() > 0) {
// /FIRST LEVEL MENU ITEMS!!!!
for (Permissionable itemChild : itemsList) {
if (itemChild instanceof Folder) {
Folder folderChild = (Folder) itemChild;
Logger.debug(this, "Folder Iteration in progress Name [" + folderChild.getName() + "], show on Menu Indicator [" + folderChild.isShowOnMenu() + "]");
// recursive method here
buildSubFolderSiteMapMenu(folderChild, 100, 1, 1);
} else if (itemChild instanceof Link) {
Link link = (Link) itemChild;
if (link.isLive() && !link.isDeleted()) {
if (link.getUrl()
.startsWith(host.getHostname())) {
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape(link
.getProtocal()
+ link.getUrl())
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
writeFile(stringbuf);
addRegistryProcessed();
}
}
} else if (itemChild instanceof HTMLPage) {
HTMLPage page = (HTMLPage) itemChild;
Logger.debug(this, "Folder Page Configuration " + page.getURI());
if (page.isLive() && !page.isDeleted()) {
String indexPageConfiguration = "/index."+ Config.getStringProperty("VELOCITY_PAGE_EXTENSION");
String pathToPageUrl = XMLUtils.xmlEscape("http://"+ host.getHostname() + page.getURI());
if (pathToPageUrl.endsWith(indexPageConfiguration)) {
pathToPageUrl = pathToPageUrl.replace(indexPageConfiguration, "");
}
stringbuf = "<url><loc>"
+ pathToPageUrl
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
writeFile(stringbuf);
addRegistryProcessed();
}
} else if (itemChild instanceof com.dotmarketing.portlets.files.model.File) {
com.dotmarketing.portlets.files.model.File file = (com.dotmarketing.portlets.files.model.File) itemChild;
if (file.isLive() && !file.isDeleted()) {
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape("http://"
+ host.getHostname()
+ file.getURI())
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
writeFile(stringbuf);
addRegistryProcessed();
}
} else if (itemChild instanceof Contentlet) {
Contentlet fileContent = (Contentlet)itemChild;
if (fileContent.isLive() && !fileContent.isArchived()) {
Identifier identifier = APILocator.getIdentifierAPI().find(fileContent);
stringbuf = "<url><loc>"
+ XMLUtils.xmlEscape("http://"
+ host.getHostname()
+ UtilMethods.encodeURIComponent(identifier.getParentPath()+fileContent.getStringProperty(FileAssetAPI.FILE_NAME_FIELD)))
+ "</loc><lastmod>"
+ modifiedDateStringValue
+ "</lastmod><changefreq>daily</changefreq></url>\n";
writeFile(stringbuf);
addRegistryProcessed();