Example usage for java.lang ClassLoader getSystemResource

List of usage examples for java.lang ClassLoader getSystemResource

Introduction

In this page you can find the example usage for java.lang ClassLoader getSystemResource.

Prototype

public static URL getSystemResource(String name) 

Source Link

Document

Find a resource of the specified name from the search path used to load classes.

Usage

From source file:com.documentgenerator.view.MainWindow.java

private ArrayList<JMenuItem> getMenuItem(JSONArray jsonMenuItems) {
    int count = jsonMenuItems.size(), i;
    menuItems = new ArrayList<>();
    for (i = 0; i < count; i++) {
        jsonMenuItem = (JSONObject) jsonMenuItems.get(i);
        String menuTitle = (String) jsonMenuItem.get("menuTitle");
        ImageIcon imageIcon = new ImageIcon(
                ClassLoader.getSystemResource((String) jsonMenuItem.get("imageIcon")));

        menuItem = new JMenuItem(menuTitle, imageIcon);
        String className = (String) jsonMenuItem.get("className");
        String shortcut = (String) jsonMenuItem.get("shortcut");
        Boolean hasSeparator = (Boolean) jsonMenuItem.get("separator");
        Boolean hasToolbar = (Boolean) jsonMenuItem.get("hasToolbar");

        if (!Strings.isNullOrEmpty(shortcut)) {
            menuItem.setAccelerator(utils.getKeyStroke(shortcut));
        }/*from www .j  a v a 2 s . c  o m*/

        if (className.equals("string")) {
            menuItem.setActionCommand(menuTitle);
            menuItem.addActionListener(actionListener);
        } else {
            menuItem.setActionCommand(className);
            menuItem.addActionListener(new MenuItemActionListener(this, className));
        }
        menu.add(menuItem);

        if (hasToolbar) {
            JButton button = new JButton(imageIcon);
            button.setToolTipText(menuTitle);
            button.addActionListener(new MenuItemActionListener(this, className));
            toolBar.add(button);
        }
    }
    return menuItems;
}

From source file:org.nebulaframework.ui.swing.node.NodeMainUI.java

/**
 * Setup System Tray Icon.//from  w  ww.j  av  a2  s  . co m
 * 
 * @param frame owner frame
 */
private void setupTrayIcon(final JFrame frame) {

    idleIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_inactive.png"));

    activeIcon = Toolkit.getDefaultToolkit()
            .getImage(ClassLoader.getSystemResource("META-INF/resources/node_active.png"));

    frame.setIconImage(idleIcon);

    // If system tray is supported by OS
    if (SystemTray.isSupported()) {
        trayIcon = new TrayIcon(idleIcon, "Nebula Grid Node", createTrayPopup());
        trayIcon.setImageAutoSize(true);
        trayIcon.addMouseListener(new MouseAdapter() {

            @Override
            public void mouseClicked(MouseEvent e) {
                if (e.getButton() == MouseEvent.BUTTON1) {
                    if (!frame.isVisible()) {
                        frame.setVisible(true);
                    }

                    frame.setExtendedState(JFrame.NORMAL);
                    frame.requestFocus();
                    frame.toFront();
                }
            }

        });

        try {
            SystemTray.getSystemTray().add(trayIcon);
        } catch (AWTException ae) {
            log.debug("[UI] Unable to Initialize Tray Icon");
            return;
        }

        frame.addWindowListener(new WindowAdapter() {

            @Override
            public void windowIconified(WindowEvent e) {
                // Hide (can be shown using tray icon)
                frame.setVisible(false);
            }

        });
    }

}

From source file:org.ldp4j.server.ServerFrontendTestHelper.java

