Package org.infoset.xml

Examples of org.infoset.xml.ItemDestination


            throws IOException
         {
            try {
               Iterator<SyncProcess> procs = db.getSyncProcesses();
               Writer out = new OutputStreamWriter(os,"UTF-8");
               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               dest.send(constructor.createDocument());
               dest.send(constructor.createElement(AdminXML.NM_SYNC_PROCESSES));
               while (procs.hasNext()) {
                  SyncProcess proc = procs.next();
                  proc.marshall();
                  DocumentSource.generate(proc.getElement(),false,dest);
               }
               dest.send(constructor.createElementEnd(AdminXML.NM_SYNC_PROCESSES));
               dest.send(constructor.createDocumentEnd());
               out.flush();
               out.close();
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot get list of sync processes from DB: "+ex.getMessage(),ex);
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Cannot get list of sync processes due to XML DB error.");
View Full Code Here


   {
      LOG.info("Loading auth from "+authFile);
      lastModified = authFile.lastModified();
      FileInputStream is = new FileInputStream(authFile);
      Reader reader = new InputStreamReader(is,"UTF-8");
      loader.generate(reader,authFile.toURI(),new ItemDestination() {
         public void send(Item item)
            throws XMLException
         {
            if (item.getType()==Item.ItemType.ElementItem) {
               Element e = (Element)item;
View Full Code Here

   public void load(URL url)
      throws IOException,XMLException
   {
      DocumentLoader loader = new SAXDocumentLoader();
      try {
         loader.generate(url.toURI(), new ItemDestination() {
            String separator = "/";
            TermNode current = null;
            public void send(Item item)
               throws XMLException
            {
View Full Code Here

      throws XMLException
   {
      if (doc==null) {
         throw new XMLException("The feed instance was not instantiated using a document.");
      }
      ItemDestination top = new ItemDestination() {
         int level = 0;
         public void send(Item item)
            throws XMLException
         {
            switch (item.getType()) {
View Full Code Here

         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()));
                           text(constructor,dest,AtomResource.TITLE_NAME,feedRep.getTitle());
                           String summary = feedRep.getSummary();
                           text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
                           term(constructor,dest,Categorization.FEED_TYPE_TERM,null);
                           Iterator<TermInstance<Feed>> terms = feed.getTerms();
                           while (terms.hasNext()) {
                              TermInstance<Feed> fterm = terms.next();
                              term(constructor,dest,fterm.getTerm().getURI(),fterm.getValue());
                           }
                           link(constructor,dest,"related",resourceBase+feed.getPath());
                           dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
                        } catch (Exception ex) {
                           throw new QueryException("Exception during feed entry generation.",ex);
                        }
                     }
                  } );
View Full Code Here

            throws IOException
         {
            try {
               Iterator<RemoteApp> apps = db.getRemoteApps();
               Writer out = new OutputStreamWriter(os,"UTF-8");
               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               dest.send(constructor.createDocument());
               dest.send(constructor.createElement(AdminXML.NM_APPS));
               while (apps.hasNext()) {
                  RemoteApp app = apps.next();
                  app.marshall();;
                  DocumentSource.generate(app.getElement(),false,dest);
               }
               dest.send(constructor.createElementEnd(AdminXML.NM_APPS));
               dest.send(constructor.createDocumentEnd());
               out.flush();
               out.close();
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot get list of remotes from DB: "+ex.getMessage(),ex);
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Cannot get list of remotes due to XML DB error.");
View Full Code Here

            throws IOException
         {
            try {
               Iterator<SyncTarget> targets = db.getSyncTargets();
               Writer out = new OutputStreamWriter(os,"UTF-8");
               ItemDestination dest = new WriterItemDestination(out,"UTF-8");
               ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
               dest.send(constructor.createDocument());
               dest.send(constructor.createElement(AdminXML.NM_TARGETS));
               while (targets.hasNext()) {
                  SyncTarget target = targets.next();
                  target.marshall();
                  DocumentSource.generate(target.getElement(),false,dest);
               }
               dest.send(constructor.createElementEnd(AdminXML.NM_TARGETS));
               dest.send(constructor.createDocumentEnd());
               out.flush();
               out.close();
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot get list of targets from DB: "+ex.getMessage(),ex);
               getResponse().setStatus(Status.SERVER_ERROR_INTERNAL,"Cannot get list of targets due to XML DB error.");
View Full Code Here

            getResponse().setStatus(Status.CLIENT_ERROR_EXPECTATION_FAILED);
            return new StringRepresentation("Cannot write to file "+outFile.getAbsolutePath());
         }
         getContext().getLogger().info("Backing up to file "+outFile.getAbsolutePath());
         OutputStreamWriter w = new OutputStreamWriter(new FileOutputStream(outFile),"UTF-8");
         ItemDestination dest = new WriterItemDestination(w,"UTF-8");
         ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor(outFile.toURI());
         dest.send(constructor.createDocument(outFile.toURI()));
         dest.send(constructor.createElement(XML.DATABASE_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createElement(XML.PERMISSIONS_NAME));
         dest.send(constructor.createCharacters("\n"));
         Iterator<Permission> permissions = db.getPermissions();
         while (permissions.hasNext()) {
            permissions.next().generate(constructor,dest);
            dest.send(constructor.createCharacters("\n"));
         }
         dest.send(constructor.createElementEnd(XML.PERMISSIONS_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createElement(XML.ROLES_NAME));
         dest.send(constructor.createCharacters("\n"));
         Iterator<Role> roles = db.getRoles();
         while (roles.hasNext()) {
            roles.next().generate(constructor,dest);
            dest.send(constructor.createCharacters("\n"));
         }
         dest.send(constructor.createElementEnd(XML.ROLES_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createElement(XML.USERS_NAME));
         dest.send(constructor.createCharacters("\n"));
         Iterator<User> users = db.getUsers();
         while (users.hasNext()) {
            users.next().generate(constructor,dest,true,true);
            dest.send(constructor.createCharacters("\n"));
         }
         dest.send(constructor.createElementEnd(XML.USERS_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createElement(XML.REALMS_NAME));
         dest.send(constructor.createCharacters("\n"));
         Iterator<Realm> realms = db.getRealms();
         while (realms.hasNext()) {
            realms.next().generate(constructor,dest,true);
            dest.send(constructor.createCharacters("\n"));
         }
         dest.send(constructor.createElementEnd(XML.REALMS_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createElementEnd(XML.DATABASE_NAME));
         dest.send(constructor.createCharacters("\n"));
         dest.send(constructor.createDocumentEnd());
         w.flush();
         w.close();
         getContext().getLogger().info("Backup finished.");
         getResponse().setStatus(Status.SUCCESS_NO_CONTENT);
      } catch (SQLException ex) {
View Full Code Here

   public void load(final ItemDestination dest)
      throws IOException,XMLException
   {
      File feedRef = new File(dir,FileStorage.FEED_DOCUMENT_NAME);
      final URI baseURI = feedRef.toURI();
      loader.generate(baseURI, new ItemDestination() {
         ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
         int level = 0;
         public void send(Item item)
            throws XMLException
         {
View Full Code Here

      Representation rep = new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            Writer out = new OutputStreamWriter(os,"UTF-8");
            ItemDestination dest = new WriterItemDestination(out,"UTF-8");
            FeedLoader feedLoader = new FeedLoader(getLogger(),loader,feedFile,entries);
            try {
               feedLoader.load(dest);
            } catch (XMLException ex) {
               throw new IOException("XML exception while loading feed: "+ex.getMessage());
View Full Code Here

TOP

Related Classes of org.infoset.xml.ItemDestination

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.