Xml attribute rendering oddness - scala

Using 2.9.0.1
<b time={None}>Hello</b>
=>
<b >Hello</b>
i.e. there is a space after the b in the starting tag.
This makes no sense from an XML perspective.
Is this "feature" supposed to happen?
Thanks.

It happens because of toString implementation of scala.xml.Elem, to be more specific
in object scala.xml.MetaInf method buildString which looks like following:
def buildString(sb: StringBuilder): StringBuilder = {
sb.append(' ')
toString1(sb)
next.buildString(sb)
}
So it's firstly adds a white space to string representation of element, and only after that appends next attribute, so if an attribute is present as class member but doesn't have any string representation you'll end up with one extra space before closing bracket

Actually, it is allowed. See Extensible Markup Language (XML) 1.0 (Fifth Edition), 3.1 Start-Tags, End-Tags, and Empty-Element Tags. From there:
STag ::= '<' Name (S Attribute)* S? '>'
Where S is whitespace and Attribute is an attribute definition. The same is true for end elements:
ETag ::= '</' Name S? '>'
So this is allowed. Whether or not it's what you want is another thing :-)

Related

How Can I Verify Text Amount in Katalon

I'm trying to verify a text in Katalon and my script isn't working.
Here's my element:
<span id="overviewTabStoreCredit" class="h2 strong amountCredit text-danger">-$100.00</span>
Here's my script:
def StoreCreditAmount = '-$100.00'
TestObject StoreCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
WebUI.verifyElementAttributeValue(StoreCreditTO, 'text', StoreCreditAmount, GlobalVariable.G_Timeout_Tiny, FailureHandling.CONTINUE_ON_FAILURE)
When running the script, I get an error message, "Object does not have attribute 'text'"
I also tried this to character it by class instead of text:
def StoreCreditAmount = 'h2 strong amountCredit text-danger'
TestObject StoreCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
WebUI.verifyElementAttributeValue(StoreCreditTO, 'class', StoreCreditAmount, GlobalVariable.G_Timeout_Tiny, FailureHandling.CONTINUE_ON_FAILURE)
I got this error:
Has attribute 'class' with actual value 'text-success h2 strong amountCredit' instead of expected value 'h2 strong amountCredit text-danger' even though the value is correct.
'Text' might not be an attribute. You can getText() from the element and then compare with the expected result. Sometimes, the value you see might not from Text, but from the attribute 'value'.
When you look at your tag there is no "text" attribute:
<span id="overviewTabStoreCredit" class="h2 strong amountCredit text-danger">
Some elements (like text-boxes) have hidden "value" elements for input text, but that is not the case here.
I believe what you want to do is check that the text between your tags equals a certain amount, in this case: "-$100.00".
To check the text between your opening/closing tags for your element use
WebUI.getText(). So your code could grab the text between the tags of your element, and then do an assert (or do it in one step) to finish your validation. I'll show it in two for readability:
def testStoreCreditAmountText = '-$100.00'
TestObject storeCreditTO = findTestObject('Baseline/Page_Side Menu/Page_Customers/Page_Customer Card/span_Verify Credit Limit')
def actualStoreCreditAmountText = WebUI.getText(storeCreditTO)
WebUI.verifyMatch(testStoreCreditAmountText, actualStoreCreditAmountText, false)
I hope that helps!

Ontology annotation type is missing in saved ontology file

I'm using OWL API 4.1. I add annotation with type XSD:string like that:
OWLAnnotationProperty annotationProperty = this.getDf().getOWLAnnotationProperty(annotationPropertyIri);
OWLLiteral lit = this.df.getOWLLiteral(annotationValue, range);
OWLAnnotation annotation = df.getOWLAnnotation(annotationProperty, lit);
this.getMng().applyChange(new AddOntologyAnnotation(this.getOnt(), annotation));
... I checked that here lit="test"^^xsd:string. But after I saved ontology (in ttl format) - there in no type ending - ^^xsd:string:
...
<http://semanticweb.rocks/whole-dataset-name/wheat-02> a owl:Ontology ;
dc:description """test""" ;
dc:source """http://mail.ru"""^^xsd:anyURI .
...
If I use other type (e.g. xsd:anyURI ) instead of ^^xsd:string the ending ^^xsd:anyURI is presented.
What is matter with ^^xsd:string?
The xsd:string type can be skipped for string literals, when there is no language tag. A literal typed with xsd:string is identical to a plain literal with no language tag.
If you load the ontology back into an OWLOntology, I expect you to see a test^^xsd:string literal attached to the ontology.

myBatis Callable Statement - java Date Issue

