Package org.gudy.azureus2.plugins.utils.xml.simpleparser

Examples of org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode


       
    SimpleXMLParserDocumentNode[] file_nodes  = null;

    for (int i=0;i<kids.length;i++){
     
      SimpleXMLParserDocumentNode  kid = kids[i];
       
      String  name = kid.getName();
               
      if ( name.equalsIgnoreCase( "PIECE_LENGTH")){
       
        torrent.setPieceLength( readGenericLong( kid ).longValue());
         
      }else if ( name.equalsIgnoreCase( "LENGTH")){
 
        torrent.setSimpleTorrent( true );
       
        torrent_length =  readGenericLong( kid ).longValue();
       
      }else if ( name.equalsIgnoreCase( "NAME")){
       
        torrent.setName( readLocalisableString( kid ));
       
      }else if ( name.equalsIgnoreCase( "FILES" )){
       
        torrent.setSimpleTorrent( false );
       
        file_nodes = kid.getChildren();
         
      }else if ( name.equalsIgnoreCase( "PIECES" )){
 
        SimpleXMLParserDocumentNode[]  piece_nodes = kid.getChildren();
       
        byte[][]  pieces = new byte[piece_nodes.length][];
       
        for (int j=0;j<pieces.length;j++){
         
          pieces[j] = readGenericBytes( piece_nodes[j] );     
        }
       
        torrent.setPieces( pieces );
       
      }else{
       
        mapEntry entry = readGenericMapEntry( kid );
         
        torrent.addAdditionalInfoProperty( entry.name, entry.value );
      }
    }
   
    if ( torrent.isSimpleTorrent()){
 
      torrent.setFiles(
        new TOTorrentFileImpl[]{
            new TOTorrentFileImpl(   torrent,
                        0,
                        torrent_length,
                        new byte[][]{ torrent.getName()})});
    }else{
     
      TOTorrentFileImpl[]  files = new TOTorrentFileImpl[ file_nodes.length ];
     
      long  offset = 0;
     
      for (int j=0;j<files.length;j++){
       
        SimpleXMLParserDocumentNode  file_node = file_nodes[j];
       
        SimpleXMLParserDocumentNode[]  file_entries = file_node.getChildren();
       
        long    file_length  = 0;
       
        boolean    length_entry_found  = false;
       
        byte[][]  path_comps  = null;
       
        Vector  additional_props  = new Vector();
       
        for ( int k=0;k<file_entries.length;k++){
         
          SimpleXMLParserDocumentNode  file_entry = file_entries[k];
         
          String  entry_name = file_entry.getName();
         
          if ( entry_name.equalsIgnoreCase( "LENGTH" )){
       
            file_length = readGenericLong(file_entry).longValue();
       
            length_entry_found = true;
           
          }else if ( entry_name.equalsIgnoreCase( "PATH" )){
           
            SimpleXMLParserDocumentNode[]  path_nodes = file_entry.getChildren();
           
            path_comps = new byte[path_nodes.length][];
           
            for (int n=0;n<path_nodes.length;n++){
             
View Full Code Here


  }
 
  public URL
  getLink()
  {
    SimpleXMLParserDocumentNode link_node = node.getChild( "link" );
   
    if ( link_node != null ){

      try{
        if ( is_atom ){
         
          SimpleXMLParserDocumentAttribute attr = link_node.getAttribute( "href" );
         
          if ( attr == null ){
           
            return( null );
          }
         
          String  value = attr.getValue().trim();
         
          if ( value.length() == 0 ){
           
            return( null );
          }
         
          return( new URL( value ));

        }else{
       
          String  value = link_node.getValue().trim();
         
          if ( value.length() == 0 ){
           
            return( null );
          }
View Full Code Here

  }
 
  public Date
  getPublicationDate()
  {
    SimpleXMLParserDocumentNode pd = node.getChild( is_atom?"published":"pubdate" );
   
    if ( pd != null ){

      if ( is_atom ){
       
        return( RSSUtils.parseAtomDate( pd.getValue()));
       
      }else{
       
        return( RSSUtils.parseRSSDate( pd.getValue()));
      }
    }
   
    return( null );
  }
View Full Code Here

  }
 
  public String
  getUID()
  {
    SimpleXMLParserDocumentNode uid = node.getChild( is_atom?"id":"guid" );

    if ( uid != null ){
       
      String value = uid.getValue().trim();
     
      if ( value.length() > 0 ){
       
        return( value );
      }
View Full Code Here

       
        int  auto_dl_state = AUTO_DL_SUPPORTED_YES;
       
        for ( int j=0; j<channel_kids.length; j++ ){

          SimpleXMLParserDocumentNode child = channel_kids[j];

          String  lc_full_child_name   = child.getFullName().toLowerCase();

          if ( lc_full_child_name.equals( "vuze:auto_dl_enabled" )){
           
            if ( !child.getValue().equalsIgnoreCase( "true" )){
             
              auto_dl_state = AUTO_DL_SUPPORTED_NO;
            }
          }
        }     
       
        setLocalLong( LD_AUTO_DL_SUPPORTED, auto_dl_state );
       
        RSSItem[] items = channel.getItems();

        for ( int j=0 ; j<items.length; j++ ){
         
          RSSItem item = items[j];
         
          WebResult result = new WebResult(this,getRootPage(),getBasePage(),getDateParser(),"");
         
          result.setPublishedDate(item.getPublicationDate());
         
          result.setNameFromHTML(item.getTitle());
         
          URL cdp_link = item.getLink();
         
          if ( cdp_link != null ){
         
            result.setCDPLink(cdp_link.toExternalForm());
          }
         
          String uid = item.getUID();
         
          if ( uid != null ){
           
            result.setUID( uid );
          }
         
          boolean got_seeds_peers = false;
         
          SimpleXMLParserDocumentNode node = item.getNode();
         
          if ( node != null ){
           
            SimpleXMLParserDocumentNode[] children = node.getChildren();
           
            boolean vuze_feed = false;
           
            for ( int k=0; k<children.length; k++ ){
                           
              SimpleXMLParserDocumentNode child = children[k];
             
              String  lc_full_child_name   = child.getFullName().toLowerCase();
             
              if ( lc_full_child_name.startsWith( "vuze:" )){
               
                vuze_feed = true;
               
                break;
              }
            }
           
            for ( int k=0; k<children.length; k++ ){
             
              SimpleXMLParserDocumentNode child = children[k];
             
              String  lc_child_name     = child.getName().toLowerCase();
              String  lc_full_child_name   = child.getFullName().toLowerCase();
             
              String  value = child.getValue();
             
              if (lc_child_name.equals( "enclosure" )){
               
                SimpleXMLParserDocumentAttribute typeAtt = child.getAttribute("type");
               
                if( typeAtt != null && typeAtt.getValue().equalsIgnoreCase( "application/x-bittorrent")) {
                 
                  SimpleXMLParserDocumentAttribute urlAtt = child.getAttribute("url");
                 
                  if( urlAtt != null ){
                   
                    result.setTorrentLink(urlAtt.getValue());
                  }
                 
                  SimpleXMLParserDocumentAttribute lengthAtt = child.getAttribute("length");
                 
                  if (lengthAtt != null){
                   
                    result.setSizeFromHTML(lengthAtt.getValue());
                  }
                }
              }else if(lc_child_name.equals( "category" )) {
                               
                result.setCategoryFromHTML( value );
               
              }else if(lc_child_name.equals( "comments" )){
               
                result.setCommentsFromHTML( value );
               
              }else if ( lc_child_name.equals( "link" ) || lc_child_name.equals( "guid" )) {
               
                String lc_value = value.toLowerCase();
                               
                try{
                  URL url = new URL(value);

                  if (   lc_value.endsWith( ".torrent" ) ||
                      lc_value.startsWith( "magnet:" ) ||
                      lc_value.startsWith( "bc:" ) ||
                      lc_value.startsWith( "bctp:" ) ||
                      lc_value.startsWith( "dht:" )){
                   
                   
                    result.setTorrentLink(value);
                   
                  }else if ( lc_child_name.equals( "link" ) && !vuze_feed ){
                 
                    long  test = getLocalLong( LD_LINK_IS_TORRENT, 0 );
                 
                    if ( test == 1 ){
                   
                      result.setTorrentLink( value );
                     
                    }else if ( test == 0 || SystemTime.getCurrentTime() - test > 60*1000 ){
                   
                      if ( linkIsToTorrent( url )){
                     
                        result.setTorrentLink(value);
                       
                        setLocalLong( LD_LINK_IS_TORRENT, 1 );
                       
                      }else{
                       
                        setLocalLong( LD_LINK_IS_TORRENT, SystemTime.getCurrentTime());
                      }
                    }
                  }
                }catch( Throwable e ){
                 
                    // see if this is an atom feed
                    //  <link rel="alternate" type="application/x-bittorrent" href="http://asdasd/
                 
                  SimpleXMLParserDocumentAttribute typeAtt = child.getAttribute( "type" );
                 
                  if ( typeAtt != null && typeAtt.getValue().equalsIgnoreCase("application/x-bittorrent")) {
                 
                    SimpleXMLParserDocumentAttribute hrefAtt = child.getAttribute( "href" );
                   
                    if ( hrefAtt != null ){
                     
                      String  href = hrefAtt.getValue().trim();
                     
                      try{
                       
                        result.setTorrentLink( new URL( href ).toExternalForm() );
                       
                      }catch( Throwable f ){
                       
                      }
                    }
                  }
                }
              }else if ( lc_child_name.equals( "content" ) && rssFeed.isAtomFeed()){
               
                SimpleXMLParserDocumentAttribute srcAtt = child.getAttribute( "src" );
               
                String  src = srcAtt==null?null:srcAtt.getValue();
                     
                if ( src != null ){
                 
                  boolean  is_dl_link = false;
                 
                  SimpleXMLParserDocumentAttribute typeAtt = child.getAttribute( "type" );
                 
                  if ( typeAtt != null && typeAtt.getValue().equalsIgnoreCase("application/x-bittorrent")) {

                    is_dl_link = true;
                  }
                 
                  if ( !is_dl_link ){
                 
                    is_dl_link = src.toLowerCase().indexOf( ".torrent" ) != -1;
                  }
                   
                  if ( is_dl_link ){
                   
                    try{
                      new URL( src );
                   
                      result.setTorrentLink( src );
                     
                    }catch( Throwable e ){
                    }
                  }
                }
              }else if ( lc_full_child_name.equals( "vuze:size" )){
               
                result.setSizeFromHTML( value );
               
              }else if ( lc_full_child_name.equals( "vuze:seeds" )){
               
                got_seeds_peers = true;
               
                result.setNbSeedsFromHTML( value );
               
              }else if ( lc_full_child_name.equals( "vuze:superseeds" )){
               
                got_seeds_peers = true;
               
                result.setNbSuperSeedsFromHTML( value );
               
              }else if ( lc_full_child_name.equals( "vuze:peers" )){
               
                got_seeds_peers = true;
               
                result.setNbPeersFromHTML( value );
               
              }else if ( lc_full_child_name.equals( "vuze:rank" )){
               
                result.setRankFromHTML( value );
               
              }else if ( lc_full_child_name.equals( "vuze:contenttype" )){
               
                String  type = value.toLowerCase();
               
                if ( type.startsWith( "video" )){
                 
                  type = Engine.CT_VIDEO;
                 
                }else if ( type.startsWith( "audio" )){
                 
                  type = Engine.CT_AUDIO;
                 
                }else if ( type.startsWith( "games" )){
                 
                  type = Engine.CT_GAME;
                }
               
                result.setContentType( type );
               
              }else if ( lc_full_child_name.equals( "vuze:downloadurl" )){

                result.setTorrentLink( value);
               
              }else if ( lc_full_child_name.equals( "vuze:playurl" )){

                result.setPlayLink( value);
               
              }else if ( lc_full_child_name.equals( "vuze:drmkey" )){

                result.setDrmKey( value);
               
              }else if ( lc_full_child_name.equals( "vuze:assethash" )){

                result.setHash( value);
              }
            }
          }
         
          if ( !got_seeds_peers ){
           
            try{
              SimpleXMLParserDocumentNode desc_node = node.getChild( "description" );
             
              if ( desc_node != null ){
               
                String desc = desc_node.getValue().trim();
               
                  // see if we can pull from description
               
                Matcher m = seed_leecher_pat.matcher( desc );
             
                while( m.find()){
                 
                  String  num = m.group(1);
                 
                  String  type = m.group(2);
                 
                  if ( type.toLowerCase().charAt(0) == 's' ){
                   
                    result.setNbSeedsFromHTML( num );
                   
                  }else{
                   
                    result.setNbPeersFromHTML( num );
                  }
                }
              }
             
            }catch( Throwable e ){
             
            }
          }
         
            // override existing values with explicit <torrent> entry if present
         
          try{
            SimpleXMLParserDocumentNode torrent_node = node.getChild( "torrent" );
           
            if ( torrent_node != null ){
           
              if ( result.getSize() <= 0 ){
               
                SimpleXMLParserDocumentNode n = torrent_node.getChild( "contentLength" );
               
                if ( n != null ){
                 
                  try{
                    long l = Long.parseLong( n.getValue().trim());
                   
                    result.setSizeFromHTML( l + " B" );
                   
                  }catch( Throwable e ){
                   
                  }
                }
              }
             
              String dlink = result.getDownloadLink();
             
              if ( dlink == null || dlink.length() == 0 ){
               
                SimpleXMLParserDocumentNode n = torrent_node.getChild( "magnetURI" );
               
                if ( n != null ){
                 
                  dlink = n.getValue().trim();
                 
                  result.setTorrentLink( dlink );
                }
              }
             
              String hash = result.getHash();
             
              if ( hash == null || hash.length() == 0 ){
               
                SimpleXMLParserDocumentNode n = torrent_node.getChild( "infoHash" );
               
                if ( n != null ){
                 
                  String h = n.getValue().trim();
                 
                  result.setHash( h );
                 
                  if ( dlink == null || dlink.length() == 0 ){
                   
                    String uri = UrlUtils.normaliseMagnetURI( h );
                   
                    if ( uri != null ){
                     
                      result.setTorrentLink( uri );
                    }
                  }
                }
              }
             
              SimpleXMLParserDocumentNode trackers_node = torrent_node.getChild( "trackers" );

              if ( trackers_node != null && !got_seeds_peers ){
               
                SimpleXMLParserDocumentNode[] groups = trackers_node.getChildren();
               
                int  max_total = -1;
               
                int  best_seeds    = 0;
                int  best_leechers  = 0;
View Full Code Here

             
        // try standard POST
     
      SimpleXMLParserDocument resp_doc  = ((UPnPDeviceImpl)action.getService().getDevice()).getUPnP().performSOAPRequest( service, soap_action, request );
           
      SimpleXMLParserDocumentNode  body = resp_doc.getChild( "Body" );
     
      SimpleXMLParserDocumentNode fault = body.getChild( "Fault" );
     
      if ( fault != null ){
       
        throw( new UPnPException( "Invoke of '" + soap_action + "' failed - fault reported: " + fault.getValue()));
      }
     
      SimpleXMLParserDocumentNode  resp_node = body.getChild( action.getName() + "Response" );
     
      if ( resp_node == null ){
       
        throw( new UPnPException( "Invoke of '" + soap_action + "' failed - response missing: " + body.getValue()));
      }
     
      SimpleXMLParserDocumentNode[]  out_nodes = resp_node.getChildren();
     
      UPnPActionArgument[]  resp = new UPnPActionArgument[out_nodes.length];
     
      for (int i=0;i<out_nodes.length;i++){
       
View Full Code Here

      request +=   "</s:Body>"+
            "</s:Envelope>";
             
      SimpleXMLParserDocument resp_doc  = ((UPnPDeviceImpl)service.getDevice()).getUPnP().performSOAPRequest( service, soap_action, request );

      SimpleXMLParserDocumentNode  body = resp_doc.getChild( "Body" );
     
      SimpleXMLParserDocumentNode fault = body.getChild( "Fault" );
     
      if ( fault != null ){
       
        throw( new UPnPException( "Invoke fails - fault reported: " + fault.getValue()));
      }
     
      SimpleXMLParserDocumentNode  resp_node = body.getChild( "QueryStateVariableResponse" );
     
      if ( resp_node == null ){
       
        throw( new UPnPException( "Invoke fails - response missing: " + body.getValue()));
      }
     
      SimpleXMLParserDocumentNode  value_node = resp_node.getChild( "return" );
     
      return( value_node.getValue());
     
    }catch( Throwable e ){
     
      if ( e instanceof UPnPException ){
       
View Full Code Here

   
    boolean  interested = device_type.equalsIgnoreCase( "urn:schemas-upnp-org:device:WANConnectionDevice:1" );
   
    root_device.getUPnP().log( indent + friendly_name + (interested?" *":""));
   
    SimpleXMLParserDocumentNode  service_list = device_node.getChild( "ServiceList" );
   
    if ( service_list != null ){
       
      SimpleXMLParserDocumentNode[] service_nodes = service_list.getChildren();
     
      for (int i=0;i<service_nodes.length;i++){
       
        services.add( new UPnPServiceImpl( this, indent + "  ", service_nodes[i]));
      }
    }
   
    SimpleXMLParserDocumentNode  dev_list = device_node.getChild( "DeviceList" );
   
    if ( dev_list != null ){
       
      SimpleXMLParserDocumentNode[] device_nodes = dev_list.getChildren();
     
      for (int i=0;i<device_nodes.length;i++){
       
        devices.add( new UPnPDeviceImpl( root_device, indent + "  ", device_nodes[i]));
      }
View Full Code Here

  protected String
  getOptionalField(
    SimpleXMLParserDocumentNode  node,
    String            name )
  {
    SimpleXMLParserDocumentNode  child = node.getChild(name);
   
    if ( child == null ){
     
      return( null);
    }
   
    return( child.getValue().trim());
  }
View Full Code Here

  protected String
  getMandatoryField(
    SimpleXMLParserDocumentNode  node,
    String            name )
  {
    SimpleXMLParserDocumentNode  child = node.getChild(name);
   
    if ( child == null ){
     
      root_device.getUPnP().log( "Mandatory field '" + name + "' is missing" );
     
      return( "<missing field '" + name + "'>" );
    }
   
    return( child.getValue().trim());
  }
View Full Code Here

TOP

Related Classes of org.gudy.azureus2.plugins.utils.xml.simpleparser.SimpleXMLParserDocumentNode

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.