Example usage for java.net URL toExternalForm

List of usage examples for java.net URL toExternalForm

Introduction

In this page you can find the example usage for java.net URL toExternalForm.

Prototype

public String toExternalForm() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:org.opensourcetlapp.tl.TLLib.java

public static TagNode TagNodeFromURLEx2(HtmlCleaner cleaner, URL url, Handler handler, Context context,
        String fullTag, boolean login) throws IOException {

    handler.sendEmptyMessage(PROGRESS_CONNECTING);

    DefaultHttpClient httpclient = new DefaultHttpClient();
    if (cookieStore != null) {
        httpclient.setCookieStore(cookieStore);
    }/*from  ww w  .j  ava2 s. c  o m*/
    HttpGet httpGet = new HttpGet(url.toExternalForm());
    HttpResponse response = httpclient.execute(httpGet);
    if (cookieStore == null) {
        cookieStore = httpclient.getCookieStore();
    }

    handler.sendEmptyMessage(PROGRESS_DOWNLOADING);
    HttpEntity httpEntity = response.getEntity();
    InputStream is = httpEntity.getContent();
    return TagNodeFromURLHelper(is, fullTag, handler, context, cleaner);
}

From source file:com.thoughtmetric.tl.TLLib.java

public static Object[] parseEditText(HtmlCleaner cleaner, URL url, TLHandler handler, Context context)
        throws IOException {
    // Although probably not THE worst hack I've written, this function ranks near the top.
    // TODO: rework this routine get rid of code duplication.

    DefaultHttpClient httpclient = new DefaultHttpClient();
    httpclient.setCookieStore(cookieStore);

    HttpGet httpGet = new HttpGet(url.toExternalForm());
    HttpResponse response = httpclient.execute(httpGet);

    handler.sendEmptyMessage(PROGRESS_DOWNLOADING);
    InputStream is = response.getEntity().getContent();

    InputStreamReader isr = new InputStreamReader(is);
    BufferedReader br = new BufferedReader(isr);

    FileOutputStream fos = context.openFileOutput(TEMP_FILE_NAME, Context.MODE_PRIVATE);
    BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(fos));

    String line;/*  ww  w . ja v a 2  s.com*/
    String formStart = "<form action=\"/forum/edit.php";
    while ((line = br.readLine()) != null) {
        if (line.startsWith(formStart)) {
            Log.d(TAG, line);
            bw.write(line);
            break;
        }
    }

    String start = "\t\t<textarea";
    String end = "\t\t<p>";
    StringBuffer sb = new StringBuffer();
    while ((line = br.readLine()) != null) {
        if (line.startsWith(start)) {
            bw.write("</form>");
            int i = line.lastIndexOf('>');
            sb.append(Html.fromHtml(line.substring(i + 1)).toString());
            sb.append("\n");
            break;
        } else {
            bw.write(line);
        }
    }

    while ((line = br.readLine()) != null) {
        if (line.startsWith(end)) {
            break;
        }
        sb.append(Html.fromHtml(line).toString());
        sb.append("\n");
    }

    bw.flush();
    bw.close();

    if (handler != null)
        handler.sendEmptyMessage(PROGRESS_PARSING);

    Object[] ret = new Object[2];

    ret[0] = sb.toString();
    ret[1] = cleaner.clean(context.openFileInput(TEMP_FILE_NAME));
    return ret;
}

From source file:com.sldeditor.ui.detail.config.symboltype.externalgraphic.RelativePath.java

/**
 * Convert URL to absolute/relative path.
 *
 * @param externalFileURL the external file URL
 * @param useRelativePaths the use relative paths
 * @return the string/*from w ww .j a  v a2s .  c om*/
 */
public static String convert(URL externalFileURL, boolean useRelativePaths) {
    String path = "";
    if (externalFileURL != null) {
        if (isLocalFile(externalFileURL)) {
            if (useRelativePaths) {
                File f = new File(externalFileURL.getFile());
                File folder = null;
                SLDDataInterface sldData = SLDEditorFile.getInstance().getSLDData();
                if ((sldData != null) && (sldData.getSLDFile() != null)) {
                    folder = sldData.getSLDFile().getParentFile();
                }

                if (folder == null) {
                    folder = new File(System.getProperty("user.dir"));
                }
                path = getRelativePath(f, folder);
            } else {
                path = externalFileURL.toExternalForm();
            }
        } else {
            path = externalFileURL.toExternalForm();
        }
    }
    return path;
}

