Package org.infoset.xml

Examples of org.infoset.xml.Element


      dateE.clear();
      dateE.addCharacters(toXSDDate(date));
   }
  
   public void update() {
      Element entryE = doc.getDocumentElement();
      Iterator<Element> categories = entryE.getElementsByName(XML.CATEGORY_NAME);
      while (categories.hasNext()) {
         Element categoryE = categories.next();
         categories.remove();
      }
      Iterator<Element> links = entryE.getElementsByName(XML.LINK_NAME);
      while (links.hasNext()) {
         Element linkE = links.next();
         links.remove();
      }
      int idPos = 0;
      for (int i=0; i<entryE.size(); i++) {
         if (entryE.get(i).getType()==Item.ItemType.ElementItem && ((Named)entryE).getName().equals(XML.ID_NAME)) {
            idPos = i;
            break;
         }
      }
      idPos++;
      if (idPos==entryE.size()) {
         idPos = -1;
      }
      for (URI termId : terms.keySet()) {
         Term term = terms.get(termId);
         URI uscheme = term.getScheme();
         String scheme = uscheme.equals(term.DEFAULT_SCHEME) ? null : uscheme.toString();
         String name = term.getName();
         if (name.length()==0) {
            name = "#";
         }
         if (term.getValues()!=null) {
            for (String value : term.getValues()) {
               Element categoryE = idPos<0 ? entryE.addElement(XML.CATEGORY_NAME) : entryE.addElement(idPos,XML.CATEGORY_NAME);
               if (scheme!=null) {
                  categoryE.setAttributeValue("scheme",scheme);
               }
               categoryE.setAttributeValue("term",name);
               categoryE.addCharacters(value);
            }
         } else {
            Element categoryE = idPos<0 ? entryE.addElement(XML.CATEGORY_NAME) : entryE.addElement(idPos,XML.CATEGORY_NAME);
            if (scheme!=null) {
               categoryE.setAttributeValue("scheme",scheme);
            }
            categoryE.setAttributeValue("term",name);
         }
      }
      URI base = entryE.getBaseURI();
      for (String rel : linkset.keySet()) {
         List<Link> relLinks = linkset.get(rel);
         for (Link link : relLinks) {
            Element linkE = idPos<0 ? entryE.addElement(XML.LINK_NAME) : entryE.addElement(idPos,XML.LINK_NAME);
            linkE.setAttributeValue("href",base==null ? link.getLink().toString() : base.relativize(link.getLink()).toString());
            if (link.getType()!=null) {
               linkE.setAttributeValue("type",link.getType().toString());
            }
            linkE.setAttributeValue("rel",link.getRelation());
         }
      }
   }
View Full Code Here


         throws XMLException
      {
         if (level==3) {
            switch (item.getType()) {
               case ElementItem:
                  Element e = (Element)item;
                  if (e.getName().equals(XML.REALM_NAME)) {
                     String sid = e.getAttributeValue("id");
                     String name = e.getAttributeValue("name");
                     if (sid==null) {
                        log.warning("A realm is missing the 'id' attribute.");
                        return;
                     }
                     if (name==null) {
                        log.warning("A realm is missing the 'realm' attribute.");
                        return;
                     }
                     try {
                        UUID id = UUID.fromString(sid);
                        realm = db.getRealm(id);
                        if (realm!=null && !realm.getName().equals(name)) {
                           log.warning("Realm ("+name+","+sid+" exists but has a different name, recreating.");
                           realm.delete();
                           realm = null;
                        } else if (realm!=null) {
                           log.info("Realm ("+name+","+sid+") already exists.");
                        }
                        if (realm==null) {
                           log.info("Creating realm ("+name+","+sid+").");
                           realm = db.createRealm(name,id);
                        }
                     } catch (IllegalArgumentException ex) {
                        log.warning("Bad UUID value '"+sid+"' on realm.");
                     } catch (SQLException ex) {
                        throw new XMLException("Database error on realm "+sid,ex);
                     }
                  }
               break;
               case ElementEndItem:
                  realm = null;
            }
         } else if (level==4) {
            switch (item.getType()) {
               case ElementItem:
                  Element e = (Element)item;
                  if (e.getName().equals(XML.USERS_NAME)) {
                     current = new RealmUsersDestination(realm,current);
                     current.send(item);
                  } else if (e.getName().equals(XML.GROUPS_NAME)) {
                     current = new RealmGroupsDestination(realm,current);
                     current.send(item);
                  }
            }
         }
View Full Code Here

         DocumentDestination dest = new DocumentDestination();
        
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_BACKUP));
         Document doc = dest.getDocument();
        
         Element top = doc.getDocumentElement();
         String location = top.getAttributeValue("location");
         if (location==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'location' attribute is missing.");
         }
         location = location.trim();
