Class CmsMessageBundleEditorModel
- java.lang.Object
-
- org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel
-
public class CmsMessageBundleEditorModel extends java.lang.Object
The class contains the logic behind the message translation editor. In particular it reads / writes the involved files and provides the contents asIndexedContainer
.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
CmsMessageBundleEditorModel.CmsCaseInsensitiveStringComparator
Comparator that compares strings case insensitive.static class
CmsMessageBundleEditorModel.ConfigurableMessages
Wrapper for the configurable messages for the column headers of the message bundle editor.static class
CmsMessageBundleEditorModel.SortedProperties
Extension ofProperties
to allow saving with keys alphabetically ordered and without time stamp as first comment.
-
Field Summary
Fields Modifier and Type Field Description static java.lang.String
PROPERTY_BUNDLE_DESCRIPTOR_LOCALIZATION
The property for configuring the message bundle used for localizing the bundle descriptors entries.
-
Constructor Summary
Constructors Constructor Description CmsMessageBundleEditorModel(CmsObject cms, CmsResource resource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
addDescriptor()
Creates a descriptor for the currently edited message bundle.boolean
canAddKeys()
Returns a flag, indicating if keys can be added in the current edit mode.void
deleteDescriptorIfNecessary()
When the descriptor was added while editing, but the change was not saved, it has to be removed when the editor is closed.java.util.Set<java.lang.Object>
getAllUsedKeys()
Returns the a set with all keys that are used at least in one translation.CmsMessageBundleEditorTypes.BundleType
getBundleType()
Returns the type of the currently edited bundle.CmsMessageBundleEditorModel.ConfigurableMessages
getConfigurableMessages(CmsMessages defaultMessages, java.util.Locale locale)
Returns the configured bundle, or the provided default bundle.com.vaadin.v7.data.util.IndexedContainer
getContainerForCurrentLocale()
Returns the container filled according to the current locale.CmsContextMenu
getContextMenuForItem(java.lang.Object itemId)
Returns the context menu for the table item.java.util.List<CmsMessageBundleEditorTypes.TableProperty>
getEditableColumns()
Returns the editable columns for the current edit mode.java.util.List<CmsMessageBundleEditorTypes.TableProperty>
getEditableColumns(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode)
Returns the editable columns for the provided edit mode.java.lang.String
getEditedFilePath()
Returns the site path for the edited bundle file.org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode
getEditMode()
Returns the current edit mode.java.util.Locale
getLocale()
Returns the currently edited locale.java.util.Collection<java.util.Locale>
getLocales()
Returns the locales available for the specific resource.boolean
getSwitchedLocaleOnOpening()
Returns a flag, indicating if the locale has been switched on opening.void
handleChange(java.lang.Object propertyId)
Handles the change of a value in the current translation.org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorModel.KeyChangeResult
handleKeyChange(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EntryChangeEvent event, boolean allLanguages)
Handles a key change.boolean
handleKeyDeletion(java.lang.String key)
Handles the deletion of a key.boolean
hasChanges()
Returns a flag, indicating if something was edited.boolean
hasDefaultValues()
Returns a flag, indicating if the descriptor specifies any default values.boolean
hasDescriptionValues()
Returns a flag, indicating if the descriptor specifies any descriptions.boolean
hasDescriptor()
Returns a flag, indicating if a bundle descriptor is present.boolean
hasMasterMode()
Returns a flag, indicating if a master edit mode is available.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.void
publish()
Publish the bundle resources directly.void
save()
Saves the messages for all languages that were opened in the editor.void
saveAsPropertyBundle()
Saves the loaded XML bundle as property bundle.boolean
setEditMode(org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode mode)
Set the edit mode.boolean
setLocale(java.util.Locale locale)
Set the currently edited locale.void
unlock()
Unlock all files opened for writing.
-
-
-
Field Detail
-
PROPERTY_BUNDLE_DESCRIPTOR_LOCALIZATION
public static final java.lang.String PROPERTY_BUNDLE_DESCRIPTOR_LOCALIZATION
The property for configuring the message bundle used for localizing the bundle descriptors entries.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
CmsMessageBundleEditorModel
public CmsMessageBundleEditorModel(CmsObject cms, CmsResource resource) throws CmsException, java.io.IOException
- Parameters:
cms
- theCmsObject
used for reading / writing.resource
- the file that is opened for editing.- Throws:
CmsException
- thrown if reading some of the involvedCmsResource
s is not possible.java.io.IOException
- initialization of a property bundle fails
-
-
Method Detail
-
addDescriptor
public boolean addDescriptor()
Creates a descriptor for the currently edited message bundle.- Returns:
true
if the descriptor could be created,false
otherwise.
-
canAddKeys
public boolean 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
public void deleteDescriptorIfNecessary() throws CmsException
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
public java.util.Set<java.lang.Object> 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
public CmsMessageBundleEditorTypes.BundleType getBundleType()
Returns the type of the currently edited bundle.- Returns:
- the type of the currently edited bundle.
-
getConfigurableMessages
public CmsMessageBundleEditorModel.ConfigurableMessages getConfigurableMessages(CmsMessages defaultMessages, java.util.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 java.io.IOException, CmsException
Returns the container filled according to the current locale.- Returns:
- the container filled according to the current locale.
- Throws:
java.io.IOException
- thrown if reading a bundle resource fails.CmsException
- thrown if reading a bundle resource fails.
-
getContextMenuForItem
public CmsContextMenu getContextMenuForItem(java.lang.Object itemId)
Returns the context menu for the table item.- Parameters:
itemId
- the table item.- Returns:
- the context menu for the given item.
-
getEditableColumns
public java.util.List<CmsMessageBundleEditorTypes.TableProperty> getEditableColumns()
Returns the editable columns for the current edit mode.- Returns:
- the editable columns for the current edit mode.
-
getEditableColumns
public java.util.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
public java.lang.String getEditedFilePath()
Returns the site path for the edited bundle file.- Returns:
- the site path for the edited bundle file.
-
getEditMode
public org.opencms.ui.editors.messagebundle.CmsMessageBundleEditorTypes.EditMode getEditMode()
Returns the current edit mode.- Returns:
- the current edit mode.
-
getLocale
public java.util.Locale getLocale()
Returns the currently edited locale.- Returns:
- the currently edited locale.
-
getLocales
public java.util.Collection<java.util.Locale> getLocales()
Returns the locales available for the specific resource.- Returns:
- the locales available for the specific resource.
-
getSwitchedLocaleOnOpening
public boolean 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
public void handleChange(java.lang.Object propertyId)
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
-true
for changing the key for all languages,false
if the key should be changed only for the current language.- Returns:
- result, indicating if the key change was successful.
-
handleKeyDeletion
public boolean handleKeyDeletion(java.lang.String key)
Handles the deletion of a key.- Parameters:
key
- the deleted key.- Returns:
true
if the deletion was successful,false
otherwise.
-
hasChanges
public boolean hasChanges()
Returns a flag, indicating if something was edited.- Returns:
- a flag, indicating if something was edited.
-
hasDefaultValues
public boolean hasDefaultValues()
Returns a flag, indicating if the descriptor specifies any default values.- Returns:
- flag, indicating if the descriptor specifies any default values.
-
hasDescriptionValues
public boolean hasDescriptionValues()
Returns a flag, indicating if the descriptor specifies any descriptions.- Returns:
- a flag, indicating if the descriptor specifies any descriptions.
-
hasDescriptor
public boolean hasDescriptor()
Returns a flag, indicating if a bundle descriptor is present.- Returns:
- flag, indicating if a bundle descriptor is present.
-
hasMasterMode
public boolean 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
public void publish()
Publish the bundle resources directly.
-
save
public void save() throws CmsException
Saves the messages for all languages that were opened in the editor.- Throws:
CmsException
- thrown if saving fails.
-
saveAsPropertyBundle
public void saveAsPropertyBundle() throws java.io.UnsupportedEncodingException, CmsException, java.io.IOException
Saves the loaded XML bundle as property bundle.- Throws:
java.io.UnsupportedEncodingException
- thrown if localizations from the XML bundle could not be loaded correctly.CmsException
- thrown if any of the interactions with the VFS fails.java.io.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
public boolean setLocale(java.util.Locale locale)
Set the currently edited locale.- Parameters:
locale
- the currently edited locale.- Returns:
true
if the locale could be set,false
otherwise.
-
unlock
public void unlock()
Unlock all files opened for writing.
-
-