From source file:net.sourceforge.dita4publishers.word2dita.Word2DitaValidationHelper.java

/**
 * @param bosOptions//  ww w  .ja v a 2 s. c  o  m
 * @param docxZip
 * @param commentsTemplateUrl
 * @return
 * @throws Exception 
 */
static Document getCommentsDom(BosConstructionOptions bosOptions, ZipComponents zipComponents,
        URL commentsTemplateUrl) throws Exception {
    Document commentsDom;
    NodeList comments;
    ZipComponent commentsXml = zipComponents.getEntry(DocxConstants.COMMENTS_XML_PATH);
    if (commentsXml == null) {
        System.err.println("No comments.xml file");
        commentsXml = zipComponents.createZipComponent(DocxConstants.COMMENTS_XML_PATH);

        // Use the template as the base for new comments.xml DOM:
        InputSource templateSource = new InputSource(commentsTemplateUrl.openStream());
        templateSource.setSystemId(commentsTemplateUrl.toExternalForm());
        commentsDom = DomUtil.getDomForSource(templateSource, bosOptions, false, false);
        comments = commentsDom.getDocumentElement().getElementsByTagNameNS(DocxConstants.nsByPrefix.get("w"),
                "comment");

        // Remove any existing comments that were in the template:
        for (int i = 0; i < comments.getLength(); i++) {
            Element comment = (Element) comments.item(i);
            commentsDom.getDocumentElement().removeChild(comment);
        }
        zipComponents.createZipComponent(DocxConstants.COMMENTS_XML_PATH, commentsDom);

    } else {
        commentsDom = zipComponents.getDomForZipComponent(bosOptions, DocxConstants.COMMENTS_XML_PATH);
    }
    return commentsDom;
}

From source file:com.jkoolcloud.tnt4j.streams.custom.kafka.interceptors.reporters.metrics.MetricsReporter.java

private static Tracker initTracker() {
    TrackerConfig trackerConfig = DefaultConfigFactory.getInstance().getConfig(MetricsReporter.class,
            SourceType.APPL, (String) null);
    String cfgSource = trackerConfig == null ? null : trackerConfig.getProperty("source"); // NON-NLS
    if (!MetricsReporter.class.getPackage().getName().equals(cfgSource)) {
        URL defaultCfg = InterceptionsManager.getDefaultTrackerConfiguration();
        trackerConfig = DefaultConfigFactory.getInstance().getConfig(MetricsReporter.class, SourceType.APPL,
                defaultCfg.toExternalForm());
    }//from  w  w w .ja  v a 2  s  .  c  o m

    Tracker tracker = TrackingLogger.getInstance(trackerConfig.build());

    return tracker;
}

From source file:com.all4tec.sa.maven.proguard.ProGuardMojo.java

private static File getProguardJar(ProGuardMojo mojo) throws MojoExecutionException {

    Artifact proguardArtifact = null;//from ww  w  . j a v  a 2 s .co  m
    int proguardArtifactDistance = -1;
    // This should be solved in Maven 2.1
    for (Iterator i = mojo.pluginArtifacts.iterator(); i.hasNext();) {
        Artifact artifact = (Artifact) i.next();
        mojo.getLog().debug("pluginArtifact: " + artifact.getFile());
        if (artifact.getArtifactId().startsWith("proguard")
                && !artifact.getArtifactId().startsWith("proguard-maven-plugin")) {
            int distance = artifact.getDependencyTrail().size();
            mojo.getLog().debug("proguard DependencyTrail: " + distance);
            if ((mojo.proguardVersion != null) && (mojo.proguardVersion.equals(artifact.getVersion()))) {
                proguardArtifact = artifact;
                break;
            } else if (proguardArtifactDistance == -1) {
                proguardArtifact = artifact;
                proguardArtifactDistance = distance;
            } else if (distance < proguardArtifactDistance) {
                proguardArtifact = artifact;
                proguardArtifactDistance = distance;
            }
        }
    }
    if (proguardArtifact != null) {
        mojo.getLog().debug("proguardArtifact: " + proguardArtifact.getFile());
        return proguardArtifact.getFile().getAbsoluteFile();
    }
    mojo.getLog().info("proguard jar not found in pluginArtifacts");

    ClassLoader cl;
    cl = mojo.getClass().getClassLoader();
    // cl = Thread.currentThread().getContextClassLoader();
    String classResource = "/" + mojo.proguardMainClass.replace('.', '/') + ".class";
    URL url = cl.getResource(classResource);
    if (url == null) {
        throw new MojoExecutionException(
                "Obfuscation failed ProGuard (" + mojo.proguardMainClass + ") not found in classpath");
    }
    String proguardJar = url.toExternalForm();
    if (proguardJar.startsWith("jar:file:")) {
        proguardJar = proguardJar.substring("jar:file:".length());
        proguardJar = proguardJar.substring(0, proguardJar.indexOf('!'));
    } else {
        throw new MojoExecutionException("Unrecognized location (" + proguardJar + ") in classpath");
    }
    return new File(proguardJar);
}

