[xwiki-users] Velocity string challenge
Hi, I'm converting a XML file into XWiki pages with a structured object, my problem is that the XML file might contain elements with problematic text I have a XSLT that gives me a velocity script (like below) {{velocity}} ##Creating a ATE Question and Answer document programatically #set($ATEPrefix = "CdLSATE") #set($ATEDocName = $ATEPrefix+'TE'+1001) #set($newATEQA = $xwiki.getDocument("CdLSATEPublic.$ATEDocName")) ##Set a title $newATEQA.setTitle("Teeth Exfoliation") ##Set parent of document to Public ATE Questions and Answers $newATEQA.setParent("CdLSATEPublic.CdLSATEPublicQAs") ##This is how you can use a template $newATEQA.setContent('{{include document="CdlsatdCode.CdLSATEPublicQATemplate"/}}') ##Create a new object on the document #set($newATEQAObject = $newATEQA.newObject("CdlsatdCode.CdLSATEPublicQAClass")) ##Set a field to a particular value $newATEQAObject.set("AlphabetSort","TE") $newATEQAObject.set("subject","Teeth Exfoliation") $newATEQAObject.set("question","Is early loss of baby teeth something to be concerned about, indicative of a bigger problem, or related to CdLS?") $newATEQAObject.set("language","en") $newATEQAObject.set("CountryCode","us") $newATEQAObject.set("answer"," It is normal for children, especially girls, to lose their lower two front teeth from 4.5 years old to 5.5 years old. 4.5 years is early, but can be considered normal. There seems to be quite a variety of times when children with CdLS find themselves loosing their primary or baby teeth. Children with CdLS can have their primary teeth fall out either early or, more often, late. If the child is four years old and there are no other underlying medical complications, such as, hypothyroidism, hypophosphatsia, etc., then I would not be too concerned about losing the teeth. If there were many teeth, including molars that are getting loose, then further investigations would be indicated. DM/ TK 7-13-10 SEE ALSO: Teeth Grinding 1 Teeth Grinding 2 Teeth Growth Teething") $newATEQAObject.set("SACApproved",1) $newATEQA.save() {{velocity $newATEQAObject.set("question","...") and $newATEQAObject.set("answer","...") give me challeges Some text elements (not this example) will contain characters or combination of characters that will have a effect; - on the script not being valid; the " (double bracket) character - having a XWiki 2.0 meaning; "--" , "**" but intending something else Help appreciated... Gerritjan
Hi Gerritjan, On Wed, Nov 16, 2011 at 5:11 PM, Gerritjan Koekkoek < [email protected]> wrote:
Hi,
I'm converting a XML file into XWiki pages with a structured object, my problem is that the XML file might contain elements with problematic text I have a XSLT that gives me a velocity script (like below) {{velocity}} ##Creating a ATE Question and Answer document programatically #set($ATEPrefix = "CdLSATE") #set($ATEDocName = $ATEPrefix+'TE'+1001) #set($newATEQA = $xwiki.getDocument("CdLSATEPublic.$ATEDocName")) ##Set a title $newATEQA.setTitle("Teeth Exfoliation") ##Set parent of document to Public ATE Questions and Answers $newATEQA.setParent("CdLSATEPublic.CdLSATEPublicQAs") ##This is how you can use a template $newATEQA.setContent('{{include document="CdlsatdCode.CdLSATEPublicQATemplate"/}}') ##Create a new object on the document #set($newATEQAObject = $newATEQA.newObject("CdlsatdCode.CdLSATEPublicQAClass")) ##Set a field to a particular value $newATEQAObject.set("AlphabetSort","TE") $newATEQAObject.set("subject","Teeth Exfoliation")
$newATEQAObject.set("question","Is early loss of baby teeth something to be concerned about, indicative of a bigger problem, or related to CdLS?")
$newATEQAObject.set("language","en") $newATEQAObject.set("CountryCode","us") $newATEQAObject.set("answer"," It is normal for children, especially girls, to lose their lower two front teeth from 4.5 years old to 5.5 years old. 4.5 years is early, but can be considered normal. There seems to be quite a variety of times when children with CdLS find themselves loosing their primary or baby teeth. Children with CdLS can have their primary teeth fall out either early or, more often, late. If the child is four years old and there are no other underlying medical complications, such as, hypothyroidism, hypophosphatsia, etc., then I would not be too concerned about losing the teeth. If there were many teeth, including molars that are getting loose, then further investigations would be indicated.
DM/ TK 7-13-10
SEE ALSO: Teeth Grinding 1 Teeth Grinding 2 Teeth Growth Teething")
$newATEQAObject.set("SACApproved",1) $newATEQA.save() {{velocity
$newATEQAObject.set("question","...") and $newATEQAObject.set("answer","...") give me challeges
Some text elements (not this example) will contain characters or combination of characters that will have a effect; - on the script not being valid; the " (double bracket) character
You need to make sure, when generating the quoted strings, to replace quotes (") with $escapetool.quote or $escapetool.q and single quotes (') with $escapetool.singleQuote or $escapetool.s. Example: $newATEQAObject.set("answer","Then the robot says: ${escapetool.q}Hello World!${escapetool.q}") Anything else, besides quotes or single quotes, should have no impact on the validity of your velocity script, as long as your string is wrapped by quotes.
- having a XWiki 2.0 meaning; "--" , "**" but intending something else
You only care about this at the presentation level, not here, at set level. This means that, in your sheet, you might want to display the values of "question" and "answer" inside a verbatim like: {{velocity}} #set ($a = "**a**") {{{ $a }}} {{/velocity}} This will escape any wiki syntax that might be contained by the values of "question" and "answer".
Help appreciated...
Hope this is what you were asking for. Thanks, Eduard
Gerritjan
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Hi, This is certainly of great help.... Verstuurd vanaf mijn iPad Op 16 nov. 2011 om 22:57 heeft Eduard Moraru <[email protected]> het volgende geschreven:
Hi Gerritjan,
On Wed, Nov 16, 2011 at 5:11 PM, Gerritjan Koekkoek < [email protected]> wrote:
Hi,
I'm converting a XML file into XWiki pages with a structured object, my problem is that the XML file might contain elements with problematic text I have a XSLT that gives me a velocity script (like below) {{velocity}} ##Creating a ATE Question and Answer document programatically #set($ATEPrefix = "CdLSATE") #set($ATEDocName = $ATEPrefix+'TE'+1001) #set($newATEQA = $xwiki.getDocument("CdLSATEPublic.$ATEDocName")) ##Set a title $newATEQA.setTitle("Teeth Exfoliation") ##Set parent of document to Public ATE Questions and Answers $newATEQA.setParent("CdLSATEPublic.CdLSATEPublicQAs") ##This is how you can use a template $newATEQA.setContent('{{include document="CdlsatdCode.CdLSATEPublicQATemplate"/}}') ##Create a new object on the document #set($newATEQAObject = $newATEQA.newObject("CdlsatdCode.CdLSATEPublicQAClass")) ##Set a field to a particular value $newATEQAObject.set("AlphabetSort","TE") $newATEQAObject.set("subject","Teeth Exfoliation")
$newATEQAObject.set("question","Is early loss of baby teeth something to be concerned about, indicative of a bigger problem, or related to CdLS?")
$newATEQAObject.set("language","en") $newATEQAObject.set("CountryCode","us") $newATEQAObject.set("answer"," It is normal for children, especially girls, to lose their lower two front teeth from 4.5 years old to 5.5 years old. 4.5 years is early, but can be considered normal. There seems to be quite a variety of times when children with CdLS find themselves loosing their primary or baby teeth. Children with CdLS can have their primary teeth fall out either early or, more often, late. If the child is four years old and there are no other underlying medical complications, such as, hypothyroidism, hypophosphatsia, etc., then I would not be too concerned about losing the teeth. If there were many teeth, including molars that are getting loose, then further investigations would be indicated.
DM/ TK 7-13-10
SEE ALSO: Teeth Grinding 1 Teeth Grinding 2 Teeth Growth Teething")
$newATEQAObject.set("SACApproved",1) $newATEQA.save() {{velocity
$newATEQAObject.set("question","...") and $newATEQAObject.set("answer","...") give me challeges
Some text elements (not this example) will contain characters or combination of characters that will have a effect; - on the script not being valid; the " (double bracket) character
You need to make sure, when generating the quoted strings, to replace quotes (") with $escapetool.quote or $escapetool.q and single quotes (') with $escapetool.singleQuote or $escapetool.s. Example:
$newATEQAObject.set("answer","Then the robot says: ${escapetool.q}Hello World!${escapetool.q}")
Anything else, besides quotes or single quotes, should have no impact on the validity of your velocity script, as long as your string is wrapped by quotes.
This is a very helpfull suggestion, but there is a next step, the semantic meaning of the quotes or any markup; most of the time (in my special case) the double quote is used to give a accent to a word, group of words; i would say xwiki markup; bold, underline, italic or combination woud be a better substitute, but in other cases " = Inch. So the logic would say if the quotes apear 2 times, enclosing some text, replacing it with markup is better, while in the inch-case above suggestion would be perfect. The challenge is how to determine if the characters are used to enclose word(s) (as markup) and when is it used semantically. I was thinking along the line; if count of character is a even number it is likely to be markup, if it is not even there is at least one occurence used semantically?
- having a XWiki 2.0 meaning; "--" , "**" but intending something else
You only care about this at the presentation level, not here, at set level. This means that, in your sheet, you might want to display the values of "question" and "answer" inside a verbatim like:
{{velocity}} #set ($a = "**a**") {{{ $a }}} {{/velocity}}
This will escape any wiki syntax that might be contained by the values of "question" and "answer".
Help appreciated...
Hope this is what you were asking for.
Thanks, Eduard
Gerritjan
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
Hi, Well, I would not encourage you to convert the semantics, since you can end up with some weird cases, like the following sentence: The product name is "LCD 17" Display". More generally speaking, whatever you do will not have a 100% cover rate and you could end up making everything bold for example. IMO, using quotes is a good and standard enough way of emphasizing words, but you know better your data and requirements. Plus, you mentioned in your second question that you don`t want text like "--" or "**" to be treated as wiki2.0 syntax. If you use my suggestion of printing the answer/question inside a verbatim, you will not be able to do replace quotes with bold as you mentioned anyway. If you don`t want to use the verbatim, you will have individually escape every xwiki2.0 syntax element in your text, except maybe bold (that you wanted to use). Looks like more work than benefit to me. What I forgot to mention in my previous mail is that you should also watch out for the dollar character ($) and replace it with $escapetool.d or $escapetool.dollar to avoid interpreting text as variables. Thanks, Eduard On Thu, Nov 17, 2011 at 9:58 AM, Gmail GJ <[email protected]>wrote:
Hi,
This is certainly of great help....
Verstuurd vanaf mijn iPad
Op 16 nov. 2011 om 22:57 heeft Eduard Moraru <[email protected]> het volgende geschreven:
Hi Gerritjan,
On Wed, Nov 16, 2011 at 5:11 PM, Gerritjan Koekkoek < [email protected]> wrote:
Hi,
I'm converting a XML file into XWiki pages with a structured object, my problem is that the XML file might contain elements with problematic text I have a XSLT that gives me a velocity script (like below) {{velocity}} ##Creating a ATE Question and Answer document programatically #set($ATEPrefix = "CdLSATE") #set($ATEDocName = $ATEPrefix+'TE'+1001) #set($newATEQA = $xwiki.getDocument("CdLSATEPublic.$ATEDocName")) ##Set a title $newATEQA.setTitle("Teeth Exfoliation") ##Set parent of document to Public ATE Questions and Answers $newATEQA.setParent("CdLSATEPublic.CdLSATEPublicQAs") ##This is how you can use a template $newATEQA.setContent('{{include document="CdlsatdCode.CdLSATEPublicQATemplate"/}}') ##Create a new object on the document #set($newATEQAObject = $newATEQA.newObject("CdlsatdCode.CdLSATEPublicQAClass")) ##Set a field to a particular value $newATEQAObject.set("AlphabetSort","TE") $newATEQAObject.set("subject","Teeth Exfoliation")
$newATEQAObject.set("question","Is early loss of baby teeth something to be concerned about, indicative of a bigger problem, or related to CdLS?")
$newATEQAObject.set("language","en") $newATEQAObject.set("CountryCode","us") $newATEQAObject.set("answer"," It is normal for children, especially girls, to lose their lower two front teeth from 4.5 years old to 5.5 years old. 4.5 years is early, but can be considered normal. There seems to be quite a variety of times when children with CdLS find themselves loosing their primary or baby teeth. Children with CdLS can have their primary teeth fall out either early or, more often, late. If the child is four years old and there are no other underlying medical complications, such as, hypothyroidism, hypophosphatsia, etc., then I would not be too concerned about losing the teeth. If there were many teeth, including molars that are getting loose, then further investigations would be indicated.
DM/ TK 7-13-10
SEE ALSO: Teeth Grinding 1 Teeth Grinding 2 Teeth Growth Teething")
$newATEQAObject.set("SACApproved",1) $newATEQA.save() {{velocity
$newATEQAObject.set("question","...") and $newATEQAObject.set("answer","...") give me challeges
Some text elements (not this example) will contain characters or combination of characters that will have a effect; - on the script not being valid; the " (double bracket) character
You need to make sure, when generating the quoted strings, to replace quotes (") with $escapetool.quote or $escapetool.q and single quotes (') with $escapetool.singleQuote or $escapetool.s. Example:
$newATEQAObject.set("answer","Then the robot says: ${escapetool.q}Hello World!${escapetool.q}")
Anything else, besides quotes or single quotes, should have no impact on the validity of your velocity script, as long as your string is wrapped by quotes.
This is a very helpfull suggestion, but there is a next step, the semantic meaning of the quotes or any markup; most of the time (in my special case) the double quote is used to give a accent to a word, group of words; i would say xwiki markup; bold, underline, italic or combination woud be a better substitute, but in other cases " = Inch. So the logic would say if the quotes apear 2 times, enclosing some text, replacing it with markup is better, while in the inch-case above suggestion would be perfect. The challenge is how to determine if the characters are used to enclose word(s) (as markup) and when is it used semantically. I was thinking along the line; if count of character is a even number it is likely to be markup, if it is not even there is at least one occurence used semantically?
- having a XWiki 2.0 meaning; "--" , "**" but intending something else
You only care about this at the presentation level, not here, at set
level.
This means that, in your sheet, you might want to display the values of "question" and "answer" inside a verbatim like:
{{velocity}} #set ($a = "**a**") {{{ $a }}} {{/velocity}}
This will escape any wiki syntax that might be contained by the values of "question" and "answer".
Help appreciated...
Hope this is what you were asking for.
Thanks, Eduard
Gerritjan
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
_______________________________________________ users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
users mailing list [email protected] http://lists.xwiki.org/mailman/listinfo/users
participants (3)
-
Eduard Moraru -
Gerritjan Koekkoek -
Gmail GJ