Example usage for java.util MissingResourceException MissingResourceException

List of usage examples for java.util MissingResourceException MissingResourceException

Introduction

In this page you can find the example usage for java.util MissingResourceException MissingResourceException.

Prototype

public MissingResourceException(String s, String className, String key) 

Source Link

Document

Constructs a MissingResourceException with the specified information.

Usage

From source file:net.wastl.webmail.xml.XMLResourceBundle.java

public static synchronized ResourceBundle getBundle(String name, Locale locale, ClassLoader cl)
        throws MissingResourceException {
    String lang = locale.getLanguage();

    ResourceBundle ret = null;//from  www  .  ja v a  2s  .  c om

    try {
        ret = new XMLResourceBundle(WebMailServer.getServer().getProperty("webmail.template.path")
                + System.getProperty("file.separator") + name + ".xml", lang);
    } catch (Exception ex) {
        log.error("Resource not found: " + name, ex);
        throw new MissingResourceException("Resource not found", name, "");
    }

    return ret;
}

From source file:edu.wisc.my.portlets.dmp.tools.XmlMenuPublisher.java

/**
 * Publishes all the menus in the XML specified by the URL.
 * /*from   w  ww . j  a va2  s  .  c o m*/
 * @param xmlSourceUrl URL to the menu XML.
 */
public void publishMenus(URL xmlSourceUrl) {
    LOG.info("Publishing menus from: " + xmlSourceUrl);

    try {
        //The XMLReader will read in the XML document
        final XMLReader reader = XMLReaderFactory.createXMLReader("org.apache.xerces.parsers.SAXParser");

        try {
            reader.setFeature("http://apache.org/xml/features/validation/dynamic", true);
            reader.setFeature("http://apache.org/xml/features/validation/schema", true);

            final URL menuSchema = this.getClass().getResource("/menu.xsd");
            if (menuSchema == null) {
                throw new MissingResourceException("Could not load menu schema. '/menu.xsd'",
                        this.getClass().getName(), "/menu.xsd");
            }

            reader.setProperty("http://apache.org/xml/properties/schema/external-noNamespaceSchemaLocation",
                    menuSchema.toString());
        } catch (SAXNotRecognizedException snre) {
            LOG.warn("Could not enable XSD validation", snre);
        } catch (SAXNotSupportedException xnse) {
            LOG.warn("Could not enable XSD validation", xnse);
        }

        final MenuItemGeneratingHandler handler = new MenuItemGeneratingHandler();

        reader.setContentHandler(handler);
        reader.parse(new InputSource(xmlSourceUrl.openStream()));

        final Map menus = handler.getMenus();

        final BeanFactory factory = this.getFactory();
        final MenuDao dao = (MenuDao) factory.getBean("menuDao", MenuDao.class);

        for (final Iterator nameItr = menus.entrySet().iterator(); nameItr.hasNext();) {
            final Map.Entry entry = (Map.Entry) nameItr.next();
            final String menuName = (String) entry.getKey();
            final MenuItem rootItem = (MenuItem) entry.getValue();

            LOG.info("Publishing menu='" + menuName + "' item='" + rootItem + "'");
            dao.storeMenu(menuName, rootItem);
        }

        LOG.info("Published menus from: " + xmlSourceUrl);
    } catch (IOException ioe) {
        LOG.error("Error publishing menus", ioe);
    } catch (SAXException saxe) {
        LOG.error("Error publishing menus", saxe);
    }
}

From source file:org.novelang.outfit.shell.AgentFileInstaller.java

public static void copyResourceToFile(final String resourceName, final File file) throws IOException {
    final URL resourceUrl = AgentFileInstaller.class.getResource(resourceName);
    if (resourceUrl == null) {
        throw new MissingResourceException(
                "The resource '" + resourceName + "' does not appear in the classpath "
                        + "(Maven should handle this, IDEs probably won't)",
                AgentFileInstaller.class.getName(), resourceName);
    }//from w w w. j av  a2  s.c om

    LOGGER.info("Copying resource '", resourceName, "' to ", "'", file.getAbsolutePath(), "'");
    FileUtils.copyURLToFile(resourceUrl, file);
}