From source file:com.xpn.xwiki.internal.template.ClassloaderResource.java

/**
 * @param url the URL of the resource//from w w w.  j  ava  2 s .c  o  m
 * @param resourceName the name of the resource
 */
public ClassloaderResource(URL url, String resourceName) {
    super(url.toExternalForm(), resourceName, null, new DefaultURLInputSource(url));
}

From source file:Main.java

private Box getEditPaneBox() {
    editorPane.setEditable(false);/*from   w w w  .ja v  a 2s.co m*/
    Box editorBox = Box.createHorizontalBox();
    editorBox.add(new JScrollPane(editorPane));

    editorPane.addHyperlinkListener((HyperlinkEvent event) -> {
        if (event.getEventType() == HyperlinkEvent.EventType.ACTIVATED) {
            go(event.getURL());
        } else if (event.getEventType() == HyperlinkEvent.EventType.ENTERED) {
            System.out.println("click this link");
        } else if (event.getEventType() == HyperlinkEvent.EventType.EXITED) {
            System.out.println("Ready");
        }
    });

    editorPane.addPropertyChangeListener((PropertyChangeEvent e) -> {
        String propertyName = e.getPropertyName();
        if (propertyName.equalsIgnoreCase("page")) {
            URL url = editorPane.getPage();
            System.out.println(url.toExternalForm());
        }
    });

    return editorBox;
}

From source file:com.abiquo.am.services.TemplateConventions.java

/**
 * Gets an URL from the hRef attribute on a File's (References section). Try to interpret the
 * hRef attribute as an absolute URL (like http://some.where.com/file.vmdk), and if it fails try
 * to interpret the hRef as OVF package URI relative.
 * //from   w  w w.  j av a2s  . c o m
 * @param relativeFilePath, the value on the hRef attribute for the File.
 * @param ovfId, the OVF Package identifier (and locator).
 * @throws DownloadException, it the URL can not be created.
 */
public static String getFileUrl(final String relativeFilePath, final String ovfId) {
    URL fileURL;

    try {
        fileURL = new URL(relativeFilePath);
    } catch (MalformedURLException e1) {
        // its a relative path
        if (e1.getMessage().startsWith("no protocol")) {
            try {
                String packageURL = ovfId.substring(0, ovfId.lastIndexOf('/'));
                fileURL = new URL(packageURL + '/' + relativeFilePath);
            } catch (MalformedURLException e) {
                final String msg = "Invalid file reference " + ovfId + '/' + relativeFilePath;
                throw new DownloadException(msg, e1);
            }
        } else {
            final String msg = "Invalid file reference " + relativeFilePath;
            throw new DownloadException(msg, e1);
        }
    }
    return fileURL.toExternalForm();
}

From source file:MainClass.java

protected void openURL(String urlString) {
    try {//from w w w . j a va2 s .  co m
        URL url = new URL(urlString);
        mEditorPane.setPage(url);
        mURLField.setText(url.toExternalForm());
    } catch (Exception e) {
        System.out.println("Couldn't open " + urlString + ":" + e);
    }
}