List of usage examples for org.apache.commons.httpclient URI URI
public URI(URI base, URI relative) throws URIException
From source file:org.zaproxy.zap.view.ContextCreateDialog.java
@Override public void save() { Context ctx = Model.getSingleton().getSession().getNewContext(this.getStringValue(NAME_FIELD)); ctx.setDescription(this.getStringValue(DESC_FIELD)); ctx.setInScope(this.getBoolValue(IN_SCOPE_FIELD)); if (topNode != null) { String url;/*www .ja v a 2s.c o m*/ try { url = new URI(topNode.getHierarchicNodeName(), false).toString(); if (topNode.isLeaf()) { url = Pattern.quote(url); } else { url = Pattern.quote(url) + ".*"; } ctx.addIncludeInContextRegex(url); } catch (URIException e) { logger.error("Bad context start url " + this.getStringValue(TOP_NODE), e); } } Model.getSingleton().getSession().saveContext(ctx); }
From source file:org.zaproxy.zap.view.popup.PopupMenuItemIncludeInContext.java
@Override public void performAction(SiteNode sn) { String url;/*from w ww . j a va 2s . c o m*/ try { url = new URI(sn.getHierarchicNodeName(), false).toString(); } catch (URIException e) { LOGGER.error("Failed to execute action include in context: " + e.getMessage(), e); return; } if (sn.isLeaf() && !(sn.getParent().getParent() == null)) { // Its a leaf and not a site url = Pattern.quote(url); } else { url = Pattern.quote(url) + ".*"; } performAction(sn.getNodeName(), url); }
From source file:phex.download.MagnetData.java
public static List<URI> lookupHttpURIs(MagnetData magnetData) { List<URI> urlList = new ArrayList<URI>(); for (String xt : magnetData.exactTopicList) { if (xt.startsWith("http://")) { try { urlList.add(new URI(xt, false)); } catch (URIException e) { // ignore try next }/*from www.j a va 2 s . c o m*/ } } for (String xs : magnetData.exactSubstituteList) { if (xs.startsWith("http://")) { try { urlList.add(new URI(xs, false)); } catch (URIException e) { // ignore try next } } } for (String as : magnetData.acceptableSubstituteList) { if (as.startsWith("http://")) { try { urlList.add(new URI(as, false)); } catch (URIException e) { // ignore try next } } } return urlList; }
From source file:phex.download.swarming.SWDownloadCandidate.java
public SWDownloadCandidate(DDownloadCandidate dCandidate, SWDownloadFile downloadFile, LogBuffer candidateLogBuffer) throws MalformedDestAddressException { this(downloadFile, candidateLogBuffer); fileIndex = dCandidate.getFileIndex(); fileName = dCandidate.getFileName(); /* setAvailableRangeSet(new HTTPRangeSet(0, downloadFile.getTotalDataSize())); */ String guidHexStr = dCandidate.getGuid(); if (guidHexStr != null) { guid = new GUID(guidHexStr); }/*from w w w .ja va2s.co m*/ String downloadUriStr = dCandidate.getDownloadUri(); if (downloadUriStr != null) { try { downloadURI = new URI(downloadUriStr, true); } catch (URIException exp) { logger.warn("Malformed URI in: {} - {} - {}", downloadFile.toString(), downloadUriStr, this.toString(), exp); // continue anyway.. download candidate might still be useful } } String resourceUrnStr = dCandidate.getResourceUrn(); if (resourceUrnStr != null) { resourceURN = new URN(resourceUrnStr); } else { // No resource urn was found there could be two reasons, the // candidate uses a download uri or the download file is from // release 3.0.2 or earlier. If no download uri is available // we use the resource urn of the download file to work around // this shortcoming and support pre 3.0.2 download lists as // good as possible. Basically this means we don't support // file index downloads anymore.. but do we really need them // nowadays.. if (downloadURI == null) { resourceURN = downloadFile.getFileURN(); } } vendor = dCandidate.getVendor(); isPushNeeded = dCandidate.isPushNeeded(); isChatSupported = dCandidate.isChatSupported(); if (dCandidate.isSetLastConnectionTime()) { lastConnectionTime = dCandidate.getLastConnectionTime(); } else { lastConnectionTime = 0; } try { hostAddress = PresentationManager.getInstance().createHostAddress(dCandidate.getRemoteHost(), DefaultDestAddress.DEFAULT_PORT); } catch (MalformedDestAddressException exp) { logger.warn("Malformed host address in: {} - {} - {}", downloadFile.toString(), dCandidate.getRemoteHost(), this.toString(), exp); throw exp; } if (dCandidate.getConnectionFailedRepetition() > 0) { errorStatus = CandidateStatus.CONNECTION_FAILED; status = CandidateStatus.CONNECTION_FAILED; errorStatusRepetition = dCandidate.getConnectionFailedRepetition(); failedConnectionTries = errorStatusRepetition; } else { status = CandidateStatus.WAITING; } // thex status is reset on startup. thexStatus = ThexStatus.OPEN; }
From source file:phex.gui.dialogs.NewDownloadDialog.java
private void createNewDownload() throws URIException { Servent servent = GUIRegistry.getInstance().getServent(); SwarmingManager swarmingMgr = servent.getDownloadService(); SharedFilesService shareService = servent.getSharedFilesService(); String uriStr = uriTF.getText().trim(); if (uriStr.length() == 0) { return;/* w ww .j a va 2 s.co m*/ } URI uri = new URI(uriStr, true); String protocol = uri.getScheme(); // in case this is no magnet we cant determine the file urn and cant // check if the download is already running. if ("magnet".equals(protocol)) { MagnetData magnetData = MagnetData.parseFromURI(uri); URN urn = MagnetData.lookupSHA1URN(magnetData); if (swarmingMgr.isURNDownloaded(urn)) { GUIUtils.showErrorMessage(Localizer.getString("NewDownload_AlreadyDownloadingMessage"), Localizer.getString("NewDownload_AlreadyDownloadingTitle")); return; } if (shareService.isURNShared(urn)) { GUIUtils.showErrorMessage(Localizer.getString("NewDownload_AlreadySharedMessage"), Localizer.getString("NewDownload_AlreadySharedTitle")); return; } } swarmingMgr.addFileToDownload(uri, true); }
From source file:phex.gui.macosx.GURLHandler.java
/** Called by the native code */ private void callback(final String uriStr) { // currently we only accept magnets through this interface... if (!uriStr.startsWith("magnet")) { return;/*w ww .j a va2 s.co m*/ } Runnable runner = new Runnable() { public void run() { try { URI uri = new URI(uriStr, true); // dont add already downloading urns. SwarmingManager swarmingMgr = GUIRegistry.getInstance().getServent().getDownloadService(); swarmingMgr.addFileToDownload(uri, true); } catch (URIException exp) { return; } } }; EventQueue.invokeLater(runner); }
From source file:phex.update.UpdateDownloader.java
private static void createDownload(String uriStr) throws URIException { if (uriStr.length() == 0) { return;//from w w w . j a v a2s. co m } URI uri = new URI(uriStr, true); Servent.getInstance().getDownloadService().addFileToDownload(uri, true); }
From source file:phex.util.SubscriptionDownloader.java
public void createDownload(String uriStr) throws URIException { if (uriStr.length() == 0) { return;/*w w w . ja va 2s .c o m*/ } URI uri = new URI(uriStr, true); peer.getDownloadService().addFileToDownload(uri, true); }
From source file:phex.utils.InternalFileHandler.java
public static void magmaReadout(File file) { try {// www . jav a 2 s. c o m BufferedInputStream inStream = new BufferedInputStream(new FileInputStream(file)); MagmaParser parser = new MagmaParser(inStream); parser.start(); List magnetList = parser.getMagnets(); String relativeDownloadDir = parser.getMagmaName(); Iterator iter = magnetList.iterator(); // Sync subscription operation with a possible rescan process, this // prevents downloads of files already existing but not yet scanned. FileRescanRunner.sync(); while (iter.hasNext()) { String magnet = (String) iter.next(); URI uri = new URI(magnet, true); // dont add already downloading or shared urns. // If we didn't get a relativeDownloadDir, // Download to the default folder. if (relativeDownloadDir.length() == 0) { downloadUri(uri); } // Else download to the relativeDOwnloadDir inside the default folder. else { downloadUri(uri, relativeDownloadDir); } } /* String uuri = parser.getUpdateURI(); if ( uuri != null) { URI uri = new URI( uuri, true ); sheduledReadout(uri, 60000); } */ } catch (IOException exp) { //NLogger.warn( InternalFileHandler.class, exp.getMessage(), exp); } }
From source file:phex.utils.InternalFileHandler.java
public static void rssReadout(File file) { if (!file.exists()) { return;/*from w ww . j a v a 2 s.co m*/ } try { Reader reader = new BufferedReader(new FileReader(file)); RSSParser parser = new RSSParser(reader); parser.start(); List magnetList = parser.getMagnets(); Iterator iter = magnetList.iterator(); // Sync subscription operation with a possible rescan process, this // prevents downloads of files already existing but not yet scanned. FileRescanRunner.sync(); while (iter.hasNext()) { String magnet = (String) iter.next(); URI uri = new URI(magnet, true); downloadUri(uri); } } catch (IOException exp) { //NLogger.error( InternalFileHandler.class, exp.getMessage(), exp); } }