Package org.jaggeryjs.scriptengine.exceptions

Examples of org.jaggeryjs.scriptengine.exceptions.ScriptException


            String uri = (String) object;
            return new JavaScriptFileImpl(uri, getFile(uri).getAbsolutePath());
        } else {
            String msg = "Unsupported parameter to the File constructor : " + object.getClass();
            log.error(msg);
            throw new ScriptException(msg);
        }
    }
View Full Code Here


        if (uri.startsWith("file://")) {
            try {
                file = FileUtils.toFile(new URL(uri));
            } catch (MalformedURLException e) {
                log.error(e.getMessage(), e);
                throw new ScriptException(e);
            }
        } else {
            String oldPath = uri;
            uri = FilenameUtils.normalizeNoEndSeparator(uri);
            if (uri == null) {
                String msg = "Invalid file URI : " + oldPath;
                log.error(msg);
                throw new ScriptException(msg);
            }
            file = new File(uri);
        }

        return file;
View Full Code Here

        File configFile = new File(configDirPath, RESOURCE_MEDIA_TYPE_MAPPINGS_FILE);
        if (!configFile.exists()) {
            String msg = "Resource media type definitions file (mime.types) file does " +
                    "not exist in the path " + configDirPath;
            log.error(msg);
            throw new ScriptException(msg);
        }


        final Map<String, String> mimeMappings = new HashMap<String, String>();

        final String mappings;
        try {
            mappings = FileUtils.readFileToString(configFile, "UTF-8");
        } catch (IOException e) {
            String msg = "Error opening resource media type definitions file " +
                    "(mime.types) : " + e.getMessage();
            throw new ScriptException(msg, e);
        }
        String[] lines = mappings.split("[\\r\\n]+");
        for (String line : lines) {
            if (!line.startsWith("#")) {
                String[] parts = line.split("\\s+");
View Full Code Here

    synchronized public static void jsFunction_getFeed(Context cx,
                                                       Scriptable thisObj, Object[] arguments, Function funObj)
            throws ScriptException {
        if (arguments.length != 1) {
            throw new ScriptException("Invalid parameter");
        }

        if (arguments[0] instanceof String) {

            feed = null;
            URL url = null;
            try {

                url = new URL((String) arguments[0]);
                feed = (Feed) Abdera.getNewParser().parse(url.openStream())
                        .getRoot();
                isRssFeed = false;
            } catch (ClassCastException e) {

                XmlReader reader = null;

                try {
                    reader = new XmlReader(url);
                    rssFeed = new SyndFeedInput().build(reader);
                    isRssFeed = true;

                    for (Iterator i = rssFeed.getEntries().iterator(); i
                            .hasNext(); ) {
                        SyndEntry entry = (SyndEntry) i.next();

                    }
                } catch (IOException e1) {
                    throw new ScriptException(e1);
                } catch (Exception e1) {
                    throw new ScriptException(e1);
                } finally {
                    if (reader != null)
                        try {
                            reader.close();
                        } catch (IOException e1) {
                            throw new ScriptException(e1);
                        }
                }
            } catch (IRISyntaxException e) {
                throw new ScriptException(e);
            } catch (MalformedURLException e) {
                throw new ScriptException(e);
            } catch (IOException e) {
                throw new ScriptException(e);
            }

        } else {
            throw new ScriptException(
                    "Invalid parameter, It is must to be a String");
        }
    }
View Full Code Here

        }

        if (date != null) {
            feed.setUpdated(date);
        } else {
            throw new ScriptException("Invalid parameter");
        }

    }
View Full Code Here

            return null;
        }
        try {
            logoStr = logo.toURL().toString();
        } catch (MalformedURLException e) {
            throw new ScriptException(e);
        } catch (URISyntaxException e) {
            throw new ScriptException(e);
        }
        return logoStr;
    }
View Full Code Here

                addEntry(nativeObject);
            }

        } else {

            throw new ScriptException("Invalid parameter");
        }
    }