public static JavaArchive getServerArchive() {
    JavaArchive coreArchive = ShrinkWrap.create(JavaArchive.class, "ldp4j-server-core.jar")
            .addPackages(true, "org.ldp4j.server")
            .addAsResource(ClassLoader.getSystemResource("META-INF/web-fragment.xml"),
                    "META-INF/web-fragment.xml")
            .addAsResource(ClassLoader.getSystemResource("beans.xml"), "beans.xml")
            .addAsServiceProvider(RuntimeInstance.class, RuntimeInstanceImpl.class)
            .addAsServiceProvider(IMediaTypeProvider.class, TurtleMediaTypeProvider.class,
                    RDFXMLMediaTypeProvider.class, JSONLDMediaTypeProvider.class);
    return coreArchive;
}

From source file:org.apache.james.mailbox.elasticsearch.json.MessageToElasticSearchJsonTest.java

@Test
public void htmlEmailShouldBeWellConvertedToJson() throws IOException {
    MessageToElasticSearchJson messageToElasticSearchJson = new MessageToElasticSearchJson(
            new DefaultTextExtractor(), ZoneId.of("Europe/Paris"), IndexAttachments.YES);
    MailboxMessage htmlMail = new SimpleMailboxMessage(MESSAGE_ID, date, SIZE, BODY_START_OCTET,
            new SharedByteArrayInputStream(
                    IOUtils.toByteArray(ClassLoader.getSystemResourceAsStream("eml/htmlMail.eml"))),
            new FlagsBuilder().add(Flags.Flag.DELETED, Flags.Flag.SEEN).add("social", "pocket-money").build(),
            propertyBuilder, MAILBOX_ID);
    htmlMail.setModSeq(MOD_SEQ);// ww  w  .  ja v a 2  s .  c  o m
    htmlMail.setUid(UID);
    assertThatJson(messageToElasticSearchJson.convertToJson(htmlMail,
            ImmutableList.of(new MockMailboxSession("username").getUser()))).when(IGNORING_ARRAY_ORDER)
                    .isEqualTo(IOUtils.toString(ClassLoader.getSystemResource("eml/htmlMail.json")));
}

From source file:org.ldp4j.server.IntegrationTestHelper.java

public static JavaArchive getServerArchive() {
    JavaArchive coreArchive = ShrinkWrap.create(JavaArchive.class, "ldp4j-server-frontend.jar")
            .addPackages(true, "org.ldp4j.server")
            .addAsResource(ClassLoader.getSystemResource("web-fragment.xml"), "META-INF/web-fragment.xml")
            .addAsResource(ClassLoader.getSystemResource("beans.xml"), "beans.xml")
            .addAsServiceProvider(RuntimeInstance.class, RuntimeInstanceImpl.class).addAsServiceProvider(
                    IMediaTypeProvider.class, TurtleMediaTypeProvider.class, RDFXMLMediaTypeProvider.class);
    return coreArchive;
}

From source file:de.decoit.simu.cbor.xml.dictionary.DictionaryTest.java

@Test
public void testFindElementByPath() throws Exception {
    Path input = Paths.get(ClassLoader.getSystemResource("namespace-with-complex-elements.dict").toURI());

    Dictionary instance = new Dictionary();
    instance.extendDictionary(input);//www  .  ja  v a  2  s.  c  o m

    String dictPath = "<http://www.trustedcomputinggroup.org/2010/IFMAP/2>access-request+nested-element";

    DictionarySimpleElement result = instance.findElementByPath(dictPath);

    assertNotNull(result);
}

From source file:org.pentaho.di.trans.dataservice.jdbc.RemoteClientTest.java

@Test
public void testGetServiceInformation() throws Exception {
    String url = "http://localhost:9080/pentaho-di/kettle/listServices";
    String xml = Resources.toString(ClassLoader.getSystemResource("jdbc/listServices.xml"), Charsets.UTF_8);
    when(httpClient.executeMethod(isA(GetMethod.class))).thenReturn(200);
    when(execMethod.getResponseBodyAsString()).thenReturn(xml);

    ThinServiceInformation serviceInformation = Iterables.getOnlyElement(remoteClient.getServiceInformation());

    verify(httpClient).executeMethod(httpMethodCaptor.capture());
    assertThat(httpMethodCaptor.getValue().getURI().toString(), equalTo(url));

    assertThat(serviceInformation.getName(), is("sequence"));
    assertThat(serviceInformation.getServiceFields().getFieldNames(), arrayContaining("valuename"));
}

