Package org.infoset.xml

Examples of org.infoset.xml.Element


      }
     
      try {
         RealmUser user = fetch();
         if (user!=null) {
            Element top = doc.getDocumentElement();
            if (top.getName().equals(XML.GROUP_NAME)) {
               if (facet==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                  return null;
               }
               if (!facet.equals(GROUP_FACET)) {
                  getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
                  return null;
               }
               if (facetId!=null || facetName!=null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_METHOD_NOT_ALLOWED);
                  return null;
               }
               String sid = top.getAttributeValue("id");
               String name = top.getAttributeValue("alias");
               Group group = null;
               if (sid!=null) {
                  group = db.getGroup(user.getRealm(),UUID.fromString(sid));
               }
               if (name!=null && group==null) {
                  group = db.getGroup(user.getRealm(),name);
               }
               if (group==null) {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Cannot find group "+name);
               } else {
                  user.addGroup(group);
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  return null;
               }
            } else if (top.getName().equals(XML.PASSWORD_NAME)) {
               String password = top.getText();
               try {
                  user.getUser().setPassword(password);
                  getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                  return null;
               } catch (NoSuchAlgorithmException ex) {
                  getContext().getLogger().log(Level.SEVERE,"Error while setting password: "+ex.getMessage(),ex);
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Algorithm encoding error while setting password.");
               }
            } else {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("Element not understood: "+top.getName());
            }

         } else {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return new StringRepresentation("The user was not found.");
View Full Code Here


                  return;
               }
               log.info("Entry: "+entryId);
               EntryClient entryClient = new EntryClient(new Reference(targetClient.getEntryLocation(entryId).toString()),target.getIdentity());
               String src = null;
               Element content = entryDoc.getDocumentElement().getFirstElementNamed(CONTENT_NAME);
               URI baseURI = null;
               MediaType contentType = null;
               if (content!=null) {
                  src = content.getAttributeValue("src");
                  String type = content.getAttributeValue("type");
                  if (type!=null) {
                     contentType = MediaType.valueOf(type);
                  }
                  baseURI = content.getBaseURI();
               }
               if (entries!=null) {
                  entries.add(entryId);
               }
              
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");

         try {
            Role rootRole = db.getRole(AuthDB.REALM_ROOT_ROLE);
            if (rootRole==null) {
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL);
View Full Code Here

   public static Document createFeedDocument(String title,UUID id,Date created)
      throws XMLException
   {
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      Document doc = constructor.createDocument();
      Element top = doc.createDocumentElement(AtomResource.FEED_NAME);
      top.addNamespaceBinding("app",APP_NAMESPACE);
      top.addElement(TITLE_NAME).addCharacters(title);
      top.addElement(ID_NAME).addCharacters("urn:uuid:"+id.toString());
      String dateString = toXSDDate(created);
      //top.addElement(PUBLISHED_NAME).addCharacters(dateString);
      top.addElement(UPDATED_NAME).addCharacters(dateString);
      //top.addElement(EDITED_NAME).addCharacters(dateString);
      Element link = top.addElement(LINK_NAME);
      link.setAttributeValue("rel","self");
      link.setAttributeValue("href","");
      link = top.addElement(LINK_NAME);
      link.setAttributeValue("rel","edit");
      link.setAttributeValue("href","");
      return doc;
   }
View Full Code Here

   public static Document createEntryDocument(String title,UUID id,Date created,String authorName)
      throws XMLException
   {
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      Document doc = constructor.createDocument();
      Element top = doc.createDocumentElement(AtomResource.ENTRY_NAME);
      top.addElement(TITLE_NAME).addCharacters(title);
      top.addElement(ID_NAME).addCharacters("urn:uuid:"+id.toString());
      String dateString = toXSDDate(created);
      top.addElement(PUBLISHED_NAME).addCharacters(dateString);
      top.addElement(UPDATED_NAME).addCharacters(dateString);
      Element edited = top.addElement(EDITED_NAME);
      edited.addCharacters(dateString);
      edited.setPrefix("app");
      Element link = top.addElement(LINK_NAME);
      link.setAttributeValue("rel","edit");
      link.setAttributeValue("href","./_/"+id);
      if (authorName!=null) {
         Element author = top.addElement(AUTHOR_NAME);
         author.addElement(NAME_NAME).addCharacters(authorName);
      }
      return doc;
   }
View Full Code Here

           
         }
          */
         if (level==3) {
            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) {
                     log.warning("A permission is missing the 'id' attribute.");
                     return;
                  }
                  if (name==null) {
View Full Code Here

   }
   public static Document createMediaEntryDocument(String title,UUID id,Date created,String authorName,String href,MediaType type)
      throws XMLException
   {
      Document entryDoc = createEntryDocument(title,id,created,authorName);
      Element top = entryDoc.getDocumentElement();
      Element link = top.addElement(LINK_NAME);
      link.setAttributeValue("rel","edit-media");
      link.setAttributeValue("href",href);
      Element content = top.addElement(CONTENT_NAME);
      content.setAttributeValue("src",href);
      content.setAttributeValue("type",type.toString());
      return entryDoc;
   }
