Search in sources :

Example 1 with Factory

use of org.apache.abdera.factory.Factory in project jaggery by wso2.

the class EntryHostObject method jsConstructor.

/**
     * Constructor the user will be using inside javaScript
     */
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) {
    EntryHostObject entryHO = new EntryHostObject();
    entryHO.abdera = new Abdera();
    Factory factory = entryHO.abdera.getFactory();
    entryHO.entry = factory.newEntry();
    entryHO.context = cx;
    return entryHO;
}
Also used : Factory(org.apache.abdera.factory.Factory) LogFactory(org.apache.commons.logging.LogFactory) Abdera(org.apache.abdera.Abdera)

Example 2 with Factory

use of org.apache.abdera.factory.Factory in project jaggery by wso2.

the class FeedHostObject method addEntry.

public void addEntry(Object entryObject) throws ScriptException {
    abdera = new Abdera();
    Factory factory = abdera.getFactory();
    entry = factory.newEntry();
    if (entryObject instanceof EntryHostObject) {
        EntryHostObject entryHostObject = (EntryHostObject) entryObject;
        entry = entryHostObject.getEntry();
        feed.addEntry(entry);
    } else if (entryObject instanceof NativeObject) {
        try {
            NativeObject nativeObject = (NativeObject) entryObject;
            ScriptableObject scriptableObject = (ScriptableObject) nativeObject;
            // author and authors processing
            Object authorProperty = ScriptableObject.getProperty(nativeObject, "author");
            if (authorProperty instanceof String) {
                entry.addAuthor((String) (authorProperty));
            }
            Object authorsProperty = ScriptableObject.getProperty(nativeObject, "authors");
            if (authorsProperty instanceof NativeArray) {
                NativeArray authorsPropertyArray = (NativeArray) authorsProperty;
                for (Object o1 : authorsPropertyArray.getIds()) {
                    int indexx = (Integer) o1;
                    String name = authorsPropertyArray.get(indexx, null).toString();
                    entry.addAuthor(name);
                }
            }
            // processing category
            Object categoryProperty = ScriptableObject.getProperty(nativeObject, "category");
            if (categoryProperty instanceof String) {
                entry.addCategory((String) (categoryProperty));
            }
            Object categoriesProperty = ScriptableObject.getProperty(nativeObject, "categories");
            if (categoriesProperty instanceof NativeArray) {
                NativeArray categoriesPropertyArray = (NativeArray) categoriesProperty;
                for (Object o1 : categoriesPropertyArray.getIds()) {
                    int indexC = (Integer) o1;
                    String name = categoriesPropertyArray.get(indexC, null).toString();
                    entry.addCategory(name);
                }
            }
            // process content
            Object content = ScriptableObject.getProperty(nativeObject, "content");
            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);
}
Also used : ScriptException(org.jaggeryjs.scriptengine.exceptions.ScriptException) Factory(org.apache.abdera.factory.Factory) LogFactory(org.apache.commons.logging.LogFactory) XMLObject(org.mozilla.javascript.xml.XMLObject) IRISyntaxException(org.apache.abdera.i18n.iri.IRISyntaxException) XMLObject(org.mozilla.javascript.xml.XMLObject) FileHostObject(org.jaggeryjs.hostobjects.file.FileHostObject) Date(java.util.Date) Abdera(org.apache.abdera.Abdera)

Example 3 with Factory

use of org.apache.abdera.factory.Factory in project jaggery by wso2.

the class FeedHostObject method jsConstructor.

/**
     * Constructor the user will be using inside javaScript
     */
public static Scriptable jsConstructor(Context cx, Object[] args, Function ctorObj, boolean inNewExpr) throws ScriptException {
    int argsCount = args.length;
    if (argsCount > 2) {
        HostObjectUtil.invalidNumberOfArgs(HOST_OBJECT_NAME, HOST_OBJECT_NAME, argsCount, true);
    }
    Abdera abdera = new Abdera();
    Factory factory = abdera.getFactory();
    feed = factory.newFeed();
    feedHostObject = new FeedHostObject();
    ctx = cx;
    if (argsCount == 0) {
        return feedHostObject;
    }
    if (argsCount == 1) {
        if (!(args[0] instanceof String)) {
            HostObjectUtil.invalidArgsError(HOST_OBJECT_NAME, HOST_OBJECT_NAME, "1", "string", args[0], true);
        }
        FeedHostObject.jsFunction_getFeed(cx, null, args, null);
    }
    return feedHostObject;
}
Also used : Factory(org.apache.abdera.factory.Factory) LogFactory(org.apache.commons.logging.LogFactory) Abdera(org.apache.abdera.Abdera)

Example 4 with Factory

use of org.apache.abdera.factory.Factory in project jaggery by wso2.

the class FeedHostObject method feedConstructor.

public Scriptable feedConstructor() {
    Abdera abdera = new Abdera();
    Factory factory = abdera.getFactory();
    feed = factory.newFeed();
    return this;
}
Also used : Factory(org.apache.abdera.factory.Factory) LogFactory(org.apache.commons.logging.LogFactory) Abdera(org.apache.abdera.Abdera)

Aggregations

Abdera (org.apache.abdera.Abdera)4 Factory (org.apache.abdera.factory.Factory)4 LogFactory (org.apache.commons.logging.LogFactory)4 Date (java.util.Date)1 IRISyntaxException (org.apache.abdera.i18n.iri.IRISyntaxException)1 FileHostObject (org.jaggeryjs.hostobjects.file.FileHostObject)1 ScriptException (org.jaggeryjs.scriptengine.exceptions.ScriptException)1 XMLObject (org.mozilla.javascript.xml.XMLObject)1