Example usage for java.net URL toString

List of usage examples for java.net URL toString

Introduction

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

Prototype

public String toString() 

Source Link

Document

Constructs a string representation of this URL .

Usage

From source file:org.eclipse.lyo.testsuite.server.util.OSLCUtils.java

public static String absoluteUrlFromRelative(String baseUrl, String url) throws MalformedURLException {
    URL base = new URL(baseUrl);
    URL result = new URL(base, url);
    return result.toString();
}

From source file:fr.gael.dhus.database.dao.ProductDao.java

public static String getPathFromURL(URL product) {
    return product.toString();
}

From source file:de.quadrillenschule.azocamsyncd.astromode.SmartPhoneWrapper.java

public static String getFromSmartPhone(WebService.WebCommands command, boolean doCheck) throws IOException {
    String retval;//from w  w w.  ja  v  a2 s.c o  m
    SmartPhoneStatus status = SmartPhoneStatus.TRYING;

    lastStatus = SmartPhoneStatus.TRYING;
    URL url;
    try {
        url = new URL(PROTOCOL + "://" + LAST_WORKING_IP + ":" + PORT + "/" + command.name());
        System.out.println("Trying " + url.toString());
        URLConnection uc = url.openConnection();
        uc.setConnectTimeout(3000);
        StringWriter sw = new StringWriter();
        IOUtils.copy((InputStream) uc.getContent(), sw);
        retval = sw.toString();
        status = SmartPhoneStatus.CONNECTED;

        lastStatus = SmartPhoneStatus.CONNECTED;
    } catch (MalformedURLException ex) {
        Logger.getLogger(SmartPhoneWrapper.class.getName()).log(Level.SEVERE, null, ex);
        status = SmartPhoneStatus.ERROR;
        retval = SmartPhoneStatus.ERROR.name();

        lastStatus = SmartPhoneStatus.ERROR;
    }

    return retval;
}

From source file:eu.eubrazilcc.lvl.core.util.UrlUtils.java

/**
 * Returns a list of name-value pairs as built from the URI's query portion.
 * @param uri - input URI//from w  w w  .j  a  va  2s .co  m
 * @return a list of name-value pairs as built from the URI's query portion.
 * @throws IllegalArgumentException If a malformed URI occurs.
 */
public static Map<String, String> getQueryParams(final URI uri) {
    checkArgument(uri != null, "Uninitialized URI");
    try {
        final URI nUri = uri.normalize();
        final URL url = nUri.isAbsolute() ? nUri.toURL()
                : new URL(new URL("http://example.org/"), nUri.toString());
        final String query = new URL(URLDecoder.decode(url.toString(), defaultCharset().name())).getQuery();
        final Map<String, String> map = newHashMap();
        final List<NameValuePair> pairs = URLEncodedUtils.parse(query, defaultCharset());
        final Iterator<NameValuePair> iterator = pairs.iterator();
        while (iterator.hasNext()) {
            final NameValuePair pair = iterator.next();
            map.put(pair.getName(), pair.getValue());
        }
        return map;
    } catch (MalformedURLException | UnsupportedEncodingException e) {
        throw new IllegalArgumentException("Malformed URI", e);
    }
}

From source file:cn.zhouyafeng.tomcat.util.modeler.modules.MbeansDescriptorsDigesterSource.java

