Package snap.web

Class WebURL

java.lang.Object
snap.web.WebURL

public class WebURL extends Object
A class to represent a URL for a WebSite and WebFile (it can be both for nested sources). Has the form: [Scheme:][//Authority][/Path[!/Path]][?Query][#HashTag]. Authority has the form: [UserInfo@]Host[:Port].

WebURL is a thin wrapper around standard URL, but provides easy access to the WebSite and WebFile.

  • Field Details

    • _asSite

      protected WebSite _asSite
  • Constructor Details

    • WebURL

      protected WebURL(Object aSource)
      Constructor for given source.
  • Method Details

    • getURL

      public static WebURL getURL(Object anObj)
      Returns a URL for given object.
    • getURLOrThrow

      public static WebURL getURLOrThrow(Object anObj)
      Returns a URL for given object.
    • getURL

      public static WebURL getURL(Class<?> aClass, String aName)
      Returns a URL for given class and resource name.
    • getSource

      public Object getSource()
      Returns the source of this URL (java.net.URL, File, String).
    • getSourceURL

      public URL getSourceURL()
      Returns the source as standard Java URL. Might contain site-path separator. See getJavaURL().
    • getString

      public String getString()
      Returns the full URL string.
    • getScheme

      public String getScheme()
      Returns the URL Scheme (lower case).
    • getHost

      public String getHost()
      Returns the Host part of the URL.
    • getPort

      public int getPort()
      Returns the port of the URL.
    • getPath

      public String getPath()
      Returns the part of the URL string that describes the file path.
    • getFilename

      public String getFilename()
      Returns the last component of the file path.
    • getFilenameSimple

      public String getFilenameSimple()
      Returns the filename without extension.
    • getType

      public String getType()
      Returns the file type (extension without the '.').
    • getQuery

      public String getQuery()
      Returns the part of the URL string that describes the query.
    • getQueryValue

      public String getQueryValue(String aKey)
      Returns the value for given Query key in URL, if available.
    • getRef

      public String getRef()
      Returns the hash tag reference from the URL as a simple string.
    • getRefValue

      public String getRefValue(String aKey)
      Returns the value for given HashTag key in URL, if available.
    • getSite

      public WebSite getSite()
      Returns the site that this URL belongs to.
    • getSiteURL

      public WebURL getSiteURL()
      Returns the URL for the site that this URL belongs to.
    • getAsSite

      public WebSite getAsSite()
      Returns the site for this URL (assumes this URL is a site).
    • getFile

      public WebFile getFile()
      Returns the file for the URL.
    • createFile

      public WebFile createFile(boolean isDir)
      Creates a file for the URL.
    • isFileURL

      public boolean isFileURL()
      Returns whether URL specifies only the file (no query/hashtags).
    • getFileURL

      public WebURL getFileURL()
      Returns the URL for the file only (no query/hashtags).
    • isQueryURL

      public boolean isQueryURL()
      Returns whether URL specifies only file and query (no hashtag references).
    • getQueryURL

      public WebURL getQueryURL()
      Returns the URL for the file and query only (no hashtag references).
    • getJavaURL

      public URL getJavaURL()
      Returns the source as standard Java URL (if possible).
    • getJavaFile

      public File getJavaFile()
      Returns the source as standard Java File (if possible).
    • isFound

      public boolean isFound()
      Returns whether URL can be found.
    • getLastModTime

      public long getLastModTime()
      Returns the last modified time.
    • getBytes

      public byte[] getBytes()
      Returns bytes for this URL.
    • getBytesOrThrow

      public byte[] getBytesOrThrow() throws IOException
      Returns bytes for this URL.
      Throws:
      IOException
    • postBytes

      public byte[] postBytes(byte[] theBytes)
      Returns bytes for this URL.
    • getText

      public String getText()
      Returns the file bytes as a string.
    • getInputStream

      public InputStream getInputStream()
      Returns an input stream for file.
    • getHead

      public WebResponse getHead()
      Returns the response for a HEAD request.
    • getFileHeader

      public FileHeader getFileHeader()
      Returns the FileHeader.
    • getResponse

      public WebResponse getResponse()
      Returns Response for a Get request.
    • getResponseAndCall

      public void getResponseAndCall(Consumer<WebResponse> aCallback)
      Returns bytes for this URL.
    • getParent

      public WebURL getParent()
      Returns the parent URL.
    • getChild

      public WebURL getChild(String aName)
      Returns the child URL for given name.
    • equals

      public boolean equals(Object anObj)
      Standard equals implementation.
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Standard HashCode implementation.
      Overrides:
      hashCode in class Object
    • toString

      public String toString()
      Standard toString implementation.
      Overrides:
      toString in class Object