class AmdJsResource extends ResourceFilter {

    @Override
    public LanguageBundle parse(InputStream inStream, FilterOptions options)
            throws IOException, ResourceFilterException {
        LanguageBundleBuilder bb = new LanguageBundleBuilder(true);

        // TODO: Rhino parse(Reader, String, int) only throws IOException on IO
        // error thrown
        // by Reader. We need to use ErrorReporter used in the Parser
        // constructor,
        // and check the reporter after parse method to detect JavaScript syntax
        // problems.
        try (InputStreamReader reader = new InputStreamReader(new BomInputStream(inStream), "UTF-8")) {
            AstRoot root = new Parser().parse(reader, null, 1);
            KeyValueVisitor visitor = new KeyValueVisitor();
            root.visitAll(visitor);
            LinkedHashMap<String, ValueData> resultMap = visitor.elements;
            for (Entry<String, ValueData> entry : resultMap.entrySet()) {
                bb.addResourceString(entry.getKey(), entry.getValue().getValue());
            }
        }

        return bb.build();
    }

}