-2

I'm currently doing a project using Spring mvc and was working on my backend part.(Dealing with bookmarks) I have created a engine interface (IBookmarkEngine) and then made my implementation (BookmarkEngine). I'm just having trouble making this work. How do I create an engine that prefixes url "http://"?

 public class BookmarkEngine implements IBookmarkEngine {

     private static final String URL_PREFIX = "http://";

     @Override
     public String getFullUrl(String url) {

         if () {
             return;
         }
         return url;
     }
 }
The_Outsider
  • 1,875
  • 2
  • 24
  • 42
RyanP
  • 43
  • 7

1 Answers1

0

Maybe you can add the prefix if it is not present. So in your IF statement you can do a startsWith search on the url. If the url does not start with the prefix, then add the prefix to the url.

 public class BookmarkEngine implements IBookmarkEngine {

     private static final String URL_PREFIX = "http://";

     @Override
     public String getFullUrl(String url) {

         if (!url.startsWith(URL_PREFIX)) {
             return  URL_PREFIX + url;
         }
         return url;
     }
 }
Jose Martinez
  • 11,452
  • 7
  • 53
  • 68