Package org.purl.sword.base

Examples of org.purl.sword.base.SwordValidationInfo


                  attributes.add(createValidAttributeInfo(ATTRIBUTE_SRC, source));
               }
            }
            else
            {
               SwordValidationInfo info = new SwordValidationInfo(xmlName,
                       new XmlName(attribute),
                       SwordValidationInfo.UNKNOWN_ATTRIBUTE,
                       SwordValidationInfoType.INFO );
                info.setContentDescription(attribute.getValue());
                attributes.add(info);
            }
         }

         // check if there is any content. If there is, add a simple message to
         // say that there are sub elements that are not used in this profile
         if( content.getChildCount() > 0 )
         {
            elements.add(new SwordValidationInfo(xmlName,
                    "This element has child elements. These are not expected as part of the SWORD profile",
                    SwordValidationInfoType.INFO));
         }

      }
      catch( Exception ex )
      {
         log.error("Unable to parse an element in Content: " + ex.getMessage());
         throw new UnmarshallException("Error parsing Content", ex);
      }

      SwordValidationInfo result = null;
      if( validationProperties != null )
      {
          result = validate(elements, attributes, validationProperties);
      }
      return result;
View Full Code Here


    */
   protected SwordValidationInfo validate(List<SwordValidationInfo> elements,
           List<SwordValidationInfo> attributes,
           Properties validationContext)
   {
       SwordValidationInfo info = new SwordValidationInfo(xmlName);

       if( source == null )
       {
           XmlName attributeName = new XmlName(xmlName.getPrefix(),
                       ATTRIBUTE_SRC,
                       xmlName.getNamespace());

          SwordValidationInfo item = new SwordValidationInfo(xmlName, attributeName,
                  SwordValidationInfo.MISSING_ATTRIBUTE_WARNING,
                  SwordValidationInfoType.ERROR);
          info.addValidationInfo(item);
       }

View Full Code Here

            email = new Email();
            validationItems.add(email.unmarshall(element, validationProperties));
         }
         else if( validationProperties != null )
         {
            SwordValidationInfo info = new SwordValidationInfo(new XmlName(element),
                    SwordValidationInfo.UNKNOWN_ELEMENT,
                    SwordValidationInfoType.INFO);
            info.setContentDescription(element.getValue());
            validationItems.add(info);
         }

      } // for

      SwordValidationInfo result = null;
      if( validationProperties != null )
      {
          result = validate(validationItems, attributeItems, validationProperties);
      }
      return result;
View Full Code Here

   public SwordValidationInfo validate(List<SwordValidationInfo> elements,
           List<SwordValidationInfo> attributes,
           Properties validationContext)
   {
       SwordValidationInfo result = new SwordValidationInfo(xmlName);

       if( name == null )
       {
           SwordValidationInfo info = new SwordValidationInfo(Name.elementName(),
                   SwordValidationInfo.MISSING_ELEMENT_ERROR,
                   SwordValidationInfoType.ERROR);
           result.addValidationInfo(info);
       }
       else if( elements == null && name != null)
View Full Code Here

             type = ContentType.XHTML;
           }
           else
           {
             log.error("Unable to parse extract type in " + getQualifiedName() );
                       SwordValidationInfo info = new SwordValidationInfo(xmlName,
                                  new XmlName(attribute),
                                  "Invalid content type has been specified",
                                  SwordValidationInfoType.ERROR);
                       info.setContentDescription(value);
                       attributeItems.add(info);
                       success = false;
           }

                   if( success )
                   {
                       SwordValidationInfo info = new SwordValidationInfo(xmlName, new XmlName(attribute));
                       info.setContentDescription(type.toString());
                       attributeItems.add(info);
                   }
         }
               else
               {
                   SwordValidationInfo info = new SwordValidationInfo(xmlName,
                              new XmlName(attribute),
                              SwordValidationInfo.UNKNOWN_ATTRIBUTE,
                              SwordValidationInfoType.INFO);
                   info.setContentDescription(attribute.getValue());
                   attributeItems.add(info);
               }
       }

       // retrieve all of the sub-elements
       int length = text.getChildCount();
       if( length > 0 )
       {
         content = unmarshallString(text);
           }

     }
     catch( Exception ex )
     {
       log.error("Unable to parse an element in " + getQualifiedName() + ": " + ex.getMessage());
       throw new UnmarshallException("Unable to parse an element in " + getQualifiedName(), ex);
     }

       SwordValidationInfo result = null;
       if( validationProperties != null )
       {
           result = validate(validationItems, attributeItems, validationProperties);
       }
       return result;