private static Digester createDigester() {

    Digester digester = new Digester();
    digester.setNamespaceAware(false);/*from w  ww  .  j av  a 2s .c  om*/
    digester.setValidating(false);
    URL url = Registry.getRegistry(null, null).getClass()
            .getResource("/org/apache/tomcat/util/modeler/mbeans-descriptors.dtd");
    digester.register("-//Apache Software Foundation//DTD Model MBeans Configuration File", url.toString());

    // Configure the parsing rules
    digester.addObjectCreate("mbeans-descriptors/mbean", "org.apache.tomcat.util.modeler.ManagedBean");
    digester.addSetProperties("mbeans-descriptors/mbean");
    digester.addSetNext("mbeans-descriptors/mbean", "add", "java.lang.Object");

    digester.addObjectCreate("mbeans-descriptors/mbean/attribute",
            "org.apache.tomcat.util.modeler.AttributeInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/attribute");
    digester.addSetNext("mbeans-descriptors/mbean/attribute", "addAttribute",
            "org.apache.tomcat.util.modeler.AttributeInfo");

    digester.addObjectCreate("mbeans-descriptors/mbean/notification",
            "org.apache.tomcat.util.modeler.NotificationInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/notification");
    digester.addSetNext("mbeans-descriptors/mbean/notification", "addNotification",
            "org.apache.tomcat.util.modeler.NotificationInfo");

    digester.addObjectCreate("mbeans-descriptors/mbean/notification/descriptor/field",
            "org.apache.tomcat.util.modeler.FieldInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/notification/descriptor/field");
    digester.addSetNext("mbeans-descriptors/mbean/notification/descriptor/field", "addField",
            "org.apache.tomcat.util.modeler.FieldInfo");

    digester.addCallMethod("mbeans-descriptors/mbean/notification/notification-type", "addNotifType", 0);

    digester.addObjectCreate("mbeans-descriptors/mbean/operation",
            "org.apache.tomcat.util.modeler.OperationInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/operation");
    digester.addSetNext("mbeans-descriptors/mbean/operation", "addOperation",
            "org.apache.tomcat.util.modeler.OperationInfo");

    digester.addObjectCreate("mbeans-descriptors/mbean/operation/descriptor/field",
            "org.apache.tomcat.util.modeler.FieldInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/operation/descriptor/field");
    digester.addSetNext("mbeans-descriptors/mbean/operation/descriptor/field", "addField",
            "org.apache.tomcat.util.modeler.FieldInfo");

    digester.addObjectCreate("mbeans-descriptors/mbean/operation/parameter",
            "org.apache.tomcat.util.modeler.ParameterInfo");
    digester.addSetProperties("mbeans-descriptors/mbean/operation/parameter");
    digester.addSetNext("mbeans-descriptors/mbean/operation/parameter", "addParameter",
            "org.apache.tomcat.util.modeler.ParameterInfo");

    return digester;

}

From source file:com.googlecode.fightinglayoutbugs.FindBugsRunner.java

private static List<String> getClassPath(Class<?> suiteClass) {
    List<String> classPath = new ArrayList<String>();
    URLClassLoader classLoader = (URLClassLoader) suiteClass.getClassLoader();
    do {//from w  w w.  jav a 2 s . c o  m
        for (URL url : classLoader.getURLs()) {
            final String temp = url.toString();
            if (temp.startsWith("file:")) {
                @SuppressWarnings("deprecation")
                String path = URLDecoder.decode(temp.substring("file:".length()));
                classPath.add(path);
            } else {
                throw new RuntimeException(
                        "Don't know how to convert class path URL '" + temp + "' into a path.");
            }
        }
        ClassLoader parentClassLoader = classLoader.getParent();
        classLoader = (parentClassLoader instanceof URLClassLoader && parentClassLoader != classLoader
                ? (URLClassLoader) parentClassLoader
                : null);
    } while (classLoader != null);
    return classPath;
}

From source file:com.opensymphony.xwork2.util.FileManager.java

public static boolean fileNeedsReloading(String fileName, Class clazz) {
    URL fileUrl = ClassLoaderUtil.getResource(fileName, clazz);
    return fileUrl != null && fileNeedsReloading(fileUrl.toString());
}

From source file:ddf.catalog.source.solr.SolrServerFactory.java

/**
 * Provides an already instantiated {@link SolrServer} object. If an instance has not already
 * been instantiated, then the single instance will be instantiated with the provided
 * configuration file. If an instance already exists, it cannot be overwritten with a new
 * configuration./*from w w  w.  j  a va2  s . c o m*/
 * 
 * @param solrConfigXml
 *            the name of the solr configuration filename such as solrconfig.xml
 * @param schemaXml
 *            filename of the schema such as schema.xml
 * @param givenConfigFileProxy
 *            a ConfigurationFileProxy instance. If instance is <code>null</code>, a new
 *            {@link ConfigurationFileProxy} is used instead.
 * @return {@link SolrServer} instance
 */
