Package org.infoset.xml.util

Examples of org.infoset.xml.util.WriterItemDestination


         conf.getHosts().put(host.getName(),host);
         conf.setKeystoreFile(keystoreFile);
         conf.setKeystorePassword("atomojo");
         conf.setKeyPassword("atomojo");
         Writer out = new OutputStreamWriter(new FileOutputStream(serverConfFile),"UTF-8");
         WriterItemDestination dest = new WriterItemDestination(out,"UTF-8");
         conf.store(serverConfFile.toURI(),dest);
         out.flush();
         out.close();
         if (!keystoreFile.exists()) {
            Main.copyResource("/org/atomojo/app/db/conf/keystore",keystoreFile);
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 write(OutputStream os)
            throws IOException
         {
            setCharacterSet(CharacterSet.UTF_8);
            try {
               generate(new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8"));
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot serialize metadata feed.",ex);
               throw new IOException("Cannot serialize metadata feed: "+ex.getMessage());
            }
         }
View Full Code Here

         public void write(OutputStream os)
            throws IOException
         {
            setCharacterSet(CharacterSet.UTF_8);
            try {
               generate(new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8"),keyTerm,termSet);
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot serialize metadata feed.",ex);
               throw new IOException("Cannot serialize metadata feed: "+ex.getMessage());
            }
         }
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

                  } else {
                     return path+".feed.atom";
                  }
               }
            },
            new WriterItemDestination(w,"UTF-8")
         );
      } catch (XMLException ex) {
         throw new IOException(ex.getMessage());
      }
      w.flush();
View Full Code Here

                  } else {
                     return path+".feed.atom";
                  }
               }
            },
            new WriterItemDestination(w,"UTF-8")
         );
         zipStream.flush();
         zipStream.closeEntry();
      } catch (XMLException ex) {
         throw new IOException(ex.getMessage());
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

      Representation rep = new OutputRepresentation(MediaType.APPLICATION_ATOM_XML) {
         public void write(OutputStream os)
            throws IOException
         {
            Writer w = new OutputStreamWriter(os,"UTF-8");
            final WriterItemDestination dest = new WriterItemDestination(w,"UTF-8",true);
            dest.setOmitXMLDeclaration(true);
            try {
               loader.generate(entry.toURI(), new ItemDestination() {
                  int level = 0;
                  public void send(Item item)
                     throws XMLException
                  {
                     switch (item.getType()) {
                        case ElementItem:
                           if (level==0) {
                              Element e = (Element)item;
                              e.setAttributeValue(Attribute.XML_BASE, feedBaseURI);
                           } else {
                              Element e = (Element)item;
                              e.setBaseURI(null);
                           }
                           level++;
                           break;
                        case ElementEndItem:
                           level--;
                     }
                     dest.send(item);
                  }
               });
            } catch (XMLException ex) {
               throw new IOException(ex.getMessage());
            }
View Full Code Here

         {
            setCharacterSet(CharacterSet.UTF_8);
            try {
               Form form = getRequest().getResourceRef().getQueryAsForm();
               String value = form.getFirstValue("value");
               generate(new WriterItemDestination(new OutputStreamWriter(os,"UTF-8"),"UTF-8"),value);
            } catch (XMLException ex) {
               getContext().getLogger().log(Level.SEVERE,"Cannot serialize metadata feed.",ex);
               throw new IOException("Cannot serialize metadata feed: "+ex.getMessage());
            }
         }
View Full Code Here

TOP

Related Classes of org.infoset.xml.util.WriterItemDestination

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.