Package org.infoset.xml

Examples of org.infoset.xml.Name


      }
      public void attach(Router router,Element child,boolean defaultRoute) {
         attach(router,null,child,defaultRoute);
      }
      protected void attach(Router router,Filter filter,Element child,boolean defaultRoute) {
         Name name = child.getName();
         Context parentContext = router==null ? filter.getContext() : router.getContext();
         if (name.equals(ROUTER)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The router element does not have the required match attribute.");
               return;
            }
            if (defaultRoute) {
               router.attachDefault(createRouter(parentContext,child));
            } else if (router!=null) {
               router.attach(match,createRouter(parentContext,child));
            } else {
               filter.setNext(createRouter(parentContext,child));
            }
         } else if (name.equals(ROUTE)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The route element does not have the required match attribute.");
               return;
            }
            Class def = getTargetClass(child);
            if (def==null) {
               return;
            }
            if (isServerResource(def)) {
               Restlet finder = Finder.createFinder(def, Finder.class, hasParametersOrAttributes(child) ? createContext(parentContext,child) : parentContext,parentContext.getLogger());
               if (defaultRoute) {
                  LOG.fine("Mapping default -> "+def.getName());
                  router.attachDefault(finder);
               } else if (router!=null) {
                  LOG.fine("Mapping "+match+" -> "+def.getName());
                  router.attach(match,finder);
               } else {
                  filter.setNext(finder);
               }
            } else {
               try {
                  Restlet restlet = createRestlet(parentContext,def,child);
                  if (defaultRoute) {
                     LOG.fine("Mapping default -> "+def.getName());
                     router.attachDefault(restlet);
                  } else if (router!=null) {
                     LOG.fine("Mapping "+match+" -> "+def.getName());
                     router.attach(match,restlet);
                  } else {
                     filter.setNext(restlet);
                  }
               } catch (Exception ex) {
                  LOG.log(Level.SEVERE,"Cannot instantiate class: "+def.getName(),ex);
               }
            }
         } else if (name.equals(FILTER)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The filter element does not have the required match attribute.");
               return;
            }
            Class def = getTargetClass(child);
            if (def==null) {
               return;
            }
            Filter childFilter = null;
            try {
               childFilter = createFilter(parentContext,def,child);
            } catch (Exception ex) {
               LOG.log(Level.SEVERE,"Cannot instantiate filter.",ex);
               return;
            }
            if (defaultRoute) {
               router.attachDefault(childFilter);
            } else if (router!=null) {
               router.attach(match,childFilter);
            } 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());
                  }
               }
            }
         } else if (name.equals(CONTENT)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The content element does not have the required match attribute.");
               return;
            }
            Restlet restlet = createContent(parentContext,child);
            if (defaultRoute) {
               router.attachDefault(restlet);
            } else if (router!=null) {
               router.attach(match,restlet);
            } else {
               filter.setNext(restlet);
            }
         } else if (name.equals(REDIRECT)) {
            String match = child.getAttributeValue("match");
            if (match==null && filter==null && !defaultRoute) {
               LOG.severe("The content element does not have the required match attribute.");
               return;
            }
            String to = child.getAttributeValue("to");
            if (to==null) {
               LOG.severe("The redirect element is missing the required 'to' attribute.");
               return;
            }
           
            Reference targetRef = new Reference(to);
            Restlet restlet = null;
            if (targetRef.isAbsolute() && targetRef.getScheme().equals("riap")) {
               restlet = new Redirector(parentContext,to,Redirector.MODE_SERVER_INBOUND);
            } else {
               restlet = new Redirector(parentContext,to,Redirector.MODE_CLIENT_SEE_OTHER);
            }
            if (defaultRoute) {
               router.attachDefault(restlet);
            } else if (router!=null) {
               String [] extraction = null;
               if (match.charAt(match.length()-1)=='}') {
                  // seek to start of bracket expression
                  int pos = match.length()-2;
                  for (; pos>0 && match.charAt(pos)!='{'; pos--);
                  if (pos>=0 && match.charAt(pos+1)=='?') {
                     String expr = match.substring(pos+2,match.length()-1);
                     extraction = expr.split(",");
                     match = match.substring(0,pos);
                     LOG.fine("redirect extraction, match="+match+", expr="+expr);
                  }
               }
               if (extraction!=null) {
                  Extractor extractor = new Extractor(parentContext,restlet);
                  for (int i=0; i<extraction.length; i++) {
                     extractor.extractFromQuery(extraction[i], extraction[i], true);
                  }
                  router.attach(match,extractor);
               } else {
                  router.attach(match,restlet);
               }
            } else {
               filter.setNext(restlet);
            }
         } else if (name.equals(DEFAULT)) {
            Iterator<Element> elements = child.getElementChildren();
            while (elements.hasNext()) {
               attach(router,elements.next(),true);
            }
           
View Full Code Here


                           builder.append("\n");
                           builder.append(errors.next().toString());
                        }
                        throw new XMLException("Element "+end.getName()+" is not valid:"+builder.toString());
                     }
                     Name name = end.getName();
                     boolean found = false;
                     for (int i=0; !found && i<names.length; i++) {
                        if (names[i].equals(name)) {
                           found = true;
                        }
View Full Code Here

               throws XMLException
            {
               switch (item.getType()) {
                  case ElementItem: {
                     Element e = (Element)item;
                     Name name = e.getName();
                     if (name.equals(CATEGORY)) {
                        String termName = e.getAttributeValue("term");
                        if (termName==null) {
                           throw new XMLException("The term element is missing the 'term' attribute.",(Location)e);
                        }
                        termName = termName.trim();
                        if (termName.length()==0) {
                           throw new XMLException("The term element's 'term' attribute is empty.",(Location)e);
                        }
                        Term term = Term.derive(current==null ? null : current.uri, e);
                        current = new TermNode(term,current,separator);
                        current.parent.children.put(term.getName(),current);
                        universe.put(term.getURI(), current);
                     } else if (name.equals(ONTOLOGY)) {
                        String tname = e.getAttributeValue("scheme");
                        if (tname==null) {
                           throw new XMLException("The ontology element is missing the 'scheme' attribute.",(Location)e);
                        }
                        separator = e.getAttributeValue("separator");
                        if (separator==null) {
                           separator = "/";
                        }
                        tname = tname.trim();
                        if (tname.length()==0) {
                           throw new XMLException("The ontology element's scheme attribute is empty.",(Location)e);
                        }
                        URI id = URI.create(tname);
                        Term term = new Term(id);
                        current = new TermNode(term,null,separator);
                        universe.put(term.getURI(), current);
                     }
                  }
                     break;
                  case ElementEndItem:
                  {
                     Name name = ((Named)item).getName();
                     if (name.equals(CATEGORY) || name.equals(ONTOLOGY)) {
                        if (current!=null) {
                           current = current.parent;
                        }
                     }
                  }
View Full Code Here

         throws XMLException
      {
         switch (state) {
            case 0:
               if (item.getType()==Item.ItemType.ElementItem) {
                  Name name = ((Named)item).getName();
                  if (name.equals(WORKSPACE) || name.equals(OLD_WORKSPACE)) {
                     state = 1;
                     startedWorkspace = false;
                  }
               }
               break;
            case 1:
               switch (item.getType()) {
                  case ElementItem:
                  {
                     Element e = (Element)item;
                     Name name = ((Named)item).getName();
                     if (name.equals(COLLECTION) || name.equals(OLD_COLLECTION)) {
                        if (!startedWorkspace) {
                           listener.onStartWorkspace("");
                           startedWorkspace = true;
                        }
                        String href = e.getAttributeValue("href");
                        if (href==null) {
                           return;
                        }
                        title = null;
                        URI base = e.getBaseURI();
                        if (base==null) {
                           base = ulocation;
                        }
                        collectionLocation = base.resolve(href);
                        //Logger.getAnonymousLogger().info("Resolved '"+href+"' against '"+base+"' to get '"+collectionLocation+"'");
                        state = 2;
                     } else if (name.equals(TITLE_NAME)) {
                        buffer = new StringBuilder();
                        title = "";
                     }
                  }
                     break;
                  case ElementEndItem:
                  {
                     Name name = ((Named)item).getName();
                     if (name.equals(WORKSPACE) || name.equals(OLD_WORKSPACE)) {
                        listener.onEndWorkspace();
                        state = 0;
                     } else if (name.equals(TITLE_NAME)) {
                        listener.onStartWorkspace(buffer.toString());
                        startedWorkspace = true;
                        buffer = null;
                     }
                  }
                     break;
                  case CharactersItem:
                     if (buffer!=null) {
                        buffer.append(((Characters)item).getText());
                     }
                    
               }
               break;
            case 2:
               switch (item.getType()) {
                  case ElementItem:
                  {
                     Name name = ((Named)item).getName();
                     if (name.equals(TITLE_NAME)) {
                        buffer = new StringBuilder();
                     }
                  }
                     break;
                  case ElementEndItem:
                  {
                     Name name = ((Named)item).getName();
                     if (name.equals(COLLECTION) || name.equals(OLD_COLLECTION)) {
                        listener.onCollection(new EntryCollection(title,collectionLocation));
                        state = 1;
                     }
                  }
                     break;
View Full Code Here

                           builder.append(errors.next().toString());
                        }
                        throw new XMLException("Element "+end.getName()+" is not valid:"+builder.toString());
                     }
                     if (topLevelElements!=null) {
                        Name name = end.getName();
                        if (!topLevelElements.contains(name)) {
                           throw new XMLException("Unexpected document element "+name);
                        }
                     }
                  }
View Full Code Here

      for (Child c : entry) {
         if (c.getType()!=Item.ItemType.ElementItem) {
            continue;
         }
         Element e = (Element)c;
         Name name = e.getName();
         //Logger.getAnonymousLogger().info("Name: "+name);
         if (name.equals(ID_NAME)) {
            String value = e.getText().trim();
            //Logger.getAnonymousLogger().info("id: "+value);
            if (value.startsWith("urn:uuid:")) {
               index.setId(UUID.fromString(value.substring(9)));
            }
         } else if (name.equals(AUTHOR_NAME)) {
            Iterator<Element> children = e.getElementsByName(NAME_NAME);
            if (children.hasNext()) {
               String authorName = children.next().getText().trim();
               if (authorName.length()>0) {
                  index.setAuthorName(authorName);
               }
            }
         } else if (name.equals(CATEGORY_NAME)) {
            String scheme = e.getAttributeValue("scheme");
            String term = e.getAttributeValue("term");
            if (term!=null) {
               term = term.trim();
               if (term.length()==0) {
View Full Code Here

      for (Child c : feed) {
         if (c.getType()!=Item.ItemType.ElementItem) {
            continue;
         }
         Element e = (Element)c;
         Name name = e.getName();
         if (name.equals(ID_NAME)) {
            String value = e.getText().trim();
            if (value.startsWith("urn:uuid:")) {
               index.setId(UUID.fromString(value.substring(9)));
            }
         } else if (name.equals(CATEGORY_NAME)) {
            String scheme = e.getAttributeValue("scheme");
            String term = e.getAttributeValue("term");
            if (term!=null) {
               term = term.trim();
               if (term.length()==0) {
View Full Code Here

            throws XMLException
         {
            if (level==1) {
            } else if (level==2) {
               if (item.getType()==Item.ItemType.ElementItem) {
                  Name name = ((Element)item).getName();
                  if (name.equals(XML.PERMISSIONS_NAME)) {
                     current = new PermissionsDestination(current);
                     current.send(item);
                  } else if (name.equals(XML.ROLES_NAME)) {
                     current = new RolesDestination(current);
                     current.send(item);
                  } else if (name.equals(XML.USERS_NAME)) {
                     current = new UsersDestination(current);
                     current.send(item);
                  } else if (name.equals(XML.REALMS_NAME)) {
                     current = new RealmsDestination(current);
                     current.send(item);
                  }
               }
            }
View Full Code Here

            try {
               Reader r = new InputStreamReader(request.getEntity().getStream(),charset);
               Document doc = loader.load(r);
               r.close();

               Name top = doc.getDocumentElement().getName();
               if (top.equals(AtomResource.FEED_NAME)) {
                  String requestPath = request.getResourceRef().getRemainingPart();
                  if (requestPath==null) {
                     requestPath = "";
                  }
                  if (getLogger().isLoggable(Level.FINE)) {
                     getLogger().fine("Creating feed at '"+requestPath+"'");
                  }
                 

                  try {
                     Feed f = app.createFeed(requestPath,doc);
                     response.setStatus(Status.SUCCESS_CREATED);
                     Representation rep = storage.getFeed(f.getPath(),f.getUUID(),f.getEntries());
                     if (rep!=null) {
                        rep.setTag(new Tag(Long.toString(f.getEdited().getTime()),false));
                     }
                     response.setEntity(rep);
                  } catch (AppException ex) {
                     if (ex.getStatus().equals(Status.SERVER_ERROR_INTERNAL)) {
                        getLogger().log(Level.SEVERE,ex.getMessage(),ex);
                     }
                     response.setStatus(ex.getStatus(),ex.getMessage());
                  }
                 
                 
                 
               } else if (top.equals(AtomResource.ENTRY_NAME)) {
                  super.handle(new NewEntryRequest(request,doc),response);
               } else {
                  response.setStatus(Status.CLIENT_ERROR_BAD_REQUEST,"Unrecognized document element: "+top);
               }
            } catch (XMLException ex) {
View Full Code Here

TOP

Related Classes of org.infoset.xml.Name

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.