1 4 package org.openedit.links; 5 6 import java.util.Collections ; 7 import java.util.Iterator ; 8 import java.util.List ; 9 10 import org.dom4j.Element; 11 12 import com.openedit.OpenEditException; 13 import com.openedit.page.Page; 14 import com.openedit.page.PageProperty; 15 import com.openedit.util.PathUtilities; 16 17 public class HtmlLinkLoader extends XmlLinkLoader 18 { 19 20 protected void checkLink(Element element, Link link) throws OpenEditException 21 { 22 String load = element.attributeValue("autoloadchildren"); 23 if( Boolean.parseBoolean(load)) 24 { 25 Page dir = getPageManager().getPage(link.getPath()); 26 if( !dir.isFolder()) 27 { 28 dir = getPageManager().getPage(dir.getDirectory() ); 29 } 30 List paths = getPageManager().getRepository().getChildrenNames(dir.getPath()); 31 Collections.sort(paths); 32 findLinks(link, paths); 33 } 34 } 35 36 protected void findLinks(Link link, List paths) throws OpenEditException 37 { 38 for (Iterator iterator = paths.iterator(); iterator.hasNext();) 39 { 40 String path = (String ) iterator.next(); 41 if( path.endsWith(".html") || path.endsWith(".htm")) 42 { 43 Page page = getPageManager().getPage(path); 44 if( page.isDraft()) 45 { 46 continue; 47 } 48 Link dlink = new Link(); 49 PageProperty title = page.getPageSettings().getFieldProperty("title"); 50 if( title != null) 51 { 52 dlink.setText(title.getValue()); 53 } 54 else 55 { 56 String pname = PathUtilities.extractPageName(path); 57 if( pname.equals("index")) 58 { 59 continue; } 61 else 62 { 63 StringBuffer name = new StringBuffer (); 65 for (int i = 0; i < pname.length(); i++) 66 { 67 char charAt = pname.charAt(i); 68 if( i != 0 && Character.isUpperCase(charAt) && !Character.isWhitespace(pname.charAt(i-1)) ) 69 { 70 name.append(' '); 71 } 72 name.append(charAt); 73 } 74 pname = name.toString(); 75 } 76 dlink.setText(pname); 77 } 78 dlink.setPath(path); 79 dlink.setId(PathUtilities.makeId(path)); 80 link.addChild(dlink); 81 } 82 } 83 } 84 85 } 86 | Popular Tags |