public class WikistyleTextToSimpleXml
extends java.lang.Object
Writing | XML-result | explanation |
---|---|---|
text |
<p>text</p><p>next paragraph... |
Two linefeeds forces separated paragraphs. Only one linefeed will be interpreted as white space. A carrige return (hexa 0d) before linefeed (hexa 0a)will be ignored. |
*text | <ul><li><p>text... |
An asterix at beginning of a line (after a linefeed) determines the beginning of a list item. The <ul> will be created if it is the first list item. One space after the asterix char will be ignored. |
**text | <ul><li>... |
Creates inside a list item a new list, or a next list item, if two list level are already present. |
*:text | <ul><li>... |
In Wikipedia Software it is used often to create an second paragraph in a list item. But in reality it is a <dd>-element of a definition list. Thats why an indentation is shown using normal CSS styles. |
*+text | <ul><li>... |
This is not standard in wikipedia, but necessary for exact XHTML image of the content. It will produced a second paragraph inside a list item. It will not create a new List item AND an indentation like using *: in Wikipedia, in Wikipedia editing there is no exactly possibility to add a second paragraph inside a list item. |
;text | <dl><dt>text... |
A definition text of a definition list. The <dl> will be created if it is the first list item. |
:text | <dl><dd>text... |
A definition data content of a definition list. The <dl> will be created if it is the first list item. |
*;text | <li>...<dl><dd>text... |
All list item types may be used nested, the correct nested XHTML content will be produced. See also examples below! |
>text | <div id="indentation1"><p>text... |
A paragraph with indentation. It results in an < div>-Tag. The <div>-tag is only created at first such paragraph. It is not possible on wikipedia editing. |
>>text | <div id="indentation2"><p>text... |
Two level indentation. |
text | <pre>text... |
preserved text, if one space is present after any line feed. |
, text | <pre>text... |
preserved text, if a colon followed by one space is present after any line feed. |
{| text | <table>... |
Start of a table. See example below. |
!! text | <th>... |
Start of a table head cell. This string may be also placed inside a table-row-line, not only at start of line. |
|| text | <td>... |
Start of a table cell. This string may be also placed inside a table-row-line, not only at start of line. |
|- text | <tr>... |
Start of a table row. |
|} text | <table>... |
Start of a table. |
Writing | XML-result | explanation |
---|---|---|
''text'' |
<i>text</i> |
italic text |
'''text''' |
<b>text</b> |
bold text |
'''''text''''' |
<b><i>text</i></b> |
bold and italic text |
,,text,, |
<code>text</code> |
Text for representation coding. This is not defined in Wikipedia. It is an enhancement. |
[[link|text]] |
<a href="#link">text</a> |
a link to a internal label, adequate to a link to a article in wikipedia. |
[[link]] |
<a href="#link">link</a> |
a link to a internal label, adequate to a link to a article in wikipedia. |
[[!link|text]] |
<a href="link">text</a> |
a link to a absolute label. |
{|!!column-title !!column-title2 |-||cell 11 ||cell 12 |-||cell 21 may be have a longer text ||thats why cell 22 is written in a new line, but cell 22 contains A list sendond item its furthermore content of cell 22, a new paragraph. |-|| and this is the third row. |}A '''simple table''' may be shown very simple, but a complex table is not readable simply, but itsn't worse as using the html tags <table><tr> and so on.
SimpleXmlOutputter
2008..2010 some changes
2010-05-13 Tabs are recognize instead spaces too, but there are converted to 2 spaces. Method replaceTabs(String)
.Modifier and Type | Field and Description |
---|---|
(package private) char |
cnl1 |
(package private) char |
cnl2 |
(package private) XmlNode |
currElem |
(package private) int |
deepnessList
If ** was written before, it is 2: List in list.
|
(package private) XmlNode |
dstElement |
(package private) java.lang.String |
dstNamespace |
(package private) java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.String,java.lang.String>> |
elementsWithAttrib
treemap of elements for attributes
|
(package private) int |
end
The end of the last line, starts with -1, the position before 0.
|
(package private) java.util.ListIterator<XmlNode> |
iterBaseElement
A list item is present.
|
(package private) int |
ixChild
The index of xmlNesting if the conversion is inside a structure with end label (table).
|
(package private) char |
kindList |
(package private) int |
preEmptylines |
(package private) Report |
report |
(package private) java.lang.String |
sClassNesting
The content of the class attributes for nesting levels.
|
(package private) int |
start
The start of the actual line.
|
(package private) int |
startNext
The start of the next line.
|
static java.lang.String |
version
Version history and license.
|
(package private) XmlNode[] |
xmlNesting
A list if list items are present.
|
(package private) XmlNode |
xmlPre
A current < pre>-Block
|
Constructor and Description |
---|
WikistyleTextToSimpleXml()
Constructor only connect the class to a report system.
|
WikistyleTextToSimpleXml(Report report)
Constructor only connect the class to a report system.
|
Modifier and Type | Method and Description |
---|---|
private void |
addToParentList(int level,
XmlNode toAdd)
Adds either into the iterator or in the topLevel element if the level is <0
or add to the xmlNesting[level]
|
private boolean |
checkCurrelem(java.lang.String tag) |
(package private) int |
checkInsertNesting_div(java.lang.String sLine,
java.lang.String sClass)
Processing a paragraph with beginning >
|
(package private) XmlNode |
checkInsertNestingTag(java.lang.String sTagNesting,
java.lang.String sClass)
Checks whether the given tag is an new tag or it is the same like the last line.
|
private void |
cleanup() |
private XmlNode |
closeChild() |
private XmlNode |
closeChild(java.lang.String sTag) |
private void |
convertLine(java.lang.String sInput,
XmlNode xmlRet,
java.lang.String dstNamespace,
java.lang.String sLabelOwn)
converts a line
|
private void |
endline(java.lang.String sLine)
It sets end and startNext.
|
(package private) java.lang.String |
getAttributeName(java.lang.String sLine)
Gets the name of attribute from a setting returned by
readAttributeSetting(String, int) . |
(package private) java.lang.String |
getAttributeValue(java.lang.String sAttribSetting)
Gets the value of attribute from a setting returned by
readAttributeSetting(String, int) . |
private java.lang.String |
getLineSpecial(java.lang.String sInput)
Gets a line
|
private void |
insertAndConvertText(java.lang.String sInput,
java.util.ListIterator<XmlNode> iter,
XmlNode dstElement,
java.util.Map<java.lang.String,java.lang.String> attributes,
java.lang.String sClass,
java.lang.String sLabelOwn)
Converts a text content in wikipedia-style to a tree of textual elements.
|
private java.lang.String |
nestingLevel(char cFirst,
java.lang.String sLine,
java.util.ListIterator<XmlNode> iterBaseElement_a,
XmlNode dstElement_a,
java.lang.String dstNamespace_a,
java.lang.String sClass)
process a nested element, may be a list item or div recursively in max 6 levels.
|
private XmlNode |
newChild(java.lang.String sTag) |
private XmlNode |
newSibling(java.lang.String sTag) |
(package private) java.lang.String |
readAttributes(java.lang.String sLine)
Reads the attribute for one elements.
|
(package private) java.lang.String |
readAttributeSetting(java.lang.String sLine,
int pos)
Reads an simple attribute setting.
|
private java.lang.String |
replaceTabs(java.lang.String src)
Replace tabs in the line with 2 spaces.
|
(package private) int |
setInset(java.lang.String sInput,
int startAfter,
XmlNode xmlRet,
java.lang.String sTag) |
void |
setWikistyleFormat(java.lang.String sInput,
XmlNode dstElement,
java.util.Map<java.lang.String,java.lang.String> attributes,
java.lang.String sClass) |
private void |
stop()
Only for debug.
|
void |
testXmlTreeAndConvert(XmlNode xmlTree)
Tests all Elements of the XML tree whether their content should be expand.
|
private void |
writeParagraphInElement(java.lang.String sLine,
XmlNode xmlParent,
java.lang.String dstNamespace,
java.util.Map<java.lang.String,java.lang.String> attributes,
java.lang.String sClass,
java.lang.String sLabelOwn) |
private void |
writeParagraphInIter(java.lang.String sLine,
java.util.ListIterator<XmlNode> iterParent,
XmlNode dstElement,
java.lang.String dstNamespace,
java.util.Map<java.lang.String,java.lang.String> attributes,
java.lang.String sClass,
java.lang.String sLabelOwn) |
public static final java.lang.String version
deepnessList
was not reseted, was 1 for next usage.
fix: cleanup improved.
endline(String)
@p.class="style"
can contained at start of a line with more content now.
Note that a line in this meaning can consist of more as one line with one carriage return inside in the source. It was a problem
writing an attribute with only one carriage return following with a text. Now you can write:
final Report report
int end
int startNext
char cnl1
char cnl2
int start
XmlNode[] xmlNesting
XmlNode currElem
java.util.ListIterator<XmlNode> iterBaseElement
XmlNode dstElement
java.lang.String dstNamespace
int ixChild
int deepnessList
char kindList
java.lang.String sClassNesting
XmlNode xmlPre
int preEmptylines
java.util.TreeMap<java.lang.String,java.util.TreeMap<java.lang.String,java.lang.String>> elementsWithAttrib
public WikistyleTextToSimpleXml()
public WikistyleTextToSimpleXml(Report report)
report
- may be null.public void testXmlTreeAndConvert(XmlNode xmlTree) throws XmlException
#insertAndConvertText(String, ListIterator, XmlNode, Map, String)
.xmlTree
- The tree to convert.XmlException
public void setWikistyleFormat(java.lang.String sInput, XmlNode dstElement, java.util.Map<java.lang.String,java.lang.String> attributes, java.lang.String sClass) throws XmlException
XmlException
private void insertAndConvertText(java.lang.String sInput, java.util.ListIterator<XmlNode> iter, XmlNode dstElement, java.util.Map<java.lang.String,java.lang.String> attributes, java.lang.String sClass, java.lang.String sLabelOwn) throws XmlException
XmlNode parent = new XmlNode("parent"); ListIterator iter = parent.getChildren().listIterator(); doSomethingAddingOtherElments(iter); String sText = getAnyTextWithWikipediaFormattingStyle(); insertInIterator(sText, iter, null);Another sample of using is implemented in the method
testXmlTreeAndConvert(XmlNode)
of this class,
xmlTree is the input argument of this method:
List listParaElements = xmlTree.getChildren(); ListIterator iterElements = listParaElements.listIterator(); while(iterElements.hasNext()) { XmlNode xmlTest = (XmlNode)(iterElements.next()); if(xmlTest.getName().equals("p") && xmlTest.getAttribute("expandWikistyle")!=null) { String sText = xmlTest.getText(); List attrib = xmlTest.getAttributes(); String sClass = xmlTest.getAttributeValue("class"); //the style attribute iterElements.remove(); insertInIterator(sText, iterElements, attrib, sClass); } else { testXmlTreeAndConvert(xmlTest); } }In this sample the actual element is replaced (removed and the new Elements are inserted) if it is a <p>-XmlNode with wikipedia-style-formatting. The Method testXmlTreeAndConvert() is called recursively for all elements. The attributes from the original <p>-XmlNode are copied to the new generated Elements.
sInput
- A String may be containing wikipedia style elements.iter
- If not null, it is an ListIterator of XML-children.
The resulting elements are added at the current position of the iterator.dstElement
- If not null, add new Elements as children into this given XmlNode.attributes
- List of attributes, type org.jdom.Attribute. All attributes are setted to
all created <p>-Elements.sClass
- Value of the class attribute from the original element.sLabelOwn
- transported in nested level, set from an Attribute expandLabelOwn.
It replaces a ~
-character in a label.XmlException
private void cleanup()
private void endline(java.lang.String sLine)
sLine
- private final java.lang.String replaceTabs(java.lang.String src)
src
- The lineprivate void convertLine(java.lang.String sInput, XmlNode xmlRet, java.lang.String dstNamespace, java.lang.String sLabelOwn) throws XmlException
sInput
- xmlRet
- dstNamespace
- sLabelOwn
- transported in nested level, set from an Attribute expandLabelOwn.
It replaces a ~
-character in a label.XmlException
private java.lang.String getLineSpecial(java.lang.String sInput)
sInput
- private java.lang.String nestingLevel(char cFirst, java.lang.String sLine, java.util.ListIterator<XmlNode> iterBaseElement_a, XmlNode dstElement_a, java.lang.String dstNamespace_a, java.lang.String sClass) throws XmlException
xmlChild
is setted to the correct level-XmlNode.sLine
- The line beginning with "*" or "#" or ";" or ":" or ">".
On recursive call it is not the first char of the absolute line, but the second, third, ...
adequate to the level.level
- The level, the user should set always 0. Only incremented if recursively called here.iterBaseElement_a
- If not null, the base level to insert level 0.dstElement_a
- If not null, the base level to insert level 0.XmlException
XmlNode checkInsertNestingTag(java.lang.String sTagNesting, java.lang.String sClass) throws XmlException
*listitem *listitemBecause the type of list is the same, no new list is inserted.
sTagNesting
- The tag, if list, than the whole list, not the list item.level
- The new level of nesting.sClass
- XmlException
int checkInsertNesting_div(java.lang.String sLine, java.lang.String sClass) throws XmlException
sLine
- level
- sClass
- XmlException
private XmlNode newChild(java.lang.String sTag) throws XmlException
XmlException
private XmlNode newSibling(java.lang.String sTag) throws XmlException
XmlException
private XmlNode closeChild()
private XmlNode closeChild(java.lang.String sTag)
private boolean checkCurrelem(java.lang.String tag)
private void addToParentList(int level, XmlNode toAdd) throws XmlException
level
- The level, -1 means add to topLeveltoAdd
- XmlNode to add, in most case it is xmlNesting[level+1]iterBaseElement
- top levels iterator if dst XmlNode = nulldstElement
- topLevel element.dstNamespace
- XmlException
int setInset(java.lang.String sInput, int startAfter, XmlNode xmlRet, java.lang.String sTag) throws XmlException
XmlException
java.lang.String readAttributeSetting(java.lang.String sLine, int pos)
sLine
- The linepos
- should be the position of the @.java.lang.String getAttributeName(java.lang.String sLine)
readAttributeSetting(String, int)
.
example: @dt.class="value" @class=valuesLine
- The Settingjava.lang.String getAttributeValue(java.lang.String sAttribSetting)
readAttributeSetting(String, int)
.
example: @dt.class="value" @class=valuejava.lang.String readAttributes(java.lang.String sLine)
sLine
- The line starting with '@'private void writeParagraphInIter(java.lang.String sLine, java.util.ListIterator<XmlNode> iterParent, XmlNode dstElement, java.lang.String dstNamespace, java.util.Map<java.lang.String,java.lang.String> attributes, java.lang.String sClass, java.lang.String sLabelOwn) throws XmlException
XmlException
private void writeParagraphInElement(java.lang.String sLine, XmlNode xmlParent, java.lang.String dstNamespace, java.util.Map<java.lang.String,java.lang.String> attributes, java.lang.String sClass, java.lang.String sLabelOwn) throws XmlException
XmlException
private void stop()