public static EmbeddedSolrServer getEmbeddedSolrServer(String solrConfigXml, String schemaXml,
        ConfigurationFileProxy givenConfigFileProxy) {

    LOGGER.info("Retrieving embedded solr with the following properties: [" + solrConfigXml + "," + schemaXml
            + "," + givenConfigFileProxy + "]");

    String solrConfigFileName = DEFAULT_SOLRCONFIG_XML;

    String schemaFileName = DEFAULT_SCHEMA_XML;

    if (isNotBlank(solrConfigXml)) {
        solrConfigFileName = solrConfigXml;
    }

    if (isNotBlank(schemaXml)) {
        schemaFileName = schemaXml;
    }

    File solrConfigFile = null;
    File solrConfigHome = null;
    File solrSchemaFile = null;

    ConfigurationFileProxy configProxy = givenConfigFileProxy;

    if (givenConfigFileProxy == null) {
        configProxy = new ConfigurationFileProxy(null, ConfigurationStore.getInstance());
    }

    File configurationDir = new File(ConfigurationFileProxy.DEFAULT_SOLR_CONFIG_PARENT_DIR,
            ConfigurationFileProxy.SOLR_CONFIG_LOCATION_IN_BUNDLE);
    configProxy.writeBundleFilesTo(configurationDir);

    try {
        URL url = configProxy.getResource(solrConfigFileName);

        LOGGER.info("Solr config url: " + url);

        solrConfigFile = new File(new URI(url.toString()).getPath());

        solrConfigHome = new File(solrConfigFile.getParent());
    } catch (URISyntaxException e) {
        LOGGER.warn(e);
    }

    try {
        URL url = configProxy.getResource(schemaFileName);

        LOGGER.info("Solr schema url: " + url);

        solrSchemaFile = new File(new URI(url.toString()).getPath());

    } catch (URISyntaxException e) {
        LOGGER.warn(e);
    }

    SolrConfig solrConfig = null;
    IndexSchema indexSchema = null;
    ClassLoader tccl = Thread.currentThread().getContextClassLoader();
    try {
        Thread.currentThread().setContextClassLoader(SolrServerFactory.class.getClassLoader());

        // NamedSPILoader uses the thread context classloader to lookup
        // codecs, posting formats, and analyzers
        solrConfig = new SolrConfig(solrConfigHome.getParent(), solrConfigFileName,
                new InputSource(FileUtils.openInputStream(solrConfigFile)));
        indexSchema = new IndexSchema(solrConfig, schemaFileName,
                new InputSource(FileUtils.openInputStream(solrSchemaFile)));
    } catch (ParserConfigurationException e) {
        LOGGER.warn(e);
    } catch (IOException e) {
        LOGGER.warn(e);
    } catch (SAXException e) {
        LOGGER.warn(e);
    } finally {
        Thread.currentThread().setContextClassLoader(tccl);
    }

    CoreContainer container = new CoreContainer(solrConfigHome.getAbsolutePath());
    container.load();
    CoreDescriptor dcore = new CoreDescriptor(container, "core1",
            solrConfig.getResourceLoader().getInstanceDir());

    File dataDir = configProxy.getDataDirectory();
    LOGGER.info("Using data directory [" + dataDir + "]");
    SolrCore core = new SolrCore("core1", dataDir.getAbsolutePath(), solrConfig, indexSchema, dcore);
    container.register("core1", core, false);

    return new EmbeddedSolrServer(container, "core1");
}

From source file:com.norconex.commons.lang.url.URLStreamer.java

/**
 * Streams URL content./*from www . ja va2s.co  m*/
 * @param url the URL to stream
 * @return a URL content InputStream
 */
public static InputStream stream(URL url) {
    return stream(url.toString(), null);
}

From source file:Main.java

public static InputSource getInputSource(URL url, InputStream is) throws IOException {
    // is = new BufferedInputStream(is);
    // String encoding = getEncoding(is);
    InputSource inputSource = new InputSource(is);
    // inputSource.setEncoding(encoding);
    // [rfeng] Make sure we set the system id as it will be used as the base URI for nested import/include 
    inputSource.setSystemId(url.toString());
    return inputSource;
}