Class InternationalStringXmlReaderWriter


  • public class InternationalStringXmlReaderWriter
    extends java.lang.Object
    Helper class to read international strings from XML and write them back to XML.

    The helper should not be initialized, just use the static utility methods.

    • Method Summary

      All Methods Static Methods Concrete Methods 
      Modifier and Type Method Description
      static java.util.Locale defaultLocaleFromXml​(org.w3c.dom.Element e)
      Returns the default locale from the default locale attribute of the given element.
      static java.util.Locale defaultLocaleFromXml​(org.w3c.dom.Element element, java.lang.String tagName)
      Reads the default locale from the international string stored in the child Element with the specified name.
      static java.util.Collection<org.faktorips.values.LocalizedString> fromXml​(org.w3c.dom.Element element)
      Reads the localized strings stored in the given XML Element.
      static java.util.Collection<org.faktorips.values.LocalizedString> fromXml​(org.w3c.dom.Element element, java.lang.String tagName)
      Reads the localized strings stored in the child Element with the specified name.
      static void setDefaultLocaleInXml​(org.w3c.dom.Node node, java.util.Locale defaultLocale)  
      static org.w3c.dom.Element toXml​(org.w3c.dom.Document doc, java.util.Collection<org.faktorips.values.LocalizedString> localizedStrings)
      Creates a new Element representing the given localized strings.
      static org.w3c.dom.Element toXml​(org.w3c.dom.Document doc, org.faktorips.values.DefaultInternationalString internationalString)
      Creates a new Element representing the given DefaultInternationalString.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Method Detail

      • toXml

        public static org.w3c.dom.Element toXml​(org.w3c.dom.Document doc,
                                                org.faktorips.values.DefaultInternationalString internationalString)
        Creates a new Element representing the given DefaultInternationalString.
        Parameters:
        doc - the XML Document that will contain the new element
        internationalString - the DefaultInternationalString to create an element for
        Returns:
        the new element representing the given international string
      • toXml

        public static org.w3c.dom.Element toXml​(org.w3c.dom.Document doc,
                                                java.util.Collection<org.faktorips.values.LocalizedString> localizedStrings)
        Creates a new Element representing the given localized strings.

        The element that is created can be used to initialize the localized string of a DefaultInternationalString but is missing the attribute for the default locale required by DefaultInternationalString. That attribute is added by org.faktorips.devtools.stdbuilder.productcmpt.ProductCmptXMLBuilder when writing a product component's XML.

        Parameters:
        doc - the XML Document that contains the new element
        localizedStrings - the localized strings to be saved
        Returns:
        the new element representing the localized strings
      • fromXml

        public static java.util.Collection<org.faktorips.values.LocalizedString> fromXml​(org.w3c.dom.Element element)
        Reads the localized strings stored in the given XML Element. If the given element is not representing an international string, an empty collection is returned.
        Parameters:
        element - the XML Element representing an international string
        Returns:
        a collection of all localized strings defined in the international string represented by the given Element.
      • fromXml

        public static java.util.Collection<org.faktorips.values.LocalizedString> fromXml​(org.w3c.dom.Element element,
                                                                                         java.lang.String tagName)
        Reads the localized strings stored in the child Element with the specified name. If the given element does not contain a child of the given name or if that child does not represent an international string, an empty collection is returned.
        Parameters:
        element - the XML Element representing the parent of an international string.
        tagName - the name of the child node representing an international string.
        Returns:
        a collection of all localized strings defined in the international string.
      • defaultLocaleFromXml

        public static java.util.Locale defaultLocaleFromXml​(org.w3c.dom.Element element,
                                                            java.lang.String tagName)
        Reads the default locale from the international string stored in the child Element with the specified name. Returns null if the given element does not contain a child of the given name, if that child does not represent an international string or if that international string does not have a default locale.

        Note that the attribute for the default locale is only written by the toXml(Document, DefaultInternationalString) method. The toXml(Document, Collection) method does not write the attribute for the default locale. org.faktorips.devtools.stdbuilder.productcmpt.ProductCmptXMLBuilder adds the default locale when writing a product component's XML.

        Parameters:
        element - the XML Element representing the parent of an international string
        tagName - the name of the child node representing an international string
        Returns:
        the default locale defined in the international string if present or null
      • defaultLocaleFromXml

        public static java.util.Locale defaultLocaleFromXml​(org.w3c.dom.Element e)
        Returns the default locale from the default locale attribute of the given element. Returns null if the element is not an localized string element or does not have a default locale attribute.

        Note that the attribute for the default locale is only written by the toXml(Document, DefaultInternationalString) method. The toXml(Document, Collection) method does not write the attribute for the default locale. org.faktorips.devtools.stdbuilder.productcmpt.ProductCmptXMLBuilder adds the default locale when writing a product component's XML.

        Parameters:
        e - the XML element representing an international string
        Returns:
        the default locale from the given element or null if the element does not represent an international string or does not have a default locale attribute
      • setDefaultLocaleInXml

        public static void setDefaultLocaleInXml​(org.w3c.dom.Node node,
                                                 java.util.Locale defaultLocale)