Public:BWmeta service/Java mapping/Rich text

From YaddaWiki

(Difference between revisions)
Jump to: navigation, search
(Helper class YRTHelper)
(Helper class YRTHelper)
Line 20: Line 20:
*<code>static YRichText buildFrom(org.jdom.Element element)</code> - builds this element from content of jdom elements. It's illegal and mpol don't like this type of interface.
*<code>static YRichText buildFrom(org.jdom.Element element)</code> - builds this element from content of jdom elements. It's illegal and mpol don't like this type of interface.
-
*<code> static List<ogg.jdom.Content> getListOfContentElementsForThisYRichText(YRichText yt)</code> - returns list of jdom fragments for this YRT.  
+
*<code> static List<org.jdom.Content> getListOfContentElementsForThisYRichText(YRichText yt)</code> - returns list of jdom fragments for this YRT.  
*<code>static String toXmlFragment(YrichText)</code> - serializes a rich text to an XML fragment.
*<code>static String toXmlFragment(YrichText)</code> - serializes a rich text to an XML fragment.

Revision as of 10:59, 20 October 2010

Service details
NameBWmeta
Code location
(relative to SVN root)
projects/dir/bwmeta-core
Javadoc
Contact personJakub Jurkiewicz

Support for rich text, introduced in BWmeta 2.0.0 calls for changes in the "Y" model.

Contents

Adding YRichText class

YRichText is mutable.

Constructors

  • YRichText(String) – constructor from plain text. Uses set text method.
  • YRichText(List<YRichText.Part>) – constructor from list of trees.

Methods

  • String toText() – returns a flattened text view of the rich text. It's a concatenation of text contents of the tree list visited in the infix order, or a simple text line if YRichText conteins only this simple line
  • setText(String text) - parses given text - first it tries to parse it as Xml and if text contains more then one node it stored as a tree, otherwise it is stored as this simple string.
  • List<YRichText.Part> toParts() – returns a list of trees which represent the rich text.
  • setParts(Collection<Part> parts) - sets this text from forest of parts.

Helper class YRTHelper

  • static YRichText buildFrom(org.jdom.Element element) - builds this element from content of jdom elements. It's illegal and mpol don't like this type of interface.
  • static List<org.jdom.Content> getListOfContentElementsForThisYRichText(YRichText yt) - returns list of jdom fragments for this YRT.
  • static String toXmlFragment(YrichText) - serializes a rich text to an XML fragment.

Changes in classes with a YRichText property

YRichText-related methods (other than the ones below) which have been already added should be @Deprecated and subsequently removed. When is said below about setting plain text - it means that method takes string and reparses it the way YRochText works in setText(String).

YName, YDescription

  • Every constructor from String text has a corresponding constructor from YRichText text.
  • String getText() – returns flattened plain text.
  • YRichText getRichText() – returns rich text.
  • T setText(String) – sets plain text.
  • T setRichText(YRichText) – sets rich text.

YAttribute

  • Every constructor from String value has a corresponding constructor from YRichText value.
  • String getValue() – returns flattened plain text.
  • YRichText getRichValue() – returns rich text.
  • YAttribute setValue(String) – sets plain text.
  • YAttribute setRichValue(YRichText) – sets rich text.

YTagList

  • List<String> getValues() – returns unmodifiable, flattened text view of the list of tags.
  • List<YRichText> getRichValues() – returns modifiable list of rich text tags.
  • YTagList setValues(Collection<String>) – sets plain text values.
  • YTagList setRichValues(Collection<YRichText>) – sets rich text values.
  • YTagList addValue(String) – adds a plain text value.
  • YTagList addRichValue(YRichText) – adds a rich text value.

Contracts

  • For any String text != null</code the following assert should pass:
yFoo.setText(text);
// ... potential serialization and deserialization ...
// ... conversion to "DL" model and back ...
// ... or all of the above in any order ...
assertEquals(text, yFoo.getText());
  • For any <code>String text != null the following assert should pass:
yFoo.setText(text);
// ... conversion to "DL" model ...
assertEquals(text, dFoo.getText());
  • Example:
yName.setText("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>");
// ... conversion Y -> DL ...
assertEquals("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>", dName.getText());
// ... conversion DL -> Y ...
assertEquals("<b xmlns="http://www.w3.org/1999/xhtml">1 &lt; 2</b>", yName.getText());
  • For any XML fragment foo if BWmeta 2.0.0 contains <name>foo</name> then:
assertEquals("foo", yName.getXml());
  • There would be no conversions from YRichText to DL and back, therefore we don;t expect identity during conversions.
  • This constraints means that from:
yName.setText("1 < 2")

we get:

yName.getText().equals("1 < 2")
Personal tools