Package org.infoset.xml

Examples of org.infoset.xml.Element


                  Text text = entry.getContent();
                  if (text == null || !text.isXML()) {
                     getContext().getLogger().warning("Ignoring host entry with missing or has incorrectly typed content for configuration.");
                     return;
                  }
                  Element hostE = text.getContent();
                  if (hostE == null) {
                     getContext().getLogger().warning("Ignoring host entry with empty content.");
                     return;
                  }
View Full Code Here


   }
   public void load(URI location)
      throws IOException,XMLException
   {
      Document doc = docLoader.load(location);
      Element top = doc.getDocumentElement();
      if (!top.getName().equals(COMPONENT)) {
         throw new XMLException("Expecting "+COMPONENT+" but found "+top.getName());
      }
      String value = top.getAttributeValue("autoconf-check");
      if (value!=null) {
         autoconfCheck = Long.parseLong(value) * 1000;
      }
     
      Element keyStoreE = top.getFirstElementNamed(KEYSTORE);
      if (keyStoreE!=null) {
         URI fileRef = keyStoreE.getBaseURI().resolve(keyStoreE.getAttributeValue("file"));
         this.keyStorePath = new File(fileRef.getSchemeSpecificPart());
         this.keyStorePassword = keyStoreE.getAttributeValue("password");
      }
     
      Iterator<Element> appdefElements = top.getElementsByName(DEFINE);
      while (appdefElements.hasNext()) {
         Element appdefE = appdefElements.next();
         String name = appdefE.getAttributeValue("name");
         String className = appdefE.getAttributeValue("class");
        
         String ref = appdefE.getAttributeValue("ref");
         if (ref!=null) {
            ClassLoader theLoader = loaders.get(ref.trim());
            if (theLoader==null) {
               throw new XMLException("Cannot find definition: "+ref);
            }
            if (className==null || name==null) {
               continue;
            }
            try {
               Class cdef = theLoader.loadClass(className);
               definitions.put(name,cdef);
            } catch (ClassNotFoundException ex) {
               throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
            }
            continue;
         }
        
         if (name!=null) {
            List<URL> libraries = new ArrayList<URL>();
            Iterator<Element> libraryElements = appdefE.getElementsByName(LIBRARY);
            while (libraryElements.hasNext()) {
               Element libE = libraryElements.next();
               String href = libE.getAttributeValue("href");
               if (href!=null) {
                  URI u = libE.getBaseURI().resolve(href);
                  libraries.add(u.toURL());
               }
            }
            ClassLoader theLoader = this.getClass().getClassLoader();
            if (libraries.size()!=0) {
               URL [] list = new URL[libraries.size()];
               list = libraries.toArray(list);
               theLoader = new URLClassLoader(list,this.getClass().getClassLoader());
               LOG.fine("ClassLoader: "+name+" -> "+theLoader);
               LOG.fine("  Libraries: "+libraries);
               loaders.put(name, theLoader);
            }
            if (className!=null) {
               try {
                  Class cdef = theLoader.loadClass(className);
                  definitions.put(name,cdef);
               } catch (ClassNotFoundException ex) {
                  throw new XMLException("Cannot find class: "+ex.getMessage(),ex);
               }
            }
         } else if (name!=null) {
            LOG.warning("The 'class' attribute is missing on the definition of '"+name+"'");
         }
      }
     
      Iterator<Element> clientElements = top.getElementsByName(CLIENT);
      while (clientElements.hasNext()) {
         Element clientDef = clientElements.next();
         String protocol = clientDef.getAttributeValue("protocol");
         if (protocol!=null) {
            Protocol p = Protocol.valueOf(protocol.trim());
            clients.add(p);
         }
      } 
     
      Iterator<Element> interfaceElements = top.getElementsByName(SERVER);
      while (interfaceElements.hasNext()) {
         Element serverE = interfaceElements.next();
         String addr = serverE.getAttributeValue("address");
         String portS = serverE.getAttributeValue("port");
         String protocol = serverE.getAttributeValue("protocol");
         Protocol p = Protocol.HTTP;
         if (protocol!=null) {
            p = Protocol.valueOf(protocol.trim());
         }
         int port = portS==null ? p.getDefaultPort() : Integer.parseInt(portS);
         Server server = new Server(addr,port,p);
         servers.add(server);
        
         Iterator<Element> links = serverE.getElementsByName(LINK);
         while (links.hasNext()) {
            Element linkE = links.next();
            String href = linkE.getAttributeValue("href");
            if (href!=null) {
               URI tlocation = linkE.getBaseURI().resolve(href);
               String mtype = linkE.getAttributeValue("type");
               Link l = new Link(linkE.getAttributeValue("rel"),mtype==null ? null : MediaType.valueOf(mtype),tlocation);
               l.setIdentity(linkE.getAttributeValue("username"),linkE.getAttributeValue("password"));
               if (l.getRelation()!=null) {
                  server.getLinks().put(l.getRelation(),l);
               }
            }
         }
        
         Iterator<Element> hostElements = serverE.getElementsByName(HOST);
         while (hostElements.hasNext()) {
            Element hostE = hostElements.next();
            Host host = createHost(hostE);
            server.getHosts().put(host.getName(),host);
         }
      }
     
View Full Code Here

         this.internalName = internalName;
         this.conf = conf;
         this.logConf = new HashMap<String,String>();
         Iterator<Element> logs = conf.getElementsByName(LOG_E);
         if (logs.hasNext()) {
            Element logE = logs.next();
            for (Name attName : logE.getAttributes().keySet()) {
               logConf.put(attName.toString(),logE.getAttributeValue(attName));
            }
         }
         this.linkSet = new LinkSet();
         Iterator<Element> links = conf.getElementsByName(LINK);
         while (links.hasNext()) {
            Element linkE = links.next();
            String href = linkE.getAttributeValue("href");
            if (href!=null) {
               URI tlocation = linkE.getBaseURI().resolve(href);
               String mtype = linkE.getAttributeValue("type");
               Link l = new Link(linkE.getAttributeValue("rel"),mtype==null ? null : MediaType.valueOf(mtype),tlocation);
               l.setIdentity(linkE.getAttributeValue("username"),linkE.getAttributeValue("password"));
               if (l.getRelation()!=null) {
                  linkSet.put(l.getRelation(),l);
               }
            }
         }
View Full Code Here

            } else {
               filter.setNext(childFilter);
            }
            Iterator<Element> elements = child.getElementChildren();
            while (elements.hasNext()) {
               Element nextChild = elements.next();
               if (nextChild.getName().equals(NEXT)) {
                  Iterator<Element> nextChildren = nextChild.getElementChildren();
                  while (nextChildren.hasNext()) {
                     attachNext(childFilter,nextChildren.next());
                  }
               }
            }
