Package org.atomojo.app.client

Examples of org.atomojo.app.client.XMLRepresentationParser


     
      Reference testUser1Loc = new Reference(adminUserLoc.toString()+"testuser.1");
      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.1".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(adminUserLoc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.2' password='mypassword.2'/>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      Reference testUser2Loc = new Reference(adminUserLoc.toString()+"testuser.2");
      response = client.handle(makeGet(testUser2Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.2".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("I/O exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(testUser1Loc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.1' password='mypassword.1.changed'><name>Test User</name></user>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("Test User".equals(top.getFirstElementNamed(Name.create("{http://www.atomojo.org/Vocabulary/Admin/2007/1/0}name")).getText()));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
View Full Code Here


   }
  
   public static void generate(Storage storage,Feed feed,Reference metaRef,Reference feedRef,String resourceBase,ItemDestination dest)
      throws XMLException
   {
      XMLRepresentationParser xmlParser = new XMLRepresentationParser();
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(AtomResource.FEED_NAME));
      link(constructor,dest,"self",metaRef.toString());
      link(constructor,dest,"related",feedRef.toString());
      try {
         org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(storage.getFeedHead(feed.getPath(), feed.getUUID())));
         text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
         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());
View Full Code Here

      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
         DocumentDestination dest = new DocumentDestination();
        
         Name [] roots = { AdminXML.NM_PUSH , AdminXML.NM_PULL };
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,roots));
         doc = dest.getDocument();
         Element top = doc.getDocumentElement();
         SyncProcess proc = new SyncProcess(db,top);
         if (proc.exists()) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
