Package org.infoset.xml

Examples of org.infoset.xml.Element


         throws XMLException
      {
         if (level==3) {
            switch (item.getType()) {
               case ElementItem:
                  Element e = (Element)item;
                  if (e.getName().equals(XML.ROLE_NAME)) {
                     String sid = e.getAttributeValue("id");
                     String name = e.getAttributeValue("name");
                     if (sid==null) {
                        log.warning("A role is missing the 'id' attribute.");
                        return;
                     }
                     if (name==null) {
                        log.warning("A role is missing the 'name' attribute.");
                        return;
                     }
                     try {
                        UUID uuid = UUID.fromString(sid);
                        role = db.getRole(uuid);
                        if (role==null) {
                           log.info("Creating role ("+name+","+sid+")");
                           role = db.createRole(name,uuid);
                        } else {
                           if (!role.getName().equals(name)) {
                              log.warning("Role ("+name+","+sid+") exists but has a different name, recreating.");
                              role.delete();
                              role = db.createRole(name,uuid);
                           } else {
                              log.info("Role ("+name+","+sid+") already exists.");
                           }
                        }
                     } catch (IllegalArgumentException ex) {
                        log.warning("Bad UUID value '"+sid+"' on role.");
                     } catch (SQLException ex) {
                        throw new XMLException("Database error creating role "+sid,ex);
                     }
                  }
               break;
               case ElementEndItem:
                  role = null;
            }
         } else if (level==4 && role!=null) {
            if (item.getType()==Item.ItemType.ElementItem) {
               Element e = (Element)item;
               if (e.getName().equals(XML.PERMISSION_NAME)) {
                  String sid = e.getAttributeValue("id");
                  String name = e.getAttributeValue("name");
                  if (sid==null && name==null) {
                     log.warning("A permission for role "+role.getUUID()+" must have at least the 'id' or 'name' attribute.");
                     return;
                  }
                  try {
View Full Code Here


  
   public void index() {
      terms = new TreeMap<URI,Term>();
      Iterator<Element> categories = doc.getDocumentElement().getElementsByName(XML.CATEGORY_NAME);
      while (categories.hasNext()) {
         Element categoryE = categories.next();
         Term term = Term.derive(categoryE);
         if (term!=null) {
            Term prevTerm = terms.get(term.getURI());
            if (prevTerm==null) {
               terms.put(term.getURI(),term);
            } else {
               prevTerm.add(term.getFirstValue());
            }
         }
      }
      linkset = new LinkSet();
      Iterator<Element> links = doc.getDocumentElement().getElementsByName(XML.LINK_NAME);
      while (links.hasNext()) {
         Element linkE = links.next();
         String rel = linkE.getAttributeValue("rel");
         String type = linkE.getAttributeValue("type");
         String href = linkE.getAttributeValue("href");
         if (rel!=null && href!=null) {
            URI base = linkE.getBaseURI();
            URI location = base!=null ? base.resolve(href) : URI.create(href);
            MediaType mtype = type==null ? null : MediaType.valueOf(type);
            Link link = new Link(rel,mtype,location);
            List<Link> list = (List<Link>)linkset.get(rel);
            if (list==null) {
View Full Code Here

      EntryIndex index = new EntryIndex();
      for (Child c : entry) {
         if (c.getType()!=Item.ItemType.ElementItem) {
            continue;
         }
         Element e = (Element)c;
         Name name = e.getName();
         //Logger.getAnonymousLogger().info("Name: "+name);
         if (name.equals(ID_NAME)) {
            String value = e.getText().trim();
            //Logger.getAnonymousLogger().info("id: "+value);
            if (value.startsWith("urn:uuid:")) {
               index.setId(UUID.fromString(value.substring(9)));
            }
         } else if (name.equals(AUTHOR_NAME)) {
            Iterator<Element> children = e.getElementsByName(NAME_NAME);
            if (children.hasNext()) {
               String authorName = children.next().getText().trim();
               if (authorName.length()>0) {
                  index.setAuthorName(authorName);
               }
            }
         } else if (name.equals(CATEGORY_NAME)) {
            String scheme = e.getAttributeValue("scheme");
            String term = e.getAttributeValue("term");
            if (term!=null) {
               term = term.trim();
               if (term.length()==0) {
                  term = null;
               } else {
View Full Code Here

      FeedIndex index = new FeedIndex();
      for (Child c : feed) {
         if (c.getType()!=Item.ItemType.ElementItem) {
            continue;
         }
         Element e = (Element)c;
         Name name = e.getName();
         if (name.equals(ID_NAME)) {
            String value = e.getText().trim();
            if (value.startsWith("urn:uuid:")) {
               index.setId(UUID.fromString(value.substring(9)));
            }
         } else if (name.equals(CATEGORY_NAME)) {
            String scheme = e.getAttributeValue("scheme");
            String term = e.getAttributeValue("term");
            if (term!=null) {
               term = term.trim();
               if (term.length()==0) {
                  term = null;
               } else {
View Full Code Here

         }
      }
   }
  
   public String getId() {
      Element idE = doc.getDocumentElement().getFirstElementNamed(XML.ID_NAME);
      return idE==null ? null : idE.getText();
   }
View Full Code Here

      return idE==null ? null : idE.getText();
   }
  
   public void setId(String uri)
   {
      Element idE = doc.getDocumentElement().getFirstElementNamed(XML.ID_NAME);
      if (idE==null) {
         if (doc.getDocumentElement().size()==0) {
            idE = doc.getDocumentElement().addElement(XML.ID_NAME);
         } else {
            idE = doc.getDocumentElement().addElement(0,XML.ID_NAME);
         }
      }
      idE.clear();
      idE.addCharacters(uri);
   }
View Full Code Here

      idE.clear();
      idE.addCharacters(uri);
   }
  
   public String getTitle() {
      Element titleE = doc.getDocumentElement().getFirstElementNamed(XML.TITLE_NAME);
      return titleE==null ? null : titleE.getText();
   }
View Full Code Here

      return titleE==null ? null : titleE.getText();
   }
  
   public Text getTitleText(boolean create)
   {
      Element titleE = doc.getDocumentElement().getFirstElementNamed(XML.TITLE_NAME);
      if (titleE==null && create) {
         titleE = doc.getDocumentElement().addElement(XML.TITLE_NAME);
      }
      return titleE==null ? null : new Text(titleE);
   }
View Full Code Here

      return titleE==null ? null : new Text(titleE);
   }
  
   public void setTitle(String text)
   {
      Element titleE = doc.getDocumentElement().getFirstElementNamed(XML.TITLE_NAME);
      if (titleE==null) {
         if (doc.getDocumentElement().size()==0) {
            titleE = doc.getDocumentElement().addElement(XML.TITLE_NAME);
         } else {
            titleE = doc.getDocumentElement().addElement(0,XML.TITLE_NAME);
         }
      }
      titleE.clear();
      titleE.addCharacters(text);
   }
View Full Code Here

         throws XMLException
      {
         if (level==3) {
            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");
                     passwordMd5 = e.getAttributeValue("password-md5");
                     if (sid==null) {
                        log.warning("A user is missing the 'id' attribute.");
                        return;
                     }
                     try {
                        id = UUID.fromString(sid);
                     } catch (IllegalArgumentException ex) {
                        log.warning("Bad UUID value '"+sid+"' on user.");
                     }
                     name = null;
                     email = null;
                  }
               break;
               case ElementEndItem:
                  create();
            }
         } else if (level==4) {
            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();
                  } else if (e.getName().equals(XML.ROLES_NAME)) {
                     User user = create();
                     if (user!=null) {
                        current = new UserRolesDestination(user,current);
                        current.send(item);
                     }
                     id = null;
                  }
               }
                  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

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.