Package org.infoset.xml.sax

Examples of org.infoset.xml.sax.SAXDocumentLoader


            {
               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);
                        }
                     }
View Full Code Here


                  }
                  link(constructor,dest,"related",resourceBase+feed.getPath());
                  dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
               }
            }
            DocumentLoader loader = new SAXDocumentLoader();
            Iterator<TermInstance<Entry>> entries = app.getDB().getEntriesByTerm(key.dbTerm,key.value);
            while (entries.hasNext()) {
               TermInstance<Entry> termValue = entries.next();
               Entry entry = termValue.getTarget();
               boolean ok = true;
               for (URI otherTerm : termSet.keySet()) {
                  TermQuery other = termSet.get(otherTerm);
                  ok = entry.hasTerm(other.dbTerm, other.value);
                  if (!ok) {
                     break;
                  }
               }
               if (ok) {
                  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();
                  loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));
               }
              
            }
         }
      } catch (Exception ex) {
View Full Code Here

      super.loadSchema(name, connection, sqlLocation);
      if (name.equals("auth")) {
         URL defaultDB = this.getClass().getResource("default-db.xml");
         if (defaultDB!=null) {
            try {
               DocumentLoader loader = new SAXDocumentLoader();
               RestoreDestination restore = new RestoreDestination(LOG,this);
               loader.generate(defaultDB.toURI(), restore);
            } catch (XMLException ex) {
               throw new IOException(ex.getMessage());
            } catch (URISyntaxException ex) {
               throw new IOException(ex.getMessage());
            }
View Full Code Here

                  term(constructor,dest,fterm.getTerm().getURI(),fterm.getValue());
               }
               link(constructor,dest,"related",resourceBase+feed.getPath());
               dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
            }
            DocumentLoader loader = new SAXDocumentLoader();
            Iterator<TermInstance<Entry>> entries = app.getDB().getEntriesByTerm(dbTerm,value);
            while (entries.hasNext()) {
               TermInstance<Entry> termValue = entries.next();
               Entry entry = termValue.getTarget();
               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();
               loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));
              
            }
         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting ancestors.",ex);
View Full Code Here

               if (progress.update) {
                  progress.status = appResponse.getStatus().getCode();
               } else {
                  try {
                     Reader r = appResponse.getEntity().getReader();
                     DocumentLoader loader = new SAXDocumentLoader();
                     Document entryDoc = loader.load(r);
                     Entry entry = new Entry(entryDoc);
                     entry.index();
                     progress.entryId = entry.getId();
                     progress.status = appResponse.getStatus().getCode();
                     getLogger().info("Entry: "+progress.entryId+", status="+progress.status);
View Full Code Here

      throws ConfigurationException
   {
      Map<String,DB> dbList = new HashMap<String,DB>();
      File dbConf = new File(dir,"db.conf");
      if (dbConf.exists()) {
         DocumentLoader loader = new SAXDocumentLoader();
         try {
            Document doc =loader.load(dbConf.toURI());
            Iterator<Element> databases = doc.getDocumentElement().getElementsByName(AdminXML.NM_DATABASE);
            while (databases.hasNext()) {
               Element databaseE = databases.next();
               URI href = databaseE.getBaseURI().resolve(databaseE.getAttributeValue("href"));
               if (!href.getScheme().equals("file")) {
View Full Code Here

     
   }
   public void load(URI location)
      throws IOException,XMLException
   {
      DocumentLoader loader = new SAXDocumentLoader();
      Document doc = loader.load(location);
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(SERVER)) {
         throw new XMLException("Expecting "+SERVER+" but found "+top.getName());
      }
      String value = top.getAttributeValue("autoconf-check");
View Full Code Here

            // avoid thread creation because reading an output representation requires a thread
            StringWriter sw = new StringWriter();
            rep.write(sw);
            rep.release();
            DocumentLoader loader = new SAXDocumentLoader();
            loader.generate(new StringReader(sw.toString()), new RemoveDocumentFilter(dest));

         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting ancestors.",ex);
      }
View Full Code Here

   {
      XMLDBStorage storage = cache.get(db.getName());
      if (storage==null) {
         File dbDir = db.getDatabaseDir();
         File xmldbDir = new File(dbDir,"xmldb");
         storage = new XMLDBStorage(xmldbDir,db.getName(),new Reference("riap://component/exist/"+db.getName()+"/"),new SAXDocumentLoader());
         cache.put(db.getName(),storage);
         storage.init(context);
      }
      return storage;
   }
View Full Code Here

         // Should be an entry
         Document doc = null;
         if (entity instanceof InfosetRepresentation) {
            doc = ((InfosetRepresentation)entity).getDocument();
         } else {
            DocumentLoader loader = new SAXDocumentLoader();
            try {
               Reader r = new InputStreamReader(entity.getStream(),charset);
               doc = loader.load(r);
               r.close();
            } catch (IOException ex) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("I/O error while parsing document: "+ex.getMessage());
            } catch (XMLException ex) {
View Full Code Here

TOP

Related Classes of org.infoset.xml.sax.SAXDocumentLoader

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.