View Full Code Here

   public static void mergeFeedDocument(Document doc,UUID id,Date created,Date modified)
   {
      boolean idDone = false;
      boolean createdDone = false;
      boolean modifiedDone = false;
      Element feed = doc.getDocumentElement();
      List<Child> toRemove = new ArrayList<Child>();
      Element linkEdit = null;
      for (Child c : feed) {
         if (c instanceof Element) {
            Element e = (Element)c;
            if (e.getName().equals(ID_NAME)) {
               idDone = true;
               e.clear();
               e.addCharacters("urn:uuid:"+id.toString());
               /*
            } else if (e.getName().equals(PUBLISHED_NAME) && created!=null) {
               createdDone = true;
               e.clear();
               e.addCharacters(toXSDDate(created));
                */
            } else if (e.getName().equals(LINK_NAME)) {
               String rel = e.getAttributeValue("rel");
               if ("edit".equals(rel)) {
                  linkEdit = e;
               } else if ("self".equals(rel)) {
                  toRemove.add(e);
               }
            } else if (e.getName().equals(UPDATED_NAME)) {
               modifiedDone = true;
               e.clear();
               e.addCharacters(toXSDDate(modified));
            } else if (e.getName().equals(ENTRY_NAME)) {
               toRemove.add(e);
            }
         }
      }
      if (!modifiedDone) {
         feed.addElement(0,UPDATED_NAME).addCharacters(toXSDDate(modified));
      }
      /*
      if (!createdDone  && created!=null) {
         feed.addElement(0,PUBLISHED_NAME).addCharacters(toXSDDate(created));
      }
       */
      if (!idDone) {
         feed.addElement(0,ID_NAME).addCharacters("urn:uuid:"+id.toString());
      }
      feed.removeAll(toRemove);
      if (linkEdit==null) {
         linkEdit = feed.addElement(LINK_NAME);
      }
      linkEdit.setAttributeValue("rel","edit");
      linkEdit.setAttributeValue("href","");
      Element selfLink = feed.addElement(LINK_NAME);
      selfLink.setAttributeValue("rel","self");
      selfLink.setAttributeValue("href","");
   }
View Full Code Here

      }
     
      try {
         User 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+"' is not a valid alias.");
            }
            if (alias!=null && !alias.equals(user.getAlias())) {
               // rename
               try {
                  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();
               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

      }
     
      try {
         User user = fetch();
         if (user!=null) {
            Element top = doc.getDocumentElement();
            if (facet!=null && facet.equals(ROLE_FACET)) {
               if (top.getName().equals(XML.ROLE_NAME)) {
                  String sid = top.getAttributeValue("id");
                  String name = top.getAttributeValue("name");
                  Role role = null;
                  if (sid!=null) {
                     role = db.getRole(UUID.fromString(sid));
                  }
                  if (name!=null && role==null) {
                     role = db.getRole(name);
                  }
                  if (role==null) {
                     getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                     return new StringRepresentation("Cannot find role "+name);
                  } else {
                     user.addRole(role);
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                     return null;
                  }
               } else {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Element "+top.getName()+" is not allowed.");
               }
            } else if (facet!=null) {
               getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
               return null;
            } else {
               if (top.getName().equals(XML.PASSWORD_NAME)) {
                  String password = top.getText();
                  try {
                     user.setPassword(password);
                     getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
                     return null;
                  } catch (NoSuchAlgorithmException ex) {
                     getContext().getLogger().log(Level.SEVERE,"Error while setting password: "+ex.getMessage(),ex);
                     getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                     return new StringRepresentation("Error encrypting password.");
                  }
               } else {
                  getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
                  return new StringRepresentation("Element "+top.getName()+" is not allowed.");
               }
            }
         } else {
            getResponse().setStatus(Status.CLIENT_ERROR_NOT_FOUND);
            return null;
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.