/** * Add a webLinkedFile in the queue if it hasn't been already downloaded and if it respect the * good host or protocol * * @param uri the URI to add * @param depth the depth of the URI * @param parent the webHtmlFile parent */ public void addLinkedFile(URI uri, int depth, WebFile parent) { // creates the webLinkedFile according to the URI if (!isUriAlreadyDownloaded(uri)) { // verification if the depth is good if (depth <= maxDepth) { discoveredURI.add(Utils.getCompletePath(uri)); WebLinkedFile webLinkedFile = new WebLinkedFile(uri, depth, parent); String webFileHost = Utils.getCompleteHost(webLinkedFile.getURI()); // filter the linked files with the Filter RE r = new RE(regExp); if (r.match(webLinkedFile.getFileName())) { if (webFileHost.equals(defaultHost)) { linkedFileToDownload.add(webLinkedFile); // add the webHtmlFile in the treeModel DiscoveryTreeNode parentNode = (DiscoveryTreeNode) treeRoot.getChild(parent); DiscoveryTreeNode node = parentNode.add(webLinkedFile); treeModel.nodesWereInserted(parentNode, new int[] {parentNode.getIndex(node)}); // add the webHtmlFile in the detailledModel detailledModel.addElement(webLinkedFile); } else { // it is not the same web site or the same protocol System.err.println( webLinkedFile.getURI() + " / " + defaultHost + ": NOT THE SAME HOST OR THE SAME PROTOCOL"); } } } } }
/** * Add a webHtmlFile in the queue if it hasn't been already downloaded and if it respect the good * host or protocol * * @param uri the URI to add * @param depth the depth of the URI */ public void addHtmlFile(URI uri, int depth) { // creates the webHtmlFile according to the URI if (!isUriAlreadyDownloaded(uri)) { // verification if the depth is good if (depth <= maxDepth) { discoveredURI.add(Utils.getCompletePath(uri)); WebHtmlFile webHtmlFile = new WebHtmlFile(uri, depth); String webFileHost = Utils.getCompleteHost(webHtmlFile.getURI()); if (webFileHost.equals(defaultHost)) { htmlFileToDownload.add(webHtmlFile); // add the webHtmlFile in the treeModel DiscoveryTreeNode node = treeRoot.add(webHtmlFile); treeModel.nodesWereInserted(treeRoot, new int[] {treeRoot.getIndex(node)}); if (tree.isRootVisible() && !tree.isExpanded(0)) { tree.expandRow(0); tree.setRootVisible(false); } // add the webHtmlFile in the detailledModel detailledModel.addElement(webHtmlFile); } else { // it is not the same web site or the same protocol System.err.println( webHtmlFile.getURI() + " / " + defaultHost + ": NOT THE SAME HOST OR THE SAME PROTOCOL"); } } } }
/** * Create a DownloadManager * * @param maxDLHtml number of maximum simultaneous html download file * @param maxDLLink number of maximum simultaneous linked download file * @param maxDepth depth of the download in the WebSite * @param startURI URI from which the download begin * @param destDirectory directory where the datas will be stored * @param regExp the filter of the linked WebFiles */ private DownloadManager( int maxDLHtml, int maxDLLink, int maxDepth, URI startURI, String destDirectory, String regExp) { htmlFileToDownload = new ArrayList<WebHtmlFile>(); linkedFileToDownload = new ArrayList<WebLinkedFile>(); htmlFileInDownloading = new ArrayList<WebHtmlFile>(); linkedFileInDownloading = new ArrayList<WebLinkedFile>(); discoveredURI = new ArrayList<String>(); this.maxDLHtml = maxDLHtml; this.maxDLLink = maxDLLink; currentDLHtml = 0; currentDLLink = 0; this.maxDepth = maxDepth; this.destDirectory = destDirectory; this.regExp = regExp; threadList = new ArrayList<DownloadAndParseFile>(); defaultHost = Utils.getCompleteHost(startURI); // raz the current jHoover project ActionManager.initAction(); detailledModel = DetailledModel.getInstance(); // creates the JTree in the discovery part createJTree(); // creates the JTable "ALL" in the detailled part GuiUtils.createNewTable(detailledModel, Labels.ALL_LABEL, Labels.ALL_REGEXP_LABEL); // creates the JTable "HTML" in the detailled part GuiUtils.createNewTable(detailledModel, Labels.HTML_LABEL, Labels.HTML_REGEXP_LABEL); // creates the JTable "FILES" in the detailled part GuiUtils.createNewTable(detailledModel, Labels.FILES_LABEL, Labels.FILES_REGEXP_LABEL); }