Package org.infoset.xml

Examples of org.infoset.xml.XMLException


      throws IOException,XMLException
   {
      Document doc = docLoader.load(location);
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(COMPONENT)) {
         throw new XMLException("Expecting "+COMPONENT+" but found "+top.getName());
      }
      String value = top.getAttributeValue("autoconf-check");
      if (value!=null) {
         autoconfCheck = Long.parseLong(value) * 1000;
      }
     
      Element keyStoreE = top.getFirstElementNamed(KEYSTORE);
      if (keyStoreE!=null) {
         URI fileRef = keyStoreE.getBaseURI().resolve(keyStoreE.getAttributeValue("file"));
         this.keyStorePath = new File(fileRef.getSchemeSpecificPart());
         this.keyStorePassword = keyStoreE.getAttributeValue("password");
      }
     
      Iterator<Element> appdefElements = top.getElementsByName(DEFINE);
      while (appdefElements.hasNext()) {
         Element appdefE = appdefElements.next();
         String name = appdefE.getAttributeValue("name");
         String className = appdefE.getAttributeValue("class");
        
         String ref = appdefE.getAttributeValue("ref");
         if (ref!=null) {
            ClassLoader theLoader = loaders.get(ref.trim());
            if (theLoader==null) {
               throw new XMLException("Cannot find definition: "+ref);
            }
            if (className==null || name==null) {
               continue;
            }
            try {
               Class cdef = theLoader.loadClass(className);
               definitions.put(name,cdef);
            } catch (ClassNotFoundException ex) {
               throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
            }
            continue;
         }
        
         if (name!=null) {
            List<URL> libraries = new ArrayList<URL>();
            Iterator<Element> libraryElements = appdefE.getElementsByName(LIBRARY);
            while (libraryElements.hasNext()) {
               Element libE = libraryElements.next();
               String href = libE.getAttributeValue("href");
               if (href!=null) {
                  URI u = libE.getBaseURI().resolve(href);
                  libraries.add(u.toURL());
               }
            }
            ClassLoader theLoader = this.getClass().getClassLoader();
            if (libraries.size()!=0) {
               URL [] list = new URL[libraries.size()];
               list = libraries.toArray(list);
               theLoader = new URLClassLoader(list,this.getClass().getClassLoader());
               LOG.fine("ClassLoader: "+name+" -> "+theLoader);
               LOG.fine("  Libraries: "+libraries);
               loaders.put(name, theLoader);
            }
            if (className!=null) {
               try {
                  Class cdef = theLoader.loadClass(className);
                  definitions.put(name,cdef);
               } catch (ClassNotFoundException ex) {
                  throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
               }
            }
         } else if (name!=null) {
            LOG.warning("The 'class' attribute is missing on the definition of '"+name+"'");
         }
View Full Code Here


   {
      DocumentLoader loader = new SAXDocumentLoader();
      Document doc = loader.load(location);
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(SERVER)) {
         throw new XMLException("Expecting "+SERVER+" but found "+top.getName());
      }
     
      Element keyStoreE = top.getFirstElementNamed(KEYSTORE);
      if (keyStoreE!=null) {
         URI fileRef = keyStoreE.getBaseURI().resolve(keyStoreE.getAttributeValue("href"));
View Full Code Here

         String summary = feedRep.getSummary();
         if (summary!=null) {
            text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting feed title.",ex);
      }
      text(constructor,dest,AtomResource.ID_NAME,feed.getUUID().toString());
      text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(feed.getEdited()));
      try {
         Iterator<TermInstance<Feed>> categorization = feed.getTerms();
         while (categorization.hasNext()) {
            TermInstance<Feed> category = categorization.next();
            term(constructor,dest,category.getTerm().getURI(),category.getValue());

         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting categorization.",ex);
        
      }
      try {
         List<Feed> ancestors = new ArrayList<Feed>();
         Feed parent = feed;
         do {
            parent = parent.getParent();
            if (parent!=null) {
               ancestors.add(parent);
            }
         } while (parent!=null);
         Collections.reverse(ancestors);
         for (Feed ancestor : ancestors) {
            org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(ancestor.getPath(), ancestor.getUUID())));
            dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
            text(constructor,dest,AtomResource.ID_NAME,ancestor.getUUID().toString());
            text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(ancestor.getCreated()));
            text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(ancestor.getEdited()));
            text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
            String summary = feedRep.getSummary();
            if (summary!=null) {
               text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
            }
            term(constructor,dest,Categorization.ANCESTOR_TERM,null);
            Iterator<TermInstance<Feed>> categorization = ancestor.getTerms();
            while (categorization.hasNext()) {
               TermInstance<Feed> category = categorization.next();
               term(constructor,dest,category.getTerm().getURI(),category.getValue());

            }
            link(constructor,dest,"related",resourceBase+ancestor.getPath());
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting ancestors.",ex);
      }
      try {
         Term hidden = feed.getDB().findTerm(Categorization.HIDDEN_TYPE_TERM);
         if (hidden==null) {
            hidden = feed.getDB().createTerm(Categorization.HIDDEN_TYPE_TERM);
         }
         Iterator<Feed> children = feed.getChildren();
         while (children.hasNext()) {
            Feed child = children.next();
            if (child.getTerm(hidden)!=null) {
               continue;
            }
            org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(child.getPath(), child.getUUID())));
            dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
            text(constructor,dest,AtomResource.ID_NAME,child.getUUID().toString());
            text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(child.getCreated()));
            text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(child.getEdited()));
            text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
            String summary = feedRep.getSummary();
            if (summary!=null) {
               text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
            }
            term(constructor,dest,Categorization.CHILD_TERM,null);
            Iterator<TermInstance<Feed>> categorization = child.getTerms();
            while (categorization.hasNext()) {
               TermInstance<Feed> category = categorization.next();
               term(constructor,dest,category.getTerm().getURI(),category.getValue());

            }
            link(constructor,dest,"related",feedRef.toString()+child.getName()+"/");
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
        
      } catch (Exception ex) {
         throw new XMLException("Exception while getting feed children.",ex);
      }
      dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

            dest.send(constructor.createCharacters(value.toString()));
         }

         dest.send(constructor.createElementEnd(AtomResource.CATEGORY_NAME));
      } catch (UnsupportedEncodingException ex) {
         throw new XMLException("Cannot decode term "+parts[1],ex);
      }
   }
View Full Code Here

               dest.send(constructor.createCharacters("\n"));
            }
            dest.send(constructor.createElementEnd(XML.GROUPS_NAME));
            dest.send(constructor.createCharacters("\n"));
         } catch (SQLException ex) {
            throw new XMLException("Database error while retrieving users and groups",ex);
         }
      }
      dest.send(constructor.createElementEnd(XML.REALM_NAME));
   }
View Full Code Here

   {
      DocumentLoader loader = new SAXDocumentLoader();
      Document doc = loader.load(location);
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(AdminXML.NM_SERVER)) {
         throw new XMLException("Expecting "+AdminXML.NM_SERVER+" but found "+top.getName());
      }
      String value = top.getAttributeValue("autoconf-check");
      if (value!=null) {
         autoconfCheck = Long.parseLong(value)*1000;
      }
     
      storageClassName = top.getAttributeValue("storage-class");
     
      value = top.getAttributeValue("logs");
      if (location.getScheme().equals("file")) {
         File locFile = new File(location.getSchemeSpecificPart());
         File test = new File(locFile,value==null ? "logs" : value);
         if (test.exists()) {
            logDir = test;
         } else {
            logDir = new File(value==null ? "logs" : value);
         }
      }
      value = top.getAttributeValue("temp.dir");
      if (location.getScheme().equals("file")) {
         File locFile = new File(location.getSchemeSpecificPart());
         tmpDir = value==null ? locFile.getParentFile() : new File(locFile,value);
      } else {
         tmpDir = new File(".");
      }
      Iterator<Element> autoconfElements = top.getElementsByName(AdminXML.NM_AUTOCONF);
      while (autoconfElements.hasNext()) {
         Element autoconfE = autoconfElements.next();
         String href = autoconfE.getAttributeValue("href");
         if (href!=null) {
            Link l = new Link("autoconf",MediaType.APPLICATION_ATOM_XML,autoconfE.getBaseURI().resolve(href));
            l.setIdentity(autoconfE.getAttributeValue("username"),autoconfE.getAttributeValue("password"));
            autoconfs.add(l);
         }
      }
      Iterator<Element> interfaceElements = top.getElementsByName(AdminXML.NM_INTERFACE);
      while (interfaceElements.hasNext()) {
         Element interfaceE = interfaceElements.next();
         String addr = interfaceE.getAttributeValue("address");
         String portS = interfaceE.getAttributeValue("port");
         boolean secure = interfaceE.getAttributeValue("secure")==null || "true".equals(interfaceE.getAttributeValue("secure"));
         int port = portS==null ? (secure ? 443 : 80) : Integer.parseInt(portS);
         interfaces.add(new Interface(addr,port,secure));
      }
     
      Iterator<Element> hostElements = top.getElementsByName(AdminXML.NM_HOST);
      while (hostElements.hasNext()) {
         Host host = createHost(hostElements.next());
         String key = host.getName();
         if (host.getPort()<0) {
            key = key+":*";
         } else {
            key = key+":"+host.getPort();
         }
         hosts.put(key,host);
      }
      Iterator<Element> adminElements = top.getElementsByName(AdminXML.NM_ADMIN);
      while (adminElements.hasNext()) {
         AdminHost host = createAdminHost(adminElements.next());
         admins.put(host.getName(),host);
      }

      Iterator<Element> resourceElements = top.getElementsByName(AdminXML.NM_RESOURCE);
      while (resourceElements.hasNext()) {
         Element spec = resourceElements.next();
         String type = spec.getAttributeValue("type");
         if (type==null || type.equals("database")) {
            ResourceHost host = createResourceHost(spec);
            resources.put(host.getName(),host);
         } else {
            throw new XMLException("Unrecognized resource host type "+type);
         }
      }

      Iterator<Element> databaseElements = top.getElementsByName(AdminXML.NM_DATABASE);
      while (databaseElements.hasNext()) {
         Element databaseE = databaseElements.next();
         String dbName = databaseE.getAttributeValue("name");
         String auth = databaseE.getAttributeValue("auth");
         String group = databaseE.getAttributeValue("group");
         String alias = databaseE.getAttributeValue("alias");
         Database database = new Database(dbName,auth,group,alias);
         databases.put(dbName,database);
      }
      Iterator<Element> authElements = top.getElementsByName(AdminXML.NM_AUTH);
      while (authElements.hasNext()) {
         Element authE = authElements.next();
         try {
            Auth auth = createAuth(authE);
            authServices.put(auth.getName(),auth);
         } catch (ClassNotFoundException ex) {
            throw new XMLException("Cannot load class "+authE.getAttributeValue("class")+" for auth service "+authE.getAttributeValue("name"),ex);
         }
      }
      Element keystoreE = top.getFirstElementNamed(AdminXML.NM_KEYSTORE);
      String href = keystoreE.getAttributeValue("href");
      URI keystoreRef = keystoreE.getBaseURI().resolve(href);
