Please wait. This can take some minutes ...
Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance.
Project price only 1 $
You can buy this project and download/modify it how often you want.
net.anotheria.anosite.bredcrambs.data.DocumentEnum Maven / Gradle / Ivy
package net.anotheria.anosite.bredcrambs.data;
import net.anotheria.anoprise.metafactory.MetaFactory;
import net.anotheria.anoprise.metafactory.MetaFactoryException;
import net.anotheria.anosite.gen.aslayoutdata.data.PageLayout;
import net.anotheria.anosite.gen.aslayoutdata.service.ASLayoutDataServiceException;
import net.anotheria.anosite.gen.aslayoutdata.service.IASLayoutDataService;
import net.anotheria.anosite.gen.assitedata.data.EntryPoint;
import net.anotheria.anosite.gen.assitedata.data.NaviItem;
import net.anotheria.anosite.gen.assitedata.data.PageAlias;
import net.anotheria.anosite.gen.assitedata.data.PageTemplate;
import net.anotheria.anosite.gen.assitedata.data.Site;
import net.anotheria.anosite.gen.assitedata.service.ASSiteDataServiceException;
import net.anotheria.anosite.gen.assitedata.service.IASSiteDataService;
import net.anotheria.anosite.gen.aswebdata.data.Attribute;
import net.anotheria.anosite.gen.aswebdata.data.Box;
import net.anotheria.anosite.gen.aswebdata.data.Pagex;
import net.anotheria.anosite.gen.aswebdata.service.ASWebDataServiceException;
import net.anotheria.anosite.gen.aswebdata.service.IASWebDataService;
import net.anotheria.asg.data.DataObject;
import net.anotheria.asg.exception.ConstantNotFoundException;
import net.anotheria.util.StringUtils;
import org.apache.commons.lang.WordUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.slf4j.MarkerFactory;
import java.util.*;
/**
* Enum represents type of elements and can find usages of current element by its id.
*
* @author vzarva
*/
public enum DocumentEnum {
//Content menu.
PAGE("PAGEX") {
@Override
public List findReferences(String pId) {
return findUsagesOfPage(pId);
}
},
BOX("BOX") {
@Override
public List findReferences(String pId) {
return findUsagesOfBox(pId);
}
},
ATTRIBUTE("ATTRIBUTE") {
@Override
public List findReferences(String pId) {
return findUsagesOfAttribute(pId);
}
},
//Site menu.
SITE("SITE") {
@Override
public List findReferences(String pId) {
return findUsagesOfSite(pId);
}
},
NAVIITEM("NAVIITEM") {
@Override
public List findReferences(String pId) {
return findUsagesOfNaviItem(pId);
}
},
PAGE_TEMPLATE("PAGETEMPLATE") {
@Override
public List findReferences(String pId) {
return findUsagesOfPageTemplate(pId);
}
},
MEDIA_LINK("MEDIALINK") {
@Override
public List findReferences(String pId) {
return findUsagesOfMediaLink(pId);
}
},
SCRIPT("SCRIPT") {
@Override
public List findReferences(String pId) {
return findUsagesOfScript(pId);
}
},
PAGE_ALIAS("PAGEALIAS") {
@Override
public List findReferences(String pId) {
return findUsagesOfPageAlias(pId);
}
},
//Layout menu.
LAYOUT("PAGELAYOUT") {
@Override
public List findReferences(String pId) {
return findUsagesOfLayout(pId);
}
},
STYLE("PAGESTYLE") {
@Override
public List findReferences(String pId) {
return findUsagesOfStyle(pId);
}
},
//Definitions menu.
GENERIC_BOX_TYPE("GENERICBOXTYPE") {
@Override
public List findReferences(String pId) {
return findUsagesOfGenericType(pId);
}
},
CUSTOM_BOX_TYPE("CUSTOMBOXTYPE") {
@Override
public List findReferences(String pId) {
return findUsagesOfCustomType(pId);
}
},
GENERIC_BOX_HANDLER("GENERICBOXHANDLERDEF") {
@Override
public List findReferences(String pId) {
return findUsagesOfGenericHandler(pId);
}
},
CUSTOM_BOX_HANDLER("CUSTOMBOXHANDLERDEF") {
@Override
public List findReferences(String pId) {
return findUsagesOfCustomHandler(pId);
}
},
GENERIC_GUARD("GENERICGUARDDEF") {
@Override
public List findReferences(String pId) {
return findUsagesOfGenericGuard(pId);
}
},
CUSTOM_GUARD("CUSTOMGUARDDEF") {
@Override
public List findReferences(String pId) {
return findUsagesOfCustomGuard(pId);
}
},
//Resources menu.
LOCALIZATION_BUNDLE("LOCALIZATIONBUNDLE") {
@Override
public List findReferences(String pId) {
return findUsagesOfLocalizationBundle(pId);
}
};
/**
* Logger by default.
*/
private static final Logger LOGGER = LoggerFactory.getLogger(DocumentEnum.class);
/**
* Data services.
*/
private static IASWebDataService webDataService;
private static IASSiteDataService siteDataService;
private static IASLayoutDataService layoutDataService;
static {
try {
webDataService = MetaFactory.get(IASWebDataService.class);
siteDataService = MetaFactory.get(IASSiteDataService.class);
layoutDataService = MetaFactory.get(IASLayoutDataService.class);
} catch (MetaFactoryException e) {
LOGGER.error(MarkerFactory.getMarker("FATAL"), "Services init failure", e);
}
}
private String value;
DocumentEnum(String value) {
this.value = value;
}
public String getValue() {
return value;
}
/**
* Method find usages of element by its id.
*
* @param pId - id of element
* @return - list of references to the elements, where element was used
*/
public abstract List findReferences(String pId);
public static DocumentEnum getConstantByValue(String value) throws ConstantNotFoundException {
for (DocumentEnum e : values()) {
if (e.getValue().equalsIgnoreCase(value)) {
return e;
}
}
throw new ConstantNotFoundException("DocumentEnum value not found by value[" + value + "]");
}
private static List findUsagesOfBox(String pId) {
List result = new ArrayList();
try {
Map mapOfAllBoxes = new HashMap();
for (Box box : webDataService.getBoxs()) {
mapOfAllBoxes.put(box.getId(), box);
}
for (Pagex p : webDataService.getPagexs()) {
result.addAll(findBoxUsages(p.getName(), p.getC1(), pId, p, Pagex.PROP_C1, mapOfAllBoxes));
result.addAll(findBoxUsages(p.getName(), p.getC2(), pId, p, Pagex.PROP_C2, mapOfAllBoxes));
result.addAll(findBoxUsages(p.getName(), p.getC3(), pId, p, Pagex.PROP_C3, mapOfAllBoxes));
result.addAll(findBoxUsages(p.getName(), p.getHeader(), pId, p, Pagex.PROP_HEADER, mapOfAllBoxes));
result.addAll(findBoxUsages(p.getName(), p.getFooter(), pId, p, Pagex.PROP_FOOTER, mapOfAllBoxes));
}
for (PageTemplate pt : siteDataService.getPageTemplates()) {
result.addAll(findBoxUsages(pt.getName(), pt.getC1first(), pId, pt, PageTemplate.PROP_C1FIRST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getC1last(), pId, pt, PageTemplate.PROP_C1LAST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getC2first(), pId, pt, PageTemplate.PROP_C2FIRST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getC2last(), pId, pt, PageTemplate.PROP_C2LAST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getC3first(), pId, pt, PageTemplate.PROP_C3FIRST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getC3last(), pId, pt, PageTemplate.PROP_C3LAST, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getMeta(), pId, pt, PageTemplate.PROP_META, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getHeader(), pId, pt, PageTemplate.PROP_HEADER, mapOfAllBoxes));
result.addAll(findBoxUsages(pt.getName(), pt.getFooter(), pId, pt, PageTemplate.PROP_FOOTER, mapOfAllBoxes));
}
for (Map.Entry entry : mapOfAllBoxes.entrySet()) {
String currentBoxId = entry.getKey();
if (currentBoxId.equalsIgnoreCase(pId))
continue;
Box curentBox = entry.getValue();
StringBuffer tempPath = new StringBuffer(" Box [" + curentBox.getName() + "] -> " +
" Subboxes ");
if (currentBoxId.equalsIgnoreCase(pId)) {
result.add(tempPath + "");
}
List subboxList = curentBox.getSubboxes();
if (!subboxList.isEmpty()) {
findBoxInSubboxesRecursively(subboxList, pId, tempPath, result, mapOfAllBoxes);
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("can't retrieve pagex getPagex()", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("can't retrieve pagex getPageTemplates()", e);
}
return result;
}
private static List findBoxUsages(String nameOfPage, List list, String searchElemId, DataObject dataObject, String c, Map mapOfAllBoxes) {
if (StringUtils.isEmpty(searchElemId) || list.isEmpty()) {
return Collections.emptyList();
}
List ret = new ArrayList();
String module = "aswebdata";
if (dataObject.getDefinedName() != null && dataObject.getDefinedName().equalsIgnoreCase("PageTemplate")) {
module = "assitedata";
}
StringBuffer pathBefore = new StringBuffer(" " + dataObject.getDefinedName() + " [" + nameOfPage + "] ->" +
" " + WordUtils.capitalize(c) + " ");
for (String id : list) {
Box box = mapOfAllBoxes.get(id);
if (box == null)
continue;
if (id.equalsIgnoreCase(searchElemId)) {
ret.add(pathBefore + "");
}
List subboxList = box.getSubboxes();
if (!subboxList.isEmpty()) {
findBoxInSubboxesRecursively(subboxList, searchElemId, pathBefore.append("-> Box [" + box.getName() + "] ->" +
" Subboxes "), ret, mapOfAllBoxes);
}
}
return ret;
}
private static void findBoxInSubboxesRecursively(List list, String searchElementId, StringBuffer pathBefore, List tempList, Map mapOfAllBoxes) {
for (String id : list) {
Box box = mapOfAllBoxes.get(id);
if (box == null)
continue;
StringBuffer tempPath = new StringBuffer(" -> Box [" + box.getName() + "] -> " +
" Subboxes ");
if (id.equalsIgnoreCase(searchElementId)) {
tempList.add(pathBefore + " ");
}
List subboxList = box.getSubboxes();
if (!subboxList.isEmpty()) {
findBoxInSubboxesRecursively(subboxList, searchElementId, pathBefore.append(tempPath), tempList, mapOfAllBoxes);
}
}
}
private static List findUsagesOfAttribute(String pId) {
List result = new ArrayList();
try {
Map mapOfAllAttributes = new HashMap();
for (Attribute attribute : webDataService.getAttributes()) {
mapOfAllAttributes.put(attribute.getId(), attribute);
}
for (Pagex pagex : webDataService.getPagexs()) {
StringBuffer pathBefore = new StringBuffer(" Pagex [" + pagex.getName() + "] ->" +
" Attributes ");
for (String attributeId : pagex.getAttributes()) {
Attribute attribute = mapOfAllAttributes.get(attributeId);
if (attribute == null)
continue;
if (attributeId.equalsIgnoreCase(pId)) {
result.add(pathBefore + "");
}
List subattrubutes = attribute.getSubattributes();
if (!subattrubutes.isEmpty()) {
StringBuffer pathWithCurrentAttr = new StringBuffer(" -> Attribute [" + attribute.getName() + "] ->" +
" Subattributes ");
findAttributeInSubattributesRecursively(subattrubutes, pId, pathBefore.append(pathWithCurrentAttr), result, mapOfAllAttributes);
}
}
}
for (Box box : webDataService.getBoxs()) {
StringBuffer pathBefore = new StringBuffer(" Box [" + box.getName() + "] ->" +
" Attributes ");
for (String attributeId : box.getAttributes()) {
Attribute attribute = mapOfAllAttributes.get(attributeId);
if (attribute == null)
continue;
if (attributeId.equalsIgnoreCase(pId)) {
result.add(pathBefore + "");
}
List subattrubutes = attribute.getSubattributes();
if (!subattrubutes.isEmpty()) {
StringBuffer pathWithCurrentAttr = new StringBuffer(" -> Attribute [" + attribute.getName() + "] ->" +
" Subattributes ");
findAttributeInSubattributesRecursively(subattrubutes, pId, pathBefore.append(pathWithCurrentAttr), result, mapOfAllAttributes);
}
}
}
for (Map.Entry entry : mapOfAllAttributes.entrySet()) {
if (entry.getKey().equalsIgnoreCase(pId))
continue;
StringBuffer pathBefore = new StringBuffer(" Attribute [" + entry.getValue().getName() + "] ->" +
" Attributes ");
for (String attributeId : entry.getValue().getSubattributes()) {
Attribute attribute = mapOfAllAttributes.get(attributeId);
if (attribute == null)
continue;
if (attributeId.equalsIgnoreCase(pId)) {
result.add(pathBefore + "");
}
List subattrubutes = attribute.getSubattributes();
if (!subattrubutes.isEmpty()) {
StringBuffer pathWithCurrentAttr = new StringBuffer(" -> Attribute [" + attribute.getName() + "] ->" +
" Subattributes ");
findAttributeInSubattributesRecursively(subattrubutes, pId, pathBefore.append(pathWithCurrentAttr), result, mapOfAllAttributes);
}
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("IASWebDataService failed.", e);
}
return result;
}
private static void findAttributeInSubattributesRecursively(List listOfSubattributes, String searcheElementId, StringBuffer pathBefore, List resList, Map mapOfAllAttributes) {
for (String subAttributeId : listOfSubattributes) {
Attribute attribute = mapOfAllAttributes.get(subAttributeId);
if (attribute == null)
continue;
if (subAttributeId.equalsIgnoreCase(searcheElementId)) {
resList.add(pathBefore + "");
}
List subattrubutes = attribute.getSubattributes();
if (!subattrubutes.isEmpty()) {
StringBuffer pathWithCurrentAttr = new StringBuffer(" -> Attribute [" + attribute.getName() + "] ->" +
" subattributes ");
findAttributeInSubattributesRecursively(subattrubutes, searcheElementId, pathBefore.append(pathWithCurrentAttr), resList, mapOfAllAttributes);
}
}
}
private static List findUsagesOfMediaLink(String scriptId) {
List result = new ArrayList();
try {
for (Pagex p : webDataService.getPagexs()) {
for (String id : p.getMediaLinks()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" Page [" + p.getName() + "] - " +
" MediaLinks ");
}
}
}
for (Box b : webDataService.getBoxs()) {
for (String id : b.getMediaLinks()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" Box [" + b.getName() + "] - " +
" MediaLinks ");
}
}
}
for (PageTemplate pt : siteDataService.getPageTemplates()) {
for (String id : pt.getMediaLinks()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" PageTemplete [" + pt.getName() + "] - " +
" MediaLinks ");
}
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService", e);
}
return result;
}
private static List findUsagesOfScript(String scriptId) {
List result = new ArrayList();
try {
for (Pagex p : webDataService.getPagexs()) {
for (String id : p.getScripts()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" Page [" + p.getName() + "] - " +
" Scripts ");
}
}
}
for (Box b : webDataService.getBoxs()) {
for (String id : b.getScripts()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" Box [" + b.getName() + "] - " +
" Scripts ");
}
}
}
for (PageTemplate pt : siteDataService.getPageTemplates()) {
for (String id : pt.getScripts()) {
if (id.equalsIgnoreCase(scriptId)) {
result.add(" PageTemplete [" + pt.getName() + "] - " +
" Scripts ");
}
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService", e);
}
return result;
}
private static List findUsagesOfCustomHandler(String handlerId) {
List result = new ArrayList();
try {
for (Box b : webDataService.getBoxs()) {
if (b == null || b.getHandler() == null)
continue;
String searchedId = "C-" + handlerId;
if (searchedId.equalsIgnoreCase(b.getHandler())) {
result.add(" Box [" + b.getName() + "] ");
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
}
return result;
}
private static List findUsagesOfGenericHandler(String handlerId) {
List result = new ArrayList();
try {
for (Box b : webDataService.getBoxs()) {
if (b == null || b.getHandler() == null)
continue;
String searchedId = "G-" + handlerId;
if (searchedId.equalsIgnoreCase(b.getHandler())) {
result.add(" Box [" + b.getName() + "] ");
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
}
return result;
}
private static List findUsagesOfCustomType(String typeId) {
List result = new ArrayList();
try {
for (Box b : webDataService.getBoxs()) {
if (b == null || b.getType() == null)
continue;
String searchedId = "C-" + typeId;
if (searchedId.equalsIgnoreCase(b.getType())) {
result.add(" Box [" + b.getName() + "] ");
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
}
return result;
}
private static List findUsagesOfGenericType(String typeId) {
List result = new ArrayList();
try {
for (Box b : webDataService.getBoxs()) {
if (b == null || b.getType() == null)
continue;
String searchedId = "G-" + typeId;
if (searchedId.equalsIgnoreCase(b.getType())) {
result.add(" Box [" + b.getName() + "] ");
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
}
return result;
}
private static List findUsagesOfGenericGuard(String guardId) {
List result = new ArrayList();
String searchedId = "G-" + guardId;
try {
for (Box b : webDataService.getBoxs()) {
for (String guard : b.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" Box [" + b.getName() + "] - " +
" Guards ");
}
}
}
for (Attribute attribute : webDataService.getAttributes()) {
for (String guard : attribute.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" Attribute [" + attribute.getName() + "] - " +
" Guards ");
}
}
}
for (NaviItem naviItem : siteDataService.getNaviItems()) {
for (String guard : naviItem.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" NaviItem [" + naviItem.getName() + "] - " +
" Guards ");
}
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfCustomGuard(String guardId) {
List result = new ArrayList();
String searchedId = "C-" + guardId;
try {
for (Box b : webDataService.getBoxs()) {
for (String guard : b.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" Box [" + b.getName() + "] - " +
" Guards ");
}
}
}
for (Attribute attribute : webDataService.getAttributes()) {
for (String guard : attribute.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" Attributes [" + attribute.getName() + "] - " +
" Guards ");
}
}
}
for (NaviItem naviItem : siteDataService.getNaviItems()) {
for (String guard : naviItem.getGuards()) {
if (searchedId.equalsIgnoreCase(guard)) {
result.add(" NaviItem [" + naviItem.getName() + "] - " +
" Guards ");
}
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfPageAlias(String pageAliasId) {
List result = new ArrayList();
try {
for (NaviItem naviItem : siteDataService.getNaviItems()) {
if (naviItem == null || naviItem.getPageAlias() == null)
continue;
if (naviItem.getPageAlias().equalsIgnoreCase(pageAliasId)) {
result.add(" NaviItem [" + naviItem.getName() + "] ");
}
}
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfPage(String pageId) {
List result = new ArrayList();
try {
for (Site site : siteDataService.getSites()) {
if (site == null || site.getSearchpage() == null || site.getStartpage() == null)
continue;
if (site.getStartpage().equalsIgnoreCase(pageId) || site.getSearchpage().equalsIgnoreCase(pageId)) {
result.add(" Site [" + site.getName() + "] ");
}
}
for (NaviItem naviItem : siteDataService.getNaviItems()) {
if (naviItem == null || naviItem.getInternalLink() == null)
continue;
if (naviItem.getInternalLink().equalsIgnoreCase(pageId)) {
result.add(" NaviItem [" + naviItem.getName() + "] ");
}
}
for (EntryPoint entryPoint : siteDataService.getEntryPoints()) {
if (entryPoint == null || entryPoint.getStartPage() == null)
continue;
if (entryPoint.getStartPage().equalsIgnoreCase(pageId)) {
result.add(" EntryPoint [" + entryPoint.getName() + "] ");
}
}
for (PageAlias pageAlias : siteDataService.getPageAliass()) {
if (pageAlias == null || pageAlias.getTargetPage() == null)
continue;
if (pageAlias.getTargetPage().equalsIgnoreCase(pageId)) {
result.add(" PageAlias [" + pageAlias.getName() + "] ");
}
}
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfSite(String siteId) {
List result = new ArrayList();
try {
for (PageTemplate pageTemplate : siteDataService.getPageTemplates()) {
if (pageTemplate == null || pageTemplate.getSite() == null)
continue;
if (pageTemplate.getSite().equalsIgnoreCase(siteId)) {
result.add(" PageTemplate [" + pageTemplate.getName() + "] ");
}
}
for (EntryPoint entryPoint : siteDataService.getEntryPoints()) {
if (entryPoint == null || entryPoint.getStartSite() == null)
continue;
if (entryPoint.getStartSite().equalsIgnoreCase(siteId)) {
result.add(" EntryPoint [" + entryPoint.getName() + "] ");
}
}
for (PageAlias pageAlias : siteDataService.getPageAliass()) {
if (pageAlias == null || pageAlias.getTargetPage() == null)
continue;
if (pageAlias.getTargetPage().equalsIgnoreCase(siteId)) {
result.add(" PageAlias [" + pageAlias.getName() + "] ");
}
}
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfPageTemplate(String pageTemplateId) {
List result = new ArrayList();
try {
for (Pagex p : webDataService.getPagexs()) {
if (p == null || p.getTemplate() == null)
continue;
if (p.getTemplate().equalsIgnoreCase(pageTemplateId)) {
result.add(" Page [" + p.getName() + "] ");
}
}
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use WebDataService.", e);
}
return result;
}
private static List findUsagesOfLayout(String layoutId) {
List result = new ArrayList();
try {
for (PageTemplate pageTemplate : siteDataService.getPageTemplates()) {
if (pageTemplate == null || pageTemplate.getLayout() == null)
continue;
if (pageTemplate.getLayout().equalsIgnoreCase(layoutId)) {
result.add(" PageTemplate [" + pageTemplate.getName() + "] ");
}
}
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static List findUsagesOfStyle(String styleId) {
List result = new ArrayList();
try {
for (PageLayout pageLayout : layoutDataService.getPageLayouts()) {
if (pageLayout == null || pageLayout.getStyle() == null)
continue;
if (pageLayout.getStyle().equalsIgnoreCase(styleId)) {
result.add(" Layout [" + pageLayout.getName() + "] ");
}
}
} catch (ASLayoutDataServiceException e) {
LOGGER.error("failed to use LayoutDataService.", e);
}
return result;
}
private static List findUsagesOfNaviItem(String naviItemId) {
List result = new ArrayList();
try {
Map mapOfAllNaviItems = new HashMap();
for (NaviItem naviItem : siteDataService.getNaviItems()) {
mapOfAllNaviItems.put(naviItem.getId(), naviItem);
}
for (Map.Entry entry : mapOfAllNaviItems.entrySet()) {
for (String naviId : entry.getValue().getSubNavi()) {
StringBuffer pathBefore = new StringBuffer(" NaviItem [" + entry.getValue().getName() + "] -> " +
" SubNavi ");
NaviItem tempNaviItem = mapOfAllNaviItems.get(naviId);
if (tempNaviItem == null)
continue;
if (naviId.equalsIgnoreCase(naviItemId)) {
result.add(pathBefore + "");
}
List subNaviList = tempNaviItem.getSubNavi();
if (!subNaviList.isEmpty()) {
StringBuffer pathWithCurrentSubNavi = new StringBuffer(" -> NaviItem [" + tempNaviItem.getName() + "] ->" +
" SubNavi ");
findNaviItemInSubNaviRecursively(subNaviList, naviItemId, pathBefore.append(pathWithCurrentSubNavi), result, mapOfAllNaviItems);
}
}
}
for (Site site : siteDataService.getSites()) {
if (site == null || site.getTopNavi() == null || site.getMainNavi() == null)
continue;
if (!site.getTopNavi().isEmpty()) {
StringBuffer pathBeforeTopNavi = new StringBuffer(" Site [" + site.getName() + "] -> " +
" TopNavi ");
findNaviItemInSubNaviRecursively(site.getTopNavi(), naviItemId, pathBeforeTopNavi, result, mapOfAllNaviItems);
}
if (!site.getMainNavi().isEmpty()) {
StringBuffer pathBeforeMainNavi = new StringBuffer(" Site [" + site.getName() + "] -> " +
" TopNavi ");
findNaviItemInSubNaviRecursively(site.getTopNavi(), naviItemId, pathBeforeMainNavi, result, mapOfAllNaviItems);
}
//TODO implement search of naviitem through site document
}
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use SiteDataService.", e);
}
return result;
}
private static void findNaviItemInSubNaviRecursively(List listOfSubNavi, String searcheElementId, StringBuffer pathBefore, List resList, Map mapOfAllNaviItems) {
for (String subNaviId : listOfSubNavi) {
NaviItem naviItem = mapOfAllNaviItems.get(subNaviId);
if (naviItem == null)
continue;
if (subNaviId.equalsIgnoreCase(searcheElementId)) {
resList.add(pathBefore + "");
}
List subNaviList = naviItem.getSubNavi();
if (!subNaviList.isEmpty()) {
StringBuffer pathWithCurrentAttr = new StringBuffer(" -> NaviItem [" + naviItem.getName() + "] " +
" SubNavi ");
findNaviItemInSubNaviRecursively(subNaviList, searcheElementId, pathBefore.append(pathWithCurrentAttr), resList, mapOfAllNaviItems);
}
}
}
private static List findUsagesOfLocalizationBundle(String bundleId) {
List result = new ArrayList();
try {
result.addAll(findUsagesOfLocalizationBundleInBoxes(bundleId));
result.addAll(findUsagesOfLocalizationBundleInPages(bundleId));
result.addAll(findUsagesOfLocalizationBundleInTemplates(bundleId));
} catch (ASWebDataServiceException e) {
LOGGER.error("failed to use ASWebDataService.", e);
} catch (ASSiteDataServiceException e) {
LOGGER.error("failed to use ASSiteDataService.", e);
}
return result;
}
private static List findUsagesOfLocalizationBundleInBoxes(String bundleId) throws ASWebDataServiceException {
List responses = new ArrayList();
for (Box box : webDataService.getBoxs()) {
String response = new ResponseBuilder()
.setContainerUrlType("aswebdataBox")
.setContainerType("Box")
.setContainerId(box.getId())
.setContainerName(box.getName())
.setContentType("Localizations")
.build();
responses.addAll(findUsages(bundleId, box.getLocalizations(), response));
}
return responses;
}
private static List findUsagesOfLocalizationBundleInPages(String bundleId) throws ASWebDataServiceException {
List responses = new ArrayList();
for (Pagex pagex : webDataService.getPagexs()) {
String response = new ResponseBuilder()
.setContainerUrlType("aswebdataPagex")
.setContainerType("Page")
.setContainerId(pagex.getId())
.setContainerName(pagex.getName())
.setContentType("Localizations")
.build();
responses.addAll(findUsages(bundleId, pagex.getLocalizations(), response));
}
return responses;
}
private static List findUsagesOfLocalizationBundleInTemplates(String bundleId) throws ASSiteDataServiceException {
List responses = new ArrayList();
for (PageTemplate pageTemplate : siteDataService.getPageTemplates()) {
String response = new ResponseBuilder()
.setContainerUrlType("assitedataPageTemplate")
.setContainerType("PageTemplate")
.setContainerId(pageTemplate.getId())
.setContainerName(pageTemplate.getName())
.setContentType("Localizations")
.build();
responses.addAll(findUsages(bundleId, pageTemplate.getLocalizations(), response));
}
return responses;
}
private static List findUsages(String contentId, List containerElemIds,
String response) {
List responses = new ArrayList();
for (String otherId : containerElemIds) {
if (otherId.equals(contentId)) {
responses.add(response);
}
}
return responses;
}
/**
* The class allows build show usage response by predefined template
*/
private static class ResponseBuilder {
public static final String RESPONSE_TEMPLATE =
" %s [%s] -> " +
" %s ";
private String containerUrlType;
private String containerType;
private String containerId;
private String containerName;
private String contentType;
public ResponseBuilder setContainerUrlType(String containerUrlType) {
this.containerUrlType = containerUrlType;
return this;
}
public ResponseBuilder setContainerType(String containerType) {
this.containerType = containerType;
return this;
}
public ResponseBuilder setContainerId(String containerId) {
this.containerId = containerId;
return this;
}
public ResponseBuilder setContainerName(String containerName) {
this.containerName = containerName;
return this;
}
public ResponseBuilder setContentType(String contentType) {
this.contentType = contentType;
return this;
}
public String build() {
return String.format(RESPONSE_TEMPLATE,
containerUrlType,
containerId,
containerType,
containerName,
containerUrlType,
contentType,
containerId,
contentType
);
}
}
}