Package org.infoset.xml

Examples of org.infoset.xml.Element


               Text text = entry.getContent();
               if (text==null || !text.isXML()) {
                  getLogger().warning("Ignoring host entry with missing or has incorrectly typed content for configuration.");
                  continue;
               }
               Element hostE = text.getContent();
               if (hostE==null) {
                  getLogger().warning("Ignoring host entry with empty content.");
                  continue;
               }
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");
         UUID id = sid==null ? UUID.randomUUID() : UUID.fromString(sid);
         String name = top.getAttributeValue("name");
         if (name==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'name' attribute must be present.");
         }
View Full Code Here

         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
     
      try {
         Role role = fetch();
         Element top = doc.getDocumentElement();
         String sid = top.getAttributeValue("id");
         String name = top.getAttributeValue("name");
         Permission p = null;
         if (sid!=null) {
            p = db.getPermission(UUID.fromString(sid));
         }
         if (name!=null) {
View Full Code Here

      } catch (Exception ex) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("XML parse error: "+ex.getMessage());
      }
     
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(NM_USER)) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Unknown document element: "+top.getName());
      }
      String alias = top.getAttributeValue("alias");
      String password = top.getAttributeValue("password");
      if (password==null) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("The password is missing.");
      }
     
      alias = alias.trim();
      password = password.trim();
      if (alias.length()==0 || password.length()==0) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Empty alias or password.");
      }
     
      Element nameE = top.getFirstElementNamed(NM_NAME);
      String name = null;
      if (nameE!=null) {
         name = nameE.getText();
      } else {
         name = alias;
      }
      Element emailE = top.getFirstElementNamed(NM_EMAIL);
      String email = null;
      if (emailE!=null) {
         email = emailE.getText();
      }
      try {
         AuthCredentials cred = new AuthCredentials(getRequest().getChallengeResponse());
         if (auth.getUser(cred,alias)!=null) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
View Full Code Here

      loader.generate(reader,authFile.toURI(),new ItemDestination() {
         public void send(Item item)
            throws XMLException
         {
            if (item.getType()==Item.ItemType.ElementItem) {
               Element e = (Element)item;
               if (e.getName().equals(AdminXML.NM_USER)) {
                  String alias = e.getAttributeValue("alias");
                  if (alias==null) {
                     LOG.warning("Missing 'alias' attribute on user.");
                     return;
                  }
                  String uuid = e.getAttributeValue("id");
                  if (uuid==null) {
                     LOG.warning("Missing 'id' attribute on user.");
                     return;
                  }
                  String password = e.getAttributeValue("password");
                  if (password==null) {
                     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;
                  }
                  String name = e.getAttributeValue("name");
                  if (name==null) {
                     name = alias;
                  }
                  String email = e.getAttributeValue("email");
                  LOG.fine(alias+","+uuid+","+name+","+email);
                  String groupsSpec = e.getAttributeValue("groups");
                  List<String> groupList = new ArrayList<String>();
                  if (groupsSpec!=null) {
                     String [] groupStrings = groupsSpec.split(",");
                     for (int i=0; i<groupStrings.length; i++) {
                        String group = groupStrings[i].trim();
                        if (group.length()!=0 && groups.get(group)!=null) {
                           LOG.fine(alias+": "+group);
                           groupList.add(group);
                        }
                     }
                  }
                  User u = new User(alias,UUID.fromString(uuid),name,email,groupList);
                  users.put(alias,u);
                  passwords.put(alias,password);
               } else if (e.getName().equals(AdminXML.NM_GROUP)) {
                  String name = e.getAttributeValue("name");
                  if (name!=null) {
                     groups.put(name,name);
                  }
               }
            }
View Full Code Here

      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(AdminXML.NM_USERS));
      dest.send(constructor.createCharacters("\n"));
      for (String group : groups.values()) {
         Element groupE = constructor.createElement(AdminXML.NM_GROUP);
         groupE.setAttributeValue("name",group);
         dest.send(groupE);
         dest.send(constructor.createElementEnd(AdminXML.NM_GROUP));
         dest.send(constructor.createCharacters("\n"));
      }
      for (User user : users.values()) {
         Element userE = constructor.createElement(AdminXML.NM_USER);
         userE.setAttributeValue("alias",user.getAlias());
         userE.setAttributeValue("id",user.getId().toString());
         userE.setAttributeValue("md5-password",passwords.get(user.getAlias()));
         userE.setAttributeValue("name",user.getName());
         if (user.getEmail()!=null) {
            userE.setAttributeValue("email",user.getName());
         }
         String groups = "";
         for (String group : user.getGroups()) {
            if (groups.length()>0) {
               groups += ",";
               groups += group;
            } else {
               groups = group;
            }
         }
         userE.setAttributeValue("groups",groups);
         dest.send(userE);
         dest.send(constructor.createElementEnd(AdminXML.NM_USER));
         dest.send(constructor.createCharacters("\n"));
      }
      dest.send(constructor.createElementEnd(AdminXML.NM_USERS));
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");
         UUID id = sid==null ? UUID.randomUUID() : UUID.fromString(sid);
         String name = top.getAttributeValue("name");
         if (name==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'name' attribute must be present.");
         }
View Full Code Here

            public void send(Item item)
               throws XMLException
            {
               switch (item.getType()) {
                  case ElementItem: {
                     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) {
View Full Code Here

         return new StringRepresentation("I/O error while parsing document: "+ex.getMessage());
      } catch (XMLException ex) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("XML error while parsing document: "+ex.getMessage());
      }
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(AtomResource.CATEGORIES_NAME)) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Unexpected document element "+top.getName());
      }
      URI firstTerm = null;
      final Map<URI,TermQuery> termSet = new TreeMap<URI,TermQuery>();
      Iterator<Element> categories = top.getElementsByName(AtomResource.CATEGORY_NAME);
      try {
         while (categories.hasNext()) {
            org.atomojo.app.client.Term term = org.atomojo.app.client.Term.derive(categories.next());
            URI termURI = term.getURI();
            String value = term.getFirstValue();
View Full Code Here

      throws XMLException
   {
      String [] parts = new String[2];
      Term.split(term,parts);
      try {
         Element termE = constructor.createElement(AtomResource.CATEGORY_NAME);
         if (!parts[0].equals("http://www.atomojo.org/O/keyword/")) {
            termE.setAttributeValue("scheme",parts[0]);
         }
         termE.setAttributeValue("term",URLDecoder.decode(parts[1],"UTF-8"));
         dest.send(termE);
         if (value!=null) {
            dest.send(constructor.createCharacters(value.toString()));
         }
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.