Package org.infoset.xml

Examples of org.infoset.xml.ItemConstructor


   public void store(URI baseURI,ItemDestination dest)
      throws XMLException
   {
      String baseURIValue = baseURI.toString();
      URI baseDir = URI.create(baseURIValue.substring(0,baseURIValue.lastIndexOf('/')+1));
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument(baseURI));
      dest.send(constructor.createElement(SERVER));
      dest.send(constructor.createCharacters("\n"));
     
      Element keystoreE = constructor.createElement(KEYSTORE);
      keystoreE.setAttributeValue("href",baseDir.relativize(keyStorePath.toURI()).toString());
      keystoreE.setAttributeValue("password",keyStorePassword);
      if (!keyStorePassword.equals(keyPassword)) {
         keystoreE.setAttributeValue("key-password",keyPassword);
      }
      dest.send(keystoreE);
      dest.send(constructor.createElementEnd(KEYSTORE));
      dest.send(constructor.createCharacters("\n"));
     
      for (Interface iface : interfaces) {

         Element ifaceE = constructor.createElement(INTERFACE);
         ifaceE.setAttributeValue("address",iface.getAddress());
         ifaceE.setAttributeValue("port",Integer.toString(iface.getPort()));
         ifaceE.setAttributeValue("secure",iface.isSecure() ? "true" : "false");
         dest.send(ifaceE);

         for (Host host : iface.getHosts().values()) {

            Element hostE = constructor.createElement(HOST);
            hostE.setAttributeValue("name",host.getName());
            dest.send(hostE);
            dest.send(constructor.createElementEnd(HOST));
            dest.send(constructor.createCharacters("\n"));
         }

         dest.send(constructor.createElementEnd(INTERFACE));
         dest.send(constructor.createCharacters("\n"));
      }

      dest.send(constructor.createElementEnd(SERVER));
      dest.send(constructor.createDocumentEnd());
   }
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());
            String summary = feedRep.getSummary();
            if (summary!=null) {
               text(constructor,dest,AtomResource.SUMMARY_NAME,summary);
            }
            term(constructor,dest,Categorization.CHILD_TERM,null);
            Iterator<TermInstance<Feed>> categorization = child.getTerms();
            while (categorization.hasNext()) {
               TermInstance<Feed> category = categorization.next();
               term(constructor,dest,category.getTerm().getURI(),category.getValue());

            }
            link(constructor,dest,"related",feedRef.toString()+child.getName()+"/");
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
        
      } catch (Exception ex) {
         throw new XMLException("Exception while getting feed children.",ex);
      }
      dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

         {
            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

   {
      AuthService auth = (AuthService)getRequest().getAttributes().get(App.AUTH_SERVICE_ATTR);
      AuthCredentials cred = new AuthCredentials(getRequest().getChallengeResponse());
      final Iterator<User> users = auth.getUsers(cred);

      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(NM_USERS));
      dest.send(constructor.createCharacters("\n"));
      while (users.hasNext()) {
         User user = users.next();
         UserResource.toXML(user,new RemoveDocumentFilter(dest));
         dest.send(constructor.createCharacters("\n"));
      }
      dest.send(constructor.createElementEnd(NM_USERS));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

   }
  
   private void generate(ItemDestination dest)
      throws XMLException
   {
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(AdminXML.NM_USERS));
      dest.send(constructor.createCharacters("\n"));
      for (String group : groups.values()) {
         Element groupE = constructor.createElement(AdminXML.NM_GROUP);
         groupE.setAttributeValue("name",group);
         dest.send(groupE);
         dest.send(constructor.createElementEnd(AdminXML.NM_GROUP));
         dest.send(constructor.createCharacters("\n"));
      }
      for (User user : users.values()) {
         Element userE = constructor.createElement(AdminXML.NM_USER);
         userE.setAttributeValue("alias",user.getAlias());
         userE.setAttributeValue("id",user.getId().toString());
         userE.setAttributeValue("md5-password",passwords.get(user.getAlias()));
         userE.setAttributeValue("name",user.getName());
         if (user.getEmail()!=null) {
            userE.setAttributeValue("email",user.getName());
         }
         String groups = "";
         for (String group : user.getGroups()) {
            if (groups.length()>0) {
               groups += ",";
               groups += group;
            } else {
               groups = group;
            }
         }
         userE.setAttributeValue("groups",groups);
         dest.send(userE);
         dest.send(constructor.createElementEnd(AdminXML.NM_USER));
         dest.send(constructor.createCharacters("\n"));
      }
      dest.send(constructor.createElementEnd(AdminXML.NM_USERS));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

  
   public void generate(ItemDestination dest)
      throws XMLException
   {
      Date now = new Date();
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument());
      dest.send(constructor.createElement(AtomResource.FEED_NAME));
      link(constructor,dest,"self",getRequest().getResourceRef().toString());
      text(constructor,dest,AtomResource.TITLE_NAME,"Terms");
      text(constructor,dest,AtomResource.ID_NAME,getRequest().getResourceRef().toString());
      text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(now));
      try {
         Iterator<Term> terms = app.getDB().getTerms();
         while (terms.hasNext()) {
            Term t = terms.next();
            dest.send(constructor.createElement(AtomResource.ENTRY_NAME));
            String termRef = termBase.toString()+t.getURI();
            text(constructor,dest,AtomResource.ID_NAME,termRef);
            text(constructor,dest,AtomResource.PUBLISHED_NAME,AtomResource.toXSDDate(now));
            text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(now));
            text(constructor,dest,AtomResource.TITLE_NAME,"Term "+t.getURI());
            term(constructor,dest,Categorization.TERM_TYPE_TERM,null);
            term(constructor,dest,t.getURI(),null);
            link(constructor,dest,"related",termRef);
            dest.send(constructor.createElementEnd(AtomResource.ENTRY_NAME));
         }
      } catch (Exception ex) {
         throw new XMLException("Exception while getting terms.",ex);
      }
      dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

   protected void init(boolean loadEntries)
      throws XMLException
   {
      if (loadEntries) {
         Iterator<Element> entries = doc.getDocumentElement().getElementsByName(XML.ENTRY_NAME);
         ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
         while (entries.hasNext()) {
            Document entryDoc = constructor.createDocument(doc.getBaseURI());
            entryDoc.add((Child)entries.next().copyOfItem(true));
            add(new Entry(entryDoc));
         }
      }
   }
