Package org.infoset.xml

Examples of org.infoset.xml.Element


      }
   }
   static void link(ItemConstructor constructor,ItemDestination dest,String rel,String href)
      throws XMLException
   {
      Element linkE = constructor.createElement(AtomResource.LINK_NAME);
      linkE.setAttributeValue("rel",rel);
      linkE.setAttributeValue("href",href);
      linkE.setAttributeValue("type","application/atom+xml");
      dest.send(linkE);
     
      dest.send(constructor.createElementEnd(AtomResource.LINK_NAME));
   }
View Full Code Here


         feedClient.setIdentity(username,password);
         if (!feedClient.exists()) {
            log.info("Creating feed "+target.feed);
            try {
               Document doc = InfosetFactory.getDefaultInfoset().createItemConstructor().createDocument();
               Element feed = doc.createDocumentElement(FeedClient.FEED_NAME);
               Element title = feed.addElement(FeedClient.TITLE_NAME);
               title.addCharacters(target.dir.getName());
               Status status = feedClient.create(doc);
               if (!status.isSuccess()) {
                  log.log(Level.SEVERE,"Cannot create feed "+target.feed+" due to error "+status.getCode());
                  continue;
               }
View Full Code Here

      }
      index();
   }
  
   public Media getMediaContent() {
      Element contentE = doc.getDocumentElement().getFirstElementNamed(XML.CONTENT_NAME);
      return contentE!=null && contentE.getAttributeValue("src")!=null ? new Media(contentE) : null;
   }
View Full Code Here

      return getContent(false);
   }
  
   public Text getContent(boolean create)
   {
      Element contentE = doc.getDocumentElement().getFirstElementNamed(XML.CONTENT_NAME);
      if (contentE==null && create) {
         contentE = doc.getDocumentElement().addElement(XML.CONTENT_NAME);
      }
      return contentE!=null ? new Text(contentE) : null;
   }
