14 package cz.vutbr.fit.knot.annotations.comet.protocolV2_0;
 
   22 import cz.vutbr.fit.knot.annotations.comet.protocolV2_0.P2Trix.*;
 
   31 import java.util.logging.Level;
 
   32 import java.util.logging.Logger;
 
   33 import javax.xml.bind.DatatypeConverter;
 
   34 import org.w3c.dom.Element;
 
   35 import org.w3c.dom.Node;
 
   36 import org.w3c.dom.NodeList;
 
   56     newAnnotation.setFragments(
new ArrayList<Fragment>());
 
   57     newAnnotation.setContent(
"");
 
   60     String annotUri = annotationEl.getAttribute(
"rdf:about");
 
   61     if(annotUri == null || annotUri.isEmpty()){
 
   63       int langNum = requestInfo.getSession().getLanguageNum();
 
   64       int lod = requestInfo.getSession().getProtocolLOD();
 
   65       String info = 
"<annotation uri=\"\" invalidProperty=\"uri\"/>";
 
   68         String msg = 
"Annotation is without uri.";
 
   69         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
   76     if (annotUriPrefix.equals(
"serv")) {
 
   78       String idString = annotUri.replace(AppBean.getBaseUri() + 
"/serv/", 
"");
 
   80         id = Integer.decode(idString);
 
   81       } 
catch (NumberFormatException ex) {
 
   83         int langNum = requestInfo.getSession().getLanguageNum();
 
   84         int lod = requestInfo.getSession().getProtocolLOD();
 
   85         String info = 
"<annotation uri=\"" + annotUri + 
"\"/>";
 
   88           String msg = 
"Can't decode annotation id. Id: " + idString;
 
   89           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
   94       newAnnotation.setId(id);
 
   95     } 
else if (annotUriPrefix.equals(
"temp")) {
 
   96       String idString = annotUri.replace(AppBean.getBaseUri() + 
"/temp/", 
"");
 
   97       newAnnotation.setTmpId(idString);
 
   98     } 
else if (annotUriPrefix.equals(
"sugg")) {
 
   99       String idString = annotUri.replace(AppBean.getBaseUri() + 
"/sugg/", 
"");
 
  100       newAnnotation.setTmpId(idString);
 
  103       int langNum = requestInfo.getSession().getLanguageNum();
 
  104       int lod = requestInfo.getSession().getProtocolLOD();
 
  105       String info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"uri\"/>";
 
  108         String msg = 
"Bad annotation uri prefix. Prefix: " + annotUriPrefix;
 
  109         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  115     NodeList anotatedByMsg = annotationEl.getElementsByTagName(
"oa:annotatedBy");
 
  116     Element anotatedByEl = (Element) anotatedByMsg.item(0);
 
  117     if(anotatedByEl != null) {
 
  124       newAnnotation.setUser(author);
 
  128     NodeList annotatedAtMsg = annotationEl.getElementsByTagName(
"oa:annotatedAt");
 
  129     Element annotatedAtEl = (Element) annotatedAtMsg.item(0);
 
  130     if(annotatedAtEl != null) {
 
  133       if(creationDate == null){
 
  138       newAnnotation.setCreated(creationDate);
 
  149     NodeList serializedAtMsg = annotationEl.getElementsByTagName(
"oa:serializedAt");
 
  150     Element serializedAtEl = (Element) serializedAtMsg.item(0);
 
  151     if(serializedAtEl != null){
 
  156     NodeList bodiesOfAnnot = annotationEl.getElementsByTagName(
"oa:hasBody");
 
  157     if(bodiesOfAnnot != null){
 
  165     NodeList targetMsg = annotationEl.getElementsByTagName(
"oa:hasTarget");
 
  166     Element targetEl = (Element) targetMsg.item(0);
 
  167     if(targetEl != null) {
 
  174     return newAnnotation;
 
  188     NodeList fragCompositeMsg = targetEl.getElementsByTagName(
"oa:Composite");
 
  189     Element fragCompositeEl = (Element) fragCompositeMsg.item(0);
 
  190     if(fragCompositeEl != null) {
 
  192       ArrayList<Fragment> fragments = 
processSRComposite(fragCompositeEl,annot,requestInfo);
 
  193       if(fragments != null && !fragments.isEmpty()){
 
  194         annot.setFragments(fragments);
 
  200         annot.setSourceDocument(doc);
 
  208     NodeList specificResourceMsg = targetEl.getElementsByTagName(
"oa:SpecificResource");
 
  209     Element specificResourceEl = (Element) specificResourceMsg.item(0);
 
  210     if (specificResourceEl != null) {
 
  214         ArrayList<Fragment> newFragments = 
new ArrayList<Fragment>();
 
  215         newFragments.add(frag);
 
  216         annot.setFragments(newFragments);
 
  222         annot.setSourceDocument(doc);
 
  230     NodeList wholeDocMsg = targetEl.getElementsByTagName(
"dctypes:Text");
 
  231     Element wholeDocEl = (Element) wholeDocMsg.item(0);
 
  232     if(wholeDocEl != null) {
 
  235       String documentUri = wholeDocEl.getAttribute(
"rdf:about");
 
  236       if(documentUri == null || documentUri.isEmpty()){
 
  238         int langNum = requestInfo.getSession().getLanguageNum();
 
  239         int lod = requestInfo.getSession().getProtocolLOD();
 
  240         String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  243           String msg = 
"Unable to find document uri (rdf:about).";
 
  244           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  250       NodeList formatMsg = targetEl.getElementsByTagName(
"dc:format");
 
  251       if(formatMsg.item(0) == null){
 
  253         int langNum = requestInfo.getSession().getLanguageNum();
 
  254         int lod = requestInfo.getSession().getProtocolLOD();
 
  255         String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  258           String msg = 
"Element format in target is missing.";
 
  259           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  265       AnnotDocument syncDocument = requestInfo.getSession().getSyncDocument();
 
  267       if (syncDocument.
getUri() != null && syncDocument.getUri().equals(documentUri)) {
 
  276       annot.setSourceDocument(doc);
 
  292     ArrayList<Fragment> fragments = 
new ArrayList<Fragment>();
 
  294     NodeList itemsMsg = compositeEl.getElementsByTagName(
"oa:item");
 
  295     int size = itemsMsg.getLength();
 
  297       for (
int index = 0; index < size; index++) {
 
  298         Element documentEl = (Element) itemsMsg.item(index);
 
  301         NodeList specificResourceMsg = documentEl.getElementsByTagName(
"oa:SpecificResource");
 
  302         Element specificResourceEl = (Element) specificResourceMsg.item(0);
 
  303         if (specificResourceEl != null) {
 
  313       int langNum = requestInfo.getSession().getLanguageNum();
 
  314       int lod = requestInfo.getSession().getProtocolLOD();
 
  315       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\"/>";
 
  318         String msg = 
"Cant find any item in composite of fragments.";
 
  319         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  337     NodeList dctypesMsg = hasSourceEl.getElementsByTagName(
"dctypes:Text");
 
  338     Element dctypesEl = (Element) dctypesMsg.item(0);
 
  339     if (dctypesEl == null) {
 
  341       int langNum = requestInfo.getSession().getLanguageNum();
 
  342       int lod = requestInfo.getSession().getProtocolLOD();
 
  343       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  346         String msg = 
"Element dctypes:Text is missing.";
 
  347         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  351       String documentUri = dctypesEl.getAttribute(
"rdf:about");
 
  352       if(documentUri == null || documentUri.isEmpty()){
 
  354         int langNum = requestInfo.getSession().getLanguageNum();
 
  355         int lod = requestInfo.getSession().getProtocolLOD();
 
  356         String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  359           String msg = 
"Unable to find document uri.";
 
  360           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  366       NodeList formatMsg = hasSourceEl.getElementsByTagName(
"dc:format");
 
  367       if(formatMsg.item(0) == null){
 
  369         int langNum = requestInfo.getSession().getLanguageNum();
 
  370         int lod = requestInfo.getSession().getProtocolLOD();
 
  371         String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  374           String msg = 
"Element format in target - source is missing.";
 
  375           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  380       AnnotDocument syncDoc = requestInfo.getSession().getSyncDocument();
 
  381       if (syncDoc.
getUri() != null && syncDoc.getUri().equals(documentUri)) {
 
  398     NodeList formatMsg = specificResourceEl.getElementsByTagName(
"oa:hasSelector");
 
  399     if(formatMsg.item(0) == null){
 
  401       int langNum = requestInfo.getSession().getLanguageNum();
 
  402       int lod = requestInfo.getSession().getProtocolLOD();
 
  403       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  406         String msg = 
"Element oa:hasSelector in target is missing.";
 
  407         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  414     NodeList documentMsg = specificResourceEl.getElementsByTagName(
"oa:FragmentSelector");
 
  415     Element documentEl = (Element) documentMsg.item(0);
 
  416     newFragment.setRefAnnotation(annot);
 
  417     newFragment.setIsGood(
true);
 
  418     if (documentEl == null) {
 
  420       int langNum = requestInfo.getSession().getLanguageNum();
 
  421       int lod = requestInfo.getSession().getProtocolLOD();
 
  422       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  425         String msg = 
"Element dcterms:conformsTo is missing.";
 
  426         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  431       NodeList xpointerMsg = documentEl.getElementsByTagName(
"rdf:value");
 
  432       Element xpointerEl = (Element) xpointerMsg.item(0);
 
  433       if(xpointerEl != null) {
 
  434         String xpointer = MessageProcessor.getElementContent(xpointerEl);
 
  435         if(xpointer == null || xpointer.isEmpty()){
 
  437           int langNum = requestInfo.getSession().getLanguageNum();
 
  438           int lod = requestInfo.getSession().getProtocolLOD();
 
  439           String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  442             String msg = 
"Cannot find xpointer value.";
 
  443             Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  450           int langNum = requestInfo.getSession().getLanguageNum();
 
  451           int lod = requestInfo.getSession().getProtocolLOD();
 
  452           String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  455             String msg = 
"Cannot process xpointer.";
 
  456             Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  478     int xpathEndIndex = xpointer.indexOf(
',');
 
  479     String xpath = xpointer.substring(0,xpathEndIndex);
 
  480     xpath = xpath.replace(
"xpointer(string-range(", 
"");
 
  481     xpath = UpdatableFragment.improveXPath(xpath);
 
  484     int textStartIndex = xpointer.indexOf(
'\'');
 
  485     int textEndIndex = xpointer.lastIndexOf(
'\'');
 
  486     String text = xpointer.substring(textStartIndex+1, textEndIndex);
 
  489     String partsList[] = xpointer.substring(textEndIndex).split(
",");
 
  495       offset = Integer.decode(partsList[1].trim());
 
  496       length = Integer.decode(partsList[2].replaceAll(
"\\)", 
"").trim());
 
  497     } 
catch (NumberFormatException ex) {
 
  499       int langNum = requestInfo.getSession().getLanguageNum();
 
  500       int lod = requestInfo.getSession().getProtocolLOD();
 
  501       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\"/>";
 
  504         String msg = 
"Unable to decode offset or length value.";
 
  505         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  510     fragment.setLength(length);
 
  511     fragment.setOffset(offset);
 
  512     fragment.setAnnotatedText(text);
 
  513     fragment.setPath(xpath);
 
  527     int bodiesCount = bodiesOfAnnot.getLength();
 
  529     if(bodiesCount == 0){
 
  531       int langNum = requestInfo.getSession().getLanguageNum();
 
  532       int lod = requestInfo.getSession().getProtocolLOD();
 
  533       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"body\"/>";
 
  536         String msg = 
"rdf:about is not presented in body.";
 
  537         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  543     for(
int index = 0; index < bodiesCount; index++){
 
  544       Element bodyEl = (Element) bodiesOfAnnot.item(index);
 
  548         NodeList annotTypeMsg = bodyEl.getElementsByTagName(
"oa:SemanticTag");
 
  549         Element annotTypeEl = (Element) annotTypeMsg.item(0);
 
  550         if(annotTypeEl != null) {
 
  559         NodeList textContentMsg = bodyEl.getElementsByTagName(
"cnt:ContentAsText");
 
  560         if(textContentMsg != null && textContentMsg.getLength() > 0){
 
  582     int contentsCount = contentsOfAnnot.getLength();
 
  584     for(
int index = 0; index < contentsCount; index++){
 
  585       Element contentEl = (Element) contentsOfAnnot.item(index);
 
  587       if(contentEl != null) {
 
  589         String typeUriAttr = contentEl.getAttribute(
"rdf:about");
 
  590         if(typeUriAttr == null || typeUriAttr.isEmpty()){
 
  592           int langNum = requestInfo.getSession().getLanguageNum();
 
  593           int lod = requestInfo.getSession().getProtocolLOD();
 
  594           String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"body\"/>";
 
  597             String msg = 
"rdf:about is not presented in body.";
 
  598             Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  634     NodeList formatMsg = bodyEl.getElementsByTagName(
"dc:format");
 
  635     if(formatMsg.item(0) == null){
 
  637       int langNum = requestInfo.getSession().getLanguageNum();
 
  638       int lod = requestInfo.getSession().getProtocolLOD();
 
  639       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"content\"/>";
 
  642         String msg = 
"Element format is missing.";
 
  643         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  648     NodeList contentTypeMsg = bodyEl.getElementsByTagName(
"rdf:type");
 
  649     Element contentTypeEl = (Element) contentTypeMsg.item(0);
 
  650     if (contentTypeEl != null) {
 
  652       NodeList charsMsg = bodyEl.getElementsByTagName(
"cnt:chars");
 
  653       Element charsEl = (Element) charsMsg.item(0);
 
  654       if (charsEl != null) {
 
  655         String bodyContent = MessageProcessor.getElementContent(charsEl);
 
  656         if (bodyContent == null) {
 
  659         annot.setContent(bodyContent);
 
  663         int langNum = requestInfo.getSession().getLanguageNum();
 
  664         int lod = requestInfo.getSession().getProtocolLOD();
 
  665         String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"content\"/>";
 
  668           String msg = 
"Element chars is missing.";
 
  669           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  675       int langNum = requestInfo.getSession().getLanguageNum();
 
  676       int lod = requestInfo.getSession().getProtocolLOD();
 
  677       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"content\"/>";
 
  680         String msg = 
"Element content type is missing.";
 
  681         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  697     NodeList personMsg = anotatedByEl.getElementsByTagName(
"foaf:Person");
 
  698     Element personEl = (Element) personMsg.item(0);
 
  699     if(personEl != null) {
 
  701       String authorUriAttr = personEl.getAttribute(
"rdf:about");
 
  702       if(authorUriAttr == null || authorUriAttr.isEmpty()){
 
  704         int langNum = requestInfo.getSession().getLanguageNum();
 
  705         int lod = requestInfo.getSession().getProtocolLOD();
 
  706         String info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"author\"/>";
 
  709           String msg = 
"Uri of author is not presented.";
 
  710           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  719         authorId = Integer.decode(authorUriAttr.replace(AppBean.getBaseUserUriV2(), 
""));
 
  720       } 
catch(NumberFormatException e){
 
  722         int langNum = requestInfo.getSession().getLanguageNum();
 
  723         int lod = requestInfo.getSession().getProtocolLOD();
 
  724         String info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"author\"/>";
 
  727           String msg = 
"Unable to decode author's id.";
 
  728           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  734       PersistM persistMan = AppBean.getPersistenceManager();
 
  735       Object[] authorParams = 
new Object[2];
 
  736       authorParams[0] = 
"id";
 
  737       authorParams[1] = authorId;
 
  738       @SuppressWarnings(
"unchecked")
 
  739       List<User> usersList = persistMan.queryDB(
"User.findById", authorParams);
 
  740       if(usersList == null || usersList.isEmpty()){
 
  742         int langNum = requestInfo.getSession().getLanguageNum();
 
  743         int lod = requestInfo.getSession().getProtocolLOD();
 
  744         String info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"author\"/>";
 
  747           String msg = 
"Unable to find author of annotation: " + authorId;
 
  748           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  753       return usersList.get(0);
 
  756       int langNum = requestInfo.getSession().getLanguageNum();
 
  757       int lod = requestInfo.getSession().getProtocolLOD();
 
  758       String info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"author\"/>";
 
  761         String msg = 
"Missing foaf:Person element.";
 
  762         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  779     String creationDateValue = MessageProcessor.getElementContent(annotatedAtEl);
 
  780     if(creationDateValue == null || creationDateValue.isEmpty()){
 
  782       int langNum = requestInfo.getSession().getLanguageNum();
 
  783       int lod = requestInfo.getSession().getProtocolLOD();
 
  786         info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"annotatedAt\"/>";
 
  787         msg = 
"Bad date and time format in annotatedAt.";
 
  790         info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"serializedAt\"/>";
 
  791         msg = 
"Bad date and time format in serializedAt.";
 
  795         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  804       dateOfCreation = DatatypeConverter.parseDateTime(creationDateValue).getTime();
 
  805     }
catch(IllegalArgumentException ex){
 
  807       int langNum = requestInfo.getSession().getLanguageNum();
 
  808       int lod = requestInfo.getSession().getProtocolLOD();
 
  811         info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"annotatedAt\"/>";
 
  812         msg = 
"Bad date and time format in annotatedAt.";
 
  815         info = 
"<annotation uri=\"" + annotUri + 
"\" invalidProperty=\"serializedAt\"/>";
 
  816         msg = 
"Bad date and time format in serializedAt.";
 
  820         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  825     return dateOfCreation;
 
  838     String typeUriAttr = annotTypeEl.getAttribute(
"rdf:about");
 
  839     if(typeUriAttr == null || typeUriAttr.isEmpty()){
 
  841       int langNum = requestInfo.getSession().getLanguageNum();
 
  842       int lod = requestInfo.getSession().getProtocolLOD();
 
  843       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"type\"/>";
 
  846         String msg = 
"Uri of annotation type is not presented.";
 
  847         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  854     PersistM persistMan = AppBean.getPersistenceManager();
 
  855     Object[] typeParams = 
new Object[2];
 
  856     typeParams[0] = 
"uri";
 
  857     typeParams[1] = typeUriAttr;
 
  858     @SuppressWarnings(
"unchecked")
 
  859     List<AnnotType> usersList = persistMan.queryDB(
"AnnotType.findByUri", typeParams);
 
  860     if(usersList == null || usersList.isEmpty()){
 
  861       if(requestInfo.
getFlier().getAddedTypes() != null && !requestInfo.
getFlier().getAddedTypes().isEmpty()){
 
  863           Iterator<AnnotType> typesIt = requestInfo.getFlier().getAddedTypes().iterator();
 
  864           while(typesIt.hasNext()){
 
  866             if(typeUriAttr.equals(currentType.
getUri())){
 
  867                 annot.setAnnotType(currentType);
 
  873         int langNum = requestInfo.getSession().getLanguageNum();
 
  874         int lod = requestInfo.getSession().getProtocolLOD();
 
  875         String info = 
"<annotation uri=\"" + typeUriAttr + 
"\"/>";
 
  878           String msg = 
"Unknown annotation type. Type uri: " + typeUriAttr;
 
  879           Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  885     annot.setAnnotType(usersList.get(0));
 
  902       documentId = Integer.decode(uri.replace(AppBean.getBaseDocumentUri(), 
""));
 
  903     } 
catch (NumberFormatException ex) {
 
  905       int langNum = requestInfo.getSession().getLanguageNum();
 
  906       int lod = requestInfo.getSession().getProtocolLOD();
 
  907       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"target\"/>";
 
  910         String msg = 
"Id of document is bad.";
 
  911         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  917     PersistM persistMan = AppBean.getPersistenceManager();
 
  919     Object[] params = 
new Object[2];
 
  921     params[1] = documentId;
 
  922     @SuppressWarnings(
"unchecked")
 
  923     List<AnnotDocument> documentsList = persistMan.queryDB(
"AnnotDocument.findById", params);
 
  924     if (documentsList != null && !documentsList.isEmpty()) {
 
  925       document = documentsList.get(0);
 
  928       int langNum = requestInfo.getSession().getLanguageNum();
 
  929       int lod = requestInfo.getSession().getProtocolLOD();
 
  932         String msg = 
"Unable to find document with uri " + uri;
 
  933         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
  948     if(uri.contains(
"#body")){
 
  962     String parts[] = uri.split(
"/");
 
  963     if(parts.length > 3){
 
  964       return parts[parts.length-2];
 
  976     HashMap<String, P2BaseTrix> trixMap = 
new HashMap<String, P2BaseTrix>();
 
  979     HashMap<String, ArrayList<String>> links = 
new HashMap<String, ArrayList<String>>();
 
  982     HashMap<String, String> nestedAnnots = 
new HashMap<String, String>();
 
  985     HashMap<String, String> priorityMap = 
new HashMap<String, String>();
 
  988     HashMap<String, String> entityDic = 
new HashMap<String, String>();
 
  990     HashMap<String, ArrayList<P2EntityAdditionalTrix>> eadtAL = 
new  HashMap<String, ArrayList<P2EntityAdditionalTrix>>();
 
  994     boolean first = 
false, second = 
false, third = 
false;
 
  995     int trixCount = trixList.getLength();
 
  997     String destinationUri = null;
 
  998     String uriInOntology = null;
 
 1000     boolean fromOntology = 
false;
 
 1003     for(
int i = 0; i < trixCount; i++){
 
 1004       Node trixNode = trixList.item(i);
 
 1009       fromOntology = 
false;
 
 1011       uriInOntology = null;
 
 1013       for(Node node = trixNode.getFirstChild(); node != null; node = node.getNextSibling()) {
 
 1014         if(!(node instanceof Element)){
 
 1018         Element element = (Element) node;
 
 1022           if(!element.getTagName().equals(
"trix:uri")){
 
 1023             int langNum = requestInfo.getSession().getLanguageNum();
 
 1024             int lod = requestInfo.getSession().getProtocolLOD();
 
 1026             String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"trix\"";
 
 1030                 Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.SEVERE, info);
 
 1035           destinationUri = MessageProcessor.getElementContent(element);
 
 1039           name = MessageProcessor.getElementContent(element);      
 
 1040           if(!element.getTagName().equals(
"trix:uri") && !element.getTagName().equals(
"trix:name")){
 
 1041             int langNum = requestInfo.getSession().getLanguageNum();
 
 1042             int lod = requestInfo.getSession().getProtocolLOD();
 
 1044             String info = 
"<attribute annotationUri=\"" + destinationUri + 
"\" name=\"\" invalidProperty=\"designation\"/>";
 
 1048                 Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.SEVERE, info);
 
 1053           if(element.getTagName().equals(
"trix:uri")){
 
 1054             fromOntology = 
true;
 
 1055             uriInOntology = name;
 
 1057             name = name.substring(name.lastIndexOf(
"#")+1);
 
 1070           if(element.getTagName().equals(
"trix:uri")){
 
 1071             String thirdValue = MessageProcessor.getElementContent(element);
 
 1075             if(thirdValue.endsWith(
"#anyEntity") || thirdValue.endsWith(
"#anyAnnotation")){
 
 1080               att.setFromOntology(fromOntology);
 
 1081               att.setUriInOntology(uriInOntology);
 
 1083             else if(thirdValue.equals(
"koae:linkedAnnotation")){
 
 1089               att = trixMap.get(name);
 
 1096                 att.setFromOntology(fromOntology);
 
 1097                 att.setUriInOntology(uriInOntology);
 
 1100             else if(thirdValue.equals(
"koae:nestedAnnotation")){
 
 1101               att = trixMap.get(name);
 
 1108                 att.setFromOntology(fromOntology);
 
 1109                 att.setUriInOntology(uriInOntology);
 
 1114               att = trixMap.get(name);
 
 1119                 att.setFromOntology(fromOntology);
 
 1120                 att.setUriInOntology(uriInOntology);
 
 1123               att.setAnnotType(thirdValue);
 
 1125             else if(thirdValue.contains(
"serv")
 
 1126                             || thirdValue.contains(
"sugg")
 
 1127                             || thirdValue.contains(
"temp")){
 
 1131                 att = trixMap.get(name);
 
 1135                     ((P2NestedTrix)att).addNestedAnnotUri(thirdValue);
 
 1138                     ((P2LinkedTrix)att).addLinkedAnnotUri(thirdValue);
 
 1142                     ArrayList<String> tmpL = links.get(name);
 
 1144                       tmpL = 
new ArrayList<String>();
 
 1146                     tmpL.add(thirdValue);
 
 1147                     links.put(name, tmpL);
 
 1149                     first = 
false; second = 
false; 
 
 1155                   ArrayList<String> tmpL = links.get(name);
 
 1157                     tmpL = 
new ArrayList<String>();
 
 1159                   tmpL.add(thirdValue);
 
 1160                   links.put(name, tmpL);
 
 1162                   first = 
false; second = 
false; 
 
 1174                 if(!name.equals(
"koae:nestedIn")){
 
 1175                   int langNum = requestInfo.getSession().getLanguageNum();
 
 1176                   int lod = requestInfo.getSession().getProtocolLOD();
 
 1178                   String info = 
"<attribute annotationUri=\"" + thirdValue + 
"\" name=\"\" invalidProperty=\"nestedIn\"/>";
 
 1182                     Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.SEVERE, info);
 
 1186                 nestedAnnots.put(destinationUri, thirdValue);
 
 1187                 first = 
false; second = 
false; 
 
 1197               if(trixMap.get(name) != null){
 
 1198                 int langNum = requestInfo.getSession().getLanguageNum();
 
 1199                 int lod = requestInfo.getSession().getProtocolLOD();
 
 1201                 String info = 
"<attribute annotationUri=\"" + destinationUri + 
"\" name=\"" + name + 
"\" invalidProperty=\"nesting\"/>";
 
 1205                   Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.SEVERE, info);
 
 1218             trixMap.put(name, att);
 
 1222           else if(element.getTagName().equals(
"trix:name")){
 
 1223             entityDic.put(destinationUri, MessageProcessor.getElementContent(element));
 
 1225           else if(element.getTagName().equals(
"trix:typedLiteral")){
 
 1227             String dataType = element.getAttribute(
"datatype");
 
 1238               adt.setEntityUri(destinationUri);
 
 1239               adt.setEntityAttributeName(name);
 
 1240               adt.setTypeUri(dataType);
 
 1242               if(element.getFirstChild() != null && element.getFirstChild().getNodeValue() != null){
 
 1243                 adt.setValue(element.getFirstChild().getNodeValue());
 
 1246               ArrayList<P2EntityAdditionalTrix> al = eadtAL.get(destinationUri);
 
 1248                 al = 
new ArrayList<P2EntityAdditionalTrix>(); 
 
 1251               eadtAL.put(destinationUri, al);
 
 1254               if(dataType.endsWith(
"#attributePriority")){
 
 1255                 if(element.getFirstChild() != null && element.getFirstChild().getNodeValue() != null){
 
 1256                     priorityMap.put(name, element.getFirstChild().getNodeValue());
 
 1265                   att.setUriInOntology(uriInOntology);
 
 1266                   att.setTypeUri(dataType);
 
 1269                 if(dataType.endsWith(
"#Point")){
 
 1271                   trixMap.put(name, att);
 
 1274                   if(element.getFirstChild() != null && element.getFirstChild().getNodeValue() != null){
 
 1275                     att.addValue(element.getFirstChild().getNodeValue());
 
 1277                   trixMap.put(name, att);
 
 1283             int langNum = requestInfo.getSession().getLanguageNum();
 
 1284             int lod = requestInfo.getSession().getProtocolLOD();
 
 1286             String info = 
"<attribute annotationUri=\"" + destinationUri + 
"\" name=\"" + name + 
"\" invalidProperty=\"designation\"/>";
 
 1290                 Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.SEVERE, 
"Wrong tag name of third element in triple");
 
 1301     Iterator it = trixMap.values().iterator();
 
 1302     while(it.hasNext()){
 
 1306       if(priorityMap.get(t.
getName()) != null){
 
 1307         t.setPriority(priorityMap.get(t.getName()));
 
 1312         if(links.get(t.
getName()) != null){
 
 1313           ((P2LinkedTrix)t).addAllLinkedAnnotUris(links.get(t.getName()));
 
 1319         if(entityDic.get(((P2EntityTrix)t).getEntityUri()) != null){
 
 1320           ((P2EntityTrix)t).setEntityType(entityDic.get(((P2EntityTrix)t).getEntityUri()));
 
 1322         if(eadtAL.get(((P2EntityTrix)t).getEntityUri()) != null){
 
 1323           ((P2EntityTrix)t).setEntityAdditionalTrixAL(eadtAL.get(((P2EntityTrix)t).getEntityUri()));
 
 1328         if(links.get(t.
getName()) != null){
 
 1329           ((P2NestedTrix)t).addAllNestedAnnotUris(links.get(t.getName()));
 
 1334         if(((P2NestedTrix)t).getNestedAnnotUris() != null){
 
 1335           String ref = nestedAnnots.get(((P2NestedTrix)t).getNestedAnnotUris().
get(0));
 
 1336           ((P2NestedTrix)t).setRefAnnotUri(ref);
 
 1341     return new ArrayList<P2BaseTrix>(trixMap.values());
 
 1351     for(Node node = el.getFirstChild(); node != null; node = node.getNextSibling()) {
 
 1352       if(!(node instanceof Element)){
 
 1356       Element tmpEl = (Element) node;
 
 1357       if(tmpEl.getTagName().equals(
"geo:Point")){
 
 1358         for(Node innerNode = tmpEl.getFirstChild(); innerNode != null; innerNode = innerNode.getNextSibling()){
 
 1359           if(!(innerNode instanceof Element)){
 
 1362           if(((Element)innerNode).getTagName().equals(
"geo:lat")){
 
 1365           else if(((Element)innerNode).getTagName().equals(
"geo:long")){
 
 1384       for(Node n = node; n != null; n = n.getNextSibling()){
 
 1385           if(n.getNodeValue() != null){
 
 1386               return n.getNodeValue();
 
 1403     NodeList contentTypeMsg = attributesEl.getElementsByTagName(
"rdf:type");
 
 1404     if(contentTypeMsg.item(0) == null){
 
 1406       int langNum = requestInfo.getSession().getLanguageNum();
 
 1407       int lod = requestInfo.getSession().getProtocolLOD();
 
 1408       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"trix\"/>";
 
 1411         String msg = 
"Element content type is missing.";
 
 1412         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
 1417     NodeList trixMsg = attributesEl.getElementsByTagName(
"trix:TriX");
 
 1418     if(trixMsg.item(0) == null){
 
 1420       int langNum = requestInfo.getSession().getLanguageNum();
 
 1421       int lod = requestInfo.getSession().getProtocolLOD();
 
 1422       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"trix\"/>";
 
 1425         String msg = 
"Element Trix is missing.";
 
 1426         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
 1431     NodeList formatMsg = attributesEl.getElementsByTagName(
"dc:format");
 
 1432     if(formatMsg.item(0) == null){
 
 1434       int langNum = requestInfo.getSession().getLanguageNum();
 
 1435       int lod = requestInfo.getSession().getProtocolLOD();
 
 1436       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"trix\"/>";
 
 1439         String msg = 
"Element format is missing.";
 
 1440         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
 1446     NodeList trixGraphMsg = attributesEl.getElementsByTagName(
"trix:graph");
 
 1447     Element trixGraphEl = (Element) trixGraphMsg.item(0);
 
 1448     if(trixGraphEl != null){
 
 1451       NodeList triplesMsg = attributesEl.getElementsByTagName(
"trix:triple");
 
 1454       ArrayList<BaseAttribute> attributesList = 
new ArrayList<BaseAttribute>();
 
 1457       if(trixesList == null){
 
 1461       Iterator<P2BaseTrix> trixesIt = trixesList.iterator();
 
 1463       while(trixesIt.hasNext()){
 
 1464           ArrayList<BaseAttribute> tmpAttList = trixesIt.next().trixToAnnotAtt(annot, requestInfo, counter);
 
 1466           if(tmpAttList == null){
 
 1470           attributesList.addAll(tmpAttList);
 
 1474       annot.setAttributes(attributesList);
 
 1479       int langNum = requestInfo.getSession().getLanguageNum();
 
 1480       int lod = requestInfo.getSession().getProtocolLOD();
 
 1481       String info = 
"<annotation uri=\"" + annot.getURIV2() + 
"\" invalidProperty=\"trix\"/>";
 
 1484         String msg = 
"Element graph is missing.";
 
 1485         Logger.getLogger(P2AnnotBaseProcessor.class.getName()).log(Level.ALL, msg);
 
boolean processTarget(Element targetEl, Annotation annot, RequestInfo requestInfo)
Class that represents entity additional attribute trix triple. 
static final int LOG_LEVEL_ALL_ERRORS
Persistence manager (database manipulator) 
Class that represents entity trix triple. 
Class representing annotated copy of document. 
ArrayList< P2BaseTrix > processTrixElements(NodeList trixList, RequestInfo requestInfo, Annotation annot)
Singleton for storing global variables. 
static String getBaseTypeUri()
boolean processBody(Element bodyEl, Annotation annot, RequestInfo requestInfo)
boolean processXpointer(String xpointer, Fragment fragment, Annotation annot, RequestInfo requestInfo)
static final int ERROR_26_ATTRIBUTE_MALFORMED
Abstract class provides a parser for the annotation of protocol version 2. 
boolean processAnnotType(Element annotTypeEl, Annotation annot, RequestInfo requestInfo)
Static class which parses and process XML with messages. 
Annotation processAnnotation(Element annotationEl, RequestInfo requestInfo)
static final int ERROR_25_BAD_FRAGMENT
static final int ERROR_81_EMPTY_COMPOSITE
User processAuthor(Element anotatedByEl, String annotUri, RequestInfo requestInfo)
Base class representing attribute of annotation. 
Class for XML document fragment. 
Class that represents simple trix triple. 
static final int LOG_LEVEL
Class representing type of annotation. 
AnnotDocument processHasSource(Annotation annot, Element hasSourceEl, RequestInfo requestInfo)
static boolean isUriOfBody(String uri)
Class that represents linked trix triple. 
Fragment processSpecificResource(Element specificResourceEl, Annotation annot, RequestInfo requestInfo)
Date processCreationDate(Element annotatedAtEl, String annotUri, RequestInfo requestInfo, boolean created)
boolean processBodies(NodeList bodiesOfAnnot, Annotation annot, RequestInfo requestInfo)
static final int ERROR_38_ANNOT_MALFORMED
static final int ERROR_29_CHANGED_ANNOT_NOT_FOUND
Class that represents nested trix triple. 
Processed informations about client request. 
Class that represents base trix triple. 
static String getBaseDocumentUri()
void parseGeoPoint(P2SimpleTrix att, Element el)
boolean processAnnotContents(NodeList contentsOfAnnot, Annotation annot, RequestInfo requestInfo)
boolean processAttributesNew(Element attributesEl, Annotation annot, RequestInfo requestInfo)
Class responsible for localised strings. 
boolean isDocumentUri(String uri)
ArrayList< Fragment > processSRComposite(Element compositeEl, Annotation annot, RequestInfo requestInfo)
static final int ERROR_53_BAD_DOCUMENT_URI
Class representing annotated fragment. 
static final int ERROR_19_TYPE_UNKNOWN
Class representing annotation. 
static String getUriType(String uri)
String getGeoPointNodeValue(Node node)
AnnotDocument getDocumentFromUri(String uri, Annotation annot, RequestInfo requestInfo)