View Full Code Here

           List<SwordValidationInfo> attributeItems,
           Properties validationContext)
   {
      boolean validateAll = (existing == null);

      SwordValidationInfo result = new SwordValidationInfo(xmlName);
      result.setContentDescription(content);
     
      // item specific rules
      if( content == null )
      {
          result.addValidationInfo(
                  new SwordValidationInfo(xmlName, "Missing content for element",
                                          SwordValidationInfoType.WARNING));
      }

      if( validateAll )
      {
          SwordValidationInfo info = new SwordValidationInfo(xmlName,
                  new XmlName(xmlName.getPrefix(), ATTRIBUTE_TYPE, xmlName.getNamespace()));
          info.setContentDescription(type.toString());
          result.addAttributeValidationInfo(info);

      }

      result.addUnmarshallValidationInfo(existing, attributeItems);
View Full Code Here

               generator = new Generator();
               generator.unmarshall(element);
            }
            else
            {
               SwordValidationInfo info = new SwordValidationInfo(new XmlName(element),
                       SwordValidationInfo.UNKNOWN_ELEMENT,
                       SwordValidationInfoType.INFO);
               info.setContentDescription(element.getValue());
               validationItems.add(info);
            }
         }
      }
      catch( Exception ex )
      {
         log.error("Unable to parse an element in Source: " + ex.getMessage());
         throw new UnmarshallException("Unable to parse an element in Source", ex);
      }

      SwordValidationInfo result = null;
      if( validationProperties != null )
      {
          result = validate(validationItems, attributeItems, validationProperties);
      }
      return result;