View Full Code Here

   }
  
   public void generate(ItemConstructor constructor,ItemDestination dest,boolean contents)
      throws XMLException
   {
      Element top = constructor.createElement(XML.ROLE_NAME);
      top.setAttributeValue("id",uuid.toString());
      top.setAttributeValue("name",name);
      dest.send(top);
      if (contents) {
         boolean first = true;
         for (Permission p : permissions) {
            if (first) {
View Full Code Here

         DocumentDestination dest = new DocumentDestination();
        
         parser.parse(entity,AdminApplication.createAdminDocumentDestination(dest,AdminXML.NM_BACKUP));
         Document doc = dest.getDocument();
        
         Element top = doc.getDocumentElement();
         String location = top.getAttributeValue("location");
         if (location==null) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'location' attribute is missing.");
         }
         location = location.trim();
         if (location.length()==0) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("The 'location' attribute is empty.");
         }
         File dir = new File(location);
         if (!dir.exists()) {
            if (!dir.mkdirs()) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
               return new StringRepresentation("The "+dir.getAbsolutePath()+" doesn't exist and can't be created.");
            }
         }
         if (!dir.canWrite()) {
            getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
            return new StringRepresentation("Cannot write to "+dir.getAbsolutePath());
         }
        
         Set<String> dbNames = new TreeSet<String>();
         Iterator<Element> names = top.getElementsByName(AdminXML.NM_NAME);
         while (names.hasNext()) {
            dbNames.add(names.next().getText());
         }

         List<Map<String,DBInfo>> lists = new ArrayList<Map<String,DBInfo>>();
View Full Code Here

         case DocumentItem:
            break;
         case ElementItem:
         {
            level++;
            Element e = (Element)item;
            switch (level) {
               case 1:
                  if (!e.getName().equals(XML.FEED_NAME)) {
                     throw new XMLException("Feed does not start with an Atom 'feed' element: "+e.getName(),(Location)e);
                  }
                  docDest = new DocumentDestination();
                  //System.out.println("Feed: "+e.isBaseURIInherited()+", "+e.getBaseURI());
                  docDest.send(e.getInfoset().createItemConstructor().createDocument(e.getBaseURI()));
                  docDest.send(e);
                  break;
               case 2:
                  if (!feedSent) {
                     if (e.getName().equals(XML.ENTRY_NAME)) {
                        // send the feed document
                        this.onFeed(docDest.getDocument());
                        feedSent = true;
                        // Now collect the first entry
                        //System.out.println("Entry: "+e.isBaseURIInherited()+", "+e.getBaseURI());
                        docDest = new DocumentDestination();
                        docDest.send(e.getInfoset().createItemConstructor().createDocument(e.getBaseURI()));
                        e.localizeNamespaceDeclarations();
                        docDest.send(e);
                     } else {
                        docDest.send(e);
                     }
                  } else {
                     if (!e.getName().equals(XML.ENTRY_NAME)) {
                        throw new XMLException("Non-entry element after the first entry: "+e.getName(),(Location)e);
                     }
                    
                     // collect the entry
                     //System.out.println("Entry: "+e.isBaseURIInherited()+", "+e.getBaseURI());
                     docDest = new DocumentDestination();
                     docDest.send(e.getInfoset().createItemConstructor().createDocument(e.getBaseURI()));
                     docDest.send(e);
                  }
                  break;
               default:
                  if (docDest!=null) {
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(AdminXML.NM_SERVER)) {
         throw new XMLException("Expecting "+AdminXML.NM_SERVER+" but found "+top.getName());
      }
      String value = top.getAttributeValue("autoconf-check");
      if (value!=null) {
         autoconfCheck = Long.parseLong(value)*1000;
      }
     
      storageClassName = top.getAttributeValue("storage-class");
     
      value = top.getAttributeValue("logs");
      if (location.getScheme().equals("file")) {
         File locFile = new File(location.getSchemeSpecificPart());
         File test = new File(locFile,value==null ? "logs" : value);
         if (test.exists()) {
            logDir = test;
         } else {
            logDir = new File(value==null ? "logs" : value);
         }
      }
      value = top.getAttributeValue("temp.dir");
      if (location.getScheme().equals("file")) {
         File locFile = new File(location.getSchemeSpecificPart());
         tmpDir = value==null ? locFile.getParentFile() : new File(locFile,value);
      } else {
         tmpDir = new File(".");
      }
      Iterator<Element> autoconfElements = top.getElementsByName(AdminXML.NM_AUTOCONF);
      while (autoconfElements.hasNext()) {
         Element autoconfE = autoconfElements.next();
         String href = autoconfE.getAttributeValue("href");
         if (href!=null) {
            Link l = new Link("autoconf",MediaType.APPLICATION_ATOM_XML,autoconfE.getBaseURI().resolve(href));
            l.setIdentity(autoconfE.getAttributeValue("username"),autoconfE.getAttributeValue("password"));
            autoconfs.add(l);
         }
      }
      Iterator<Element> interfaceElements = top.getElementsByName(AdminXML.NM_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);
         interfaces.add(new Interface(addr,port,secure));
      }
     
      Iterator<Element> hostElements = top.getElementsByName(AdminXML.NM_HOST);
      while (hostElements.hasNext()) {
         Host host = createHost(hostElements.next());
         String key = host.getName();
         if (host.getPort()<0) {
            key = key+":*";
         } else {
            key = key+":"+host.getPort();
         }
         hosts.put(key,host);
      }
      Iterator<Element> adminElements = top.getElementsByName(AdminXML.NM_ADMIN);
      while (adminElements.hasNext()) {
         AdminHost host = createAdminHost(adminElements.next());
         admins.put(host.getName(),host);
      }

      Iterator<Element> resourceElements = top.getElementsByName(AdminXML.NM_RESOURCE);
      while (resourceElements.hasNext()) {
         Element spec = resourceElements.next();
         String type = spec.getAttributeValue("type");
         if (type==null || type.equals("database")) {
            ResourceHost host = createResourceHost(spec);
            resources.put(host.getName(),host);
         } else {
            throw new XMLException("Unrecognized resource host type "+type);
         }
      }

      Iterator<Element> databaseElements = top.getElementsByName(AdminXML.NM_DATABASE);
      while (databaseElements.hasNext()) {
         Element databaseE = databaseElements.next();
         String dbName = databaseE.getAttributeValue("name");
         String auth = databaseE.getAttributeValue("auth");
         String group = databaseE.getAttributeValue("group");
         String alias = databaseE.getAttributeValue("alias");
         Database database = new Database(dbName,auth,group,alias);
         databases.put(dbName,database);
      }
      Iterator<Element> authElements = top.getElementsByName(AdminXML.NM_AUTH);
      while (authElements.hasNext()) {
         Element authE = authElements.next();
         try {
            Auth auth = createAuth(authE);
            authServices.put(auth.getName(),auth);
         } catch (ClassNotFoundException ex) {
            throw new XMLException("Cannot load class "+authE.getAttributeValue("class")+" for auth service "+authE.getAttributeValue("name"),ex);
         }
      }
      Element keystoreE = top.getFirstElementNamed(AdminXML.NM_KEYSTORE);
      String href = keystoreE.getAttributeValue("href");
      URI keystoreRef = keystoreE.getBaseURI().resolve(href);
      keystoreFile = new File(keystoreRef.getSchemeSpecificPart());
      keystorePassword = keystoreE.getAttributeValue("password");
      keyPassword = keystorePassword;
      String altPassword = keystoreE.getAttributeValue("key-password");
      if (altPassword!=null) {
         keyPassword = altPassword;
      }
   }
View Full Code Here

     
      try {
         DocumentDestination dest = new DocumentDestination();
         parser.parse(entity,dest);
         doc = dest.getDocument();
         Element top = doc.getDocumentElement();
         String sid = top.getAttributeValue("id");
         UUID id = sid==null ? UUID.randomUUID() : UUID.fromString(sid);
         String alias = top.getAttributeValue("alias");

         try {
            Realm realm = fetchRealm();
            if (realm==null) {
               getResponse().setStatus(Status.CLIENT_ERROR_BAD_REQUEST);
View Full Code Here

   {
      String baseURIValue = baseURI.toString();
      URI baseDir = URI.create(baseURIValue.substring(0,baseURIValue.lastIndexOf('/')+1));
      ItemConstructor constructor = InfosetFactory.getDefaultInfoset().createItemConstructor();
      dest.send(constructor.createDocument(baseURI));
      Element top = constructor.createElement(AdminXML.NM_SERVER);
      if (autoconfCheck!=((long)(180*1000))) {
         top.setAttributeValue("autoconf-check",Long.toString(autoconfCheck/1000));
      }
      dest.send(top);
      dest.send(constructor.createCharacters("\n"));
     
      Element keystoreE = constructor.createElement(AdminXML.NM_KEYSTORE);
      keystoreE.setAttributeValue("href",baseDir.relativize(keystoreFile.toURI()).toString());
      keystoreE.setAttributeValue("password",keystorePassword);
      if (!keystorePassword.equals(keyPassword)) {
         keystoreE.setAttributeValue("key-password",keyPassword);
      }
      dest.send(keystoreE);
      dest.send(constructor.createElementEnd(AdminXML.NM_KEYSTORE));
      dest.send(constructor.createCharacters("\n"));
     
      for (Auth auth : authServices.values()) {
         Element authE = constructor.createElement(AdminXML.NM_AUTH);
         for (Object nameO : auth.getProperties().keySet()) {
            String name = nameO.toString();
            authE.setAttributeValue(name,auth.getProperties().getProperty(name));
         }
         dest.send(authE);
         dest.send(constructor.createElementEnd(AdminXML.NM_AUTH));
         dest.send(constructor.createCharacters("\n"));
      }
     
      for (Link link : autoconfs) {
         Element autoconfE = constructor.createElement(AdminXML.NM_AUTOCONF);
         autoconfE.setAttributeValue("href",baseURI.relativize(link.getLink()).toString());
         if (link.getUsername()!=null) {
            autoconfE.setAttributeValue("username",link.getUsername());
            autoconfE.setAttributeValue("password",link.getPassword());
         }
         dest.send(autoconfE);
         dest.send(constructor.createElementEnd(AdminXML.NM_AUTOCONF));
         dest.send(constructor.createCharacters("\n"));
      }
     
      for (Database database : databases.values()) {
         Element databaseE = constructor.createElement(AdminXML.NM_DATABASE);
         databaseE.setAttributeValue("name",database.getName());
         databaseE.setAttributeValue("auth",database.getAuthName());
         dest.send(databaseE);
         dest.send(constructor.createElementEnd(AdminXML.NM_DATABASE));
         dest.send(constructor.createCharacters("\n"));
      }
      for (Interface iface : interfaces) {

         Element ifaceE = constructor.createElement(AdminXML.NM_INTERFACE);
         ifaceE.setAttributeValue("address",iface.getAddress());
         ifaceE.setAttributeValue("port",Integer.toString(iface.getPort()));
         ifaceE.setAttributeValue("secure",iface.isSecure() ? "true" : "false");
         dest.send(ifaceE);
         dest.send(constructor.createElementEnd(AdminXML.NM_INTERFACE));
         dest.send(constructor.createCharacters("\n"));
      }

      for (AdminHost host : admins.values()) {
        
         Element hostE = constructor.createElement(AdminXML.NM_ADMIN);
         hostE.setAttributeValue("name",host.getName());
         if (host.getAddress()!=null) {
            hostE.setAttributeValue("address",host.getAddress());
         }
         if (host.getPort()>0) {
            hostE.setAttributeValue("port",Integer.toString(host.getPort()));
         }
         if (host.getAuthName()!=null) {
            hostE.setAttributeValue("auth",host.getAuthName());
         }
         dest.send(hostE);
         dest.send(constructor.createElementEnd(AdminXML.NM_ADMIN));
         dest.send(constructor.createCharacters("\n"));
      }
     
      for (Host host : hosts.values()) {
        
         Element hostE = constructor.createElement(AdminXML.NM_HOST);
         hostE.setAttributeValue("database",host.getDatabaseName());
         hostE.setAttributeValue("name",host.getName());
         if (host.getAddress()!=null) {
            hostE.setAttributeValue("address",host.getAddress());
         }
         if (host.getPort()>0) {
            hostE.setAttributeValue("port",Integer.toString(host.getPort()));
         }
         dest.send(hostE);
         dest.send(constructor.createElementEnd(AdminXML.NM_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.