View Full Code Here

      authURL = serviceBase.resolve("./auth?session=false").toString();
      sessionURL = serviceBase.resolve("./auth/").toString();
      Protocol protocol = Protocol.valueOf(serviceBase.getScheme());
      client = new Client(new Context(LOG),protocol);
      client.getContext().getAttributes().put("hostnameVerifier", org.apache.commons.ssl.HostnameVerifier.DEFAULT);
      parser = new XMLRepresentationParser();
      passwords = new TreeMap<String,String>();
      userCache = new Cache<String,User>(100,2*60*1000) {
         public User fetch(AuthCredentials cred,String alias)
            throws AuthException
         {
View Full Code Here

         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      final String name = getRequest().getAttributes().get("name").toString();
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
         DocumentDestination dest = new DocumentDestination();
         Name [] names = { AdminXML.NM_PULL, AdminXML.NM_PUSH };
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,names));
         doc = dest.getDocument();
         SyncProcess proc = new SyncProcess(db,doc.getDocumentElement());
         String lname = proc.getName();
         if (!lname.equals(name)) {
            getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
View Full Code Here

         Query query = parser.parseQuery(r);
         r.close();

         getResponse().setStatus(Status.SUCCESS_OK);
         final QueryContext context = new QueryContext(getLogger(),app.getDB(),query);
         final XMLRepresentationParser xmlParser = new XMLRepresentationParser();
         return new OutputRepresentation(MediaType.APPLICATION_ATOM) {
            public void write(OutputStream os)
               throws IOException
            {
               final ItemDestination dest = new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8");
               final ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               try {
                  context.execute(new QueryContext.ResultListener() {
                     DocumentLoader loader = new SAXDocumentLoader();
                     public void onStart() throws QueryException {
                        try {
                           dest.send(constructor.createDocument());
                           dest.send(constructor.createElement(AtomResource.FEED_NAME));
                           dest.send(constructor.createCharacters("\n"));
                           link(constructor,dest,"self",getRequest().getResourceRef().toString());
                           dest.send(constructor.createCharacters("\n"));
                           text(constructor,dest,AtomResource.TITLE_NAME,"Term Query");
                           dest.send(constructor.createCharacters("\n"));
                           text(constructor,dest,AtomResource.ID_NAME,UUID.randomUUID().toString());
                           dest.send(constructor.createCharacters("\n"));
                           text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(new Date()));
                        } catch (XMLException ex) {
                           throw new QueryException("Exception during feed start.",ex);
                        }
                     }

                     public void onEnd() throws QueryException {
                        try {
                           dest.send(constructor.createCharacters("\n"));
                           dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
                           dest.send(constructor.createDocumentEnd());
                        } catch (XMLException ex) {
                           throw new QueryException("Exception during feed end.",ex);
                        }
                     }

                     public void onEntry(Entry entry) throws QueryException {
                        try {
                           Feed feed = entry.getFeed();
                           String feedPath = feed.getPath();
                           String feedBaseURI = resourceBase.toString()+feedPath;
                           dest.send(constructor.createCharacters("\n"));

                           // get the entry representation
                           Representation rep = app.getStorage().getEntry(feedBaseURI,feedPath,feed.getUUID(),entry.getUUID());

                           // avoid thread creation because reading an output representation requires a thread
                           StringWriter sw = new StringWriter();
                           rep.write(sw);
                           rep.release();

                           // TODO: optimize by giving item destination to storage
                           loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));
                        } catch (Exception ex) {
                           throw new QueryException("Exception during feed entry generation.",ex);
                        }
                     }

                     public void onFeed(Feed feed) throws QueryException {
                        try {
                           org.atomojo.app.client.Feed feedRep = new org.atomojo.app.client.Feed(xmlParser.load(app.getStorage().getFeedHead(feed.getPath(), feed.getUUID())));
                           dest.send(constructor.createCharacters("\n"));
                           dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
                           text(constructor,dest,AtomResource.ID_NAME,feed.getUUID().toString());
                           text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(feed.getCreated()));
                           text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(feed.getEdited()));
View Full Code Here

      }
     
      Map<String,DBInfo> dbList = (Map<String,DBInfo>)getContext().getAttributes().get(DatabaseListResource.DB_LIST);
      Map<String,DBInfo> autodbList = (Map<String,DBInfo>)getContext().getAttributes().get(DatabaseListResource.AUTO_DB_LIST);
      StorageFactory storageFactory = (StorageFactory)getContext().getAttributes().get(DatabaseListResource.STORAGE_FACTORY);
      XMLRepresentationParser parser = new XMLRepresentationParser();
      try {
         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) {
View Full Code Here

      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
         DocumentDestination dest = new DocumentDestination();
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_APP));
         doc = dest.getDocument();
         RemoteApp app = new RemoteApp(db,doc.getDocumentElement());
         if (app.exists()) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
            return new StringRepresentation("Remote app with name "+app.getName()+" already exists.");
View Full Code Here

         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
     
      final DB db = (DB)getRequest().getAttributes().get(App.DB_ATTR);
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
         DocumentDestination dest = new DocumentDestination();
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_TARGET));
         doc = dest.getDocument();
         SyncTarget target = new SyncTarget(db,doc.getDocumentElement());
         if (target.exists()) {
            getResponse().setStatus(Status.CLIENT_ERROR_CONFLICT);
            return new StringRepresentation("Target with name "+target.getName()+" already exists.");
View Full Code Here

      final String name = getRequest().getAttributes().get("name").toString();
      if (!XMLRepresentationParser.isXML(entity.getMediaType())) {
         getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
         return new StringRepresentation("Non-XML media type for entity body: "+entity.getMediaType().getName());
      }
      XMLRepresentationParser parser = new XMLRepresentationParser();
      Document doc = null;
     
      try {
         DocumentDestination dest = new DocumentDestination();
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_TARGET));
         doc = dest.getDocument();
         SyncTarget target = new SyncTarget(db,doc.getDocumentElement());
         String lname = target.getName();
         if (!lname.equals(name)) {
            getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
View Full Code Here

TOP

Related Classes of org.atomojo.app.client.XMLRepresentationParser

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.