19 package cz.vutbr.fit.knot.annotations.entity;
 
   26 import cz.vutbr.fit.knot.annotations.entity.attribute.*;
 
   31 import java.io.Serializable;
 
   32 import java.text.SimpleDateFormat;
 
   33 import java.util.ArrayList;
 
   34 import java.util.Collections;
 
   35 import java.util.Date;
 
   36 import java.util.Iterator;
 
   37 import java.util.List;
 
   38 import java.util.logging.Level;
 
   39 import java.util.logging.Logger;
 
   40 import javax.persistence.Basic;
 
   41 import javax.persistence.CascadeType;
 
   42 import javax.persistence.Column;
 
   43 import javax.persistence.Entity;
 
   44 import javax.persistence.GeneratedValue;
 
   45 import javax.persistence.GenerationType;
 
   46 import javax.persistence.Id;
 
   47 import javax.persistence.JoinColumn;
 
   48 import javax.persistence.Lob;
 
   49 import javax.persistence.NamedQueries;
 
   50 import javax.persistence.NamedQuery;
 
   51 import javax.persistence.OneToMany;
 
   52 import javax.persistence.OneToOne;
 
   53 import javax.persistence.Table;
 
   54 import javax.persistence.Temporal;
 
   55 import javax.persistence.TemporalType;
 
   56 import javax.persistence.Transient;
 
   57 import org.w3c.dom.Document;
 
   66 @Table(name = 
"annotation")
 
   68   @NamedQuery(name = 
"Annotation.findAll", query = 
"SELECT a FROM Annotation a"),
 
   69   @NamedQuery(name = 
"Annotation.findById", query = 
"SELECT a FROM Annotation a WHERE a.id = :id"),
 
   70   @NamedQuery(name = 
"Annotation.findByType", query = 
"SELECT a FROM Annotation a WHERE a.type = :type"),
 
   71   @NamedQuery(name = 
"Annotation.findByCreated", query = 
"SELECT a FROM Annotation a WHERE a.created = :created"),
 
   72   @NamedQuery(name = 
"Annotation.findByAuthor", query = 
"SELECT a FROM Annotation a WHERE a.authorId = :authorId"),
 
   73   @NamedQuery(name = 
"Annotation.findByAuthorName", query = 
"SELECT a FROM Annotation a WHERE a.authorName = :authorName"),
 
   74   @NamedQuery(name = 
"Annotation.findByAuthorAddress", query = 
"SELECT a FROM Annotation a WHERE a.authorAddress = :authorAddress"),
 
   75   @NamedQuery(name = 
"Annotation.findBySource", query = 
"SELECT a FROM Annotation a WHERE a.source = :source"),
 
   76   @NamedQuery(name = 
"Annotation.findBySourceDocumentID", query = 
"SELECT a FROM Annotation a WHERE a.sourceDocumentId = :sourceDocumentId"),
 
   77   @NamedQuery(name = 
"Annotation.findBySourceDocumentIDAndAuthor", query = 
"SELECT a FROM Annotation a WHERE a.sourceDocumentId = :sourceDocumentId AND a.authorId = :authorId"),
 
   78   @NamedQuery(name = 
"Annotation.findBySourceDocumentIDNoNested", query = 
"SELECT a FROM Annotation a WHERE a.sourceDocumentId = :sourceDocumentId AND a.nestedIn IS NULL"),
 
   79   @NamedQuery(name = 
"Annotation.findByNestedIn", query = 
"SELECT a FROM Annotation a WHERE a.nestedIn = :nestedIn")})
 
   81   private static final long serialVersionUID = 1L;
 
   84   @GeneratedValue(strategy = GenerationType.IDENTITY)
 
   85   @Basic(optional = 
false)
 
   89   @Basic(optional = false)
 
   90   @Column(name = "type", nullable=false, insertable=false, updatable=false)
 
   93   @Basic(optional = false)
 
   94   @Column(name = "created")
 
   95   @Temporal(TemporalType.TIMESTAMP)
 
   98   @Basic(optional = false)
 
   99   @Column(name = "authorIdStr")
 
  100   private String authorIdStr;
 
  102   @Basic(optional = true)
 
  103   @Column(name = "authorName")
 
  104   private String authorName;
 
  106   @Basic(optional = true)
 
  107   @Column(name = "authorAddress")
 
  108   private String authorAddress;
 
  110   @Basic(optional = true)
 
  111   @Column(name = "authorId", insertable=false, updatable=false)
 
  112   private String authorId;
 
  114   @Basic(optional = false)
 
  115   @Column(name = "source")
 
  116   private String source;
 
  118   @Basic(optional = false)
 
  119   @Column(name = "sourceDocumentId", nullable=false, insertable=false, updatable=false)
 
  120   private Integer sourceDocumentId;
 
  122   @Basic(optional = false)
 
  124   @Column(name = "content")
 
  125   private String content;
 
  127   @Column(name = "nestedIn", insertable=false, updatable=false)
 
  128   private String nestedIn;
 
  131   @OneToOne(optional = false)
 
  132   @JoinColumn(name = "type", referencedColumnName = "
id")
 
  135   @OneToOne(optional = false)
 
  136   @JoinColumn(name = "sourceDocumentId", referencedColumnName = "
id")
 
  139   @OneToMany(mappedBy = "refAnnotation", cascade = CascadeType.ALL,
 
  143   @OneToMany(mappedBy = "refAnnotation", cascade = CascadeType.ALL,
 
  147   @OneToOne(optional = true)
 
  148   @JoinColumn(name = "authorId", referencedColumnName = "
id")
 
  151   @OneToOne(optional = true)
 
  152   @JoinColumn(name = "nestedIn", referencedColumnName = "
id")
 
  157   private String tmpId;
 
  165   private List<Integer> linkedByBeforeRemove;
 
  195   public Annotation(Integer 
id, Date created, String authorIdStr, String authorName, String authorAddress, 
AnnotDocument sourceDocument, String content, String nestedIn) {
 
  197     this.created = created;
 
  198     this.authorIdStr = authorIdStr;
 
  199     this.authorName = authorName;
 
  200     this.authorAddress = authorAddress;
 
  201     this.sourceDocument = sourceDocument;
 
  202     if (sourceDocument != null) {
 
  203       this.source = sourceDocument.getUriForAnnot();
 
  205     this.content = content;
 
  206     this.nestedIn = nestedIn;
 
  207     this.nestedInAnnot = null;
 
  208     this.attributes = 
new ArrayList<BaseAttribute>();
 
  209     this.fragments = 
new ArrayList<Fragment>();
 
  224     this.annotType = annotType;
 
  225     this.created = created;
 
  226     this.authorIdStr = authorIdStr;
 
  227     this.authorName = authorName;
 
  228     this.authorAddress = authorAddress;
 
  229     this.sourceDocument = sourceDocument;
 
  230     if (sourceDocument != null) {
 
  231       this.source = sourceDocument.getUriForAnnot();
 
  233     this.content = content;
 
  234     this.nestedInAnnot = null;
 
  235     this.attributes = 
new ArrayList<BaseAttribute>();
 
  236     this.fragments = 
new ArrayList<Fragment>();
 
  252     this.annotType = annotType;
 
  253     this.created = created;
 
  254     this.authorIdStr = authorIdStr;
 
  255     this.authorName = authorName;
 
  256     this.authorAddress = authorAddress;
 
  257     this.sourceDocument = sourceDocument;
 
  258     if (sourceDocument != null) {
 
  259       this.source = sourceDocument.getUriForAnnot();
 
  261     this.content = content;
 
  262     this.nestedInAnnot = nestedInAnnot;
 
  263     this.attributes = 
new ArrayList<BaseAttribute>();
 
  264     this.fragments = 
new ArrayList<Fragment>();
 
  273     this.type = newData.getAnnotType().getId();
 
  274     this.created = newData.getCreated();
 
  275     this.authorIdStr = newData.getAuthorIdStr();
 
  276     this.authorName = newData.getAuthorName();
 
  277     this.authorAddress = newData.getAuthorAddress();
 
  278     this.source = newData.getSource();
 
  279     this.sourceDocumentId = newData.getSourceDocument().getId();
 
  280     this.content = newData.getContent();
 
  282       this.nestedIn = newData.getNestedInAnnot().getId().toString();
 
  284     this.annotType = newData.getAnnotType();
 
  285     this.sourceDocument = newData.getSourceDocument();
 
  286     this.attributes = newData.getAttributes();
 
  287     this.fragments = newData.getFragments();
 
  288     this.user = newData.getUser();
 
  289     this.nestedInAnnot = newData.getNestedInAnnot();
 
  298     this.type = newData.getAnnotType().getId();
 
  299     this.created = newData.getCreated();
 
  300     this.authorIdStr = newData.getAuthorIdStr();
 
  301     this.authorName = newData.getAuthorName();
 
  302     this.authorAddress = newData.getAuthorAddress();
 
  303     this.source = newData.getSource();
 
  304     this.sourceDocumentId = newData.getSourceDocument().getId();
 
  305     this.content = newData.getContent();
 
  307     this.annotType = newData.getAnnotType();
 
  308     this.sourceDocument = newData.getSourceDocument();
 
  309     this.fragments = 
new ArrayList<Fragment>();
 
  311       Iterator<SuggestionFragment> frIt = newData.getFragments().iterator();
 
  312       while (frIt.hasNext()) {
 
  315         fragments.add(newFr);
 
  318     this.attributes = 
new ArrayList<BaseAttribute>();
 
  320       Iterator<SugBaseAttribute> atIt = newData.getAttributes().iterator();
 
  321       while (atIt.hasNext()) {
 
  324         String simpleType = sugAt.getSimpleType();
 
  325         if (simpleType != null && simpleType.equals(
"SuggestionLink")) {
 
  326           simpleType = 
"AnnotationLink";
 
  327         } 
else if (simpleType != null && simpleType.equals(
"NestedSuggestion")) {
 
  328           simpleType = 
"NestedAnnotation";
 
  331           newAt = AttributeManager.createAttribute(sugAt.getName(), simpleType, 
this);
 
  332         } 
catch (ClassNotFoundException ex) {
 
  333           String msg = 
"Unable to create annotation attribute with type = " + sugAt.getSimpleType();
 
  334           Logger.getLogger(Annotation.class.getName()).log(Level.SEVERE, null, msg);
 
  337         newAt.updateFromSugBaseAttributeAll(sugAt);
 
  338         this.attributes.add(newAt);
 
  341     this.user = newData.getUser();
 
  377     this.annotType = annotType;
 
  398       authorIdStr = user.getURI();
 
  399       if (user.
getName() != null && !user.getName().contentEquals(
"")) {
 
  400         authorName = user.getName();
 
  402       if (user.
getEmail() != null && !user.getEmail().contentEquals(
"")) {
 
  403         authorAddress = user.getEmail();
 
  423     this.created = created;
 
  441     this.authorIdStr = authorIdStr;
 
  459     this.authorName = authorName;
 
  468     return authorAddress;
 
  477     this.authorAddress = authorAddress;
 
  495     this.source = source;
 
  513     return new ArrayList<Fragment>(fragments);
 
  522     this.fragments = fragments;
 
  531     fragments.add(fragment);
 
  549     this.content = content;
 
  567     this.nestedIn = nestedIn;
 
  585     this.attributes = attributes;
 
  594     this.attributes.add(attribute);
 
  603     return nestedInAnnot;
 
  612     this.nestedInAnnot = nestedInAnnot;
 
  621     return sourceDocumentId;
 
  630     this.sourceDocumentId = sourceDocumentId;
 
  657     return sourceDocument;
 
  667     this.sourceDocument = sourceDocument;
 
  668     if (sourceDocument != null) {
 
  669       this.source = sourceDocument.getUriForAnnot();
 
  688     this.authorId = authorId;
 
  700     return AppBean.getBaseAnnotUri() + 
id;
 
  710       return AppBean.getBaseUri() + 
"/serv/" + 
id;
 
  712     else if(tmpId != null){
 
  713       return AppBean.getBaseUri() + 
"/temp/" + tmpId;
 
  723     hash += (
id != null ? id.hashCode() : 0);
 
  739     Annotation other = (Annotation) 
object;
 
  740     if ((this.
id == null && other.
id != null) || (this.id != null && !this.id.equals(other.id))) {
 
  744     if(other.
id == null && 
this.id == null){
 
  745       if(!contentEquals(
object)){
 
  761   public boolean equals(Object 
object, 
boolean noLinked){
 
  765     Annotation other = (Annotation) 
object;
 
  766     if ((this.
id == null && other.
id != null) || (this.id != null && !this.id.equals(other.id))) {
 
  770     if(other.
id == null && 
this.id == null){
 
  771       if(!contentEquals(
object,
false,noLinked)){
 
  788     return contentEquals(obj,
false,
false);
 
  801   public boolean contentEquals(Object obj, 
boolean withCreated, 
boolean noLinked) {
 
  805     if (getClass() != obj.getClass()) {
 
  810       if (this.created != other.
created && (
this.created == null || !
this.created.equals(other.
created))) {
 
  814     if ((this.authorIdStr == null) ? (other.authorIdStr != null) : !this.authorIdStr.equals(other.
authorIdStr)) {
 
  817     if ((this.authorName == null) ? (other.authorName != null) : !this.authorName.equals(other.
authorName)) {
 
  820     if ((this.authorAddress == null) ? (other.authorAddress != null) : !this.authorAddress.equals(other.
authorAddress)) {
 
  823     if ((this.source == null) ? (other.source != null) : !this.source.equals(other.
source)) {
 
  826     if ((this.content == null) ? (other.content != null) : !this.content.equals(other.
content)) {
 
  829     if (this.annotType != other.
annotType && (
this.annotType == null || !
this.annotType.equals(other.
annotType))) {
 
  832     if (this.sourceDocument != other.
sourceDocument && (
this.sourceDocument == null || !
this.sourceDocument.equals(other.
sourceDocument))) {
 
  835     if (this.tmpId != other.
tmpId && (
this.tmpId == null || !
this.tmpId.equals(other.
tmpId))) {
 
  839     if (this.attributes == null && other.
attributes != null) {
 
  841     } 
else if (this.attributes != null && other.
attributes == null) {
 
  843     } 
else if (this.attributes != other.
attributes && 
this.attributes != null && other.
attributes != null) {
 
  844       if (this.attributes.size() != other.attributes.size()) {
 
  847       Iterator<BaseAttribute> atIt = this.attributes.iterator();
 
  848       while (atIt.hasNext()) {
 
  850         boolean found = 
false;
 
  851         Iterator<BaseAttribute> oAtIt = other.attributes.iterator();
 
  855         while (oAtIt.hasNext()) {
 
  858           if(at instanceof LinkedAnnotationAttribute && oAt instanceof LinkedAnnotationAttribute){
 
  875     if (this.fragments == null && other.
fragments != null) {
 
  877     } 
else if (this.fragments != null && other.
fragments == null) {
 
  879     } 
else if (this.fragments != other.
fragments && 
this.fragments != null && other.
fragments != null) {
 
  880       if (this.fragments.size() != other.fragments.size()) {
 
  883       Iterator<Fragment> frIt = this.fragments.iterator();
 
  884       while (frIt.hasNext()) {
 
  886         boolean found = 
false;
 
  887         Iterator<Fragment> oFrIt = other.fragments.iterator();
 
  888         while (oFrIt.hasNext()) {
 
  900     if (this.user != other.
user && (
this.user == null || !
this.user.equals(other.
user))) {
 
  903     if (this.nestedInAnnot == null && other.
nestedInAnnot != null) {
 
  905     } 
else if (this.nestedInAnnot != null && other.
nestedInAnnot == null) {
 
  913     return "cz.vutbr.fit.knot.annotations.entity.Annotation[id=" + 
id + 
",content=" + content + 
"]";
 
  924     return toSXMLString(addSpaces, 
false);
 
  936     StringBuilder sb = 
new StringBuilder();
 
  938     ArrayList<Fragment> linearized = 
new ArrayList<Fragment>();
 
  940     if (fragments != null && !fragments.isEmpty()) {  
 
  943       ArrayList<ArrayList<Fragment>> tmpList = 
new ArrayList<ArrayList<Fragment>>();
 
  944       ArrayList<ArrayList<Fragment>> failed = 
new ArrayList<ArrayList<Fragment>>();
 
  945       tmpList.add(
new ArrayList<Fragment>(fragments));
 
  950         doc = mProvider.getDocumentFromString(sourceDocument.getContent(), 
true, 
true);
 
  951       } 
catch (Exception ex) {
 
  952         String msg = 
"Error while parsing the annotated document.";
 
  953         Logger.getLogger(Annotation.class.getName()).log(Level.SEVERE, msg, ex);
 
  956       linearized = Linearizer.fragmentsToLinFragments(tmpList, doc, failed, addSpaces);
 
  958       if (!failed.isEmpty()) {
 
  959         ArrayList<Fragment> failedList = failed.get(0);
 
  960         if (!failedList.isEmpty()) {
 
  961           String msg = 
"Error during linearization of fragments.";
 
  962           Logger.getLogger(Annotation.class.getName()).log(Level.SEVERE, msg);
 
  967     if (!linearized.isEmpty()) {
 
  968       Fragment fragment = linearized.get(0);
 
  969       if (fragment != null) {
 
  970         sb.append(
"<text s_offset=\"").append(fragment.
getOffset()).append(
"\" ");
 
  971         sb.append(
"e_offset=\"").append((fragment.
getOffset() + fragment.getLength())).append(
"\" ");
 
  974         String msg = 
"Error during linearization of fragments.";
 
  975         Logger.getLogger(Annotation.class.getName()).log(Level.SEVERE, msg);
 
  976         linearized = 
new ArrayList<Fragment>();
 
  980     String createdStr = 
"";
 
  982       createdStr = 
" created=\"" + Util.toRFC3339Date(created) + 
"\"";
 
  985     sb.append(
"<annotation type=\"").append(annotType.getName()).append(
"\" id=\"").append(getURI()).append(
"\"").append(createdStr).append(
">");
 
  989     if (attributes != null) {
 
  990       Iterator<BaseAttribute> attIt = attributes.iterator();
 
  992       while (attIt.hasNext()) {
 
  994         sb.append(tmpAtt.toSXMLString());
 
  999     sb.append(
"</annotation>");
 
 1001     if (!linearized.isEmpty()) {
 
 1002       sb.append(
"</text>");
 
 1005     return sb.toString();
 
 1016   public String 
toXMLStringV2(ArrayList<String> attFilter, 
int langNum, Boolean KBRefMode){
 
 1017     if (attFilter == null) {
 
 1018       attFilter = 
new ArrayList<String>();
 
 1021     if (KBRefMode == null) {
 
 1024     StringBuilder result = 
new StringBuilder();
 
 1025     String annotUri = getURIV2();
 
 1028     result.append(
"<oa:Annotation rdf:about=\"");
 
 1029     result.append(annotUri);
 
 1030     result.append(
"\">");
 
 1033     result.append(
"<oa:hasBody>");
 
 1034     result.append(
"<oa:SemanticTag rdf:about=\"");
 
 1035     result.append(annotType.getUri());
 
 1036     result.append(
"\"/>");
 
 1037     result.append(
"</oa:hasBody>");
 
 1040     if(fragments == null || fragments.isEmpty()){
 
 1042       result.append(
"<oa:hasTarget>");
 
 1044       result.append(
"<dctypes:Text rdf:about=\"");
 
 1045       result.append(source);
 
 1046       result.append(
"\">");
 
 1047       result.append(
"<dc:format>text/xml</dc:format>");
 
 1048       result.append(
"</dctypes:Text>");
 
 1050       result.append(
"</oa:hasTarget>");
 
 1051     } 
else if (fragments.size() == 1) {
 
 1053       result.append(
"<oa:hasTarget>");
 
 1054       result.append(((
Fragment) fragments.get(0)).toXMLStringV2());
 
 1055       result.append(
"</oa:hasTarget>");
 
 1056     } 
else if (fragments.size() > 1) {
 
 1058       result.append(
"<oa:hasTarget>");
 
 1059       result.append(
"<oa:Composite rdf:about=\"");
 
 1061       result.append(source);
 
 1062       result.append(getFragmentXpointersV2());
 
 1063       result.append(
"\">");
 
 1065       Iterator<Fragment> fragIt = fragments.iterator();
 
 1066       while(fragIt.hasNext()){
 
 1068         result.append(
"<oa:item>");
 
 1069         result.append(tmpFrag.toXMLStringV2());
 
 1070         result.append(
"</oa:item>");
 
 1073       result.append(
"</oa:Composite>");
 
 1074       result.append(
"</oa:hasTarget>");
 
 1078     result.append(
"<oa:hasBody>");
 
 1080     result.append(
"<cnt:ContentAsText rdf:about=\"");
 
 1081     result.append(annotUri);
 
 1082     result.append(
"#body\">");
 
 1084     result.append(
"<rdf:type rdf:resource=\"http://purl.org/dc/dcmitype/Text\"/>");
 
 1085     result.append(
"<cnt:chars><![CDATA[");
 
 1086     result.append(content);
 
 1087     result.append(
"]]></cnt:chars><dc:format>text/plain</dc:format>");
 
 1088     result.append(
"</cnt:ContentAsText>");
 
 1089     result.append(
"</oa:hasBody>");
 
 1093     result.append(
"<oa:hasBody>");
 
 1095     result.append(
"<cnt:ContentAsText rdf:about=\"");
 
 1096     result.append(source);
 
 1097     result.append(
"\">");
 
 1099     result.append(
"<rdf:type rdf:resource=\"http://www.w3.org/2004/03/trix/rdfg-1/Graph\"/>");
 
 1101     result.append(
"<trix:TriX>");
 
 1102     result.append(
"<trix:graph>");
 
 1106         && canBeDisplayedInKBRefMode()) {
 
 1108       result.append(attributesToKBRefString(attFilter, langNum));
 
 1110       Collections.sort(attributes);
 
 1111       Iterator<BaseAttribute> attribIt = attributes.iterator();
 
 1112       while (attribIt.hasNext()) {
 
 1115           tmpAttrib = AttributeManager.changeAttributeInstance(tmpAttrib);
 
 1117         String aName = tmpAttrib.getName();
 
 1118         if (attFilter.contains(aName)) {
 
 1121         result.append(tmpAttrib.toXMLStringV2());
 
 1125     result.append(
"</trix:graph>");
 
 1126     result.append(
"</trix:TriX>");
 
 1128     result.append(
"<dc:format>text/xml</dc:format>");
 
 1129     result.append(
"</cnt:ContentAsText>");
 
 1130     result.append(
"</oa:hasBody>");
 
 1133     result.append(
"<oa:annotatedBy>");
 
 1135     result.append(
"<foaf:Person rdf:about=\"");
 
 1136     result.append(user.getURIV2());
 
 1137     result.append(
"\">");
 
 1139     result.append(
"<foaf:mbox>mailto:");
 
 1140     result.append(authorAddress);
 
 1141     result.append(
"</foaf:mbox>");
 
 1143     result.append(
"<foaf:name>");
 
 1144     result.append(authorName);
 
 1145     result.append(
"</foaf:name>");
 
 1147     result.append(
"</foaf:Person>");
 
 1148     result.append(
"</oa:annotatedBy>");
 
 1152     SimpleDateFormat df = 
new SimpleDateFormat(
"yyyy-MM-dd'T'hh:mm:ssZ");
 
 1153     String date = df.format(created);
 
 1155     result.append(
"<oa:annotatedAt>");
 
 1156     result.append(date);
 
 1157     result.append(
"</oa:annotatedAt>");
 
 1159     result.append(
"<oa:serializedAt>");
 
 1160     result.append(date);
 
 1161     result.append(
"</oa:serializedAt>");
 
 1164     result.append(
"</oa:Annotation>");
 
 1167     Iterator<BaseAttribute> attrNestedIt = attributes.iterator();
 
 1168     while (attrNestedIt.hasNext()) {
 
 1170       String aName = tmpAttrib.getName();
 
 1171       if (attFilter.contains(aName)) {
 
 1175         result.append(tmpAttrib.getNestedAnnotation().toXMLStringV2(attFilter, langNum, KBRefMode));
 
 1179     return result.toString();
 
 1190     Iterator<BaseAttribute> attrIt = attributes.iterator();
 
 1191     boolean isUpdatableAnnot = 
false;
 
 1192     while(attrIt.hasNext()){
 
 1198         isUpdatableAnnot = tmpAttrib.getBoolValue();
 
 1201     return isUpdatableAnnot;
 
 1212     StringBuilder result = 
new StringBuilder();
 
 1213     StringBuilder tmpResult = 
new StringBuilder();
 
 1214     Iterator<BaseAttribute> attribIt = attributes.iterator();
 
 1216     kRefAt.setSimpleType(
"Entity");
 
 1217     kRefAt.setEntityAdditionalAttributes(
new ArrayList<EntityAdditionalAttribute>());
 
 1218     kRefAt.setRefAnnotation(
this);
 
 1220     kRefAt.setEntityType(this.getAnnotType().getName());
 
 1221     Boolean nameSet = 
false;
 
 1222     Boolean uriSet = 
false;  
 
 1223     Boolean vrSet = 
false;
 
 1224     Boolean desSet = 
false;
 
 1225     while (attribIt.hasNext()) {
 
 1227       Boolean processed = 
false;  
 
 1229         tmpAttrib = AttributeManager.changeAttributeInstance(tmpAttrib);
 
 1233           kRefAt.setEntityName(tmpAttrib.getStringValue());
 
 1242               kRefAt.setDescription(kRefAt.getDescription() + tmpAttrib.
getTextValue());
 
 1244               kRefAt.setDescription(tmpAttrib.getTextValue());
 
 1252               kRefAt.setDescription(kRefAt.getDescription() + tmpAttrib.
getStringValue());
 
 1254               kRefAt.setDescription(tmpAttrib.getStringValue());
 
 1260         if (tmpAttrib.
getUri() != null && !uriSet) {
 
 1261           kRefAt.setUri(tmpAttrib.getUri());
 
 1266         if (tmpAttrib.
getUri() != null) {
 
 1267           kRefAt.setEntityVisualURI(tmpAttrib.getUri());
 
 1273         String aName = tmpAttrib.getName();
 
 1274         if (attFilter.contains(aName)) {
 
 1278           tmpResult.append(tmpAttrib.toXMLStringV2());
 
 1282             adAt.setRefEntityAttribute(kRefAt);
 
 1283             kRefAt.getEntityAdditionalAttributes().add(adAt);
 
 1285             tmpResult.append(tmpAttrib.toXMLStringV2());
 
 1290     if (nameSet && desSet && uriSet) {  
 
 1291       result.append(kRefAt.toXMLStringV2());
 
 1292       result.append(tmpResult);
 
 1294       attribIt = attributes.iterator();
 
 1295       while (attribIt.hasNext()) {
 
 1298           tmpAttrib = AttributeManager.changeAttributeInstance(tmpAttrib);
 
 1300         String aName = tmpAttrib.getName();
 
 1301         if (attFilter.contains(aName)) {
 
 1304         result.append(tmpAttrib.toXMLStringV2());
 
 1316     String xpointers = 
"";
 
 1318     Iterator<Fragment> fragIt = fragments.iterator();
 
 1319     while(fragIt.hasNext()){
 
 1320       xpointers += 
"#" + fragIt.next().getXpointerV2();
 
 1333     return toXMLString(
true, 
"", proto11, 
false);
 
 1345   public String 
toXMLString(
boolean annotTag, String annotTagAttrs, 
boolean proto11, 
boolean tmpIdForNested) {
 
 1346     String authorAttr = 
"";
 
 1347     if (authorName != null) {
 
 1348       authorAttr = authorAttr + 
" name=\"" + authorName + 
"\"";
 
 1350     if (authorAddress != null) {
 
 1351       authorAttr = authorAttr + 
" address=\"" + authorAddress + 
"\"";
 
 1353     String aboutStr = 
"";
 
 1355       aboutStr = AppBean.getBaseAnnotUri() + 
id;
 
 1357     String tIdForD = 
"";
 
 1358     if (tmpIdForNested  && nestedInAnnot != null) {
 
 1359       tIdForD = 
" tmpId=\"" + tmpId + 
"\"";
 
 1362       return "<annotation" + annotTagAttrs + 
">" 
 1363         + 
"<rdf:Description" + tIdForD + 
" rdf:about=\"" + aboutStr + 
"\">" 
 1364           + 
"<rdf:type rdf:resource=\"" + annotType.getUri() + 
"\"/>" 
 1366           + 
"<a:author id=\"" + authorIdStr + 
"\"" + authorAttr + 
"/>" 
 1367           + 
"<a:source rdf:resource=\"" + source + 
"\"/>" 
 1368           + fragmentsToXMLString()
 
 1374           + attributesToXMLString(proto11, tmpIdForNested)
 
 1375         + 
"</rdf:Description>" 
 1378     return "<rdf:Description" + tIdForD + 
" rdf:about=\"" + aboutStr + 
"\">" 
 1379         + 
"<rdf:type rdf:resource=\"" + annotType.getUri() + 
"\"/>" 
 1381         + 
"<a:author id=\"" + authorIdStr + 
"\"" + authorAttr + 
"/>" 
 1382         + 
"<a:source rdf:resource=\"" + source + 
"\"/>" 
 1383         + fragmentsToXMLString()
 
 1389         + attributesToXMLString(proto11, tmpIdForNested)
 
 1390       + 
"</rdf:Description>";
 
 1399     String fragmentsString = 
"";
 
 1400     Iterator<Fragment> fragIt = fragments.iterator();
 
 1402     while (fragIt.hasNext()) {
 
 1404       fragmentsString += fr.toXMLString();
 
 1406     return fragmentsString;
 
 1417     String attrString = 
"";
 
 1418     Collections.sort(attributes);
 
 1419     Iterator<BaseAttribute> attrIt = attributes.iterator();
 
 1421     while (attrIt.hasNext()) {
 
 1422       attr = attrIt.next();
 
 1423       attrString += attr.toXMLString(proto11, tmpIdForNested, 
false);
 
 1436     String result = source;
 
 1438     if (result != null) {
 
 1439       result = result.replace(
"\\", 
"\\\\");
 
 1440       result = result.replace(
"\"", 
"\\\"");
 
 1454     String retJson = 
"{\"startOffset\":";
 
 1455     StringBuilder sb = 
new StringBuilder(retJson);
 
 1458     sb.append(
",\"endOffset\":");
 
 1460     sb.append(
",\"uri\":\"");
 
 1462     sb.append(this.getURI());
 
 1464     sb.append(
"\",\"annotTypePath\":\"");
 
 1465     if (this.getAnnotType() != null) {
 
 1466       String typeUri = this.getAnnotType().getUri();
 
 1468       String strippedServer = typeUri.replace(AppBean.getBaseTypeUri(), 
"");
 
 1469       String strippedGroup = strippedServer.replaceFirst(
"g[0-9]+\\/", 
"");
 
 1470       sb.append(strippedGroup);
 
 1472     sb.append(
"\",\"typeUriInOntology\":\"");
 
 1473     if (this.getAnnotType() != null) {
 
 1474       sb.append(this.getAnnotType().getUriInOntology());
 
 1477     sb.append(
"\",\"authorGroups\":[");
 
 1478     for (Iterator<UserGroup> ug = this.user.groups.iterator(); ug.hasNext();) {
 
 1480       sb.append(
"{\"uri\":\"");
 
 1482       sb.append(nextUG.getUri());
 
 1484       sb.append(
"\",\"name\":\"");
 
 1485       sb.append(nextUG.getName());
 
 1488     sb.deleteCharAt(sb.length()-1);
 
 1489     sb.append(
"],\"annotTypeGroup\":\"");
 
 1490     if (this.getAnnotType() != null && this.getAnnotType().getGroup() != null) {
 
 1491         sb.append(this.getAnnotType().getGroup().getUri());
 
 1493     sb.append(
"\",\"sourceUri\":\"");
 
 1495     sb.append(this.sourceDocument.getUri());
 
 1496     sb.append(
"\",\"content\":\"");
 
 1498     sb.append(EscapeCharsToSend(this.content));
 
 1499     sb.append(
"\",\"annoText\":\"");
 
 1501     for (Iterator<Fragment> frIt = this.fragments.iterator(); frIt.hasNext();) {
 
 1502       sb.append(EscapeCharsToSend(frIt.next().getAnnotatedText()));
 
 1504     sb.append(
"\",\"attributes\":[");
 
 1505     if (this.attributes != null && !this.attributes.isEmpty()) {
 
 1507       for (Iterator<BaseAttribute> atIt = this.attributes.iterator(); atIt.hasNext();) {
 
 1509         sb.append(att.toJSONString());
 
 1513           att.getNestedAnnotation().setNestedIn(this.
id.toString());
 
 1516       sb.deleteCharAt(sb.length()-1);
 
 1518     sb.append(
"],\"nestedIn\":\"");
 
 1519     if (this.getNestedInAnnot() != null) {
 
 1520       sb.append(this.getNestedInAnnot().getURI());
 
 1526     return sb.toString();
 
 1530     StringBuilder retStr = 
new StringBuilder();
 
 1531     retStr.append(
"<annotation tempUri=\"");
 
 1532     retStr.append(AppBean.getBaseAnnotUri());
 
 1533     retStr.append(
"temp/");
 
 1534     retStr.append(tmpId);
 
 1535     retStr.append(
"\" servUri=\"");
 
 1536     retStr.append(AppBean.getBaseAnnotUri());
 
 1537     retStr.append(
"serv/");
 
 1538     retStr.append(id.toString());
 
 1539     retStr.append(
"/>");
 
 1540     return retStr.toString();
 
 1566       return this.linkedByBeforeRemove;
 
 1576     if (this.linkedByBeforeRemove == null) {
 
 1577       this.linkedByBeforeRemove = 
new ArrayList<Integer>();
 
 1580     if (!this.linkedByBeforeRemove.contains(
id)) {
 
 1581       this.linkedByBeforeRemove.add(id);
 
 1590     this.linkedByBeforeRemove.clear();
 
 1599     if(this.linkedByBeforeRemove == null){
 
 1600       this.linkedByBeforeRemove = 
new ArrayList<Integer>();
 
 1602     this.linkedByBeforeRemove.addAll(IDs);
 
AnnotDocument getSourceDocument()
 
List< Fragment > fragments
 
List< Integer > getLinkedByBeforeRemove()
 
void addAllLinkedByBeforeRemove(List< Integer > IDs)
 
String fragmentsToXMLString()
 
void setSourceDocumentId(Integer sourceDocumentId)
 
Utility functions for document linearization. 
 
Annotation getNestedAnnotation()
 
StringBuilder attributesToKBRefString(ArrayList< String > attFilter, int langNum)
 
boolean contentEquals(Object obj)
 
Class representing attribute of type String.. 
 
static final ArrayList< String > FORBIDDEN_ENTITY_TYPES
 
boolean contentEquals(Object obj)
 
List< BaseAttribute > attributes
 
void clearLinkedByBeforeRemove()
 
static final int KB_ENTITY_URI
 
Additional attribute of entity in annotation attribute. 
 
Class representing annotated copy of document. 
 
void setNestedInAnnot(Annotation nestedInAnnot)
 
Singleton for storing global variables. 
 
String getAuthorAddress()
 
AnnotDocument sourceDocument
 
static String escapeForXml(String str)
 
Class providing access to available matchers. 
 
Class representing attribute of type Text. 
 
Annotation(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, Annotation nestedInAnnot)
 
String toXMLStringV2(ArrayList< String > attFilter, int langNum, Boolean KBRefMode)
 
void setContent(String content)
 
Class representing vocabulary entity attribute. 
 
Class representing attribute of type AnnotationLink. 
 
void setNestedIn(String nestedIn)
 
Class representing attribute of suggestion. 
 
static final int KB_DISAMBIGUATION
 
Class representing suggested annotation fragment. 
 
void setCreated(Date created)
 
String toXMLString(boolean annotTag, String annotTagAttrs, boolean proto11, boolean tmpIdForNested)
 
String getAnnotatedText()
 
List< Fragment > getFragments()
 
ArrayList< Fragment > getFragmentsAL()
 
Class representing user group. 
 
void setAttributes(ArrayList< BaseAttribute > attributes)
 
static boolean hasAttributeRightInstance(BaseAttribute attr)
 
void setSourceDocument(AnnotDocument sourceDocument)
 
Annotation(Integer id, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content, String nestedIn)
 
void setAnnotType(AnnotType annotType)
 
static final String UPDATABLE_AN_AT_NAME
 
void setType(Integer type)
 
void updateWithSuggestion(Suggestion newData)
 
boolean equals(Object object, boolean noLinked)
 
void setAuthorAddress(String authorAddress)
 
String attributesToXMLString(boolean proto11, boolean tmpIdForNested)
 
boolean contentEquals(Object obj)
 
static final String KB_REF_ATT_NAME
 
List< SuggestionFragment > getFragments()
 
void addFragment(Fragment fragment)
 
void setTmpId(String tmpId)
 
String EscapeCharsToSend(String source)
 
Base class representing attribute of annotation. 
 
boolean equals(Object object)
 
Class representing type of annotation. 
 
static final int KB_DESCRIPTION
 
String getFragmentXpointersV2()
 
void setAuthorIdStr(String authorIdStr)
 
Integer getSourceDocumentId()
 
Annotation(AnnotType annotType, Date created, String authorIdStr, String authorName, String authorAddress, AnnotDocument sourceDocument, String content)
 
List< SugBaseAttribute > getAttributes()
 
void setSource(String source)
 
void setAuthorName(String authorName)
 
String toSXMLString(boolean addSpaces, boolean addCreated)
 
void addAttribute(BaseAttribute attribute)
 
void addLinkedByBeforeRemove(Integer id)
 
Class attribute manager provides a way how to create new attributes. 
 
Class representing suggestion of annotation. 
 
String toSXMLString(boolean addSpaces)
 
Annotation getNestedInAnnot()
 
boolean contentEquals(Object obj, boolean withCreated, boolean noLinked)
 
void updateWithAnnotation(Annotation newData)
 
Class responsible for localised strings. 
 
String toXMLString(boolean proto11)
 
boolean canBeDisplayedInKBRefMode()
 
static final int KB_VISUAL_REPRESENTATION
 
void setFragments(ArrayList< Fragment > fragments)
 
Utility class (manipulates RFC 3339 dates) 
 
Class representing annotated fragment. 
 
static final int KB_ARTWORK_NAME
 
List< BaseAttribute > getAttributes()
 
Class representing annotation. 
 
String toJsonString(Integer sOffset, Integer eOffset)
 
void setAuthorId(String authorId)
 
static String toRFC3339Date(Date date)
 
abstract Object getValue()