View Full Code Here

      }
     
      protected boolean hasParametersOrAttributes(Element useConf) {
         Iterator<Element> children = useConf.getElementChildren();
         if (children.hasNext()) {
            Element child = children.next();
            return child.getName().equals(PARAMETER) || child.getName().equals(ATTRIBUTE);
         }
         return false;
      }
View Full Code Here

            if (!hasLinks) {
               LinkSet set = new LinkSet();
               set.addLinkSet(linkSet);
               confLinks = set;
            }
            Element linkE = appLinks.next();
            String href = linkE.getAttributeValue("href");
            if (href!=null) {
               URI tlocation = linkE.getBaseURI().resolve(href);
               String mtype = linkE.getAttributeValue("type");
               Link l = new Link(linkE.getAttributeValue("rel"),mtype==null ? null : MediaType.valueOf(mtype),tlocation);
               l.setIdentity(linkE.getAttributeValue("username"),linkE.getAttributeValue("password"));
               if (l.getRelation()!=null) {
                  confLinks.put(l.getRelation(),l);
               }
            }
         }
View Full Code Here

      {
         LOG.fine("Loading context: "+appContext);
        
         Iterator<Element> children = useConf.getElementChildren();
         while (children.hasNext()) {
            Element child = children.next();
            if (child.getName().equals(ATTRIBUTE)) {
               Element attrE = child;
               String name = attrE.getAttributeValue("name");
               String value = attrE.getAttributeValue("value");
               String href = attrE.getAttributeValue("href");
               if (href!=null) {
                  value = attrE.getBaseURI().resolve(href).toString();
               }
               Class def = getTargetClass(attrE);
               if (value!=null) {
                  LOG.fine("Attribute: "+name+"="+value);
                  appContext.getAttributes().put(name,value);
               } else if (def!=null) {
                  try {
                     Object obj = null;
                     try {
                        Constructor<Object> makeit = def.getConstructor(Context.class);
                        obj = makeit.newInstance(appContext);
                     } catch (NoSuchMethodException ex) {
                        Constructor<Restlet> makeit = def.getConstructor();
                        obj = makeit.newInstance();
                     }
                     LOG.fine("Attribute: "+name+"="+obj);
                     appContext.getAttributes().put(name,obj);
                  } catch (Exception ex) {
                     LOG.log(Level.SEVERE,"Cannot instantiate "+def.getName()+" for attribute "+name);
                  }
               } else {
                  List<Object> values = new ArrayList<Object>();
                  Iterator<Element> attChildren = attrE.getElementChildren();
                  while (attChildren.hasNext()) {
                     Element attChild = attChildren.next();
                     if (attChild.getName().equals(PARAMETER)) {
                        String pname = attChild.getAttributeValue("name");
                        if (pname!=null) {
                           String pvalue = attChild.getAttributeValue("value");
                           String phref = attChild.getAttributeValue("href");
                           if (phref!=null) {
                              pvalue = attChild.getBaseURI().resolve(phref).toString();
                           }
                           if (pvalue==null) {
                              pvalue = "";
                           }
                           values.add(new Parameter(pname,pvalue));
                        }
                     } else {
                        // Switch to DOM
                        try {
                           StringWriter xml = new StringWriter();
                           XMLWriter.writeElement(attChild, xml);
                           LOG.fine("Attribute XML: "+xml.toString());
                           values.add(docBuilder.parse(new InputSource(new StringReader(xml.toString()))));
                        } catch (Exception ex) {
                           LOG.log(Level.SEVERE,"Cannot serialize attribute XML.",ex);
                        }

                     }
                  }
                  LOG.fine("Attribute: "+name+" is list of values.");
                  appContext.getAttributes().put(name,values);
               }
            } else if (child.getName().equals(PARAMETER)) {
               Element paramE = child;
               String pname = paramE.getAttributeValue("name");
               if (pname!=null) {
                  String value = paramE.getAttributeValue("value");
                  String href = paramE.getAttributeValue("href");
                  if (href!=null) {
                     value = paramE.getBaseURI().resolve(href).toString();
                  }
                  String resource = paramE.getAttributeValue("resource");
                  String ref = paramE.getAttributeValue("ref");
                  LOG.fine("resource="+resource+", ref="+ref);
                  if (resource!=null && ref!=null) {
                     ClassLoader loader = loaders.get(ref);
                     if (loader==null) {
                        Class targetClass = definitions.get(ref);
                        if (targetClass!=null) {
                           targetClass.getClassLoader();
                        }
                     }
                     if (loader!=null) {
                        URL uvalue = loader.getResource(resource);
                        if (uvalue!=null) {
                           value = uvalue.toString();
                        }
                     } else {
                        LOG.warning("Cannot find definition of "+ref);
                     }
                  }
                  if (value==null) {
                     value = "";
                  }
                  LOG.fine("Setting parameter "+pname+"="+value);
                  if ("true".equals(paramE.getAttributeValue("replace"))) {
                     Parameter toRemove;
                     while ((toRemove = appContext.getParameters().getFirst(pname))!=null) {
                        appContext.getParameters().remove(toRemove);
                     }
                  }
                  appContext.getParameters().add(pname,value);
               }
              
            } else if (child.getName().equals(INCLUDE)) {
               String href = child.getAttributeValue("href");
               if (href==null) {
                  continue;
               }
               URI location = child.getBaseURI().resolve(href);
               try {
                  Document included = docLoader.load(location);
                  Element top = included.getDocumentElement();
                  if (!top.getName().equals(CONTEXT)) {
                     continue;
                  }
                  loadContext(appContext,top);
               } catch (Exception ex) {
                  LOG.log(Level.SEVERE,"Cannot load included document: "+location,ex);
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());
      }
     
      Element keyStoreE = top.getFirstElementNamed(KEYSTORE);
      if (keyStoreE!=null) {
         URI fileRef = keyStoreE.getBaseURI().resolve(keyStoreE.getAttributeValue("href"));
         this.keyStorePath = new File(fileRef.getSchemeSpecificPart());
         this.keyStorePassword = keyStoreE.getAttributeValue("password");
         this.keyPassword = keyStoreE.getAttributeValue("key-password");
      }
     
      Iterator<Element> interfaceElements = top.getElementsByName(INTERFACE);
      while (interfaceElements.hasNext()) {
         Element interfaceE = interfaceElements.next();
         String addr = interfaceE.getAttributeValue("address");
         String portS = interfaceE.getAttributeValue("port");
         boolean secure = interfaceE.getAttributeValue("secure")==null || "true".equals(interfaceE.getAttributeValue("secure"));
         int port = portS==null ? (secure ? 443 : 80) : Integer.parseInt(portS);
         Interface iface = new Interface(addr,port,secure);
         interfaces.add(iface);
         Iterator<Element> hostElements = interfaceE.getElementsByName(HOST);
         while (hostElements.hasNext()) {
            Element hostE = hostElements.next();
            String name = hostE.getAttributeValue("name");
            String hostPort = hostE.getAttributeValue("port");
            Host host = new Host(name,hostPort);
            iface.getHosts().put(name,host);
         }
      }
     
View Full Code Here

      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.1".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(adminUserLoc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.2' password='mypassword.2'/>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      Reference testUser2Loc = new Reference(adminUserLoc.toString()+"testuser.2");
      response = client.handle(makeGet(testUser2Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("testuser.2".equals(top.getAttributeValue("alias")));
      } catch (Exception ex) {
         fail("I/O exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makePost(testUser1Loc,new StringRepresentation("<user xmlns='http://www.atomojo.org/Vocabulary/Admin/2007/1/0' alias='testuser.1' password='mypassword.1.changed'><name>Test User</name></user>",MediaType.APPLICATION_XML)));
      assertTrue(response.getStatus().isSuccess());
     
      response = client.handle(makeGet(testUser1Loc));
      assertTrue(response.getStatus().isSuccess());
      try {
         XMLRepresentationParser parser = new XMLRepresentationParser();
         Document doc = parser.load(response.getEntity());
         Element top = doc.getDocumentElement();
         assertTrue("Test User".equals(top.getFirstElementNamed(Name.create("{http://www.atomojo.org/Vocabulary/Admin/2007/1/0}name")).getText()));
      } catch (Exception ex) {
         fail("Exception on get user testuser.1 response: "+ex.getMessage());
      }
     
      response = client.handle(makeDelete(testUser2Loc));
View Full Code Here

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

TOP

Related Classes of org.infoset.xml.Element

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.