Class InternationalStringXmlReaderWriter

java.lang.Object
org.faktorips.runtime.internal.InternationalStringXmlReaderWriter

public class InternationalStringXmlReaderWriter extends 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.

  • Field Details

  • Method Details

    • toXml

      public static Element toXml(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 Element toXml(Document doc, 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 Collection<org.faktorips.values.LocalizedString> fromXml(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 Collection<org.faktorips.values.LocalizedString> fromXml(Element element, 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 Locale defaultLocaleFromXml(Element element, 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 Locale defaultLocaleFromXml(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(Node node, Locale defaultLocale)