View Full Code Here

         throws XMLException
      {
         if (level==5) {
            switch (item.getType()) {
               case ElementItem:
                  Element e = (Element)item;
                  if (e.getName().equals(XML.USER_NAME)) {
                     String sid = e.getAttributeValue("id");
                     alias = e.getAttributeValue("alias");
                     if (sid==null) {
                        log.warning("A realm user is missing the 'id' attribute.");
                        return;
                     }
                     try {
                        id = UUID.fromString(sid);
                     } catch (IllegalArgumentException ex) {
                        log.warning("Bad UUID value '"+sid+"' on realm user.");
                     }
                     name = null;
                     email = null;
                  }
               break;
               case ElementEndItem:
                  if (id!=null) {
                     try {
                        User user = db.getUser(id);
                        if (user==null) {
                           log.warning("Cannot find user with id "+id);
                           return;
                        }
                        RealmUser ruser = db.getRealmUser(realm,id);
                        if (ruser!=null) {
                           log.info("Changing realm user ("+alias+","+id+","+name+","+email+")");
                           if (!ruser.changeAlias(alias)) {
                              log.warning("Could not change alias to '"+alias+"'");
                           }
                           ruser.setName(name);
                           ruser.setEmail(email);
                        } else {
                           log.info("Creating realm user ("+alias+","+id+","+name+","+email+")");
                           ruser = db.createRealmUser(realm,user,alias,name,email);
                           if (ruser==null) {
                              log.warning("Creation of realm user with alias "+alias+" refused.");
                           }
                        }
                        id = null;
                        name = null;
                        email = null;
                        alias = null;
                     } catch (SQLException ex) {
                        throw new XMLException("Database error while creating realm user ("+alias+","+id+")",ex);
                     }
                  }
            }
         } else if (level==6) {
            switch (item.getType()) {
               case ElementItem:
               {
                  Element e = (Element)item;
                  if (e.getName().equals(XML.NAME_NAME)) {
                     buffer = new StringBuilder();
                  } else if (e.getName().equals(XML.EMAIL_NAME)) {
                     buffer = new StringBuilder();
                  }
               }
                  break;
               case ElementEndItem:
               {
                  ElementEnd e = (ElementEnd)item;
                  if (e.getName().equals(XML.NAME_NAME)) {
                     name = buffer.toString();
                  } else if (e.getName().equals(XML.EMAIL_NAME)) {
                     email = buffer.toString();
                  }
                  buffer = null;
                  break;
               }
View Full Code Here

         throws XMLException
      {
         if (level==5) {
            switch (item.getType()) {
               case ElementItem:
                  Element e = (Element)item;
                  if (e.getName().equals(XML.GROUP_NAME)) {
                     String sid = e.getAttributeValue("id");
                     String alias = e.getAttributeValue("alias");
                     if (sid==null) {
                        log.warning("A group is missing the 'id' attribute.");
                        return;
                     }
                     if (alias==null) {
                        log.warning("A group is missing the 'alias' attribute.");
                        return;
                     }
                     try {
                        UUID id = UUID.fromString(sid);
                        group = db.getGroup(realm,id);
                        if (group==null) {
                           log.info("Creating group ("+alias+","+id+")");
                           group = db.createGroup(realm,id,alias);
                        } else {
                           log.info("Group ("+alias+","+id+") already exists.");
                        }
                     } catch (SQLException ex) {
                        throw new XMLException("Database error while creating group ("+alias+","+sid+")",ex);
                     } catch (IllegalArgumentException ex) {
                        log.warning("Bad UUID value '"+sid+"' on group.");
                     }
                  }
               break;
               case ElementEndItem:
                  group = null;
            }
         } else if (level==6) {
            switch (item.getType()) {
               case ElementItem:
               {
                  Element e = (Element)item;
                  if (e.getName().equals(XML.ROLES_NAME)) {
                     current = new GroupRolesDestination(group,current);
                     current.send(item);
                  } else if (e.getName().equals(XML.USERS_NAME)) {
                     current = new GroupUsersDestination(group,current);
                     current.send(item);
                  }
               }
            }
View Full Code Here

      }
      public void send(Item item)
         throws XMLException
      {
         if (level==7 && item.getType()==Item.ItemType.ElementItem) {
            Element e = (Element)item;
            if (e.getName().equals(XML.ROLE_NAME)) {
               String sid = e.getAttributeValue("id");
               if (sid==null) {
                  log.warning("A role in group ("+group.getAlias()+","+group.getUUID()+") is missing the 'id' attribute.");
                  return;
               }
               try {
View Full Code Here

      }
      public void send(Item item)
         throws XMLException
      {
         if (level==7 && item.getType()==Item.ItemType.ElementItem) {
            Element e = (Element)item;
            if (e.getName().equals(XML.USER_NAME)) {
               String sid = e.getAttributeValue("id");
               if (sid==null) {
                  log.warning("A user in group ("+group.getAlias()+","+group.getUUID()+") is missing the 'id' attribute.");
                  return;
               }
               try {
View Full Code Here

     
      try {
         DocumentDestination dest = new DocumentDestination();
         parser.parse(entity,dest);
         doc = dest.getDocument();
         Element top = doc.getDocumentElement();
         String sid = top.getAttributeValue("id");
         String alias = top.getAttributeValue("alias");
         if (sid==null && alias==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("One of the 'id' or 'alias' attributes must be specified.");
         }
         UUID id = null;
         if (sid!=null) {
            try {
               id = UUID.fromString(sid);
            } catch (IllegalArgumentException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Invalid UUID value for user id.");
            }
         }
         String password = top.getAttributeValue("password");
         Element name = top.getFirstElementNamed(XML.NAME_NAME);
         Element email = top.getFirstElementNamed(XML.EMAIL_NAME);

         if (alias!=null && !User.isAlias(alias)) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The alias '"+alias+"' does not contain all letters or digits.");
         }
        
         try {
            Realm realm = null;
            try {
               realm = fetch();
            } catch (IllegalArgumentException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Invalid UUID value for realm id.");
            }
            if (realm==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return new StringRepresentation("Realm not found.");
            }
            User user = null;
            if (id!=null) {
               user = db.getUser(id);
               if (user==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  return new StringRepresentation("User with id "+id+" not found.");
               } else if (alias==null && user.getAlias()==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("The global user "+id+" does not have an alias and the alias was not specified on the request.");
               }
            }
            if (user==null) {
               // we have a request to create a realm user not tied to an existing user.
               // create a new user and then the realm user
               user = db.createUser(UUID.randomUUID(),null,null,null);
               if (user==null) {
                  // this really shouldn't happen because we don't have an alias
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  return new StringRepresentation("User creation is not available.");
               }
               // set the password if they specified it
               if (password!=null) {
                  user.setPassword(password);
               }
            }
            if (alias!=null && alias.equals(user.getAlias())) {
               // inherit the alias as it is the same
               alias = null;
            }
           
            if (db.isRealmUserAliasAvailable(realm,user,alias)) {
               RealmUser realmUser = db.createRealmUser(realm,user,alias,name==null ? null : name.getText(),email==null ? null : email.getText());
               if (realmUser==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
                  return new StringRepresentation("The realm user could not be created.");
               } else {
                  Representation responseEntity = new DBObjectRepresentation(MediaType.APPLICATION_XML,realmUser);
View Full Code Here

                                    boolean started = false;
                                    public void send(Item item)
                                       throws XMLException
                                    {
                                       if (!started && item.getType()==Item.ItemType.ElementItem) {
                                          Element top = (Element)item;
                                          top.setBaseURI(baseURI);
                                          top.getAttributes().remove(Attribute.XML_BASE);
                                       }
                                       dest.send(item);
                                    }
                                    public void attach(ItemDestination dest) {
                                    }
View Full Code Here

         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
      try {
         RealmUser user = fetch();
         if (user!=null) {
            Element top = doc.getDocumentElement();
            String alias = top.getAttributeValue("alias");
            Element name = top.getFirstElementNamed(XML.NAME_NAME);
            Element email = top.getFirstElementNamed(XML.EMAIL_NAME);
            if (alias!=null && !User.isAlias(alias)) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("The alias '"+alias+"' does not contain all letters or digits.");
            }
            if ((alias!=null && !alias.equals(user.getAlias())) ||
                (alias==null && !user.getAlias().equals(user.getUser().getAlias())) ){
               // rename or unset
               try {
                  if (alias!=null && alias.equals(user.getUser().getAlias())) {
                     // unset
                     if (!user.changeAlias(null)) {
                        getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
                        return new StringRepresentation("The alias '"+alias+"' is not available.");
                     }
                  } else {
                     if (!user.changeAlias(alias)) {
                        getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
                        return new StringRepresentation("The alias '"+alias+"' is not available.");
                     }
                  }
               } catch (SQLException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Database error during while changing alias: "+ex.getMessage(),ex);
                  getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
                  return new StringRepresentation("The alias '"+alias+"' is not available.");
               }
            }
            if (name!=null) {
               String value = name.getText();
               getContext().getLogger().info("Setting name to: "+value);
               if (!value.equals(user.getName())) {
                  // set name
                  user.setName(value);
               }
            } else {
               if (user.getName()!=null) {
                  user.setName(null);
               }
            }
            if (email!=null) {
               String value = email.getText();
               if (!value.equals(user.getEmail())) {
                  // set email
                  user.setEmail(value);
               }
            } else {
View Full Code Here

TOP

Related Classes of org.infoset.xml.Element

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.