1 14 41 42 package org.jahia.data.viewhelper.sitemap; 43 44 import java.text.MessageFormat ; 45 import java.util.Hashtable ; 46 import java.util.Locale ; 47 48 import org.jahia.exceptions.JahiaException; 49 import org.jahia.resourcebundle.JahiaResourceBundle; 50 import org.jahia.services.pages.ContentPage; 51 import org.jahia.services.pages.JahiaPageBaseService; 52 import org.jahia.utils.LanguageCodeConverters; 53 import java.io.Serializable ; 54 55 66 final class PageSiteMap implements Serializable { 67 68 public PageSiteMap(int pageID, int pageLevel, boolean hasChild, 69 int parentPageID, boolean isLastSister, Hashtable titles, 70 int currentLevel, int defaultMaxLevel) { 71 this.pageLevel = pageLevel; 72 this.pageID = pageID; 73 this.hasChild = hasChild; 74 this.parentPageID = parentPageID; 75 this.isLastSister = isLastSister; 76 this.titles = titles; 77 this.expanded = currentLevel < defaultMaxLevel && hasChild ? true : false; 78 this.displayable = currentLevel <= defaultMaxLevel ? true : false; 79 this.showInformation = false; 80 this.showWarnings = false; 81 this.showErrors = false; 82 this.showEvents = false; 83 } 84 85 public int getPageID() { 86 return pageID; 87 } 88 89 public int getPageLevel() { 90 return pageLevel; 91 } 92 93 public boolean hasChild() { 94 return hasChild; 95 } 96 97 public int getParentPageID() { 98 return parentPageID; 99 } 100 101 public boolean isLastSister() { 102 return isLastSister; 103 } 104 105 public String getPageTitle(String languageCode) { 106 return getAPageTitleAnyway(languageCode); 107 } 108 109 public boolean isDisplayable() { 110 return displayable; 111 } 112 113 public void setDisplayable(boolean displayable) { 114 this.displayable = displayable; 115 } 116 117 public void setExpanded(boolean expanded) { 118 this.expanded = expanded; 119 } 120 121 public boolean isExpanded() { 122 return expanded; 123 } 124 125 public void setShowInformation(boolean showInformation) { 126 this.showInformation = showInformation; 127 } 128 129 public boolean isShowInformation() { 130 return showInformation; 131 } 132 133 public void setShowWarnings(boolean showWarnings) { 134 this.showWarnings = showWarnings; 135 } 136 137 public boolean isShowWarnings() { 138 return showWarnings; 139 } 140 141 public void setShowErrors(boolean showErrors) { 142 this.showErrors = showErrors; 143 } 144 145 public boolean isShowErrors() { 146 return showErrors; 147 } 148 149 public void setShowEvents(boolean showEvents) { 150 this.showEvents = showEvents; 151 } 152 153 public boolean isShowEvents() { 154 return showEvents; 155 } 156 157 private String getAPageTitleAnyway(String languageCode) { 158 String pageTitle1 = ((String )this.titles.get(languageCode)); 159 if (pageTitle1 == null) { 160 Locale locale = LanguageCodeConverters.languageCodeToLocale(languageCode); 161 try { 162 ContentPage contentPage = JahiaPageBaseService.getInstance(). 163 lookupContentPage(pageID, false); 164 if (contentPage.isStagedEntryMarkedForDeletion(languageCode)) { 165 Hashtable titles = contentPage.getTitles(ContentPage.ACTIVATED_PAGE_TITLES); 166 pageTitle1 = (String )titles.get(languageCode); 167 } else { 168 String msgFormat = JahiaResourceBundle.getMessageResource("org.jahia.engines.workflow.pageNotApplicable", locale); 169 Object [] arguments = {new Integer (this.pageID), LanguageCodeConverters.languageCodeToLocale(languageCode).getDisplayName(locale)}; 170 pageTitle1 = MessageFormat.format(msgFormat, arguments); 171 } 172 } catch (JahiaException je) { 173 logger.debug("Cannot recover the page with ID " + pageID); 174 return JahiaResourceBundle.getMessageResource("org.jahia.engines.workflow.pageNotExisting", locale); 175 } 176 } 177 return pageTitle1; 178 } 179 180 private final int pageID; 182 private final int pageLevel; 183 private final boolean hasChild; 184 private final int parentPageID; 185 private final boolean isLastSister; 186 private final Hashtable titles; 187 private boolean expanded; 189 private boolean displayable; 190 private boolean showInformation; 191 private boolean showWarnings; 192 private boolean showErrors; 193 private boolean showEvents; 194 195 private static org.apache.log4j.Logger logger = 196 org.apache.log4j.Logger.getLogger(PageSiteMap.class); 197 } 198 | Popular Tags |