Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /*
   * To change this template, choose Tools | Templates
   * and open the template in the editor.
   */
  package it.grabz.grabzit;
  
 import java.io.File;
 import java.net.URL;
 import java.util.Date;
This client provides access to the GrabzIt web services This API allows you to take screenshot of websites for free and convert them into images, PDF's and tables.

Author(s):
GrabzIt
Version:
2.0
See also:
GrabzIt Java API
 
 public class GrabzItClient {
     private String applicationKey;
     private String applicationSecret;
 
     private String request;
     private String signaturePartOne;
     private String signaturePartTwo;
     
     private final String BASE_URL = "http://grabz.it/services/";

    
Create a new instance of the Client class in order to access the GrabzIt API.

Parameters:
applicationKey your application key
applicationSecret your application secret
See also:
You can get an application key and secret by registering for free with GrabzIt
 
     public GrabzItClient(String applicationKeyString applicationSecret)
     {
         this. = applicationKey;
         this. = applicationSecret;
     }
    
    
This method sets the parameters required to take a screenshot of a web page.

Parameters:
url The URL that the screenshot should be made of
customId A custom identifier that you can pass through to the screenshot web service. This will be returned with the callback URL you have specified
browserWidth The width of the browser in pixels
browserHeight The height of the browser in pixels
outputWidth The height of the resulting screenshot in pixels
outputHeight The width of the resulting screenshot in pixels
format The format the screenshot should be in: bmp8, bmp16, bmp24, bmp, tiff, jpg, png
delay The number of milliseconds to wait before taking the screenshot
targetElement The id of the only HTML element in the web page to turn into a screenshot
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
customWaterMarkId Add a custom watermark to the image
quality The quality of the image where 0 is poor and 100 excellent. The default is -1 which uses the recommended quality for the specified image format
country Request the screenshot from different countries: Default, UK or US
Throws:
java.io.UnsupportedEncodingException
 
     public void SetImageOptions(String urlString customIdint browserWidthint browserHeightint outputWidthint outputHeightImageFormat formatint delayString targetElementBrowserType requestAsString customWaterMarkIdint qualityCountry countrythrows UnsupportedEncodingException
     {
         this. = String.format("%stakepicture.ashx?url=%s&key=%s&width=%s&height=%s&bwidth=%s&bheight=%s&format=%s&customid=%s&delay=%s&target=%s&customwatermarkid=%s&requestmobileversion=%s&country=%s&quality=%s&callback=",
                                                               encode(url), outputWidthoutputHeight,
                                                               browserWidthbrowserHeightformat.getValue(), encode(customId), delayencode(targetElement), encode(customWaterMarkId), requestAs.getValue(), country.getValue(), quality);
         this. =  + "|" + url + "|";
         this. = "|" + format.getValue() + "|" + outputHeight + "|" + outputWidth + "|" + browserHeight + "|" + browserWidth + "|" + customId + "|" + delay + "|" + targetElement + "|" + customWaterMarkId + "|" + requestAs.getValue() + "|" + country.getValue() + "|" + quality;
     }

        
This method sets the parameters required to take a screenshot of a web page.

Parameters:
url The URL that the screenshot should be made of
customId A custom identifier that you can pass through to the screenshot web service. This will be returned with the callback URL you have specified
browserWidth The width of the browser in pixels
browserHeight The height of the browser in pixels
outputWidth The height of the resulting screenshot in pixels
outputHeight The width of the resulting screenshot in pixels
format The format the screenshot should be in: bmp8, bmp16, bmp24, bmp, tiff, jpg, png
delay The number of milliseconds to wait before taking the screenshot
targetElement The id of the only HTML element in the web page to turn into a screenshot
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
customWaterMarkId Add a custom watermark to the image
Throws:
java.io.UnsupportedEncodingException
    public void SetImageOptions(String urlString customIdint browserWidthint browserHeightint outputWidthint outputHeightImageFormat formatint delayString targetElementBrowserType requestAsString customWaterMarkIdthrows UnsupportedEncodingException
    {
        SetImageOptions(urlcustomIdbrowserWidthbrowserHeightoutputWidthoutputHeightformatdelaytargetElementrequestAscustomWaterMarkId, -1, .);
    }

    
This method sets the parameters required to take a screenshot of a web page.

Parameters:
url The URL that the screenshot should be made of
Throws:
java.io.UnsupportedEncodingException
    public void SetImageOptions(String urlthrows UnsupportedEncodingException
    {
        SetImageOptions(url"", 0, 0, 0, 0, ., 0, ""."");
    }

    
This method sets the parameters required to take a screenshot of a web page.

Parameters:
url The URL that the screenshot should be made of
customId A custom identifier that you can pass through to the screenshot web service. This will be returned with the callback URL you have specified
Throws:
java.io.UnsupportedEncodingException
    public void SetImageOptions(String urlString customIdthrows UnsupportedEncodingException
    {
        SetImageOptions(urlcustomId, 0, 0, 0, 0, ., 0, ""."");
    }

    
This method sets the parameters required to extract all tables from a web page.

Parameters:
url The URL that the should be used to extract tables
customId A custom identifier that you can pass through to the web service. This will be returned with the callback URL you have specified
tableNumberToInclude Which table to include, in order from the beginning of the page to the end
format The format the table should be in: csv, xlsx
includeHeaderNames If true header names will be included in the table
includeAllTables If true all table on the web page will be extracted with each table appearing in a separate spreadsheet sheet. Only available with the XLSX format
targetElement The id of the only HTML element in the web page that should be used to extract tables from
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
country Request the screenshot from different countries: Default, UK or US
Throws:
java.io.UnsupportedEncodingException
    public void SetTableOptions(String urlString customIdint tableNumberToIncludeTableFormat formatboolean includeHeaderNamesboolean includeAllTablesString targetElementBrowserType requestAsCountry countrythrows UnsupportedEncodingException
    {
        this. =  + "taketable.ashx?key=" + encode()+"&url="+encode(url)+"&includeAllTables="toInt(includeAllTables)+"&includeHeaderNames="+toInt(includeHeaderNames)+"&format="+format.getValue()+"&tableToInclude="+tableNumberToInclude+"&customid="+encode(customId)+"&target="+encode(targetElement)+"&requestmobileversion="+requestAs.getValue()+"&country="+country.getValue()+"&callback=";
        this. = +"|"+url+"|";
        this. = "|"+customId+"|"+tableNumberToInclude+"|"+toInt(includeAllTables)+"|"+toInt(includeHeaderNames)+"|"+targetElement+"|"+format.getValue()+"|"+requestAs.getValue()+"|"+country.getValue();
    }
    
     
This method sets the parameters required to extract all tables from a web page.

Parameters:
url The URL that the should be used to extract tables
customId A custom identifier that you can pass through to the web service. This will be returned with the callback URL you have specified
tableNumberToInclude Which table to include, in order from the beginning of the page to the end
format The format the table should be in: csv, xlsx
includeHeaderNames If true header names will be included in the table
includeAllTables If true all table on the web page will be extracted with each table appearing in a separate spreadsheet sheet. Only available with the XLSX format
targetElement The id of the only HTML element in the web page that should be used to extract tables from
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
Throws:
java.io.UnsupportedEncodingException
    public void SetTableOptions(String urlString customIdint tableNumberToIncludeTableFormat formatboolean includeHeaderNamesboolean includeAllTablesString targetElementBrowserType requestAsthrows UnsupportedEncodingException
    {
        SetTableOptions(urlcustomIdtableNumberToIncludeformatincludeHeaderNamesincludeAllTablestargetElementrequestAs.);
    }   

    
This method sets the parameters required to extract all tables from a web page.

Parameters:
url The URL that the should be used to extract tables
customId A custom identifier that you can pass through to the web service. This will be returned with the callback URL you have specified
Throws:
java.io.UnsupportedEncodingException
    public void SetTableOptions(String urlString customIdthrows UnsupportedEncodingException
    {
        SetTableOptions(urlcustomId, 1, .truefalse"".);
    }

    
This method sets the parameters required to extract all tables from a web page.

Parameters:
url The URL that the should be used to extract tables
Throws:
java.io.UnsupportedEncodingException
    public void SetTableOptions(String urlthrows UnsupportedEncodingException
    {
        SetTableOptions(url"", 1, .truefalse"".);
    }

    
This method sets the parameters required to convert a web page into a PDF.

Parameters:
url The URL that the should be converted into a PDF
customId A custom identifier that you can pass through to the webs ervice. This will be returned with the callback URL you have specified
includeBackground If true the background of the web page should be included in the screenshot
pagesize The page size of the PDF to be returned: 'A3', 'A4', 'A5', 'B3', 'B4', 'B5', 'Letter'
orientation The orientation of the PDF to be returned: 'Landscape' or 'Portrait'
includeLinks True if links should be included in the PDF
includeOutline True if the PDF outline should be included
title Provide a title to the PDF document
coverURL The URL of a web page that should be used as a cover page for the PDF
marginTop The margin that should appear at the top of the PDF document page
marginLeft The margin that should appear at the left of the PDF document page
marginBottom The margin that should appear at the bottom of the PDF document page
marginRight The margin that should appear at the right of the PDF document
delay The number of milliseconds to wait before taking the screenshot
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
customWaterMarkId Add a custom watermark to each page of the PDF document
quality The quality of the PDF where 0 is poor and 100 excellent. The default is -1 which uses the recommended quality
country Request the screenshot from different countries: Default, UK or US
Throws:
java.io.UnsupportedEncodingException
    public void SetPDFOptions(String urlString customIdboolean includeBackgroundPageSize pagesizePageOrientation orientationboolean includeLinksboolean includeOutlineString titleString coverURLint marginTopint marginLeftint marginBottomint marginRightint delayBrowserType requestAsString customWaterMarkIdint qualityCountry countrythrows UnsupportedEncodingException
    {
        this. =  + "takepdf.ashx?key=" + encode() + "&url=" + encode(url) + "&background=" + toInt(includeBackground) + "&pagesize=" + pagesize.getValue() + "&orientation=" + orientation.getValue() + "&customid=" + encode(customId) + "&customwatermarkid=" + encode(customWaterMarkId) + "&includelinks=" + toInt(includeLinks) + "&includeoutline=" + toInt(includeOutline) + "&title=" + encode(title) + "&coverurl=" + encode(coverURL) + "&mleft=" + marginLeft + "&mright=" + marginRight + "&mtop=" + marginTop + "&mbottom=" + marginBottom + "&delay=" + delay + "&requestmobileversion=" + requestAs.getValue() + "&country=" + country.getValue() + "&quality=" + quality + "&callback=";
        this. =  + "|" + url + "|";
        this. = "|" + customId + "|" + toInt(includeBackground) + "|" + pagesize.getValue() + "|" + orientation.getValue() + "|" + customWaterMarkId + "|" + toInt(includeLinks) + "|" + toInt(includeOutline) + "|" + title + "|" + coverURL + "|" + marginTop + "|" + marginLeft + "|" + marginBottom + "|" + marginRight + "|" + delay + "|" + requestAs.getValue() + "|" + country.getValue() + "|" + quality;
    }

   
This method sets the parameters required to convert a web page into a PDF.

Parameters:
url The URL that the should be converted into a PDF
customId A custom identifier that you can pass through to the webs ervice. This will be returned with the callback URL you have specified
includeBackground If true the background of the web page should be included in the screenshot
pagesize The page size of the PDF to be returned: 'A3', 'A4', 'A5', 'B3', 'B4', 'B5', 'Letter'
orientation The orientation of the PDF to be returned: 'Landscape' or 'Portrait'
includeLinks True if links should be included in the PDF
includeOutline True if the PDF outline should be included
title Provide a title to the PDF document
coverURL The URL of a web page that should be used as a cover page for the PDF
marginTop The margin that should appear at the top of the PDF document page
marginLeft The margin that should appear at the left of the PDF document page
marginBottom The margin that should appear at the bottom of the PDF document page
marginRight The margin that should appear at the right of the PDF document
delay The number of milliseconds to wait before taking the screenshot
requestAs Request screenshot in different forms: Standard Browser, Mobile Browser and Search Engine
customWaterMarkId Add a custom watermark to each page of the PDF document
Throws:
java.io.UnsupportedEncodingException
    public void SetPDFOptions(String urlString customIdboolean includeBackgroundPageSize pagesizePageOrientation orientationboolean includeLinksboolean includeOutlineString titleString coverURLint marginTopint marginLeftint marginBottomint marginRightint delayBrowserType requestAsString customWaterMarkIdthrows UnsupportedEncodingException
    {
        SetPDFOptions(urlcustomIdincludeBackgroundpagesizeorientationincludeLinksincludeOutlinetitlecoverURLmarginTopmarginLeftmarginBottommarginRightdelayrequestAscustomWaterMarkId, -1, .);
    }
    
This method sets the parameters required to convert a web page into a PDF.

Parameters:
url The URL that the should be converted into a PDF
customId A custom identifier that you can pass through to the web service. This will be returned with the callback URL you have specified
Throws:
java.io.UnsupportedEncodingException
    public void SetPDFOptions(String urlString customId)  throws UnsupportedEncodingException
    {
        SetPDFOptions(urlcustomIdtrue..truefalse"""", 10, 10, 10, 10, 0, ."");
    }

    
This method sets the parameters required to convert a web page into a PDF.

Parameters:
url The URL that the should be converted into a PDF
Throws:
java.io.UnsupportedEncodingException
    public void SetPDFOptions(String url)  throws UnsupportedEncodingException
    {
        SetPDFOptions(url""true..truefalse"""", 10, 10, 10, 10, 0, ."");
    }

    
Calls the GrabzIt web service to take the screenshot.

Parameters:
callBackURL The handler the GrabzIt web service should call after it has completed its work
Returns:
The unique identifier of the screenshot. This can be used to get the screenshot with the GetResult method
Throws:
java.lang.Exception
    public String Save(String callBackURLthrows Exception
    {
        if (isNullOrEmpty(this.) && isNullOrEmpty(this.) && isNullOrEmpty(this.))
        {
            throw new GrabzItException("No screenshot parameters have been set.".);
        }
        String sig = encrypt(this. + callBackURL + this.);
        String currentRequest = this.;
        
        currentRequest += encode(callBackURL) + "&sig=" + encode(sig);
        TakeScreenShotResult result = get(currentRequestTakeScreenShotResult.class);
        checkForError(result);
        return result.getId();
    }

    
Calls the GrabzIt web service to take the screenshot.

Returns:
The unique identifier of the screenshot. This can be used to get the screenshot with the GetResult method
Throws:
java.lang.Exception
    public String Save() throws Exception
    {
        return Save("");
    }

    
Calls the GrabzIt web service to take the screenshot and returns a GrabzItFile object Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response

Returns:
Returns a GrabzItFile object containing the screenshot data.
Throws:
java.lang.Exception
    public GrabzItFile SaveTo() throws Exception
    {
        String id = Save();
        
        if (isNullOrEmpty(id))
        {
            return null;
        }
        
        //Wait for it to be ready.
        while (true)
        {
            Status status = GetStatus(id);
            if (!status.isCached() && !status.isProcessing())
            {
                throw new GrabzItException("The screenshot did not complete with the error: " + status.getMessage(), .);
            }
            if (status.isCached())
            {
                GrabzItFile result = GetResult(id);
                if (result == null)
                {
                    throw new GrabzItException("The screenshot could not be found on GrabzIt.".);
                }
                return result;
            }
            Thread.sleep(3000);
        }
    }    
    
    
Calls the GrabzIt web service to take the screenshot and saves it to the target path provided Warning, this is a SYNCHONOUS method and can take up to 5 minutes before a response

Parameters:
saveToFile The file path that the screenshot should saved to
Returns:
Returns the true if it is successful otherwise it throws an exception
Throws:
java.lang.Exception
    public boolean SaveTo(String saveToFilethrows Exception
    {
        int attempt = 0;
        while (true)
        {
            try
            {
                GrabzItFile result = SaveTo();
                if (result == null)
                {
                    return false;
                }
                result.Save(saveToFile);
                break;
            }
            catch (Exception ex)
            {
                if (attempt < 3)
                {
                    attempt++;
                    continue;
                }
                throw new GrabzItException("An error occurred trying to save the screenshot to: " +
                                    saveToFile.);
            }
        }
        return true;
    }

    
Get the current status of a GrabzIt screenshot

Parameters:
id The id of the screenshot
Returns:
A Status object representing the screenshot status
Throws:
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    public Status GetStatus(String idthrows IOExceptionJAXBExceptionException
    {
        if (isNullOrEmpty(id))
        {
            return null;
        }
        return get( + "getstatus.ashx?id=" + idStatus.class);
    }

    
Get all the cookies that GrabzIt is using for a particular domain. This may include your user set cookies as well.

Parameters:
domain The domain to return cookies for
Returns:
An array of Cookie objects
Throws:
java.lang.Exception
    public Cookie[] GetCookies(String domainthrows Exception
    {
        String sig = encrypt(String.format("%s|%s"this.domain));
        String url = String.format("%sgetcookies.ashx?domain=%s&key=%s&sig=%s",
                                                  domainsig);
        Cookies cookies = get(urlCookies.class);
        
        checkForError(cookies);
        
        return cookies.getCookies();
    }

    
Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden. This can be useful if a websites functionality is controlled by cookies.

Parameters:
name The name of the cookie to set
domain The domain of the website to set the cookie for
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    {
        return SetCookie(namedomain""""falsenull);
    }

    
Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden. This can be useful if a websites functionality is controlled by cookies.

Parameters:
name The name of the cookie to set
domain The domain of the website to set the cookie for
value The value of the cookie
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    {
        return SetCookie(namedomainvalue""falsenull);
    }

    
Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden. This can be useful if a websites functionality is controlled by cookies.

Parameters:
name The name of the cookie to set
domain The domain of the website to set the cookie for
value The value of the cookie
path The website path the cookie relates to
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    public boolean SetCookie(String nameString domainString valueString paththrows UnsupportedEncodingExceptionNoSuchAlgorithmExceptionIOExceptionJAXBExceptionException
    {
        return SetCookie(namedomainvaluepathfalsenull);
    }

    
Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden. This can be useful if a websites functionality is controlled by cookies.

Parameters:
name The name of the cookie to set
domain The domain of the website to set the cookie for
value The value of the cookie
path The website path the cookie relates to
httponly Is the cookie only used on HTTP
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    public boolean SetCookie(String nameString domainString valueString pathboolean httponlythrows UnsupportedEncodingExceptionNoSuchAlgorithmExceptionIOExceptionJAXBExceptionException
    {
        return SetCookie(namedomainvaluepathhttponlynull);
    }

    
Sets a new custom cookie on GrabzIt, if the custom cookie has the same name and domain as a global cookie the global cookie is overridden. This can be useful if a websites functionality is controlled by cookies.

Parameters:
name The name of the cookie to set
domain The domain of the website to set the cookie for
value The value of the cookie
path The website path the cookie relates to
httponly Is the cookie only used on HTTP
expires When the cookie expires. Pass a null value if it does not expire
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    public boolean SetCookie(String nameString domainString valueString pathboolean httponlyDate expiresthrows UnsupportedEncodingExceptionNoSuchAlgorithmExceptionIOExceptionJAXBExceptionException
    {
        String expiresStr = "";
        if (expires != null)
        {
            DateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
            expiresStr = df.format(expires);
        }
        
        String sig = encrypt(String.format("%s|%s|%s|%s|%s|%s|%s|%s"namedomain,
                                      valuepath, (httponly ? 1 : 0), expiresStr, 0));
        
        String url = String.format("%ssetcookie.ashx?name=%s&domain=%s&value=%s&path=%s&httponly=%s&expires=%s&key=%s&sig=%s",
                                                  encode(name), encode(domain), encode(value), encode(path), (httponly ? 1 : 0), encode(expiresStr), sig);
        GenericResult webResult = get(urlGenericResult.class);
        checkForError(webResult);
        return Boolean.valueOf(webResult.getResult());
    }

    
Delete a custom cookie or block a global cookie from being used.

Parameters:
name The name of the cookie to delete
domain The website the cookie belongs to
Returns:
Returns true if the cookie was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    {
        String sig = encrypt(String.format("%s|%s|%s|%s"namedomain, 1));
        String url = String.format("%ssetcookie.ashx?name=%s&domain=%s&delete=1&key=%s&sig=%s",
                                                  encode(name), encode(domain), sig);
        GenericResult webResult = get(urlGenericResult.class);
        checkForError(webResult);
        return Boolean.valueOf(webResult.getResult());
    }

    
Add a new custom watermark.

Parameters:
identifier The identifier you want to give the custom watermark. It is important that this identifier is unique
path The absolute path of the watermark on your server. For instance C:/watermark/1.png
xpos The horizontal position you want the screenshot to appear at
ypos The vertical position you want the screenshot to appear at
Returns:
Returns true if the watermark was successfully set
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.net.MalformedURLException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    {
        File fileToUpload = new File(path);
        if(!fileToUpload.exists())
        {
            throw new GrabzItException("File: " + path + " does not exist".);
        }
        
        String sig = encrypt(String.format("%s|%s|%s|%s"identifier, String.valueOf(xpos.getValue()), String.valueOf(ypos.getValue())));
        String url = String.format("%saddwatermark.ashx");
        
        Post post = new Post(url"UTF-8");
 
        post.addFormField("key");
        post.addFormField("identifier"identifier);
        post.addFormField("xpos", String.valueOf(xpos.getValue()));
        post.addFormField("ypos", String.valueOf(ypos.getValue()));
        post.addFormField("sig"sig);
        post.addFilePart("watermark"fileToUpload);
        GenericResult webResult = post.finish(GenericResult.class);
        checkForError(webResult);
        return Boolean.valueOf(webResult.getResult());
    }

    
Delete a custom watermark.

Parameters:
identifier The identifier of the custom watermark you want to delete
Returns:
Returns true if the watermark was successfully deleted
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.lang.Exception
    {
        String sig = encrypt(String.format("%s|%s"identifier));
        String url = String.format("%sdeletewatermark.ashx?key=%s&identifier=%s&sig=%s",
                                                              encode(), encode(identifier), sig);
        GenericResult webResult = get(urlGenericResult.class);
        checkForError(webResult);
        return Boolean.valueOf(webResult.getResult());
    }

    
    {
        return getWaterMarks("");
    }

    
Get a particular custom watermark.

Parameters:
identifier The identifier of a particular custom watermark you want to view
Returns:
A WaterMark object
Throws:
java.io.UnsupportedEncodingException
java.security.NoSuchAlgorithmException
java.io.IOException
javax.xml.bind.JAXBException
java.lang.Exception
    {
        WaterMark[] waterMarks = getWaterMarks(identifier);
        if (waterMarks == null || waterMarks.length != 1)
        {
            return null;
        }
        return waterMarks[0];
    }
    {
        String sig =  encrypt(String.format("%s|%s"identifier));
        String url = String.format("%sgetwatermarks.ashx?key=%s&identifier=%s&sig=%s",
                                                          encode(), encode(identifier), sig);
        WaterMarks watermarks = get(urlWaterMarks.class);
        if (watermarks == null)
        {
            return new WaterMark[0];
        }
        
        checkForError(watermarks);
        return watermarks.getWaterMarks();
    }

    
This method returns the screenshot.

Parameters:
id The unique identifier of the screenshot, returned by the callback handler or the Save method
Returns:
A GrabzItFile object representing the screenshot
Throws:
java.io.IOException
java.lang.Exception
    public GrabzItFile GetResult(String idthrows IOExceptionException
    {
        String url = String.format("%sgetfile.ashx?id=%s"id);
        URL requestUrl = new URL(url);
        URLConnection connection = (URLConnectionrequestUrl.openConnection();
        HttpUtility.CheckResponse(connection);
        InputStream in = null;
        ByteArrayOutputStream buffer = null;
        try
        {
            in = connection.getInputStream();
            buffer = new ByteArrayOutputStream();
            int nRead;
            byte[] data = new byte[16384];
            while ((nRead = in.read(data, 0, data.length)) != -1)
            {
                buffer.write(data, 0, nRead);
            }
            buffer.flush();
            return new GrabzItFile(buffer.toByteArray());
        } 
        finally
        {
            if (in != null)
            {
                in.close();
            }
            if (buffer != null)
            {
                buffer.close();
            }
        }
    }
    private void checkForError(IMessageResult resultthrows Exception
    {
        if (!isNullOrEmpty(result.getMessage()))
        {
            throw new GrabzItException(result.getMessage(), result.getCode());
        }
    }
    
    private <T> T get(String urlClass<T> clazzthrows IOExceptionJAXBExceptionException
    {
        try
        {
            URL request = new URL(url);
            URLConnection connection = (URLConnectionrequest.openConnection();
            HttpUtility.CheckResponse(connection);        
            Response response = new Response();        
            return response.Parse(connectionclazz);
        }
        catch(UnknownHostException e)
        {
            throw new GrabzItException("A network error occured when connecting to the GrabzIt servers.".);
        }
    }
    {
        if (value == null || value.isEmpty())
        {
            return "";
        }
        MessageDigest md = MessageDigest.getInstance("MD5");
        md.update(value.getBytes("ASCII"));
        byte[] hash = md.digest();
        
        StringBuilder sb = new StringBuilder(hash.length); 
        for(byte b : hash)
        { 
            sb.append(String.format("%02x"b&0xff)); 
        }
        return sb.toString();
    }
    private String encode(String valuethrows UnsupportedEncodingException
    {
        return URLEncoder.encode(value"UTF-8");
    }
    private boolean isNullOrEmpty(String toTest)
    {
        return (toTest == null || toTest.isEmpty());
    }
    private int toInt(boolean value)
    {
        return (value ? 1 : 0);
    }
New to GrepCode? Check out our FAQ X