From source file:edu.ksu.cis.indus.tools.slicer.criteria.specification.SliceCriterionSpec.java

/**
 * Retrieves the criteria represented by this spec relative to the given scene.
 *
 * @param scene relative to which the criteria will be generated.
 *
 * @return the collection of slice criterion.
 *
 * @throws MissingResourceException when the any of the types used in the criterion specification cannot be found.
 * @throws IllegalStateException when the method in the spec does not have a body or the specified statment/expr does not
 *          exists./* w  w w.j  a v  a  2 s . c o m*/
 */
public Collection<ISliceCriterion> getCriteria(final Scene scene) {
    trim();

    final SootClass _sc = scene.getSootClass(className);

    if (_sc == null) {
        final String _msg = className + " is not available in the System.";
        LOGGER.error(_msg);
        throw new MissingResourceException("Given class not available in the System.", className, null);
    }

    final List<Type> _parameterTypes = new ArrayList<Type>();

    for (final Iterator<String> _i = parameterTypeNames.iterator(); _i.hasNext();) {
        final String _name = _i.next();
        _parameterTypes.add(Util.getTypeFor(_name, scene));
    }

    final SootMethod _sm = _sc.getMethod(methodName, _parameterTypes, Util.getTypeFor(returnTypeName, scene));
    _sc.setApplicationClass();

    final Body _body = _sm.retrieveActiveBody();

    if (_body == null) {
        final String _msg = returnTypeName + " " + methodName + "(" + parameterTypeNames
                + ") does not have a body.";
        LOGGER.error(_msg);
        throw new IllegalStateException(_msg);
    }

    final List<Stmt> _stmts = Collections.list(Collections.<Stmt>enumeration(_body.getUnits()));

    if (_stmts.size() < stmtIndex + 1) {
        final String _msg = returnTypeName + " " + methodName + "(" + parameterTypeNames + ") has only "
                + _stmts.size() + " statements. [" + stmtIndex + "]";
        LOGGER.error(_msg);
        throw new IllegalStateException(_msg);
    }

    final Collection<ISliceCriterion> _result;

    if (stmtIndex == -1) {
        _result = CRITERIA_FACTORY.getCriteria(_sm);
    } else {
        final Stmt _stmt = _stmts.get(stmtIndex);

        if (exprIndex == -1) {
            _result = CRITERIA_FACTORY.getCriteria(_sm, _stmt, considerEntireStmt, considerExecution);
        } else {
            _result = CRITERIA_FACTORY.getCriteria(_sm, _stmt,
                    (ValueBox) _stmt.getUseAndDefBoxes().get(exprIndex), considerExecution);
        }
    }

    return _result;
}

From source file:org.apereo.portal.portlets.portletadmin.xmlsupport.XmlChannelPublishingDefinitionDao.java

private PortletPublishingDefinition loadChannelPublishingDefinition(int channelTypeId) {
    // if the CPD is not already in the cache, determine the CPD URI
    final String cpdUri;
    if (channelTypeId >= 0) {
        final IPortletType type = this.portletTypeRegistry.getPortletType(channelTypeId);
        if (type == null) {
            throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
        }/*  w  w  w.  j a va2s .co  m*/
        cpdUri = type.getCpdUri();
    } else {
        throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
    }

    // read and parse the CPD
    final PortletPublishingDefinition def;
    final Resource cpdResource = this.resourceLoader.getResource("classpath:" + cpdUri);
    if (!cpdResource.exists()) {
        throw new MissingResourceException(
                "Failed to find CPD '" + cpdUri + "' for channel type " + channelTypeId,
                this.getClass().getName(), cpdUri);
    }

    final InputStream cpdStream;
    try {
        cpdStream = cpdResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException(
                "Failed to load CPD '" + cpdUri + "' for channel type " + channelTypeId,
                this.getClass().getName(), cpdUri);
    }

    try {
        def = (PortletPublishingDefinition) this.unmarshaller.unmarshal(cpdStream);
        final List<Step> sharedParameters = this.getSharedParameters();
        def.getSteps().addAll(sharedParameters);
        // add the CPD to the cache and return it
        this.cpdCache.put(channelTypeId, def);

        return def;
    } catch (JAXBException e) {
    } finally {
        IOUtils.closeQuietly(cpdStream);
    }

    return null;

}