View Full Code Here

      {
         return handleIncorrectElement(entry, validationProperties);
      }

      // used to hold the element and attribute unmarshal info results
      SwordValidationInfo result = new SwordValidationInfo(xmlName);

      try
      {
         initialise();

         // FIXME - attributes?

         // retrieve all of the sub-elements
         Elements elements = entry.getChildElements();
         Element element = null;
         int length = elements.size();

         for (int i = 0; i < length; i++)
         {
            element = elements.get(i);

            if (isInstanceOf(element, Author.elementName()))
            {
               Author author = new Author();
               result.addUnmarshallElementInfo(author.unmarshall(element, validationProperties));
               authors.add(author);
            }
            else if (isInstanceOf(element, Category.elementName()))
            {
               Category category = new Category();
               result.addUnmarshallElementInfo(category.unmarshall(element, validationProperties));
               categories.add(category);
            }
            else if (isInstanceOf(element, Content.elementName()))
            {
               if( content == null )
               {
                  content = new Content();
                  result.addUnmarshallElementInfo(content.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                   SwordValidationInfo info = new SwordValidationInfo(Content.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }

            }
            else if (isInstanceOf(element, Generator.elementName()))
            {
               if( generator == null )
               {
                  generator = new Generator();
                  result.addUnmarshallElementInfo(generator.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Generator.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Contributor.elementName()))
            {
               Contributor contributor = new Contributor();
               result.addUnmarshallElementInfo(contributor.unmarshall(element, validationProperties));
               contributors.add(contributor);
            }
            else if (isInstanceOf(element, Id.elementName()))
            {
               if( id == null )
               {
                 id = new Id();
                 result.addUnmarshallElementInfo(id.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Id.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }

            }
            else if (isInstanceOf(element, Link.elementName()))
            {
               Link link = new Link();
               result.addUnmarshallElementInfo(link.unmarshall(element, validationProperties));
               links.add(link);
            }
            else if (isInstanceOf(element, Published.elementName()))
            {
               if( published == null )
               {
                  published = new Published();
                  result.addUnmarshallElementInfo(published.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Published.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Rights.elementName()))
            {
               if( rights == null )
               {
                  rights = new Rights();
                  result.addUnmarshallElementInfo(rights.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Rights.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Summary.elementName()))
            {
               if( summary == null )
               {
                  summary = new Summary();
                  result.addUnmarshallElementInfo(summary.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Summary.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Title.elementName()))
            {
               if( title == null )
               {
                  title = new Title();
                  result.addUnmarshallElementInfo(title.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Title.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Updated.elementName()))
            {
               if( updated == null )
               {
                  updated = new Updated();
                  result.addUnmarshallElementInfo(updated.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Updated.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if (isInstanceOf(element, Source.elementName()))
            {
               if( source == null )
               {
                  source = new Source();
                  result.addUnmarshallElementInfo(source.unmarshall(element, validationProperties));
               }
               else if( validationProperties != null )
               {
                  SwordValidationInfo info = new SwordValidationInfo(Source.elementName(),
                          SwordValidationInfo.DUPLICATE_ELEMENT,
                          SwordValidationInfoType.WARNING);
                  info.setContentDescription(element.getValue());
                  result.addUnmarshallElementInfo(info);
               }
            }
            else if( validationProperties != null )
            {
                XmlName name = new XmlName(element);
                if( ! isElementChecked(name) )
                {
                   SwordValidationInfo info = new SwordValidationInfo(name,
                          SwordValidationInfo.UNKNOWN_ELEMENT,
                          SwordValidationInfoType.INFO);
                   info.setContentDescription(element.getValue());
                   result.addUnmarshallElementInfo(info);
                }
            }

         } // for
View Full Code Here

   public SwordValidationInfo unmarshall(Element entry, Properties validationProperties)
   throws UnmarshallException
   {

      SwordValidationInfo result = unmarshallWithoutValidate(entry, validationProperties);
      if( validationProperties != null )
      {
          result = validate(result, validationProperties);
      }
      return result;
View Full Code Here

            Properties validationContext)
   {
       // determine if a full validation is required
       boolean validateAll = (info == null);

       SwordValidationInfo result = info;
       if( result == null )
       {
          result = new SwordValidationInfo(xmlName);
       }
      
       // id, title an updated are required
       if( id == null )
       {
          result.addValidationInfo(new SwordValidationInfo(Id.elementName(),
                  SwordValidationInfo.MISSING_ELEMENT_ERROR,
                  SwordValidationInfoType.ERROR));
       }
       else if( id != null && validateAll )
       {
           result.addValidationInfo(id.validate(validationContext));
       }

       if( title == null )
       {
          result.addValidationInfo(new SwordValidationInfo(Title.elementName(),
                  SwordValidationInfo.MISSING_ELEMENT_ERROR,
                  SwordValidationInfoType.ERROR));
       }
       else if( title != null && validateAll )
       {
           result.addValidationInfo(title.validate(validationContext));
       }

       if( updated == null )
       {
          result.addValidationInfo(new SwordValidationInfo(Updated.elementName(),
                  SwordValidationInfo.MISSING_ELEMENT_ERROR,
                  SwordValidationInfoType.ERROR));
       }
       else if( updated != null && validateAll )
       {
           result.addValidationInfo(updated.validate(validationContext));
       }

       // additional sword requirements on the element
       if( contributors.isEmpty() )
       {
          String contributor = validationContext.getProperty(HttpHeaders.X_ON_BEHALF_OF);
          if( contributor != null )
          {
             result.addValidationInfo(new SwordValidationInfo(Contributor.elementName(),
                  SwordValidationInfo.MISSING_ELEMENT_ERROR +
                    " This item SHOULD contain the value of the X-On-Behalf-Of header, if one was present in the POST request.",
                  SwordValidationInfoType.ERROR));
          }
       }
       else if( (! contributors.isEmpty()) && validateAll )
       {
           Iterator<Contributor> iterator = contributors.iterator();
           while( iterator.hasNext() )
           {
              Contributor contributor = iterator.next();
              result.addValidationInfo(contributor.validate(validationContext));
           }
       }

       if( generator == null )
       {
           result.addValidationInfo(new SwordValidationInfo(Generator.elementName(),
                   SwordValidationInfo.MISSING_ELEMENT_ERROR +
                    " SHOULD contain the URI and version of the server software.",
                   SwordValidationInfoType.ERROR));
       }
       else if( generator != null && validateAll )
       {
           result.addValidationInfo(generator.validate(validationContext));
       }

       if( validateAll )
       {
           // process the remaining items
           Iterator<Link> linksIterator = links.iterator();
           while( linksIterator.hasNext() )
           {
              Link link = linksIterator.next();
              result.addValidationInfo(link.validate(validationContext));
           }

           Iterator<Author> authorIterator = authors.iterator();
           while( authorIterator.hasNext() )
           {
              Author author = authorIterator.next();
              result.addValidationInfo(author.validate(validationContext));
           }

           if( content != null )
           {
               result.addValidationInfo(content.validate(validationContext));
           }

           if( published != null )
           {
               result.addValidationInfo(published.validate(validationContext));
           }

           if( rights != null )
           {
               result.addValidationInfo(rights.validate(validationContext));
           }

           if( summary != null )
           {
               result.addValidationInfo(summary.validate(validationContext));
           }

           Iterator<Category> categoryIterator = categories.iterator();
           while( categoryIterator.hasNext() )
           {
              Category category = categoryIterator.next();
              result.addValidationInfo(category.validate(validationContext));
           }
          
       }

       return result;
View Full Code Here

TOP

Related Classes of org.purl.sword.base.SwordValidationInfo

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.