Examples of XMLSchemaValidationFilter


Examples of org.infoset.xml.xerces.XMLSchemaValidationFilter

      return createAdminDocumentDestination(end,names);
   }
   static ItemDestination createAdminDocumentDestination(ItemDestination end,final Name [] names)
      throws XMLException
   {
      final XMLSchemaValidationFilter validate = new XMLSchemaValidationFilter();
      URL adminXSD = AdminXML.class.getResource("admin.xsd");
      if (adminXSD==null) {
         throw new RuntimeException("Cannot find admin.xsd relative to class path.");
      }
      validate.addNamespaceMap(AdminXML.NAMESPACE,adminXSD);
      ItemFilter checkValidity = new ItemFilter() {
         ItemDestination output;
         int level = -1;
         public void send(Item item)
            throws XMLException
         {
            switch (item.getType()) {
               case DocumentItem:
                  level = -1;
                  break;
               case ElementItem:
                  level++;
                  break;
               case ElementEndItem:
                  level--;
                  ElementEnd end = (ElementEnd)item;
                  if (level<0) {
                     if (end.getValidity()!=Validity.VALID) {
                        StringBuilder builder = new StringBuilder();
                        Iterator errors = validate.getErrors();
                        while (errors.hasNext()) {
                           builder.append("\n");
                           builder.append(errors.next().toString());
                        }
                        throw new XMLException("Element "+end.getName()+" is not valid:"+builder.toString());
                     }
                     Name name = end.getName();
                     boolean found = false;
                     for (int i=0; !found && i<names.length; i++) {
                        if (names[i].equals(name)) {
                           found = true;
                        }
                     }
                     if (!found) {
                        throw new XMLException("Unexpected document element "+name);
                     }
                  }
                  break;
            }
            output.send(item);
         }
         public void attach(ItemDestination output) {
            this.output = output;
         }
      };
      validate.attach(checkValidity);
      checkValidity.attach(end);
      return validate;
   }
View Full Code Here

Examples of org.infoset.xml.xerces.XMLSchemaValidationFilter

   }
  
   protected ItemFilter createValidationFilter(ItemDestination end)
      throws XMLException
   {
      final XMLSchemaValidationFilter validate = new XMLSchemaValidationFilter();
      if (schemaMap!=null) {
         for (URI namespace : schemaMap.keySet()) {
            validate.addNamespaceMap(namespace,schemaMap.get(namespace));
         }
      }
      ItemFilter checkValidity = new ItemFilter() {
         ItemDestination output;
         int level = -1;
         public void send(Item item)
            throws XMLException
         {
            switch (item.getType()) {
               case DocumentItem:
                  level = -1;
                  break;
               case ElementItem:
                  level++;
                  break;
               case ElementEndItem:
                  level--;
                  ElementEnd end = (ElementEnd)item;
                  if (level<0) {
                     if (end.getValidity()!=Validity.VALID) {
                        StringBuilder builder = new StringBuilder();
                        Iterator errors = validate.getErrors();
                        while (errors.hasNext()) {
                           builder.append("\n");
                           builder.append(errors.next().toString());
                        }
                        throw new XMLException("Element "+end.getName()+" is not valid:"+builder.toString());
                     }
                     if (topLevelElements!=null) {
                        Name name = end.getName();
                        if (!topLevelElements.contains(name)) {
                           throw new XMLException("Unexpected document element "+name);
                        }
                     }
                  }
                  break;
            }
            output.send(item);
         }
         public void attach(ItemDestination output) {
            this.output = output;
         }
      };
      validate.attach(checkValidity);
      checkValidity.attach(end);
      return validate;
   }
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.