Index: portal-render-engine-impl/pack/src/webapp/vm/neoskin/includeTabs.vm =================================================================== --- portal-render-engine-impl/pack/src/webapp/vm/neoskin/includeTabs.vm (revision 125737) +++ portal-render-engine-impl/pack/src/webapp/vm/neoskin/includeTabs.vm (working copy) @@ -203,7 +203,7 @@ #else
  • - ${site.fullTitle} Tools + ${site.siteTitle} Tools
  • #end #end @@ -214,7 +214,7 @@
    Index: portal-impl/impl/src/test/org/sakaiproject/portal/charon/site/PortalSiteHelperTest.java =================================================================== --- portal-impl/impl/src/test/org/sakaiproject/portal/charon/site/PortalSiteHelperTest.java (revision 0) +++ portal-impl/impl/src/test/org/sakaiproject/portal/charon/site/PortalSiteHelperTest.java (revision 0) @@ -0,0 +1,50 @@ +package org.sakaiproject.portal.charon.site; + +import junit.framework.TestCase; + +public class PortalSiteHelperTest extends TestCase { + + private static final String [] SITE_TITLES = new String[] { + "This is a really long site with a very high number of characters on it, an probably with strange behaviour in the portal.", + "This is a really long site with a very high number of characters on it, an probably with strange behaviour in the portal.", + "Short", + "Not so long title" + }; + + private static final String [] CUT_METHODS = new String[]{"100:0","50:50","0:100","70:30","-1","100:100","a:b"}; + private static final int [] MAX_LENGTHS = new int[]{25,50,15,8,25,50,125}; + private static final String [] CUT_SEPARATORS = new String[]{" ...","...","{..}"," ...","...","{..}","......"}; + + + public void testGetResumeTitles() { + for (int k=0; kMAX_LENGTHS[k] && MAX_LENGTHS[k]>=10) { + // The title must to be cut, so it has to contains cut separator + assertEquals(true,resumeTitle.contains(CUT_SEPARATORS[k])); + int [] finalCutMethod = helper.getCutMethod(CUT_METHODS[k]); + // Check if ends or start with cut separator + if (finalCutMethod[1]==0) assertEquals(true,resumeTitle.endsWith(CUT_SEPARATORS[k])); + else assertEquals(false,resumeTitle.endsWith(CUT_SEPARATORS[k])); + if (finalCutMethod[0]==0) assertEquals(true,resumeTitle.startsWith(CUT_SEPARATORS[k])); + else assertEquals(false,resumeTitle.startsWith(CUT_SEPARATORS[k])); + } else if (siteTitle.length()>MAX_LENGTHS[k]) { + // Title truncate + assertEquals(siteTitle.trim().substring(0,MAX_LENGTHS[k]),resumeTitle); + } else { + // Title without change + assertEquals(siteTitle.trim(),resumeTitle); + } + } + } + +} Property changes on: portal-impl/impl/src/test/org/sakaiproject/portal/charon/site/PortalSiteHelperTest.java ___________________________________________________________________ Added: svn:eol-style + native Index: portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/PortalSiteHelperImpl.java =================================================================== --- portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/PortalSiteHelperImpl.java (revision 125737) +++ portal-impl/impl/src/java/org/sakaiproject/portal/charon/site/PortalSiteHelperImpl.java (working copy) @@ -316,6 +316,51 @@ } /** + * SAK-23567 Gets an array with 2 int values {left,right} + * left: left percentage (before cut separator) + * right: right percentage (after separator) + */ + protected int [] getCutMethod(String siteTitleCutMethodString) { + String [] siteTitleCutMethod = siteTitleCutMethodString.split(":"); + int [] cutMethod = new int[]{100,0}; + try { + if (siteTitleCutMethod.length==2) { + cutMethod[0] = Integer.parseInt(siteTitleCutMethod[0]); + cutMethod[1] = Integer.parseInt(siteTitleCutMethod[1]); + if (cutMethod[0]+cutMethod[1]!=100) throw new Exception(); + } + } catch (Throwable ex) { + cutMethod[0] = 100; cutMethod[1] = 0; + } + return cutMethod; + } + /** + * SAK-23567 Gets the resumed version of the title + */ + protected String getResumeTitle(String fullTitle,String cutMethod,int siteTitleMaxLength,String cutSeparator) { + String titleStr = fullTitle; + if ( titleStr != null ) + { + titleStr = titleStr.trim(); + if ( titleStr.length() > siteTitleMaxLength && siteTitleMaxLength >= 10 ) + { + int [] siteTitleCutMethod = getCutMethod(cutMethod); + int begin = Math.round(((siteTitleMaxLength-cutSeparator.length())*siteTitleCutMethod[0])/100); + int end = Math.round(((siteTitleMaxLength-cutSeparator.length())*siteTitleCutMethod[1])/100); + // Adjust odd character to the begin + begin += (siteTitleMaxLength - (begin + cutSeparator.length() + end)); + titleStr = ((begin>0)?titleStr.substring(0,begin):"") + cutSeparator +((end>0)?titleStr.substring(titleStr.length()-end):""); + } + else if ( titleStr.length() > siteTitleMaxLength ) + { + titleStr = titleStr.substring(0,siteTitleMaxLength); + } + //titleStr = titleStr.trim(); + } + return titleStr; + } + + /** * Explode a site into a map suitable for use in the map * * @see org.sakaiproject.portal.api.PortalSiteHelper#convertSiteToMap(javax.servlet.http.HttpServletRequest, @@ -341,22 +386,11 @@ m.put("isMyWorkspace", Boolean.valueOf(myWorkspaceSiteId != null && (s.getId().equals(myWorkspaceSiteId) || effectiveSite .equals(myWorkspaceSiteId)))); - int siteTitleMaxLength = ServerConfigurationService.getInt("site.title.maxlength", 25); - String titleStr = s.getTitle(); - String fullTitle = titleStr; - if ( titleStr != null ) - { - titleStr = titleStr.trim(); - if ( titleStr.length() > siteTitleMaxLength && siteTitleMaxLength >= 10 ) - { - titleStr = titleStr.substring(0,siteTitleMaxLength-4) + " ..."; - } - else if ( titleStr.length() > siteTitleMaxLength ) - { - titleStr = titleStr.substring(0,siteTitleMaxLength); - } - titleStr = titleStr.trim(); - } + String fullTitle = s.getTitle(); + String titleStr = getResumeTitle(fullTitle + ,ServerConfigurationService.getString("site.title.cut.method", "100:0") + ,ServerConfigurationService.getInt("site.title.maxlength", 25) + ,ServerConfigurationService.getString("site.title.cut.separator", " ...")); m.put("siteTitle", Web.escapeHtml(titleStr)); m.put("fullTitle", Web.escapeHtml(fullTitle)); m.put("siteDescription", s.getHtmlDescription());