HTTPReadAppUpdatesJavaAgent | HTTPAppUrlVersionReader.java


/**
 * Copyright 2013 Dököll Solutions, Inc.
   Licensed under the Apache License, Version 2.0 (the "License");
   you may not use this file except in compliance with the License.
   You may obtain a copy of the License at
 
       http://www.apache.org/licenses/LICENSE-2.0
 
   Unless required by applicable law or agreed to in writing, software
   distributed under the License is distributed on an "AS IS" BASIS,
   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
   See the License for the specific language governing permissions and
   limitations under the License.
 *
 * @AppName: DöcuContent.nsf
 * Program: HTTPReadAppUpdatesJavaAgent | HTTPAppUrlVersionReader.java
 * App Version Report via URL Connect, to be read by JavaBean/Xpages
 * Created: 2013.12.22.7.36.PM
 * Updated: 2013.12.26.6.14.PM
 * Purpose: Removed bug in redirect, added listeners for buttons
 *          changed pop up messages...
 */

import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.net.URL;
import java.net.URLConnection;

import javax.swing.JOptionPane;

/**
 * @author Dököll Solutions, Inc.
 * @version 2013.12.26.12.46.AM
 * 
 */

public class HTTPAppUrlVersionReader {
	// grab coordinates from button method to perform search
	public static String getSiteUrlData(String originatingURL) throws Exception {
		// instantiate URL Object retrieved...
		URL siteURL = new URL(originatingURL);
		// establish a connection to specific URL Object...
		URLConnection connectToOrgURL = siteURL.openConnection();
		// read data obtained from incoming URL
		BufferedReader incomingUrl = new BufferedReader(new InputStreamReader(
				connectToOrgURL.getInputStream()));

		// create a String from data recorded to be thrown into the Program
		StringBuilder siteURLDataFound = new StringBuilder();
		String inputLine;

		// maintain connection to URL until full string has been read
		while ((inputLine = incomingUrl.readLine()) != null)
			siteURLDataFound.append(inputLine);

		// close the URL connection at this point
		incomingUrl.close();

		// release coordinates for viewing...
		return siteURLDataFound.toString();
	}

	// public static void doGetSiteVersionInfo() throws Exception {

	public static void main(String[] args) throws Exception {
		// declare variables
		String myOriginatingURL = "http://www.dokollsolutionsinc.com/Download.html";
		String myPreferredURL = "http://www.openntf.org/Internal/home.nsf/projects.xsp";
		String siteContent = HTTPAppUrlVersionReader
				.getSiteUrlData(myOriginatingURL);
		String strFetchFromUrl = "docucontentv2.zip";
		String strNewSearch = "please Perfom a New Search...";

		// TODO: Add Debug messages, convert to BackingBean, load messages to
		// Xpages

		// perform URL search/ send coordinates to get Method
		// ... keep as debug data
		System.out.println(siteContent);
		// ensure the string searched is valid or not
		// TODO: perform multiple String search, create XML file
		// Feed to Xpages via JavaBean
		if (siteContent.contains(strFetchFromUrl)) {

			// plug search results into variable
			String strFoundInURL = strFetchFromUrl;
			// add messages to log for debug purposes, where string(s) found
			System.out.println("Found String: " + strFoundInURL + " from "
					+ myOriginatingURL);

			if (strFoundInURL.equals("docucontentv2.zip")) {
				//alert user App available for download

				int userInput = JOptionPane.showConfirmDialog(null,
				
						"Döcu Content V2 Available, please Download...\n\n(1) Yes to Download from Dököll Solutions, Inc.\n(2) No to Download versions @ OpenNTF\n(3) Cancel to Close the Program");
				//in this case use wants to download		
				if (userInput == JOptionPane.YES_OPTION) {

					//tell user what to expect...
					// ...
					JOptionPane
							.showMessageDialog(
									null,
									"Download Döcu Content V2 from Dököll Solutions, Inc.  \nYou will be redirected to www.dokollsolutionsinc.com...",
									"www.dokollsolutionsinc.com/Download.html",
									1);
					// load myOriginatingURL hurl to user by way of
					// java.awt.Desktop
					String LoadOrgURLToUser = myOriginatingURL.toString();
					// Open user Browser to show originating URL
					java.awt.Desktop OpenOrigUrlUserBrowser = java.awt.Desktop
							.getDesktop();
					// make visible URL...
					java.net.URI ShowOrigUrlToUser = new java.net.URI(
							LoadOrgURLToUser);
					OpenOrigUrlUserBrowser.browse(ShowOrigUrlToUser);
					// add messages to log for debug purposes, where user want to download from Dököll Solutions, Inc.
					System.out.println("Download @ Dököll Solutions, Inc. instead, grab: " + strFetchFromUrl
							+ " from " + myOriginatingURL);
				}

				// in this case user wants to download from OpenNTF
				if (userInput == JOptionPane.NO_OPTION) {

					// open dialog box to view message to user
					JOptionPane
							.showMessageDialog(
									null,
									"View OpenNTF Apps available for Download.  \nYou will be redirected to http://www.openntf.org/Internal/home.nsf/projects.xsp...",
									"www.openntf.org", 1);
					// load myPreferedURL hurl to user by way of
					// java.awt.Desktop
					String LoadPrefURLToUser = myPreferredURL.toString();
					// Open user Browser to show preferred URL
					java.awt.Desktop OpenPrefUrlUserBrowser = java.awt.Desktop
							.getDesktop();
					// make visible URL...
					java.net.URI ShowPrefUrlToUser = new java.net.URI(
							LoadPrefURLToUser);
					OpenPrefUrlUserBrowser.browse(ShowPrefUrlToUser);

					// add messages to log for debug purposes, where user want to download from OpenNTF
					System.out.println("Download @ OpenNTF instead, grab: " + strFetchFromUrl
							+ " from " + myPreferredURL);
				}

				//user would rather not download anything
				if (userInput == JOptionPane.CANCEL_OPTION) {

					// open dialog box to view message to user
					JOptionPane
							.showMessageDialog(
									null,
									"You decided to not download Apps.  \nthe program will close now, Thanks!",
									"Program Closing Form", 1);

					// add messages to log for debug purposes, where user does not want to download
					System.out.println("No Download: " + strFetchFromUrl
							+ " from " + myOriginatingURL + " "
							+ strNewSearch);
				}

			}

		}

	}
}//end of program...

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>
+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++>>

// as a BackingBean, change button code to name of choice
// and plug it into beforePageLoad tags via Xpages


	public static void doGetSiteVersionInfo() throws Exception {

	//public static void main(String[] args) throws Exception {
		// declare variables
		String myOriginatingURL = "http://www.dokollsolutionsinc.com/Download.html";
		String myPreferredURL = "http://www.openntf.org/Internal/home.nsf/projects.xsp";
		String siteContent = UserBrowserLoadBean
				.getSiteUrlData(myOriginatingURL);
		String strFetchFromUrl = "docucontentv2.zip";
		String strNewSearch = "please Perfom a New Search...";

//...//...

}
All code submitted to OpenNTF XSnippets, whether submitted as a "Snippet" or in the body of a Comment, is provided under the Apache License Version 2.0. See Terms of Use for full details.
No comments yetLogin first to comment...