1 31 32 package org.opencms.setup.xml; 33 34 import org.opencms.configuration.CmsConfigurationManager; 35 import org.opencms.configuration.CmsVfsConfiguration; 36 import org.opencms.configuration.I_CmsXmlConfiguration; 37 import org.opencms.loader.CmsImageLoader; 38 import org.opencms.setup.CmsSetupBean; 39 import org.opencms.util.CmsStringUtil; 40 41 import java.util.Collections ; 42 import java.util.List ; 43 44 import org.dom4j.Document; 45 import org.dom4j.Node; 46 47 56 public class CmsXmlAddImageLoader extends A_CmsSetupXmlUpdate { 57 58 59 private List m_xpaths; 60 61 64 public String getName() { 65 66 return "Add new Image Loader"; 67 } 68 69 72 public String getXmlFilename() { 73 74 return CmsVfsConfiguration.DEFAULT_XML_FILE_NAME; 75 } 76 77 80 public boolean validate(CmsSetupBean setupBean) throws Exception { 81 82 return CmsStringUtil.isNotEmptyOrWhitespaceOnly(getCodeToChange(setupBean)); 83 } 84 85 88 protected boolean executeUpdate(Document document, String xpath) { 89 90 Node node = document.selectSingleNode(xpath); 91 if (node == null) { 92 if (xpath.equals(getXPathsToUpdate().get(0))) { 93 CmsSetupXmlHelper.setValue( 94 document, 95 xpath + "/@" + I_CmsXmlConfiguration.A_CLASS, 96 CmsImageLoader.class.getName()); 97 CmsSetupXmlHelper.setValue( 98 document, 99 xpath + "/" + I_CmsXmlConfiguration.N_PARAM, 100 Boolean.TRUE.toString()); 101 CmsSetupXmlHelper.setValue(document, xpath 102 + "/" 103 + I_CmsXmlConfiguration.N_PARAM 104 + "/@" 105 + I_CmsXmlConfiguration.A_NAME, CmsImageLoader.CONFIGURATION_SCALING_ENABLED); 106 } 107 return true; 108 } 109 return false; 110 } 111 112 115 protected String getCommonPath() { 116 117 return new StringBuffer ("/").append(CmsConfigurationManager.N_ROOT).append("/").append( 119 CmsVfsConfiguration.N_VFS).append("/").append(CmsVfsConfiguration.N_RESOURCES).append("/").append( 120 CmsVfsConfiguration.N_RESOURCELOADERS).toString(); 121 } 122 123 126 protected List getXPathsToUpdate() { 127 128 if (m_xpaths == null) { 129 StringBuffer xp = new StringBuffer (256); 131 xp.append("/").append(CmsConfigurationManager.N_ROOT); 132 xp.append("/").append(CmsVfsConfiguration.N_VFS); 133 xp.append("/").append(CmsVfsConfiguration.N_RESOURCES); 134 xp.append("/").append(CmsVfsConfiguration.N_RESOURCELOADERS); 135 xp.append("/").append(CmsVfsConfiguration.N_LOADER); 136 xp.append("[@").append(I_CmsXmlConfiguration.A_CLASS); 137 xp.append("='").append(CmsImageLoader.class.getName()).append("']"); 138 m_xpaths = Collections.singletonList(xp.toString()); 139 } 140 return m_xpaths; 141 } 142 143 } | Popular Tags |