1 31 32 package org.opencms.xml.types; 33 34 import org.opencms.file.CmsObject; 35 import org.opencms.main.CmsIllegalArgumentException; 36 import org.opencms.main.CmsRuntimeException; 37 import org.opencms.staticexport.CmsLink; 38 import org.opencms.staticexport.CmsLinkManager; 39 import org.opencms.staticexport.CmsLinkTable; 40 import org.opencms.util.CmsStringUtil; 41 import org.opencms.xml.I_CmsXmlDocument; 42 43 import java.util.Locale ; 44 45 import org.dom4j.Element; 46 47 56 public class CmsXmlVfsFileValue extends A_CmsXmlContentValue { 57 58 59 public static final String NO_LINK = "none"; 60 61 62 public static final String TYPE_NAME = "OpenCmsVfsFile"; 63 64 65 private String m_stringValue; 66 67 70 public CmsXmlVfsFileValue() { 71 72 } 74 75 83 public CmsXmlVfsFileValue(I_CmsXmlDocument document, Element element, Locale locale, I_CmsXmlSchemaType type) { 84 85 super(document, element, locale, type); 86 m_stringValue = element.getText(); 87 } 88 89 96 public CmsXmlVfsFileValue(String name, String minOccurs, String maxOccurs) { 97 98 super(name, minOccurs, maxOccurs); 99 } 100 101 104 public I_CmsXmlContentValue createValue(I_CmsXmlDocument document, Element element, Locale locale) { 105 106 return new CmsXmlVfsFileValue(document, element, locale, this); 107 } 108 109 114 public CmsLinkTable getLinkTable() { 115 116 CmsLinkTable linkTable = new CmsLinkTable(); 117 if (!NO_LINK.equals(m_element.getText())) { 118 CmsLink link = new CmsLink("link0", "vfs", m_element.getText(), true); 119 linkTable.addLink(link); 120 } 121 return linkTable; 122 } 123 124 127 public String getSchemaDefinition() { 128 129 return "<xsd:simpleType name=\"" + TYPE_NAME + "\"><xsd:restriction base=\"xsd:string\" /></xsd:simpleType>"; 130 } 131 132 135 public String getStringValue(CmsObject cms) throws CmsRuntimeException { 136 137 if (cms != null && CmsStringUtil.isNotEmpty(m_stringValue) && !NO_LINK.equals(m_stringValue)) { 138 return cms.getRequestContext().removeSiteRoot(m_stringValue); 139 } else { 140 return m_stringValue; 141 } 142 } 143 144 147 public String getTypeName() { 148 149 return TYPE_NAME; 150 } 151 152 155 public I_CmsXmlSchemaType newInstance(String name, String minOccurs, String maxOccurs) { 156 157 return new CmsXmlVfsFileValue(name, minOccurs, maxOccurs); 158 } 159 160 163 public void setStringValue(CmsObject cms, String value) throws CmsIllegalArgumentException { 164 165 if (cms != null && !NO_LINK.equals(value)) { 166 value = CmsLinkManager.getSitePath(cms, null, value); 168 } 169 170 m_element.clearContent(); 172 if (CmsStringUtil.isNotEmpty(value)) { 173 m_element.addText(value); 174 m_stringValue = value; 175 } else { 176 m_stringValue = null; 177 } 178 } 179 } | Popular Tags |