View Full Code Here

         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

            found = false;
            break;
         }
      }
     
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      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,getRequest().getResourceRef().toString());
      dest.send(constructor.createCharacters("\n"));
      text(constructor,dest,AtomResource.UPDATED_NAME,AtomResource.toXSDDate(new Date()));
      try {
         if (found) {
            Iterator<TermInstance<Feed>> feeds = app.getDB().getFeedsByTerm(key.dbTerm,key.value);
            while (feeds.hasNext()) {
               TermInstance<Feed> termValue = feeds.next();
               Feed feed = termValue.getTarget();
               boolean ok = true;
               for (URI otherTerm : termSet.keySet()) {
                  TermQuery other = termSet.get(otherTerm);
                  ok = feed.hasTerm(other.dbTerm, other.value);
                  if (!ok) {
                     break;
                  }
               }
               if (ok) {
                  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,app.getStorage().getFeedTitle(feed.getPath(),feed.getUUID()));
                  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));
               }
            }
            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) {
         throw new XMLException("Exception while getting ancestors.",ex);
      }
      dest.send(constructor.createCharacters("\n"));
      dest.send(constructor.createElementEnd(AtomResource.FEED_NAME));
      dest.send(constructor.createDocumentEnd());
   }
View Full Code Here

      throws IOException
   {
      OutputStreamWriter w = new OutputStreamWriter(os,getCharacterSet().toString());
      try {
         WriterItemDestination dest = new WriterItemDestination(w,getCharacterSet().toString());
         ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
         dest.send(constructor.createDocument());
         dest.send(constructor.createElement(root));
         while (iter.hasNext()) {
            DBObject obj = iter.next();
            if (obj instanceof XMLObject) {
               ((XMLObject)obj).generate(constructor,dest,contents);
            }
         }
         dest.send(constructor.createElementEnd(root));
         dest.send(constructor.createDocumentEnd());
      } catch (XMLException ex) {
         throw new IOException(ex.getMessage());
      }
      w.flush();
   }
View Full Code Here

TOP

Related Classes of org.infoset.xml.ItemConstructor

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.