From source file:com.opengamma.web.WebResourceTestUtils.java

public static JSONObject loadJson(String filePath) throws IOException, JSONException {
    URL jsonResource = ClassLoader.getSystemResource(filePath);
    assertNotNull(jsonResource);//from w  w  w.java2  s .c om
    String jsonText = FileUtils.readFileToString(new File(jsonResource.getPath()));
    return new JSONObject(jsonText);
}

From source file:com.autentia.common.util.FileSystemUtils.java

/**
 * Devuelve un <tt>InputStream</tt> apuntando al <tt>resource</tt> que se ha localizado en el CLASSPATH.
 * <p>// ww  w.j av a2s.c  o m
 * Primero se busca en el CLASSPATH asociado al Thread, luego en el ClassLoader, y por ltimo en el ClassLoader de
 * esta clase.
 * 
 * @param resource recurso que se quiere localizar en el CLASSPATH.
 * @return un <tt>InputStream</tt> apuntando al <tt>resource</tt> que se ha localizado en el CLASSPATH.
 *         <tt>null</tt> si no se ha encontrado.
 */
public static String searchInClasspath(String resource) {
    URL url = Thread.currentThread().getContextClassLoader().getResource(resource);
    if (url == null) {
        url = ClassLoader.getSystemResource(resource);
        if (url == null) {
            url = FileSystemUtils.class.getClassLoader().getResource(resource);
            if (url == null) {
                throw new MissingResourceException("Cannot find resource '" + resource + "' in none classpath",
                        FileSystemUtils.class.getName(), resource);
            }
        }
    }

    return url.getPath();
}

From source file:org.soaplab.services.GenUtils.java

/*********************************************************************
 * Return the location of the specified resource by searching the
 * current directory, user home directory, the current classpath
 * and the system classpath. <p>//from   ww w .  j  av  a2 s.  c  o  m
 *
 * The code was inspired by Apache Commons class
 * <tt>ConfigurationUtils</tt> (authors Herve Quiroz, Oliver
 * Heger, and Emmanuel Bourg). <p>
 *
 * @param name the name of the resource - usually a file name
 * (absolute or relative)
 *
 * @return a URL of the resource location
 *
 * @throw FileNotFoundException if the resource cannot be found;
 * or if the 'name' is null or otherwise invalid
 ********************************************************************/
public static URL locateFile(String name) throws FileNotFoundException {

    if (name == null)
        throw new FileNotFoundException("Null file name.");

    // attempt to create a URL directly
    try {
        return new URL(name);
    } catch (IOException e) {
        // let's make another attempt
    }

    // attempt to load from an absolute path, or from the current directory
    File file = new File(name);
    if (file.isAbsolute() || file.exists()) {
        try {
            return file.toURI().toURL();
        } catch (IOException e) {
            throw new FileNotFoundException("Malformed path: " + name);
        }
    }

    // attempt to load from the user home directory
    try {
        StringBuilder fName = new StringBuilder();
        fName.append(System.getProperty("user.home"));
        fName.append(File.separator);
        fName.append(name);
        file = new File(fName.toString());
        if (file.exists())
            return file.toURI().toURL();
    } catch (IOException e) {
        // let's make another attempt
    }

    // attempt to load from the context classpath
    ClassLoader loader = Thread.currentThread().getContextClassLoader();
    URL url = loader.getResource(name);
    if (url != null)
        return url;

    // attempt to load from the system classpath
    url = ClassLoader.getSystemResource(name);
    if (url != null)
        return url;

    throw new FileNotFoundException(name);
}