Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import javax.swing.*;
- import java.awt.Desktop;
- import java.awt.*;
- import java.awt.event.*;
- public class Testxl {
- static String menu;
- static String title = "DownsLink 0.3";
- static void openUrl(String link) {
- Desktop desk = java.awt.Desktop.getDesktop();
- try {
- desk.browse(new java.net.URI(link));
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- static void startSystem(){
- String user = System.getProperty("user.name");
- try {
- menu = "Software Info:\nDeveloped by: Utroz(RSC)\nE-mail: [email protected]\nBlog: www.GCoders.info\n---------------------\n\nHello "+user+",\n\n[Menu Options]:\nSearch link and show: [1]\nSearch link and open: [2]\nText reverse: [3]\nCatch Links: [4]\nExit system: [5]\n---------------------\n\nPlease input a option:";
- JTextArea area = new JTextArea(menu);
- JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- scroll.setPreferredSize(new Dimension(300,300));
- int options = Integer.parseInt(JOptionPane.showInputDialog(null,scroll, title, JOptionPane.PLAIN_MESSAGE));
- switch(options){
- case 1:
- newUrl(false);
- break;
- case 2:
- newUrl(true);
- break;
- case 3: reverseText();
- break;
- case 4: searchLink();
- break;
- case 5:
- JOptionPane.showMessageDialog(null, "Thanks for use the system!");
- System.exit(0);
- }
- } catch (NumberFormatException ex){
- startSystem();
- }
- }
- static void reverseText(){
- String reverse = "";
- String link = JOptionPane.showInputDialog(null, "Developed by: Utroz(RSC)\nE-mail: [email protected]\n\nPlease input a Text to be reverse:", title, JOptionPane.PLAIN_MESSAGE);
- for(int i = link.length()-1; i >= 0; i--){
- reverse += link.charAt(i);
- }
- JTextArea area = new JTextArea("Reverse Text: \n"+reverse+"");
- JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- scroll.setPreferredSize(new Dimension(300,300));
- JOptionPane.showMessageDialog(null,scroll);
- startSystem();
- }
- static void searchLink () {
- String linkx = JOptionPane.showInputDialog(null, "Developed by: Utroz(RSC)\nE-mail: [email protected]\n\nPlease input a URL to Links catch:\nExample Format: [http://www.google.com.br]", title, JOptionPane.PLAIN_MESSAGE);
- HTMLUtils.start(linkx);
- startSystem();
- }
- static void newUrl(boolean arg){
- try {
- String link;
- if (arg == true){
- link = JOptionPane.showInputDialog(null, "Developed by: Utroz(RSC)\nE-mail: [email protected]\n\nPlease input a Link (Browser) to be open:", title, JOptionPane.PLAIN_MESSAGE);
- } else {
- link = JOptionPane.showInputDialog(null, "Developed by: Utroz(RSC)\nE-mail: [email protected]\n\nPlease input a Link (Browser) to be revert:", title, JOptionPane.PLAIN_MESSAGE);
- }
- boolean isTrue = false;
- String url = "", newLink = "", revertLink = "", urlB = "";
- for(int i = 0; i < link.length(); i++){
- if(link.charAt(i) == 117){
- url += link.charAt(i);
- url += link.charAt(i + 1);
- url += link.charAt(i + 2);
- url += link.charAt(i + 3);
- }
- if(url.equals("url=")){ // search for 'url='.
- i = i + 4;
- for(int x = i; x < link.length(); x++){
- if(link.charAt(x) == 61){
- urlB += link.charAt(x);
- urlB += link.charAt(x + 1);
- urlB += link.charAt(x + 2);
- urlB += link.charAt(x + 3);
- }
- if(urlB.equals("=lru")){ // search for '=lru'.
- break;
- }
- else {
- urlB = "";
- }
- newLink += link.charAt(x); // catch link after 'url'.
- }
- isTrue = true;
- break;
- } else {
- url = "";
- isTrue = false;
- }
- }
- if(isTrue == true){
- for(int revert = newLink.length()-1; revert >= 0; revert--){ // reverse link.
- revertLink += newLink.charAt(revert);
- }
- if(arg == true){
- JOptionPane.showMessageDialog(null, "Link was opened sucessfully!");
- openUrl(revertLink);
- } else {
- JOptionPane.showMessageDialog(null, "Link was reverted sucessfully!");
- JTextArea area = new JTextArea("Reverse Link: \n"+revertLink+"");
- JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- scroll.setPreferredSize(new Dimension(300,300));
- JOptionPane.showMessageDialog(null,scroll);
- }
- } else if (isTrue == false){
- JOptionPane.showMessageDialog(null, "Error: Wrong Link!", "Message:", JOptionPane.ERROR_MESSAGE);
- }
- startSystem();
- } catch(IndexOutOfBoundsException ex){
- JOptionPane.showMessageDialog(null, "Error: Wrong Link!", "Message:", JOptionPane.ERROR_MESSAGE);
- startSystem();
- }
- }
- public static void main (String[] args) {
- startSystem();
- }
- }
- import java.io.IOException;
- import java.util.ArrayList;
- import javax.swing.*;
- import org.jsoup.nodes.Document;
- import org.jsoup.Jsoup;
- import org.jsoup.nodes.Element;
- import org.jsoup.select.Elements;
- import java.awt.*;
- import java.awt.event.*;
- public class HTMLUtils {
- public static void start(String url) {
- extractLinks(url);
- }
- static void extractLinks (String url){
- try{
- ArrayList <String> pageLinks = new ArrayList<String>();
- Document doc = Jsoup.connect(url).get();
- Elements links = doc.select("a[href]");
- String codeFont;
- StringBuffer newStr = new StringBuffer ();
- newStr.setLength(0);
- for(Element link : links){
- codeFont = link.toString(); // take Code Font on the page.
- StringBuffer str = new StringBuffer();
- str.setLength(0);
- for(int i = 0; i < codeFont.length(); i++){
- if(codeFont.charAt(i) == 'h'){
- str.append(codeFont.charAt(i)); // h
- str.append(codeFont.charAt(i+1)); // r
- str.append(codeFont.charAt(i+2)); // e
- str.append(codeFont.charAt(i+3)); // f
- if(str.toString().equals("href")){
- i += 6; /* salt 3 positions on string. href=" */
- for(int it = i; it < codeFont.length(); it++){
- if((codeFont.charAt(it) == '"') || (codeFont.charAt(it) == ' ')){
- if(codeFont.charAt(it) == '"'){
- str.setLength(0);
- str.append(codeFont.charAt(it));
- str.append(codeFont.charAt(it + 1));
- if(str.toString().equals("\">")){ // ">
- pageLinks.add(newStr.toString()); // add to arrayList.
- newStr.setLength(0);
- str.setLength(0);
- break;
- }
- } else if(codeFont.charAt(it) == ' '){
- pageLinks.add(newStr.toString()); // add to arrayList.
- newStr.setLength(0);
- str.setLength(0);
- break;
- }
- } else {
- newStr.append(codeFont.charAt(it));
- }
- }
- } else {
- str.setLength(0);
- continue;
- }
- } else {
- continue;
- }
- } // for end.
- } // for end.
- printArray(pageLinks); // send arrayList
- }catch(IOException ex){
- }
- }
- static void printArray (ArrayList <String> arg){
- StringBuffer print = new StringBuffer(); // final print.
- for(int i = 0; i < arg.size(); i++){
- print.append(arg.get(i));
- print.append("\n");
- }
- JTextArea area = new JTextArea(print.toString());
- JScrollPane scroll = new JScrollPane(area, JScrollPane.VERTICAL_SCROLLBAR_ALWAYS, JScrollPane.HORIZONTAL_SCROLLBAR_ALWAYS);
- scroll.setPreferredSize(new Dimension(640,480));
- JOptionPane.showMessageDialog(null,scroll);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement