cmsdefaultxmlcontenthandler.java
来自「找了很久才找到到源代码」· Java 代码 · 共 1,448 行 · 第 1/5 页
JAVA
1,448 行
String regex,
String valueStr,
boolean matchResult,
boolean isWarning) {
String message = null;
if (isWarning) {
message = (String)m_validationWarningMessages.get(value.getName());
} else {
message = (String)m_validationErrorMessages.get(value.getName());
}
if (message == null) {
if (isWarning) {
message = MESSAGE_VALIDATION_DEFAULT_WARNING;
} else {
message = MESSAGE_VALIDATION_DEFAULT_ERROR;
}
}
// create additional macro values
Map additionalValues = new HashMap();
additionalValues.put(CmsMacroResolver.KEY_VALIDATION_VALUE, valueStr);
additionalValues.put(CmsMacroResolver.KEY_VALIDATION_REGEX, ((!matchResult) ? "!" : "") + regex);
additionalValues.put(CmsMacroResolver.KEY_VALIDATION_PATH, value.getPath());
CmsMacroResolver resolver = CmsMacroResolver.newInstance().setCmsObject(cms).setMessages(
getMessages(cms.getRequestContext().getLocale())).setAdditionalMacros(additionalValues);
return resolver.resolveMacros(message);
}
/**
* Called when this content handler is initialized.<p>
*/
protected void init() {
m_elementMappings = new HashMap();
m_elementWidgets = new HashMap();
m_validationErrorRules = new HashMap();
m_validationErrorMessages = new HashMap();
m_validationWarningRules = new HashMap();
m_validationWarningMessages = new HashMap();
m_defaultValues = new HashMap();
m_configurationValues = new HashMap();
m_searchSettings = new HashMap();
m_relations = new HashMap();
m_previewLocation = null;
m_modelFolder = null;
}
/**
* Initializes the default values for this content handler.<p>
*
* Using the default values from the appinfo node, it's possible to have more
* sophisticated logic for generating the defaults then just using the XML schema "default"
* attribute.<p>
*
* @param root the "defaults" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the default values belong to
* @throws CmsXmlException if something goes wrong
*/
protected void initDefaultValues(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
Iterator i = root.elementIterator(APPINFO_DEFAULT);
while (i.hasNext()) {
// iterate all "default" elements in the "defaults" node
Element element = (Element)i.next();
String elementName = element.attributeValue(APPINFO_ATTR_ELEMENT);
String defaultValue = element.attributeValue(APPINFO_ATTR_VALUE);
if ((elementName != null) && (defaultValue != null)) {
// add a default value mapping for the element
addDefault(contentDefinition, elementName, defaultValue);
}
}
}
/**
* Initializes the layout for this content handler.<p>
*
* Unless otherwise instructed, the editor uses one specific GUI widget for each
* XML value schema type. For example, for a {@link org.opencms.xml.types.CmsXmlStringValue}
* the default widget is the {@link org.opencms.widgets.CmsInputWidget}.
* However, certain values can also use more then one widget, for example you may
* also use a {@link org.opencms.widgets.CmsCheckboxWidget} for a String value,
* and as a result the Strings possible values would be eithe <code>"false"</code> or <code>"true"</code>,
* but nevertheless be a String.<p>
*
* The widget to use can further be controlled using the <code>widget</code> attribute.
* You can specify either a valid widget alias such as <code>StringWidget</code>,
* or the name of a Java class that implements <code>{@link I_CmsWidget}</code>.<p>
*
* Configuration options to the widget can be passed using the <code>configuration</code>
* attribute. You can specify any String as configuration. This String is then passed
* to the widget during initialization. It's up to the individual widget implementation
* to interpret this configuration String.<p>
*
* @param root the "layouts" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the layout belongs to
*
* @throws CmsXmlException if something goes wrong
*/
protected void initLayouts(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
Iterator i = root.elementIterator(APPINFO_LAYOUT);
while (i.hasNext()) {
// iterate all "layout" elements in the "layouts" node
Element element = (Element)i.next();
String elementName = element.attributeValue(APPINFO_ATTR_ELEMENT);
String widgetClassOrAlias = element.attributeValue(APPINFO_ATTR_WIDGET);
String configuration = element.attributeValue(APPINFO_ATTR_CONFIGURATION);
if ((elementName != null) && (widgetClassOrAlias != null)) {
// add a widget mapping for the element
addWidget(contentDefinition, elementName, widgetClassOrAlias);
if (configuration != null) {
addConfiguration(contentDefinition, elementName, configuration);
}
}
}
}
/**
* Initializes the element mappings for this content handler.<p>
*
* Element mappings allow storing values from the XML content in other locations.
* For example, if you have an element called "Title", it's likely a good idea to
* store the value of this element also in the "Title" property of a XML content resource.<p>
*
* @param root the "mappings" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the mappings belong to
* @throws CmsXmlException if something goes wrong
*/
protected void initMappings(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
Iterator i = root.elementIterator(APPINFO_MAPPING);
while (i.hasNext()) {
// iterate all "mapping" elements in the "mappings" node
Element element = (Element)i.next();
// this is a mapping node
String elementName = element.attributeValue(APPINFO_ATTR_ELEMENT);
String maptoName = element.attributeValue(APPINFO_ATTR_MAPTO);
if ((elementName != null) && (maptoName != null)) {
// add the element mapping
addMapping(contentDefinition, elementName, maptoName);
}
}
}
/**
* Initializes the folder containing the model file(s) for this content handler.<p>
*
* @param root the "modelfolder" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the model folder belongs to
* @throws CmsXmlException if something goes wrong
*/
protected void initModelFolder(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
String master = root.attributeValue(APPINFO_ATTR_URI);
if (master == null) {
throw new CmsXmlException(Messages.get().container(
Messages.ERR_XMLCONTENT_MISSING_MODELFOLDER_URI_2,
root.getName(),
contentDefinition.getSchemaLocation()));
}
m_modelFolder = master;
}
/**
* Initializes the preview location for this content handler.<p>
*
* @param root the "preview" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the validation rules belong to
* @throws CmsXmlException if something goes wrong
*/
protected void initPreview(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
String preview = root.attributeValue(APPINFO_ATTR_URI);
if (preview == null) {
throw new CmsXmlException(Messages.get().container(
Messages.ERR_XMLCONTENT_MISSING_PREVIEW_URI_2,
root.getName(),
contentDefinition.getSchemaLocation()));
}
m_previewLocation = preview;
}
/**
* Initializes the relation configuration for this content handler.<p>
*
* OpenCms performs link checks for all OPTIONAL links defined in XML content values of type
* OpenCmsVfsFile. However, for most projects in the real world a more fine-grained control
* over the link check process is required. For these cases, individual relation behavior can
* be defined for the appinfo node.<p>
*
* Additional here can be defined an optional type for the relations, for instance.<p>
*
* @param root the "relations" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the check rules belong to
*
* @throws CmsXmlException if something goes wrong
*/
protected void initRelations(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
Iterator i = root.elementIterator(APPINFO_RELATION);
while (i.hasNext()) {
// iterate all "checkrule" elements in the "checkrule" node
Element element = (Element)i.next();
String elementName = element.attributeValue(APPINFO_ATTR_ELEMENT);
String invalidate = element.attributeValue(APPINFO_ATTR_INVALIDATE);
if (invalidate != null) {
invalidate = invalidate.toUpperCase();
}
String type = element.attributeValue(APPINFO_ATTR_TYPE);
if (type != null) {
type = type.toLowerCase();
}
if (elementName != null) {
// add a check rule for the element
addCheckRule(contentDefinition, elementName, invalidate, type);
}
}
}
/**
* Initializes the resource bundle to use for localized messages in this content handler.<p>
*
* @param root the "resourcebundle" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the validation rules belong to
*
* @throws CmsXmlException if something goes wrong
*/
protected void initResourceBundle(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
String name = root.attributeValue(APPINFO_ATTR_NAME);
if (name == null) {
throw new CmsXmlException(Messages.get().container(
Messages.ERR_XMLCONTENT_MISSING_RESOURCE_BUNDLE_NAME_2,
root.getName(),
contentDefinition.getSchemaLocation()));
}
m_messageBundleName = name;
}
/**
* Initializes the search exclusions values for this content handler.<p>
*
* For the full text search, the value of all elements in one locale of the XML content are combined
* to one big text, which is referred to as the "content" in the context of the full text search.
* With this option, it is possible to hide certain elements from this "content" that does not make sense
* to include in the full text search.<p>
*
* @param root the "searchsettings" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the default values belong to
*
* @throws CmsXmlException if something goes wrong
*/
protected void initSearchSettings(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
Iterator i = root.elementIterator(APPINFO_SEARCHSETTING);
while (i.hasNext()) {
// iterate all "searchsetting" elements in the "searchsettings" node
Element element = (Element)i.next();
String elementName = element.attributeValue(APPINFO_ATTR_ELEMENT);
String searchContent = element.attributeValue(APPINFO_ATTR_SEARCHCONTENT);
boolean include = CmsStringUtil.isEmpty(searchContent) || Boolean.valueOf(searchContent).booleanValue();
if (elementName != null) {
// add search exclusion for the element
// this may also be "false" in case a default of "true" is to be overwritten
addSearchSetting(contentDefinition, elementName, Boolean.valueOf(include));
}
}
}
/**
* Initializes the validation rules this content handler.<p>
*
* OpenCms always performs XML schema validation for all XML contents. However,
* for most projects in the real world a more fine-grained control over the validation process is
* required. For these cases, individual validation rules can be defined for the appinfo node.<p>
*
* @param root the "validationrules" element from the appinfo node of the XML content definition
* @param contentDefinition the content definition the validation rules belong to
*
* @throws CmsXmlException if something goes wrong
*/
protected void initValidationRules(Element root, CmsXmlContentDefinition contentDefinition) throws CmsXmlException {
List elements = new
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?