Public:BWmeta service/Java mapping/Rich text

From YaddaWiki

< Public:BWmeta service | Java mapping(Difference between revisions)
Jump to: navigation, search
(Adding RichTextSerialization utility class)
 
(27 intermediate revisions not shown)
Line 3: Line 3:
Support for rich text, [[BWmeta format#Rich text support|introduced in BWmeta 2.0.0]] calls for changes in the "Y" model.
Support for rich text, [[BWmeta format#Rich text support|introduced in BWmeta 2.0.0]] calls for changes in the "Y" model.
-
=== Adding [[YRichTextImplementation|<code>YRichText</code>]] class ===
+
=== Adding <code>YRichText</code> class ===
-
<code>YRichText</code> is mutable.
+
<code>YRichText</code> is mutable.  
==== Constructors ====
==== Constructors ====
-
* <code>YRichText(String)</code> – constructor from plain text.
+
* <code>YRichText(String)</code> – constructor from plain text. Uses set text method.  
* <code>YRichText(List<YRichText.Part>)</code> – constructor from list of trees.
* <code>YRichText(List<YRichText.Part>)</code> – constructor from list of trees.
==== Methods ====
==== Methods ====
-
* <code>String toText()</code> – 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.
+
* <code>String toText()</code> – 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. Note that toText().isEmpty() does not mean that this tree has no content.
-
* <code>List<YRichText.Part> toParts()</code> – returns a list of trees which represent the rich text. It could return null - this means that this RichText contains only one string comtent which could be obtained via toText() method
+
* <code>setText(String text)</code> - stores this text literally in YRich text as one node(leaf) tree.  
 +
* <code>List<YRichText.Part> toParts()</code> – returns a list of trees which represent the rich text.
 +
* <code>setParts(Collection<Part> parts)</code> - sets this text from forest of parts.
 +
* <code>isEmpty()</code> - says if this yrich text has no content ( nulls are not allowed so empty means null)
 +
 
 +
==== Helper class <code>YRTHelper</code> ====
 +
this clas is in package pl.edu.icm.yadda.bwmeta.serialization.
 +
*<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<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.
=== Changes in classes with a <code>YRichText</code> property ===
=== Changes in classes with a <code>YRichText</code> property ===
<code>YRichText</code>-related methods (other than the ones below) which have been already added should be <code>@Deprecated</code> and subsequently removed.
<code>YRichText</code>-related methods (other than the ones below) which have been already added should be <code>@Deprecated</code> 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).
==== <code>YName</code>, <code>YDescription</code> ====
==== <code>YName</code>, <code>YDescription</code> ====
* Every constructor from <code>String text</code> has a corresponding constructor from <code>YRichText text</code>.
* Every constructor from <code>String text</code> has a corresponding constructor from <code>YRichText text</code>.
-
* <code>String getText()</code> – returns flattened text.
+
* <code>String getText()</code> – returns flattened plain text.
* <code>YRichText getRichText()</code> – returns rich text.
* <code>YRichText getRichText()</code> – returns rich text.
* <code>T setText(String)</code> – sets plain text.
* <code>T setText(String)</code> – sets plain text.
Line 28: Line 39:
==== <code>YAttribute</code> ====
==== <code>YAttribute</code> ====
* Every constructor from <code>String value</code> has a corresponding constructor from <code>YRichText value</code>.
* Every constructor from <code>String value</code> has a corresponding constructor from <code>YRichText value</code>.
-
* <code>String getValue()</code> – returns plain text.
+
* <code>String getValue()</code> – returns flattened  plain text.
* <code>YRichText getRichValue()</code> – returns rich text.
* <code>YRichText getRichValue()</code> – returns rich text.
* <code>YAttribute setValue(String)</code> – sets plain text.
* <code>YAttribute setValue(String)</code> – sets plain text.
Line 64: Line 75:
  assertEquals("''foo''", yName.getXml());
  assertEquals("''foo''", yName.getXml());
-
* After all processes without editing we got eqal rich text objects
+
* There would be no conversions from YRichText to DL and back, therefore we don;t expect identity during conversions.  
-
YrichText text=yFoo.getRichText();
+
-
// ... potential serialization and deserialization ...
+
-
// ... conversion to "DL" model and back ...
+
-
// .. no edition etc...
+
-
// ... or all of the above in any order ...
+
-
YrichText text1=yFoo.getRichText();
+
-
assertEquals(text, text1);
+
-
 
+
-
*Partticularly:
+
-
YrichText rtext=yFoo.getRichText();
+
-
String text=yFoo.getText();
+
-
yFoo.setText(text);
+
-
YrichText rtext1=yFoo.getRichText();
+
-
assertEquals(rtext.getText(), rtext1.getText());
+
-
 
+
-
 
+
-
*Partticularly:
+
-
YrichText rtext=yFoo.getRichText();
+
-
String text=yFoo.getText();
+
-
yFoo.setText(text);
+
-
//yFoo serialize deserilize
+
-
YrichText rtext1=yFoo.getRichText();
+
-
assertEquals(rtext, rtext1);
+
-
 
+
* This constraints means that from:
* This constraints means that from:

Latest revision as of 15:17, 7 March 2013

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. Note that toText().isEmpty() does not mean that this tree has no content.
  • setText(String text) - stores this text literally in YRich text as one node(leaf) tree.
  • 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.
  • isEmpty() - says if this yrich text has no content ( nulls are not allowed so empty means null)

Helper class YRTHelper

this clas is in package pl.edu.icm.yadda.bwmeta.serialization.

  • 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 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 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