ResourceMessage

Dieser Ausdruck erstellt aus einer Eigenschaftenressource eine lokalisierbare Nachricht (siehe Lokalisierungsunterstützung).

Die Eigenschaft kann optional Platzhalter für formatierte Argumente enthalten. Die Unterstützung und die Syntax für die Formatierung ist im JavaDoc für MessageFormat beschrieben.

Achtung: Falls die Ausgabe ein einfaches Anführungszeichen oder Hochkomma (') enthalten soll, müssen Sie - wie auch im JavaDoc erläutert - im Eigenschaftentext zwei einfache Anführungszeichen ('') angeben.

Wenn die Ausgabe im XML- oder HTML-Format erfolgen soll und keine komplexe Tokenformatierung erfolgen oder keine Möglichkeit zur Änderung des Nachrichtentextes ohne eine Änderung von Regeln bestehen muss, kann es sinnvoll sein, stattdessen den Ausdruck "XmlMessage" (siehe XmlMessage) zu verwenden.

<?xml version="1.0" encoding="UTF-8"?>
<RuleSet name="Example_ResourceMessage"
  xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:noNamespaceSchemaLocation=
"http://www.curamsoftware.com/CreoleRulesSchema.xsd">
  <Class name="Person">

    <Attribute name="gender">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="isMarried">
      <type>
        <javaclass name="Boolean"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="firstName">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="surname">
      <type>
        <javaclass name="String"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <Attribute name="income">
      <type>
        <javaclass name="Number"/>
      </type>
      <derivation>
        <specified/>
      </derivation>
    </Attribute>

    <!-- Returns a greeting which can be
        output in the user's locale -->
    <Attribute name="simpleGreetingMessage">
      <type>
        <javaclass name="curam.creole.value.Message"/>
      </type>
      <derivation>
        <ResourceMessage key="simpleGreeting"
          resourceBundle="curam.creole.example.Messages"/>
      </derivation>
    </Attribute>

    <!-- Returns a greeting which contains
         the person's title and surname.
         The greeting and title are localized,
         the surname is not (it is identical
         in all locales). -->
    <Attribute name="parameterizedGreetingMessage">
      <type>
        <javaclass name="curam.creole.value.Message"/>
      </type>
      <derivation>
        <!-- pass in arguments to
             the message placeholders -->
        <ResourceMessage key="parameterizedGreeting"
          resourceBundle="curam.creole.example.Messages">
          <!-- Title -->
          <choose>
            <type>
              <javaclass name="curam.creole.value.Message"/>
            </type>
            <when>
              <condition>
                <equals>
                  <reference attribute="gender"/>
                  <String value="Male"/>
                </equals>
              </condition>
              <value>
                <ResourceMessage key="title.male"
                  resourceBundle="curam.creole.example.Messages"/>
              </value>
            </when>
            <when>
              <condition>
                <reference attribute="isMarried"/>
              </condition>
              <value>
                <ResourceMessage key="title.female.married"
                  resourceBundle="curam.creole.example.Messages"/>
              </value>
            </when>
            <otherwise>
              <value>
                <ResourceMessage key="title.female.single"
                  resourceBundle="curam.creole.example.Messages"/>
              </value>
            </otherwise>
          </choose>

          <!-- Surname -->
          <reference attribute="surname"/>

        </ResourceMessage>
      </derivation>
    </Attribute>

    <!-- Formats a number to 2 decimal places,
         with decimal point and thousands
         separator in the user's locale -->
    <Attribute name="incomeStatementMessage">
      <type>
        <javaclass name="curam.creole.value.Message"/>
      </type>
      <derivation>
        <ResourceMessage key="incomeStatement"
          resourceBundle="curam.creole.example.Messages">
          <reference attribute="income"/>
        </ResourceMessage>
      </derivation>
    </Attribute>

  </Class>

</RuleSet>
Abbildung 1. Beispiel für Eigenschaften - Englisch
# file curam/creole/example/Messages_en.properties

simpleGreeting=Hello
parameterizedGreeting=Hello, {0} {1}
title.male=Mr.
title.female.single=Miss
title.female.married=Mrs.
incomeStatement=Income: USD{0,number,#0.00}
Abbildung 2. Beispiel für Eigenschaften - Französisch
# file curam/creole/example/Messages_fr.properties

simpleGreeting=Bonjour
parameterizedGreeting=Bonjour, {0} {1}
title.male=M.
title.female.single=Mlle.
title.female.married=Mme.
incomeStatement=Revenue: EUR{0,number,#0.00}