Package org.atomojo.app.client

Examples of org.atomojo.app.client.Term


      return vhost;
   }
  
   static String getTerm(Entry entry,URI uterm)
   {
      Term term = entry.getTerm(uterm);
      return term==null ? null : term.getFirstValue();
   }
View Full Code Here


            List<SecurityGuard.SecureRoute> copyOfRoutes = new ArrayList<SecurityGuard.SecureRoute>();
            copyOfRoutes.addAll(security.getRoutes());
            try {
               security.getRoutes().clear();
               for (Entry entry : feed.getEntriesByTerm(T_SECURITY_PROTECTED_PATH)) {
                  Term paths = entry.getTerm(T_SECURITY_PROTECTED_PATH);

                  getLogger().info("Security entry "+entry.getId());
                  String unauthorized = getTerm(entry,T_SECURITY_REDIRECT_UNAUTHORIZED);
                  Reference unauthorizedRef = unauthorized==null ? null : new Reference(unauthorized);
                  String login = getTerm(entry,T_SECURITY_REDIRECT_UNAUTHORIZED);
                  Reference loginRef = login==null ? null : new Reference(login);
                 
                  try {
                     Set<UUID> groups = new TreeSet<UUID>();
                     Term groupSpec = entry.getTerm(T_SECURITY_GROUP_ID);
                     if (groupSpec!=null) {
                        for (String id : groupSpec.getValues()) {
                           UUID uuid = UUID.fromString(id);
                           groups.add(uuid);
                           getLogger().info("... group "+uuid+" required.");
                        }
                     }
                     Set<UUID> roles = new TreeSet<UUID>();
                     Term rolesSpec = entry.getTerm(T_SECURITY_ROLE_ID);
                     if (rolesSpec!=null) {
                        for (String id : rolesSpec.getValues()) {
                           UUID uuid = UUID.fromString(id);
                           roles.add(uuid);
                           getLogger().info("... role "+uuid+" required.");
                        }
                     }
View Full Code Here

               for (Term term : entry.getTerms().values()) {
                  if (!term.getURI().toString().startsWith(base)) {
                     criteria.add(term);
                  }
               }
               Term match = entry.getTerm(T_LAYOUT_MATCH);
               Term mediaTypeT = entry.getTerm(T_LAYOUT_MEDIA_TYPE);
               Term priorityT = entry.getTerm(T_LAYOUT_PRIORITY);
               MediaType mediaType = mediaTypeT==null ? MediaType.APPLICATION_XHTML_XML : MediaType.valueOf(mediaTypeT.getFirstValue());
               String matchValue = match==null ? null : match.getFirstValue();
               if (matchValue==null && match!=null) {
                  // set the value to the empty string
                  matchValue = "";
               }
               int priority = priorityT==null ? -1 : Integer.parseInt(priorityT.getFirstValue());
               if (info!=null) {
                  getLogger().info("Reloading script entry "+id+", location="+location);
                  scriptManager.reload(id,entry.getEdited(),criteria,matchValue,priority,mediaType);
               } else {
                  getLogger().info("Configuring script entry "+id+", location="+location);
View Full Code Here

            String base = T_BASE.toString();
            for (Entry entry : feed.getEntriesByTerm(T_RESOURCE)) {
               String id = entry.getId();
               ids.add(id);
               ResourceManager.Entry info = resourceManager.get(id);
               Term nameT = entry.getTerm(T_RESOURCE_NAME);
               Term pathT = entry.getTerm(T_RESOURCE_PATH);
               Term relationT = entry.getTerm(T_RESOURCE_RELATION);
               Term queryT = entry.getTerm(T_RESOURCE_QUERY);
               Term mediaTypeT = entry.getTerm(T_RESOURCE_MEDIA_TYPE);
               if (nameT==null || nameT.getFirstValue()==null) {
                  getLogger().warning("Ignoring resource "+id+" without a name.");
                  continue;
               }
               String name = nameT.getFirstValue();
               if (info!=null && entry.getEdited().equals(info.getEdited())) {
                  getLogger().info("Resource entry "+id+" named "+name+" not modified.");
                  continue;
               }
               String query = null;
               if (queryT==null || queryT.getFirstValue()==null) {
                  Text text = entry.getContent();
                  if (text.getSourceLink()!=null) {
                     URI location = text.getElement().getBaseURI().resolve(text.getSourceLink());
                  }
               } else {
                  query = queryT.getFirstValue();
               }
               MediaType mediaType = mediaTypeT==null ? null : MediaType.valueOf(mediaTypeT.getFirstValue());
               if (info!=null) {
                  getLogger().info("Reloading resource entry "+id+" named "+name);
                  resourceManager.reload(id,entry.getEdited(),name,pathT==null ? null : pathT.getFirstValue(),relationT==null ? null : relationT.getFirstValue(),mediaType,query);
               } else {
                  getLogger().info("Configuring resource entry "+id+" named "+name);
View Full Code Here

            Set<String> ids = new TreeSet<String>();
            List<Entry> entries = new ArrayList<Entry>();
            entries.addAll(feed.getEntriesByTerm(T_APP));
            Comparator<Entry> sorter = new Comparator<Entry>() {
               public int compare(Entry A, Entry B) {
                  Term AP = A.getTerm(T_APP_PRIORITY);
                  Term BP = B.getTerm(T_APP_PRIORITY);
                  //getLogger().info("A: "+A.getTitle()+" "+AP+" vs B: "+B.getTitle()+" "+BP);
                  if (BP==null && AP==null) {
                     return 0;
                  } else if (AP!=null && BP==null) {
                     return -1;
                  } else if (AP==null && BP!=null) {
                     return 1;
                  } else {
                     int a = Integer.parseInt(AP.getFirstValue());
                     int b = Integer.parseInt(BP.getFirstValue());
                     return a>b ? -1 : a==b ? 0 : 1;
                  }
               }
               public boolean equals(Object obj) {
                  return obj==this;
               }
            };
            Collections.sort(entries,sorter);
            Collections.reverse(entries);
            for (Entry entry : entries) {
               found = true;
               URI baseURI = entry.getDocument().getBaseURI();
               Term priority = entry.getTerm(T_APP_PRIORITY);
               getLogger().info("Application: title: "+entry.getTitle()+", base: "+baseURI+", priority: "+(priority==null ? "" : priority.getFirstValue()));
               ids.add(entry.getId());
              
               boolean exact = false;
               if (entry.getTerm(T_APP_MATCH_MODE)!=null) {
                  exact = "exact".equals(entry.getTerm(T_APP_MATCH_MODE).getFirstValue());
               }
              
               AppInfo appInfo = applications.get(entry.getId());
               if (appInfo!=null && appInfo.edited.getTime()>=entry.getEdited().getTime()) {
                  // reattach to make sure it is in the right order
                  router.detach(appInfo.app);
                  Term match = entry.getTerm(T_APP_MATCH);
                  if (match!=null && match.getValues()!=null) {
                     for (String pattern : match.getValues()) {
                        TemplateRoute route = router.attach(pattern,appInfo.app);
                        if (exact) {
                           route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
                        }
                     }
                  } else {
                     TemplateRoute route = router.attach("",appInfo.app);
                     if (exact) {
                        route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
                     }
                  }
                  getLogger().info("No changes, skipping.");
                  continue;
               }
               for (Term t : entry.getTerms().values()) {
                  getLogger().info(t.getURI()+": "+t.getFirstValue());
               }
               getLogger().info(T_APP_MATCH.toString());
               Term classTerm = entry.getTerm(T_APP_CLASS);
               Term proxyTerm = entry.getTerm(T_APP_PROXY);
               Context appContext = context.createChildContext();
               LinkSet set = new LinkSet();
               set.addLinkSet(entry.getLinks());
               set.addLinkSet(hostConf.getLinks());
               appContext.getAttributes().put(WebComponent.LINKS_ATTR,set);
               appContext.getAttributes().put(ScriptManager.ATTR,scriptManager);
               appContext.getAttributes().put(ResourceManager.ATTR,resourceManager);
               for (URI t : entry.getTerms().keySet()) {
                  String value = entry.getTerm(t).getFirstValue();
                  getLogger().info("Setting parameter: "+t+"="+value);
                  appContext.getParameters().set(t.toString(),value,false);
               }
               appContext.getParameters().set("username",autoConf.getUsername(),false);
               appContext.getParameters().set("password",autoConf.getPassword(),false);
               for (Term t : entry.getTerms().values()) {
                  String key = t.getURI().toString();
                  if (t.getValues()!=null) {
                     for (String value : t.getValues()) {
                        appContext.getParameters().add(key, value);
                     }
                  } else {
                     appContext.getParameters().add(key,"true");
                  }
               }
               Application app = null;
               if (proxyTerm!=null) {
                  String value = proxyTerm.getFirstValue();
                  List<Link> links = entry.getLinks().get(value);
                  Link target = null;
                  if (links!=null && links.size()>0) {
                     target = links.get(0);
                  }
                  if (target==null) {
                     links = hostConf.getLinks().get(value);
                     if (links!=null && links.size()>0) {
                        target = links.get(0);
                     }
                  }
                  if (target!=null) {
                     app = new ProxyApplication(appContext,target);
                  }
               } else if (classTerm!=null) {
                  String className = classTerm.getFirstValue();
                  List<Link> libraryLinks = entry.getLinks().get("library");
                  String href = null;
                  Text text = entry.getContent();
                  if (text!=null) {
                     href = text.getSourceLink();
                  }
                  Class<Application> appClass = null;
                  Class<?> foundClass = null;
                  if ((libraryLinks==null || libraryLinks.size()==0) && href==null) {
                     foundClass = Class.forName(className);
                  } else {
                     URL [] downloads = new URL[(libraryLinks==null ? 0 : libraryLinks.size())+(href==null ? 0 : 1)];
                     if (href!=null) {
                        downloads[0] = entry.getDocument().getDocumentElement().getBaseURI().resolve(href).toURL();
                     }
                     if (libraryLinks!=null) {
                        for (int pos = href==null ? 0 : 1; pos<libraryLinks.size(); pos++) {
                           Link link = libraryLinks.get(pos);
                           downloads[pos] = link.getLink().toURL();
                        }
                     }
                    
                     URL [] urls = new URL[downloads.length];
                     for (int i=0; i<downloads.length; i++) {
                        File jarfile = File.createTempFile("jar-T"+System.currentTimeMillis()+"-", ".jar");
                        urls[i] = jarfile.toURL();
                        URLRetriever retriever = new URLRetriever(downloads[i]);
                        try {
                           retriever.retrieve(jarfile, autoConf.getUsername(), autoConf.getPassword());
                        } catch (IOException ex) {
                           getLogger().info("Cannot download "+downloads[i]+" due to: "+ex.getMessage());
                           continue;
                        }
                     }
                     URLClassLoader classLoader = new URLClassLoader(urls,ConfiguredHost.class.getClassLoader()) {
                        protected PermissionCollection getPermissions(CodeSource source) {
                           PermissionCollection collection = super.getPermissions(source);
                           URL url = source.getLocation();
                           getLogger().info("Code source: "+url);
                           Enumeration<Permission> permissions = collection.elements();
                           while (permissions.hasMoreElements()) {
                              Permission p = permissions.nextElement();
                              getLogger().info("Permission: "+p.getName()+", "+p.getClass().getName()+", action: "+p.getActions());
                           }
                           return collection;
                        }
                     };
                     foundClass = classLoader.loadClass(className);
                     PermissionCollection collection = foundClass.getProtectionDomain().getPermissions();
                     Enumeration<Permission> permissions = collection.elements();
                     while (permissions.hasMoreElements()) {
                        Permission p = permissions.nextElement();
                        getLogger().info("Permission: "+p.getName()+", "+p.getClass().getName()+", action: "+p.getActions());
                     }
                  }
                  if (!Application.class.isAssignableFrom(foundClass)) {
                     getLogger().info("Class "+className+" is not an subclas of "+Application.class.getName());
                     continue;
                  }
                  appClass = (Class<Application>)foundClass;
                  Constructor<Application> makeit = appClass.getConstructor(Context.class);
                  app = makeit.newInstance(appContext);
               }
               if (app!=null) {
                  if (appInfo!=null) {
                     router.detach(appInfo.app);
                     appInfo.app = app;
                     appInfo.edited = entry.getEdited();
                     Term match = entry.getTerm(T_APP_MATCH);
                     if (match!=null && match.getValues()!=null) {
                        for (String pattern : match.getValues()) {
                           TemplateRoute route = router.attach(pattern,app);
                           if (exact) {
                              route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
                           }
                        }
                     } else {
                        TemplateRoute route = router.attach("",app);
                        if (exact) {
                           route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
                        }
                     }
                  } else {
                     applications.put(entry.getId(),new AppInfo(app,entry.getEdited()));
                     Term match = entry.getTerm(T_APP_MATCH);
                     if (match!=null && match.getValues()!=null) {
                        for (String pattern : match.getValues()) {
                           TemplateRoute route = router.attach(pattern,app);
                           if (exact) {
                              route.getTemplate().setMatchingMode(Template.MODE_EQUALS);
                           }
                        }
View Full Code Here

                 
                  if (entry.getTerm(REALM_TERM)==null) {
                     // ignore non-realm entry
                     return;
                  }
                  Term nameT = entry.getTerm(REALM_NAME_TERM);
                  if (nameT==null) {
                     return;
                  }
                  String name = nameT.getFirstValue();
                  List<Link> services = entry.getLinks().get("service");
                  if (services==null) {
                     getLogger().warning("Missing 'service' relation link on realm "+name);
                  } else {
                     URI service = services.get(0).getLink();
                     AuthProtocolService auth = (AuthProtocolService)autoServices.get(name);
                     if (auth!=null) {
                        if (!auth.getServiceURI().equals(service)) {
                           // The service URI has changed
                           autoServices.remove(name);
                           auth = null;
                           changedAuth.put(name,Boolean.TRUE);
                        }
                     }
                     if (auth==null) {
                        getLogger().info("Adding realm "+name+" from service "+service);
                        auth = new AuthProtocolService();
                        Properties props = new Properties();
                        props.setProperty("href",service.toString());
                        try {
                           auth.init(props);
                           autoServices.put(name,auth);
                           currentAuthList.put(name,Boolean.TRUE);
                        } catch (AuthException ex) {
                           getLogger().log(Level.SEVERE,"Cannot initialize auth service for realm "+name,ex);
                        }
                     }
                  }
               }
            });
           
            // Configure the databases
            final Map<String,Boolean> currentDBList = new TreeMap<String,Boolean>();
            for (Entry entry : dbToDo) {
               Term nameT = entry.getTerm(DB_NAME_TERM);
               if (nameT==null) {
                  getLogger().warning("Ignoring db entry that does not have name term "+DB_NAME_TERM);
                  return;
               }
               Term authT = entry.getTerm(DB_AUTH_TERM);
               if (authT==null) {
                  getLogger().warning("Ignoring db entry that does not have auth term "+DB_AUTH_TERM);
                  return;
               }
               Term groupT = entry.getTerm(DB_GROUP_TERM);
               Term aliasT = entry.getTerm(DB_ALIAS_TERM);
               String dbName = nameT.getFirstValue();
               String authName = authT.getFirstValue();
               if (dbName==null) {
                  getLogger().warning("Ignoring db entry where name term "+DB_NAME_TERM+" does not have a value.");
                  return;
               }
               if (authName==null) {
                  getLogger().warning("Ignoring db entry where auth term "+DB_NAME_TERM+" does not have a value.");
                  return;
               }
               AuthService auth = services.get(authName);
               if (auth==null) {
                  auth = autoServices.get(authName);
               }
               if (auth==null) {
                  getLogger().warning("Cannot configure db entry for "+dbName+" as auth service "+authName+" does not exist.");
                  return;
               }
               DBInfo dbinfo = autodbList.get(dbName);
               Storage storage = null;
               if (dbinfo==null) {
                  getLogger().info("Creating DB "+dbName);
                  DB db = new DB(getLogger(),new File(dbDir,dbName));
                  dbinfo = new DBInfo(dbName,db,auth,groupT!=null ?  groupT.getFirstValue() : null, aliasT!=null ? aliasT.getFirstValue() : null);
                  storage = storageFactory.getStorage(db);
                  try {
                     getLogger().info("Connecting to DB "+dbName);
                     db.connect();
                     getLogger().info("Connected to DB "+dbName);
View Full Code Here

      return vhost;
   }
  
   static String getTerm(Entry entry,URI uterm)
   {
      Term term = entry.getTerm(uterm);
      return term==null ? null : term.getFirstValue();
   }
View Full Code Here

            List<SecurityGuard.SecureRoute> copyOfRoutes = new ArrayList<SecurityGuard.SecureRoute>();
            copyOfRoutes.addAll(security.getRoutes());
            try {
               security.getRoutes().clear();
               for (Entry entry : feed.getEntriesByTerm(T_SECURITY_PROTECTED_PATH)) {
                  Term paths = entry.getTerm(T_SECURITY_PROTECTED_PATH);

                  getLogger().info("Security entry "+entry.getId());
                  String unauthorized = getTerm(entry,T_SECURITY_REDIRECT_UNAUTHORIZED);
                  Reference unauthorizedRef = unauthorized==null ? null : new Reference(unauthorized);
                  String login = getTerm(entry,T_SECURITY_REDIRECT_UNAUTHORIZED);
                  Reference loginRef = login==null ? null : new Reference(login);
                 
                  try {
                     Set<UUID> groups = new TreeSet<UUID>();
                     Term groupSpec = entry.getTerm(T_SECURITY_GROUP_ID);
                     if (groupSpec!=null) {
                        for (String id : groupSpec.getValues()) {
                           UUID uuid = UUID.fromString(id);
                           groups.add(uuid);
                           getLogger().info("... group "+uuid+" required.");
                        }
                     }
                     Set<UUID> roles = new TreeSet<UUID>();
                     Term rolesSpec = entry.getTerm(T_SECURITY_ROLE_ID);
                     if (rolesSpec!=null) {
                        for (String id : rolesSpec.getValues()) {
                           UUID uuid = UUID.fromString(id);
                           roles.add(uuid);
                           getLogger().info("... role "+uuid+" required.");
                        }
                     }
View Full Code Here

               for (Term term : entry.getTerms().values()) {
                  if (!term.getURI().toString().startsWith(base)) {
                     criteria.add(term);
                  }
               }
               Term match = entry.getTerm(T_LAYOUT_MATCH);
               Term mediaTypeT = entry.getTerm(T_LAYOUT_MEDIA_TYPE);
               Term priorityT = entry.getTerm(T_LAYOUT_PRIORITY);
               MediaType mediaType = mediaTypeT==null ? MediaType.APPLICATION_XHTML_XML : MediaType.valueOf(mediaTypeT.getFirstValue());
               String matchValue = match==null ? null : match.getFirstValue();
               if (matchValue==null && match!=null) {
                  // set the value to the empty string
                  matchValue = "";
               }
               int priority = priorityT==null ? -1 : Integer.parseInt(priorityT.getFirstValue());
               if (info!=null) {
                  getLogger().info("Reloading script entry "+id+", location="+location);
                  scriptManager.reload(id,entry.getEdited(),criteria,matchValue,priority,mediaType);
               } else {
                  getLogger().info("Configuring script entry "+id+", location="+location);
View Full Code Here

            String base = T_BASE.toString();
            for (Entry entry : feed.getEntriesByTerm(T_RESOURCE)) {
               String id = entry.getId();
               ids.add(id);
               ResourceManager.Entry info = resourceManager.get(id);
               Term nameT = entry.getTerm(T_RESOURCE_NAME);
               Term pathT = entry.getTerm(T_RESOURCE_PATH);
               Term relationT = entry.getTerm(T_RESOURCE_RELATION);
               Term queryT = entry.getTerm(T_RESOURCE_QUERY);
               Term mediaTypeT = entry.getTerm(T_RESOURCE_MEDIA_TYPE);
               if (nameT==null || nameT.getFirstValue()==null) {
                  getLogger().warning("Ignoring resource "+id+" without a name.");
                  continue;
               }
               String name = nameT.getFirstValue();
               if (info!=null && entry.getEdited().equals(info.getEdited())) {
                  getLogger().info("Resource entry "+id+" named "+name+" not modified.");
                  continue;
               }
               String query = null;
               if (queryT==null || queryT.getFirstValue()==null) {
                  Text text = entry.getContent();
                  if (text.getSourceLink()!=null) {
                     URI location = text.getElement().getBaseURI().resolve(text.getSourceLink());
                  }
               } else {
                  query = queryT.getFirstValue();
               }
               MediaType mediaType = mediaTypeT==null ? null : MediaType.valueOf(mediaTypeT.getFirstValue());
               if (info!=null) {
                  getLogger().info("Reloading resource entry "+id+" named "+name);
                  resourceManager.reload(id,entry.getEdited(),name,pathT==null ? null : pathT.getFirstValue(),relationT==null ? null : relationT.getFirstValue(),mediaType,query);
               } else {
                  getLogger().info("Configuring resource entry "+id+" named "+name);
View Full Code Here

TOP

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

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.