Class CmsMessageBundleEditorModel
java.lang.Object
org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel
The class contains the logic behind the message translation editor.
In particular it reads / writes the involved files and provides the contents as
IndexedContainer.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final classComparator that compares strings case insensitive.static final classWrapper for the configurable messages for the column headers of the message bundle editor.static final classExtension ofPropertiesto allow saving with keys alphabetically ordered and without time stamp as first comment. -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final StringThe property for configuring the message bundle used for localizing the bundle descriptors entries. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleanCreates a descriptor for the currently edited message bundle.booleanReturns a flag, indicating if keys can be added in the current edit mode.voidWhen the descriptor was added while editing, but the change was not saved, it has to be removed when the editor is closed.Returns the a set with all keys that are used at least in one translation.Returns the type of the currently edited bundle.getConfigurableMessages(CmsMessages defaultMessages, Locale locale) Returns the configured bundle, or the provided default bundle.com.vaadin.v7.data.util.IndexedContainerReturns the container filled according to the current locale.getContextMenuForItem(Object itemId) Returns the context menu for the table item.Returns the editable columns for the current edit mode.getEditableColumns(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Returns the editable columns for the provided edit mode.Returns the site path for the edited bundle file.org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditModeReturns the current edit mode.Returns the currently edited locale.Returns the locales available for the specific resource.booleanReturns a flag, indicating if the locale has been switched on opening.voidhandleChange(Object propertyId) Handles the change of a value in the current translation.org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel.KeyChangeResulthandleKeyChange(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EntryChangeEvent event, boolean allLanguages) Handles a key change.booleanhandleKeyDeletion(String key) Handles the deletion of a key.booleanReturns a flag, indicating if something was edited.booleanReturns a flag, indicating if the descriptor specifies any default values.booleanReturns a flag, indicating if the descriptor specifies any descriptions.booleanReturns a flag, indicating if a bundle descriptor is present.booleanReturns a flag, indicating if a master edit mode is available.booleanisShowOptionsColumn(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Returns a flag, indicating if the options column (with add and delete option for rows) should be shown in the given edit mode.voidpublish()Publish the bundle resources directly.voidsave()Saves the messages for all languages that were opened in the editor.voidSaves the loaded XML bundle as property bundle.booleansetEditMode(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Set the edit mode.booleanSet the currently edited locale.voidunlock()Unlock all files opened for writing.
-
Field Details
-
PROPERTY_BUNDLE_DESCRIPTOR_LOCALIZATION
The property for configuring the message bundle used for localizing the bundle descriptors entries.- See Also:
-
-
Constructor Details
-
CmsMessageBundleEditorModel
public CmsMessageBundleEditorModel(CmsObject cms, CmsResource resource) throws CmsException, IOException - Parameters:
cms- theCmsObjectused for reading / writing.resource- the file that is opened for editing.- Throws:
CmsException- thrown if reading some of the involvedCmsResources is not possible.IOException- initialization of a property bundle fails
-
-
Method Details
-
addDescriptor
Creates a descriptor for the currently edited message bundle.- Returns:
trueif the descriptor could be created,falseotherwise.
-
canAddKeys
Returns a flag, indicating if keys can be added in the current edit mode.- Returns:
- a flag, indicating if keys can be added in the current edit mode.
-
deleteDescriptorIfNecessary
When the descriptor was added while editing, but the change was not saved, it has to be removed when the editor is closed.- Throws:
CmsException- thrown when deleting the descriptor resource fails
-
getAllUsedKeys
Returns the a set with all keys that are used at least in one translation.- Returns:
- the a set with all keys that are used at least in one translation.
-
getBundleType
Returns the type of the currently edited bundle.- Returns:
- the type of the currently edited bundle.
-
getConfigurableMessages
public CmsMessageBundleEditorModel.ConfigurableMessages getConfigurableMessages(CmsMessages defaultMessages, Locale locale) Returns the configured bundle, or the provided default bundle.- Parameters:
defaultMessages- the default bundlelocale- the preferred locale- Returns:
- the configured bundle or, if not found, the default bundle.
-
getContainerForCurrentLocale
public com.vaadin.v7.data.util.IndexedContainer getContainerForCurrentLocale() throws IOException, CmsExceptionReturns the container filled according to the current locale.- Returns:
- the container filled according to the current locale.
- Throws:
IOException- thrown if reading a bundle resource fails.CmsException- thrown if reading a bundle resource fails.
-
getContextMenuForItem
Returns the context menu for the table item.- Parameters:
itemId- the table item.- Returns:
- the context menu for the given item.
-
getEditableColumns
Returns the editable columns for the current edit mode.- Returns:
- the editable columns for the current edit mode.
-
getEditableColumns
public List<CmsMessageBundleEditorTypes.TableProperty> getEditableColumns(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Returns the editable columns for the provided edit mode.- Parameters:
mode- the edit mode.- Returns:
- the editable columns for the provided edit mode.
-
getEditedFilePath
Returns the site path for the edited bundle file.- Returns:
- the site path for the edited bundle file.
-
getEditMode
Returns the current edit mode.- Returns:
- the current edit mode.
-
getLocale
Returns the currently edited locale.- Returns:
- the currently edited locale.
-
getLocales
Returns the locales available for the specific resource.- Returns:
- the locales available for the specific resource.
-
getSwitchedLocaleOnOpening
Returns a flag, indicating if the locale has been switched on opening.- Returns:
- a flag, indicating if the locale has been switched on opening.
-
handleChange
Handles the change of a value in the current translation.- Parameters:
propertyId- the property id of the column where the value has changed.
-
handleKeyChange
public org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel.KeyChangeResult handleKeyChange(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EntryChangeEvent event, boolean allLanguages) Handles a key change.- Parameters:
event- the key change event.allLanguages-truefor changing the key for all languages,falseif the key should be changed only for the current language.- Returns:
- result, indicating if the key change was successful.
-
handleKeyDeletion
Handles the deletion of a key.- Parameters:
key- the deleted key.- Returns:
trueif the deletion was successful,falseotherwise.
-
hasChanges
Returns a flag, indicating if something was edited.- Returns:
- a flag, indicating if something was edited.
-
hasDefaultValues
Returns a flag, indicating if the descriptor specifies any default values.- Returns:
- flag, indicating if the descriptor specifies any default values.
-
hasDescriptionValues
Returns a flag, indicating if the descriptor specifies any descriptions.- Returns:
- a flag, indicating if the descriptor specifies any descriptions.
-
hasDescriptor
Returns a flag, indicating if a bundle descriptor is present.- Returns:
- flag, indicating if a bundle descriptor is present.
-
hasMasterMode
Returns a flag, indicating if a master edit mode is available.- Returns:
- a flag, indicating if a master edit mode is available.
-
isShowOptionsColumn
public boolean isShowOptionsColumn(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Returns a flag, indicating if the options column (with add and delete option for rows) should be shown in the given edit mode.- Parameters:
mode- the edit mode for which the column option is requested.- Returns:
- a flag, indicating if the options column (with add and delete option for rows)
-
publish
Publish the bundle resources directly. -
save
Saves the messages for all languages that were opened in the editor.- Throws:
CmsException- thrown if saving fails.
-
saveAsPropertyBundle
Saves the loaded XML bundle as property bundle.- Throws:
UnsupportedEncodingException- thrown if localizations from the XML bundle could not be loaded correctly.CmsException- thrown if any of the interactions with the VFS fails.IOException- thrown if localizations from the XML bundle could not be loaded correctly.
-
setEditMode
public boolean setEditMode(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode) Set the edit mode.- Parameters:
mode- the edit mode to set.- Returns:
- flag, indicating if the mode could be changed.
-
setLocale
Set the currently edited locale.- Parameters:
locale- the currently edited locale.- Returns:
trueif the locale could be set,falseotherwise.
-
unlock
Unlock all files opened for writing.
-