Menu

substitute relative href into absolute href.

Help
2005-02-28
2013-04-27
  • mikeliu1976

    mikeliu1976 - 2005-02-28

    regards:

    it's me again.=.=
    substitute relative href into absolute href.

    followings is my design codes.
    ----------------------------------------------------------------------------------------------------
    code 
    ----------------------------------------------------------------------------------------------------
               if(tag instanceof LinkTag){
              
               String LinkTagsrc=((LinkTag)tag).getLinkText();
              
                  if(LinkTagsrc.startsWith("null")){
                   tag.setAttribute("href",tag.getAttribute("href"));
                 
                  }

                  else if(LinkTagsrc.startsWith("http://www.yzu.edu.tw")){
                   tag.setAttribute("href",tag.getAttribute("href"));
               }
           
               else if(LinkTagsrc.startsWith("http")){
                   tag.setAttribute("href",tag.getAttribute("href"));
               }
                  else{
                   tag.setAttribute("href","http://www.yzu.edu.tw"+tag.getAttribute("href"));
    ----------------------------------------------------------------------------------------------------
    code 
    ----------------------------------------------------------------------------------------------------

    ----------------------------------------------------------------------------------------------------
    unexpected output
    ----------------------------------------------------------------------------------------------------
    <p>
    <a href="http://www.yzu.edu.tw/bb/email.htm?PHPSESSID=edb89fb07665da94de90524c7dc93ba5">&#38651;&#23376;&#37109;&#20214;</a><br>
    <a href="http://www.yzu.edu.twhttp://isdna1.yzu.edu.tw/Cnstdsel/default.aspx" target="_blank">&#36984;&#35506;&#31995;&#32113;</a>
            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    </p> 
    ----------------------------------------------------------------------------------------------------
    "^^^^^^^^" part is unexpected output.

    Any positive suggestion is welcome.Did I miss something important?.....@@. 
    thank you 
    May goodness be with you all

     
    • mikeliu1976

      mikeliu1976 - 2005-02-28

      sorry...topic should be

      =.=
      substitute relative href with absolute href.

                                                                                     
      thank you
      May goodness be with you all

       
    • mikeliu1976

      mikeliu1976 - 2005-02-28

      regards:

      <a href="http://www.yzu.edu.twhttp://isdna1.yzu.edu.tw/.....omitted.....
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
      </p>
      "^^^^^^^^"
      part is unexpected output.

        I think it should be
        <href="http://isdna1.yzu.edu.tw/Cnstdsel/default.aspx" target="_blank">

        I want to check that if attribute of a href tag is a absolute hyperlink or "null",
        then make no changes.

        if attribute of a href tag is a relative hyperlink,
        then add a String "http://www.yzu.edu.tw" ahead of the relative hyperlink.

        Did I miss something important?.....@@.

        Any positive suggestion is welcome.
        thank you 
        May goodness be with you all

       
      • Derrick Oswald

        Derrick Oswald - 2005-02-28

        getLinkText() is used to get the contents of the link, i.e. between <a> and </a>, not the URL. You probably want getLink().

         
    • mikeliu1976

      mikeliu1976 - 2005-02-28

      regards:

      it's me again.=.=
      In my small opinion,may be
      I will try.....

      step1:identify the tag's name is 'a'
      step2:check the attribute of "href";and assign the attribute value to a variable(attributehref)
      step3:comparison between attributehref and

      (1)null
      (2)http://www.yzu.edu.tw
      (3)http://

      Does it make sense?...@@.

      Any positive suggestion is welcome.Did I miss something important?.....@@. 
      thank you 
      May goodness be with you all

       
    • mikeliu1976

      mikeliu1976 - 2005-03-01

      regards: 

      it's me again.=.= 
      sorry....it doesn't work well.
      I will try another way.

      step1:identify the tag's name is 'a'
      step2:check the attribute of "href";and assign the attribute value to a variable(attributehref)
      step3:comparison between attributehref and

      (1)null
      (2)http://www.yzu.edu.tw
      (3)http://

      ---------------------------------------------------------------------------------------------------- 

      thank you for your patient reply and instructions.^^ 

      thank you 
      May goodness be with you all
      ----------------------------------------------------------------------------------------------------

       
    • mikeliu1976

      mikeliu1976 - 2005-03-01

      regards:

      dear Derrick Oswald

      it's me again.=.= 
      The following way is ok.=.=
      ---------------------------------------------------------------------------------------------------- 
      code
      ---------------------------------------------------------------------------------------------------- 
      if(tag instanceof LinkTag){
                    
                 String LinkTagsrc=tag.getAttribute("href");
                
          //       ((LinkTag)tag).getLinkText();
                
                    if(LinkTagsrc.startsWith("null")){
                     tag.setAttribute("href",tag.getAttribute("href"));
                   
                    }

                    else if(LinkTagsrc.startsWith("http://www.yzu.edu.tw")){
                     tag.setAttribute("href",tag.getAttribute("href"));
                 }
             
                 else if(LinkTagsrc.startsWith("http")){
                     tag.setAttribute("href",tag.getAttribute("href"));
                 }
                    else{
                     tag.setAttribute("href","http://www.yzu.edu.tw"+tag.getAttribute("href"));
                 }
          }
      ---------------------------------------------------------------------------------------------------- 
      code
      ---------------------------------------------------------------------------------------------------- 
      thank you for your patient reply and instructions.^^ 

      thank you 
      May goodness be with you all 
      ---------------------------------------------------------------------------------------------------- 

       

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.