View Full Code Here

                if (content instanceof XMLObject) {
                    entry.setContentAsXhtml(content.toString());
                } else if (content instanceof String) {
                    entry.setContent(content.toString());
                } else {
                    throw new ScriptException("Unsupported Content");
                }

                // process contributor
                Object contributorProperty = ScriptableObject.getProperty(
                        nativeObject, "contributor");
                if (contributorProperty instanceof String) {
                    entry.addContributor(contributorProperty.toString());
                }
                Object contributorsProperty = ScriptableObject.getProperty(
                        nativeObject, "contributors");
                if (contributorsProperty instanceof NativeArray) {
                    NativeArray contributorsPropertyArray = (NativeArray) contributorsProperty;
                    for (Object o1 : contributorsPropertyArray.getIds()) {

                        int index = (Integer) o1;
                        String name = contributorsPropertyArray
                                .get(index, null).toString();

                        entry.addContributor(name);
                    }
                }

                // process id
                Object idProperty = ScriptableObject.getProperty(nativeObject,
                        "id");
                if (idProperty instanceof String) {
                    entry.setId((String) (idProperty));
                } else {
                    entry.setId(FOMHelper.generateUuid());
                }

                // process link
                // TODO link object
                Object linkProperty = ScriptableObject.getProperty(
                        nativeObject, "link");
                if (linkProperty instanceof String) {
                    entry.addLink((String) (linkProperty));
                }
                Object linksProperty = ScriptableObject.getProperty(
                        nativeObject, "links");
                if (linksProperty instanceof NativeArray) {
                    NativeArray linksPropertyArray = (NativeArray) contributorsProperty;
                    for (Object o1 : linksPropertyArray.getIds()) {

                        int index = (Integer) o1;
                        String name = linksPropertyArray.get(index, null)
                                .toString();

                        entry.addLink(name);
                    }
                }

                // process published
                // TODO handle javascript date
                Object publishedProperty = ScriptableObject.getProperty(
                        nativeObject, "published");
                if (publishedProperty instanceof String) {
                    if (publishedProperty.equals("now")) {
                        entry.setPublished(new Date(System.currentTimeMillis()));
                    } else {
                        entry.setPublished(publishedProperty.toString());
                    }
                }

                // process rights
                Object rights = ScriptableObject.getProperty(nativeObject,
                        "rights");
                if (rights instanceof XMLObject) {
                    entry.setRightsAsXhtml(rights.toString());
                } else if (rights instanceof String) {
                    entry.setRights(rights.toString());
                }

                // process summary
                Object summary = ScriptableObject.getProperty(nativeObject,
                        "summary");
                if (summary instanceof XMLObject) {
                    entry.setSummaryAsXhtml(summary.toString());
                } else if (summary instanceof String) {
                    entry.setSummary(summary.toString());
                }

                // process title
                Object title = ScriptableObject.getProperty(nativeObject,
                        "title");
                if (title instanceof XMLObject) {
                    entry.setTitleAsXhtml(title.toString());
                } else if (title instanceof String) {
                    entry.setTitle(title.toString());
                } else {
                    throw new ScriptException("An Entry MUST have a title.");
                }

                // process updated
                Object updated = ScriptableObject.getProperty(nativeObject,
                        "updated");
                if (updated instanceof String) {
                    if (updated.equals("now")) {
                        entry.setUpdated(new Date(System.currentTimeMillis()));
                    } else {
                        entry.setUpdated((String) updated);
                    }
                }

            } catch (IRISyntaxException e) {
                throw new ScriptException(e);
            }
        } else if (!(entryObject instanceof EntryHostObject)) {
            throw new ScriptException("Invalid parameter");
        }
        // log.info("New Added Entry" + entry);
    }
View Full Code Here

                outputStreamWriter = new OutputStreamWriter(
                        fileHostObject.getOutputStream());
                feedObject.feed.writeTo(outputStreamWriter);
                outputStreamWriter.flush();
            } else {
                throw new ScriptException("Invalid parameter");
            }
            return feedObject;
        } catch (IOException e) {
            throw new ScriptException(e);
        } finally {
            if (outputStreamWriter != null) {
                try {
                    outputStreamWriter.close();
                } catch (IOException e) {
View Full Code Here

            boolean uriMatch = uriTemplate.matches(uriho.uriToBeMatched, urlParts);
            if (!uriMatch) {
                return null;
            }
        } catch (URITemplateException e) {
            throw new ScriptException(e);
        }

        ScriptableObject nobj = (ScriptableObject) cx.newObject(thisObj);
        for (Map.Entry<String, String> entry : urlParts.entrySet()) {
            nobj.put(entry.getKey(), nobj, entry.getValue());
View Full Code Here

TOP

Related Classes of org.jaggeryjs.scriptengine.exceptions.ScriptException

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.