From source file:org.jasig.portal.portlets.portletadmin.xmlsupport.XmlChannelPublishingDefinitionDao.java

private PortletPublishingDefinition loadChannelPublishingDefinition(int channelTypeId) {
    // if the CPD is not already in the cache, determine the CPD URI
    final String cpdUri;
    if (channelTypeId >= 0) {
        final IPortletType type = this.portletTypeRegistry.getPortletType(channelTypeId);
        if (type == null) {
            throw new IllegalArgumentException("No ChannelType registered with id: " + channelTypeId);
        }//  ww  w  .  j  a v a  2s  .c  o m
        cpdUri = type.getCpdUri();
    } else {
        cpdUri = CUSTOM_CPD_PATH;
    }

    // read and parse the CPD
    final PortletPublishingDefinition def;
    final Resource cpdResource = this.resourceLoader.getResource("classpath:" + cpdUri);
    if (!cpdResource.exists()) {
        throw new MissingResourceException(
                "Failed to find CPD '" + cpdUri + "' for channel type " + channelTypeId,
                this.getClass().getName(), cpdUri);
    }

    final InputStream cpdStream;
    try {
        cpdStream = cpdResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException(
                "Failed to load CPD '" + cpdUri + "' for channel type " + channelTypeId,
                this.getClass().getName(), cpdUri);
    }

    try {
        def = (PortletPublishingDefinition) this.unmarshaller.unmarshal(cpdStream);
        final List<Step> sharedParameters = this.getSharedParameters();
        def.getSteps().addAll(sharedParameters);
        // add the CPD to the cache and return it
        this.cpdCache.put(channelTypeId, def);

        return def;
    } catch (JAXBException e) {
    } finally {
        IOUtils.closeQuietly(cpdStream);
    }

    return null;

}

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

/**
 * Devuelve el path completo donde se encuentra el fichero <tt>fileName</tt>. Este fichero <tt>fileName</tt> se
 * busca en el la lista de directorios definida por <tt>searchPath</tt>. Esta es un lista de directorios del estilo
 * del PATH o del LD_LIBRARY_PATH, es decir una lista de directorios donde el separador es ';' en Windows o ':' en
 * Unix.//w  w w .  j a  va 2 s. co  m
 * 
 * @see File#pathSeparatorChar
 * @param searchPath lista de directorios del estilo del PATH o del LD_LIBRARY_PATH, es decir una lista de
 *            directorios donde el separador es ';' en Windows o ':' en Unix
 * @param fileName nombre del fichero que se quiere buscar en <tt>searchPath</tt>.
 * @return el path completo donde se encuentra el fichero <tt>fileName</tt>.
 * @throws MissingResourceException si no se encuentra <tt>fileName</tt> en ningn direcotorio definido por
 *             <tt>searchPath</tt>.
 */
public static String searchFileInPath(String searchPath, String fileName) {
    final String[] paths = searchPath.split(File.pathSeparator);
    for (int i = 0; i < paths.length; i++) {
        String filePath = paths[i];
        if (!filePath.endsWith(File.separator)) {
            filePath += File.separator;
        }
        filePath += fileName;
        if (log.isDebugEnabled())
            log.trace("Searching: " + filePath);

        final File propertiesFile = new File(filePath);
        if (propertiesFile.canRead()) {
            if (log.isDebugEnabled())
                log.trace("Found and is readable: " + filePath);
            return filePath;
        }
    }
    throw new MissingResourceException(
            "Cannot find file '" + fileName + "' in path '" + searchPath + "', or cannot be read",
            FileSystemUtils.class.getName(), fileName);
}

From source file:com.flexive.shared.exceptions.FxExceptionMessage.java