I was using mybatis-3.1.1 and there was no issue in the following code.
DAO Implementation
#Override
public ItunesPriorityReportDates getWeeklyPriorityDates(Date reportRunDate){
ItunesPriorityReportDates itunesPriorityReportDates = new ItunesPriorityReportDates();
Map<String,Object> weeklyPriorityDatesParamMap = new HashMap<>();
weeklyPriorityDatesParamMap.put("reportRunDate", reportRunDate);
log.debug("Report Run Date : " + reportRunDate);
this.getItunesAnalysisMapper().getWeeklyPriorityDates(weeklyPriorityDatesParamMap);
itunesPriorityReportDates.setAriaWeekStartDate((Date)weeklyPriorityDatesParamMap.get("ariaWeekStartDate"));
itunesPriorityReportDates.setAriaWeekEndDate((Date)weeklyPriorityDatesParamMap.get("ariaWeekEndDate"));
itunesPriorityReportDates.setitunesAccountPeriodStartDate((Date)weeklyPriorityDatesParamMap.get("itunesAccountPeriodStartDate"));
itunesPriorityReportDates.setitunesAccountPeriodEndDate((Date)weeklyPriorityDatesParamMap.get("itunesAccountPeriodEndDate"));
return itunesPriorityReportDates;
}
Mapper
public ItunesPriorityReportDates getWeeklyPriorityDates(Map<String,Object> weeklyPriorityDatesParamMap);
Mapper XML.
<select id="getWeeklyPriorityDates" parameterType="java.util.HashMap" statementType="CALLABLE">
{CALL external_reporting.itunes_sales.get_weekly_priority_dates(#{reportRunDate mode=IN, jdbcType=DATE},
#{ariaWeekStartDate mode=OUT, jdbcType=DATE},
#{ariaWeekEndDate mode=OUT, jdbcType=DATE},
#{itunesAccountPeriodStartDate mode=OUT, jdbcType=DATE},
#{itunesAccountPeriodEndDate mode=OUT, jdbcType=DATE}
)
}
</select>
After upgrading to mybatis-3.2.5 now it is passing null as DATE to Oracle procedure.
Can you please help me with this? Not sure whether I have to update my mapper XML and include something to tell it to parse correctly.
I am using java.util.Date in java.
Thanks
Chirag
Got solution from Eduardo Macarron (myBatis developer)
I got it. It is an interesting finding. Have a look at the expression you posted.
{reportRunDate mode=IN, jdbcType=DATE},
There is no comma separating the property name and the mode!
What is happening is that 3.0 and 3.1 admitted using an space as a separator, though that was undocumented, untested and at least in my case unknown :)
3.2 parsing code was improved and now it supports a well defined grammar:
Inline parameter expression parser. Supported grammar (simplified):
inline-parameter = (propertyName | expression) oldJdbcType attributes
propertyName = /expression language's property navigation path/
expression = '(' /expression language's expression/ ')'
oldJdbcType = ':' /any valid jdbc type/
attributes = (',' attribute)*
attribute = name '=' value
And the space is not a valid separator (so properties can in fact be called "input date").
This change was unwanted but was introduced in 3.2 one year ago so I am afraid we cannot go back.
I hope you just missed the comma and that was not intentional. Sorry!

Are digits allowed in a knockout.js custom binding name?

I have an application with a custom binding declared like
ko.bindingHandlers.slideContent2 = {
init: ...,
update: ...
}
and I use that in my html with (among other things)
<div data-bind="slideContent2: true"></div>
It works and produces no errors. Today I discover that the new knockout.js syntax checker in Netbeans 7.4 thinks that <div data-bind="slideContent2: true"> is in error. It objects to the digit 2. If I remove that, it thinks the name is fine. Looking around web examples, I haven't found an example of a digit used in the name of a custom binding.
Are digits legal in custom binding names? Is the Netbeans checker being overenthusiastic?
From the Knockout point of view every valid JavaScript identifier name is a valid custom binding handler name.
So you can have digits in custom binding handlers. For the full identifier name reference you can check: Valid identifier names
However from the Netbeans syntax checker point of view only letters are allowed in custom binding names.
For reference check out the source of KODataBindLexer (I've added some comments)
case IN_KEY:
if (!Character.isLetter(c)) { // the character 2 is not a letter
if (c == ':') {
state = State.AFTER_KEY;
input.backup(1); //backup the colon
return tokenFactory.createToken(KODataBindTokenId.KEY);
} else if (Character.isWhitespace(c)) {
state = State.WS_AFTER_KEY;
input.backup(1); //backup the ws
return tokenFactory.createToken(KODataBindTokenId.KEY);
} else { // 2 is not a the colon and not a whitespace so it returns Error:
state = State.INIT;
return tokenFactory.createToken(KODataBindTokenId.ERROR);
}
}
//stay in IN_KEY
break;

How to define a `separator` tag in play-1.x without modifing play's source code

I want to define a tag separator tag, which inside a list tag, can add separator between items.
The sample code is:
List<String> users = new ArrayList<String>();
users.add("Jeff");
users.add("Mike");
#{list users, as: 'user'}
#{separator ' + ' /}
<span>${user}</span>
#{/list}
If I don't use the separator tag, the code will be:
#{list users, as: 'user'}
${user_isFirst ? '' : ' + '}
<span>${user}</span>
#{/list}
The generated html code will be:
<span>Jeff</span> + <span>Mike</span>
I tried defined a fastTag:
public static void _separator(Map<?, ?> args, Closure body, PrintWriter out, GroovyTemplate.ExecutableTemplate template, int fromLine) {
Object value = args.get("arg");
// TODO how to get the value of `as` defined in parent `list` tag?
out.print(value);
}
But the problem is I can't get the value of as defined in list tag (which is user) in this case.
You can create a custom list tag in groovy like this
#{list items:_arg, as:'tmp'}
%{
attrs = [:]
attrs.put(_as, tmp)
}%
#{ifnot tmp_isFirst}${_sep}#{/ifnot}
#{doBody vars:attrs /}
#{/list}
and use it like this
#{myList users, as:'user', sep:','}
${user}
#{/myList}
You should trace into your FastTag implementation. I think you'll see all the variables in scope inside the args map. This is from memory - so, sorry if not.
That said, I think it might be simpler if you copy the Java code for #{list} and add a new parameter, like
#{list users, as: 'user', separator: '+' }
and handle the logic in there. It seems a bit cleaner too from a design point of view - if it is a separator, how come you can put it anywhere you like in the code (and why not put it in twice!).
A final option is to look at Groovy or Java collection operators. http://groovy.codehaus.org/groovy-jdk/java/util/Collection.html