Skip to content

Literal.java update #2

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Update Literal.java
truncate too long strings to avoid db exceptions (and consequently loss of triple batch)
RastislavHudak committed May 3, 2013
commit 0f44a4ddacd294cceda652e123a139d25ac1c4e9
22 changes: 21 additions & 1 deletion src/main/java/org/nsdl/mptstore/rdf/Literal.java
Original file line number Diff line number Diff line change
@@ -15,6 +15,9 @@
* RDF Concepts and Abstract Syntax, Section 6.5</a>
*/
public class Literal implements ObjectNode {

/* Max length of the literal including language and datatype suffix. This should not be greater than the varchar size of the table column (uless the server truncates the string automatically). */
private static final int LITERAL_MAXLEN = 255;

/**
* The lexical value of this literal.
@@ -100,7 +103,24 @@ public String getValue() {
public String toString() {
StringBuffer out = new StringBuffer();
out.append('"');
out.append(NTriplesUtil.escapeLiteralValue(_value));

// 2 is the length of "" and ...
int suffixLenght = 5;
if(_language != null){
// it might be 2 or 3 letter code
suffixLenght += 1 + _language.length();
}
if(_datatype != null){
suffixLenght += 2 + _datatype.toString().length();
}

String escaped = NTriplesUtil.escapeLiteralValue(_value);
if(LITERAL_MAXLEN > 0 && escaped.length() > (LITERAL_MAXLEN-suffixLenght)){
out.append(escaped.substring(0,(LITERAL_MAXLEN-suffixLenght))+"...");
}else{
out.append(escaped);
}

out.append('"');
if (_language != null) {
out.append("@" + _language);