1 12 13 package com.openedit.modules.settings; 14 15 import java.io.StringReader ; 16 import java.util.ArrayList ; 17 import java.util.List ; 18 import java.util.Map ; 19 import java.util.Set ; 20 21 import com.openedit.OpenEditException; 22 import com.openedit.WebPageRequest; 23 import com.openedit.config.Configuration; 24 import com.openedit.config.XMLConfiguration; 25 import com.openedit.page.Page; 26 import com.openedit.page.XconfConfiguration; 27 28 29 36 public class HtmlToXconfReader 37 { 38 protected boolean fieldAdvancedMode; 39 40 public void saveChangesToConfig(WebPageRequest inReq, XconfConfiguration inConfig) throws OpenEditException 41 { 42 Map props = inReq.getParameterMap(); 43 44 Configuration oldeditable = inConfig.getProperty("editable"); 46 inConfig.removeAllProperties(); 47 48 saveProperties(inReq, inConfig); 49 50 if ( isAdvancedMode() ) 51 { 52 saveStandard(props, inConfig); 53 saveLayout(props, inConfig); 54 savePermissions( props, inConfig); 55 } 56 else 57 { 58 if ( oldeditable != null) 59 { 60 inConfig.saveProperty("editable",oldeditable.getValue(),null); 61 } 62 } 63 } 65 66 protected void savePermissions(Map inProps, XconfConfiguration inConfig) 67 { 68 String view = (String )inProps.get("view-requirements"); 69 inConfig.removeElements("view-requirements"); 70 if( view != null && view.trim().length() > 0) 71 { 72 Configuration nconf = inConfig.addChild("view-requirements"); 73 StringReader read = new StringReader (view); 74 nconf.addChild(new XMLConfiguration(read) ); 75 } 76 77 String edit = (String )inProps.get("edit-requirements"); 78 inConfig.removeElements("edit-requirements"); 79 if( edit != null && edit.trim().length() > 0) 80 { 81 Configuration nconf = inConfig.addChild("edit-requirements"); 82 StringReader read = new StringReader (edit); 83 nconf.addChild(new XMLConfiguration(read) ); 84 } 85 } 86 87 protected void saveContentFile(Map inProperties, XconfConfiguration inConfig) 88 { 89 String contentfile = (String ) inProperties.get("contentfile"); 91 92 inConfig.setContentFile(contentfile); 93 } 94 95 protected void saveGenerators(Map inProperties, XconfConfiguration inConfig) 96 { 97 inConfig.removeElements("generator"); 99 100 String generatorKey = "generator"; 101 102 String generator = (String ) inProperties.get(generatorKey); 104 105 if ((generator == null) || (generator.length() == 0) || "default".equals(generator)) 106 { 107 return; 108 } 109 else 110 { 111 XMLConfiguration currentGen = (XMLConfiguration)inConfig.addChild("generator"); 112 String xslt = (String ) inProperties.get(generatorKey + ".xslt"); 113 114 currentGen.setAttribute("name", generator); 115 116 117 } 119 } 120 121 protected void saveNewProperty(WebPageRequest inReq, XconfConfiguration inConfig, int inCount) 122 { 123 String name = inReq.getRequestParameter("newproperty." + inCount + ".name"); 125 126 String value = inReq.getRequestParameter("newproperty." + inCount + ".value"); 127 128 if ((value != null) && (value.length() != 0)) 129 { 130 String locale = inReq.getRequestParameter("newproperty." + inCount + ".language"); 131 inConfig.saveProperty(name, value, locale); 132 } 133 else 134 { 135 inConfig.removeProperty(name); 136 } 137 } 138 139 protected void saveProperties(WebPageRequest inReq, XconfConfiguration inConfig) 140 { 141 142 Map props = inReq.getParameterMap(); 143 144 145 Set set = props.keySet(); 146 List keys = new ArrayList (set); 147 162 for (int i = 0; i < keys.size(); i++) 163 { 164 String propname = inReq.getRequestParameter("property." + i + ".name"); 165 if( propname != null && propname.length() > 0 ) 166 { 167 String valuetag = "property." + i + ".value"; 168 String [] values = inReq.getRequestParameters(valuetag); 169 String langtag = "property." + i + ".language"; 170 String [] locales = inReq.getRequestParameters(langtag); 171 172 if ((values != null) && (values.length > 0)) 173 { 174 for (int v = 0; v < values.length; v++) 175 { 176 String value = values[v]; 177 if( value != null && value.length() > 0) 178 { 179 if( value.equals("on")) 180 { 181 value = "true"; 182 183 } 184 String locale = locales[v]; 185 inConfig.saveProperty(propname, value, locale); 186 } 187 } 188 } 189 } 190 } 191 saveNewProperty(inReq, inConfig, 1); 193 saveNewProperty(inReq, inConfig, 2); 194 } 195 196 protected void saveLayout(Map inProperties, XconfConfiguration inConfig) 197 { 198 String layout = (String ) inProperties.get("layout"); 200 inConfig.removeConfigurations("layout"); 201 202 if ( layout != null && layout.equals(Page.BLANK_LAYOUT)) 203 { 204 inConfig.addChild("layout"); 205 } 206 else if (layout != null && layout.length() > 0) 207 { 208 inConfig.addChild("layout").setValue(layout); 209 } 210 211 String innerlayout = (String ) inProperties.get("inner-layout"); 212 inConfig.removeConfigurations("inner-layout"); 213 if ( innerlayout != null && innerlayout.equals(Page.BLANK_LAYOUT)) 214 { 215 inConfig.addChild("inner-layout"); 216 } 217 else if (innerlayout != null && innerlayout.length() > 0) 218 { 219 inConfig.addChild("inner-layout").setValue(innerlayout); 220 } 221 } 222 223 protected void saveStandard(Map inProperties, XconfConfiguration inConfig) 224 { 225 String editable = (String ) inProperties.get("editable"); 226 if ( editable != null && editable.length() > 0) 227 { 228 if( editable.equals("ok")) 229 { 230 editable = "true"; 231 } 232 inConfig.saveProperty("editable",editable,null); 233 } 234 235 } 236 237 public boolean isAdvancedMode() 238 { 239 return fieldAdvancedMode; 240 } 241 242 public void setAdvancedMode(boolean inAdvancedMode) 243 { 244 fieldAdvancedMode = inAdvancedMode; 245 } 246 247 } 248 | Popular Tags |