1 22 23 package org.meshcms.taglib; 24 25 import java.io.*; 26 import java.util.*; 27 import javax.servlet.jsp.JspException ; 28 import org.meshcms.core.*; 29 import org.meshcms.util.*; 30 31 public class LangMenu extends AbstractTag { 32 private String separator = " "; 33 private String pre; 34 private String post; 35 36 public void setSeparator(String separator) { 37 if (separator != null) { 38 this.separator = separator; 39 } 40 } 41 42 public String getSeparator() { 43 return separator; 44 } 45 46 public void writeTag() throws IOException, JspException { 47 SiteMap siteMap = webSite.getSiteMap(); 48 49 if (pagePath.isRoot() || siteMap.getPageInfo(pagePath) == null) { 50 return; 51 } 52 53 List langList = siteMap.getLangList(); 54 55 if (langList.size() > 1) { 56 Iterator iter = langList.iterator(); 57 boolean putSeparator = false; 58 Writer w = getOut(); 59 60 if (pre != null) { 61 w.write(pre); 62 } 63 64 while (iter.hasNext()) { 65 if (putSeparator) { 66 w.write(separator); 67 } 68 69 putSeparator = true; 70 SiteMap.CodeLocalePair lang = (SiteMap.CodeLocalePair) iter.next(); 71 String langCode = lang.getCode(); 72 String localeName = Utils.encodeHTML(lang.getName()); 73 String link = null; 74 String msg = null; 75 76 if (!langCode.equalsIgnoreCase(pagePath.getElementAt(0))) { 77 Path path = siteMap.getServedPath(pagePath.replace(0, langCode)); 78 79 if (!webSite.getFile(path).isFile()) { 80 if (userInfo != null && userInfo.canWrite(webSite, path)) { 81 PageInfo ppi = siteMap.getParentPageInfo(pagePath); 82 83 if (ppi != null && ppi.getLevel() > 0) { 84 Path pPath = ppi.getPath().replace(0, langCode); 85 86 if (siteMap.getPageInfo(pPath) != null) { 87 if (msg == null) { 88 ResourceBundle bundle = 89 ResourceBundle.getBundle("org/meshcms/webui/Locales", 90 WebUtils.getPageLocale(pageContext)); 91 msg = Utils.replace(bundle.getString("confirmTranslation"), 92 '\'', "\\'"); 93 } 94 link = "javascript:if (confirm('" + msg +"')) location.href='" + 95 afp + "/createpage.jsp?popup=false&newdir=false&fullpath=" + 96 path + "';"; 97 } 98 } 99 } 100 101 if (link == null) { 102 path = new Path(langCode); 103 } 104 } 105 106 if (link == null) { 107 link = cp + webSite.getLink(path); 108 } 109 } 110 111 if (link == null) { 112 w.write(localeName); 113 } else { 114 w.write("<a HREF=\"" + link + "\">" + localeName + "</a>"); 115 } 116 } 117 118 if (post != null) { 119 w.write(post); 120 } 121 } 122 } 123 124 public String getPre() { 125 return pre; 126 } 127 128 public void setPre(String pre) { 129 this.pre = pre; 130 } 131 132 public String getPost() { 133 return post; 134 } 135 136 public void setPost(String post) { 137 this.post = post; 138 } 139 } 140 | Popular Tags |