/**
 * Returns the resource bundle, which is cached within the request.
 *
 * @param key       resource key/*from w w  w  . jav a 2s. co  m*/
 * @param locale    the requested locale
 * @return the resource bundle value
 */
public String getResource(String key, Locale locale) {
    if (!initialized) {
        initialize();
    }
    final FxSharedUtils.MessageKey messageKey = new FxSharedUtils.MessageKey(locale, key);
    String cachedMessage = cachedMessages.get(messageKey);
    if (cachedMessage != null) {
        return cachedMessage;
    }
    for (FxSharedUtils.BundleReference bundleReference : resourceBundles) {
        try {
            final ResourceBundle bundle = getResources(bundleReference, locale);
            final String message = bundle.getString(key);
            cachedMessage = cachedMessages.putIfAbsent(messageKey, message);
            return cachedMessage != null ? cachedMessage : message;
        } catch (MissingResourceException e) {
            // continue with next bundle
        }
    }
    if (!locale.equals(Locale.ENGLISH)) {
        //try to find the locale in english as last resort
        //this is a fix for using PropertyResourceBundles which can only handle one locale (have to use them thanks to JBoss 5...)
        for (FxSharedUtils.BundleReference bundleReference : resourceBundles) {
            try {
                final ResourceBundle bundle = getResources(bundleReference, Locale.ENGLISH);
                final String message = bundle.getString(key);
                cachedMessage = cachedMessages.putIfAbsent(messageKey, message);
                return cachedMessage != null ? cachedMessage : message;
            } catch (MissingResourceException e) {
                // continue with next bundle
            }
        }
    }
    throw new MissingResourceException("Resource not found", FxExceptionMessage.class.getCanonicalName(), key);
}

From source file:org.apache.click.util.MessagesMap.java

/**
 * Return localized resource message for the given key. If the message is
 * not found a <tt>MissingResourceException</tt> will be thrown.
 *
 * @see java.util.Map#get(Object)//  ww w.  j  av a2 s .com
 * @throws MissingResourceException if the given key was not found
 */
public String get(Object key) {
    String value = null;
    if (key != null) {
        ensureInitialized();
        value = messages.get(key.toString());
    }

    if (value == null) {
        String msg = "Message \"{0}\" not found in bundle \"{1}\" for locale \"{2}\"";
        String keyStr = (key != null) ? key.toString() : null;
        Object[] args = { keyStr, baseClass.getName(), locale };
        msg = MessageFormat.format(msg, args);
        throw new MissingResourceException(msg, baseClass.getName(), keyStr);
    }
    return value;
}

From source file:org.apereo.portal.portlets.portletadmin.xmlsupport.XmlChannelPublishingDefinitionDao.java

private List<Step> getSharedParameters() {
    if (this.sharedParameters != null) {
        return this.sharedParameters;
    }/*from  w  w  w  .  j a v a 2  s. c om*/

    // read and parse the shared CPD
    final Resource paramResource = this.resourceLoader.getResource("classpath:" + SHARED_PARAMETERS_PATH);
    if (!paramResource.exists()) {
        throw new MissingResourceException(
                "Failed to find shared parameters CPD '" + SHARED_PARAMETERS_PATH + "'",
                this.getClass().getName(), SHARED_PARAMETERS_PATH);
    }

    final InputStream paramStream;
    try {
        paramStream = paramResource.getInputStream();
    } catch (IOException e) {
        throw new MissingResourceException("Failed to load CPD '" + SHARED_PARAMETERS_PATH + "'",
                this.getClass().getName(), SHARED_PARAMETERS_PATH);
    }

    // parse the shared CPD and add its steps to the end of the type-specific
    try {
        PortletPublishingDefinition config = (PortletPublishingDefinition) unmarshaller.unmarshal(paramStream);
        this.sharedParameters = config.getSteps();
    } catch (JAXBException e) {
        logger.warn("Failed to parse: " + paramResource, e);
    } finally {
        IOUtils.closeQuietly(paramStream);
    }
    return this.sharedParameters;
}