Package org.vietspider.token.attribute

Examples of org.vietspider.token.attribute.Attributes


    downloadResources(address, tokens, resources);

    for(int i = 0; i < tokens.size(); i++) {
      NodeImpl token = tokens.get(i);
      if(token.getType() != TypeToken.TAG || !token.isNode(Name.A)) continue;
      Attributes attributes = token.getAttributes();
      Attribute attribute = attributes.get("href");
      if(attribute == null) continue;
      String link  = attribute.getValue();
      if(link == null || link.trim().length() < 1) continue;
      link  = urlUtils.createURL(parent, link);
      String subName = "";
      try {
        URL subUrl = new URL(link);
        String temp = subUrl.getPath();
        if(temp != null) subName += temp;
        temp = subUrl.getQuery();
        if(temp != null) subName += "_"+temp;
        subName = toName(subName);
      }catch (Exception e) {
      }
      if(subName == null || subName.trim().length() < 1) subName = toName(link);
      try{
        crawl(new URL(address), link, subName, level+1, depth);
      }catch (Exception e) {
        System.err.println(e);
      }
      attribute.setValue(subName+".html");
      attributes.set(attribute);
    }


    StringBuilder contentBuilder = new StringBuilder();
    for(int i = 0; i < tokens.size(); i++) {
View Full Code Here


      NodeImpl token = tokens.get(i);
      if(token.getType() != TypeToken.TAG) continue;
      for(Resource resource : resources) {
        if(!token.isNode(resource.tag))  continue;
        try {
          Attributes attributes = token.getAttributes();
          for(Attribute attribute : attributes) {
            if(!attribute.getName().equalsIgnoreCase(resource.attr))  continue;
            String rscName = toName(attribute.getValue());
            File file = new File(folder, rscName);
            String link = urlUtils.createURL(url, attribute.getValue());
            System.out.println("downloading "+link+" ...");
            if(!file.exists()) loadResource(referer, link, file);
            attribute.setValue(rscName);
            attributes.set(attribute);
          }
        } catch (Exception e) {
          System.err.println(e);
        }
      }
View Full Code Here

    if (map == null) return ;
    toXMLValue(clazz, object, node);
  }
 
  private void toXMLValue(Class<?> clazz, Object bean, XMLNode nodethrows Exception  {
    Attributes attrs = AttributeParser.parse(node);
    for(Attribute attr : attrs) {
      Field field = getField(attr.getName(), clazz);
      if(field == null) continue;
      Class<?> type = field.getType();
      if(type.isPrimitive() || reflectUtil.isPrimitiveType(type) || type.isEnum()) {
View Full Code Here

      Collection collection = null;
     
      if(current != null && current instanceof Collection) {
        collection = (Collection) current;
      } else if(type.isInterface())  {
        Attributes attributes = AttributeParser.parse(node);
        Attribute attr = attributes.get("type");
        if(attr != null) {
          String typeName = attr.getValue();
          Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(typeName);
          collection = (Collection) clazz.newInstance();
        } else {
View Full Code Here

    Map<Object, Object> map = null;
   
    if(current != null && current instanceof Map<?,?>) {
      map = (Map<Object, Object>) current;
    } else if(type.isInterface())  {
      Attributes attributes = AttributeParser.parse(node);
      Attribute attr = attributes.get("type");
      if(attr != null) {
        String typeName = attr.getValue();
        Class<?> clazz = Thread.currentThread().getContextClassLoader().loadClass(typeName);
        map =  (Map<Object, Object>) clazz.newInstance();
      } else {
View Full Code Here

    node.addChild(new XMLNode(value.toCharArray(), null, TypeToken.CONTENT));
    children.add(node);
  }
 
  private void setAttribute(XMLNode parent, String name, String value) {
    Attributes attrs = AttributeParser.parse(parent);
    for(Attribute ele : attrs) {
      if(ele.getName().equals(name)){
        ele.setValue(value);
        return ;
      }
    }
    Attribute attr = new Attribute(name, value);
    attrs.add(attr);
  }
View Full Code Here

    if(children == null) return ;
    for(XMLNode child : children) {
      if(child.isNode(LINK) && child.getChildren().size() > 0) {
        item.addLink(new MetaLink(child.getChild(0).getTextValue()));
      } else if(child.isNode(ENCLOSURE)) {
        Attributes attributes = AttributeParser.parse(child);
        MetaLink metaLink  = new MetaLink();
        Attribute attribute = attributes.get(URL);
        if(attribute != null) metaLink.setHref(attribute.getValue());
        attribute = attributes.get(TYPE);
        if(attribute != null) metaLink.setType(attribute.getValue());
        item.addLink(metaLink);
      }
    }
  }
View Full Code Here

   
    for(XMLNode child : children) {
      if(!child.isNode(LINK)) continue;
      MetaLink metaLink = toBean.toBean(MetaLink.class, child);
      if(metaLink.getHref() == null || metaLink.getHref().trim().isEmpty()) {
        Attributes attributes = AttributeParser.parse(child);
        Attribute attribute = attributes.get(REF);
        if(attribute != null) metaLink.setHref(attribute.getValue());
      }
      item.addLink(metaLink);
    }
  }
View Full Code Here

    }
  }

  protected void removeIFrameSource(HTMLNode node) {
    if(node.isNode(Name.IFRAME)) {
      Attributes attributes = node.getAttributes();
      attributes.remove("src");
    }
    List<HTMLNode> children = node.getChildren();
    if(children == null || children.size() < 1) return;
    for(int i = 0; i < children.size(); i++) {
      removeIFrameSource(children.get(i));
View Full Code Here

          System.out.println("===================================================");
          System.out.println(node.getChild(0).getTextValue());
        }
        continue;
      }
      Attributes attributes = node.getAttributes();
      for(int i = 0; i < attributes.size(); i++) {
        String value = attributes.get(i).getValue();
        if(attributes.get(i).getName().startsWith("on")
            || value.toLowerCase().startsWith("javascript")) {
          System.out.println("===================================================");
          System.out.println(value);
        }
      }
View Full Code Here

TOP

Related Classes of org.vietspider.token.attribute.Attributes

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.