View Full Code Here

                     password = e.getAttributeValue("md5-password");
                  } else {
                     try {
                        password = User.md5Password(password);
                     } catch (NoSuchAlgorithmException ex) {
                        throw new XMLException("Cannot MD5 password.",ex);
                     }
                  }
                  if (password==null) {
                     LOG.warning("Missing 'md5-password' or 'password' attribute on user.");
                     return;
View Full Code Here

                        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);
View Full Code Here

            String md5 = getEncryptedPassword();
            if (md5!=null) {
               user.setAttributeValue("password-md5",md5);
            }
         } catch (SQLException ex) {
            throw new XMLException("Cannot get password from database for user "+uuid,ex);
         }
      }
      dest.send(user);
      if (name!=null) {
         dest.send(constructor.createElement(XML.NAME_NAME));
         dest.send(constructor.createCharacters(name));
         dest.send(constructor.createElementEnd(XML.NAME_NAME));
      }
      if (email!=null) {
         dest.send(constructor.createElement(XML.EMAIL_NAME));
         dest.send(constructor.createCharacters(email));
         dest.send(constructor.createElementEnd(XML.EMAIL_NAME));
      }
      if (showRoles) {
         try {
            dest.send(constructor.createElement(XML.ROLES_NAME));
            Iterator<Role> roles = getRoles();
            boolean first = true;
            while (roles.hasNext()) {
               if (first) {
                  constructor.createCharacters("\n");
                  first = false;
               }
               roles.next().generate(constructor,dest,false);
               constructor.createCharacters("\n");
            }
            dest.send(constructor.createElementEnd(XML.ROLES_NAME));
         } catch (SQLException ex) {
            throw new XMLException("Cannot get user roles.",ex);
         }
      }
      dest.send(constructor.createElementEnd(XML.USER_NAME));
   }
View Full Code Here

                     Element e = (Element)item;
                     Name name = e.getName();
                     if (name.equals(CATEGORY)) {
                        String termName = e.getAttributeValue("term");
                        if (termName==null) {
                           throw new XMLException("The term element is missing the 'term' attribute.",(Location)e);
                        }
                        termName = termName.trim();
                        if (termName.length()==0) {
                           throw new XMLException("The term element's 'term' attribute is empty.",(Location)e);
                        }
                        Term term = Term.derive(current==null ? null : current.uri, e);
                        current = new TermNode(term,current,separator);
                        current.parent.children.put(term.getName(),current);
                        universe.put(term.getURI(), current);
                     } else if (name.equals(ONTOLOGY)) {
                        String tname = e.getAttributeValue("scheme");
                        if (tname==null) {
                           throw new XMLException("The ontology element is missing the 'scheme' attribute.",(Location)e);
                        }
                        separator = e.getAttributeValue("separator");
                        if (separator==null) {
                           separator = "/";
                        }
                        tname = tname.trim();
                        if (tname.length()==0) {
                           throw new XMLException("The ontology element's scheme attribute is empty.",(Location)e);
                        }
                        URI id = URI.create(tname);
                        Term term = new Term(id);
                        current = new TermNode(term,null,separator);
                        universe.put(term.getURI(), current);
                     }
                  }
                     break;
                  case ElementEndItem:
                  {
                     Name name = ((Named)item).getName();
                     if (name.equals(CATEGORY) || name.equals(ONTOLOGY)) {
                        if (current!=null) {
                           current = current.parent;
                        }
                     }
                  }
                     break;
               }
            }
         });
      } catch (URISyntaxException ex) {
         throw new XMLException("Cannot convert URL to URI.",ex);
      }
   }
View Full Code Here

TOP

Related Classes of org.infoset.xml.XMLException

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.