1 48 49 package org.jpublish.page; 50 51 import java.io.InputStream ; 52 import java.io.InputStreamReader ; 53 import java.io.Reader ; 54 import java.io.UnsupportedEncodingException ; 55 import java.util.HashMap ; 56 import java.util.Map ; 57 58 import com.anthonyeden.lib.config.Configuration; 59 import com.anthonyeden.lib.config.ConfigurationException; 60 import com.anthonyeden.lib.config.sax.SAXConfigurationFactory; 61 import org.jpublish.SiteContext; 62 import org.jpublish.util.PathUtilities; 63 import org.jpublish.util.encoding.CharacterEncodingManager; 64 import org.jpublish.util.encoding.CharacterEncodingMap; 65 66 71 72 public class PageDefinition { 73 74 private SiteContext siteContext = null; 75 private String path = null; 76 private Configuration configuration = null; 77 private Map pageCache = new HashMap (); 78 79 85 86 public PageDefinition(SiteContext siteContext, String path) { 87 this.siteContext = siteContext; 88 this.path = path; 89 90 pageCache = new HashMap (); 91 } 92 93 98 99 public String getPath() { 100 return path; 101 } 102 103 111 112 public synchronized PageInstance getPageInstance(String path) 113 throws ConfigurationException { 114 PageInstance page = (PageInstance) pageCache.get(path); 115 if (page == null) { 116 page = new PageInstance(siteContext, path, 117 PathUtilities.extractPageName(path), 118 PathUtilities.extractPageType(path), 119 PathUtilities.extractPageParent(path)); 120 page.loadConfiguration(configuration); 121 pageCache.put(path, page); 122 } 123 return page; 124 } 125 126 132 133 public void loadConfiguration(Reader in) throws ConfigurationException { 134 Configuration configuration = 135 SAXConfigurationFactory.getInstance().getConfiguration(path, in); 136 loadConfiguration(configuration); 137 } 138 139 145 146 public void loadConfiguration(InputStream in) 147 throws ConfigurationException { 148 CharacterEncodingManager characterEncodingManager = 149 siteContext.getCharacterEncodingManager(); 150 CharacterEncodingMap characterEncodingMap = 151 characterEncodingManager.getMap(path); 152 try { 153 loadConfiguration(new InputStreamReader (in, 155 characterEncodingMap.getPageEncoding())); 156 } catch (UnsupportedEncodingException e) { 157 throw new ConfigurationException("Error reading page configuration", e); 158 } 159 163 } 164 165 171 172 public void loadConfiguration(Configuration configuration) 173 throws ConfigurationException { 174 this.configuration = configuration; 175 pageCache.clear(); 176 } 177 178 } 179 | Popular Tags |