Package org.webharvest.runtime.variables

Examples of org.webharvest.runtime.variables.NodeVariable


    public Variable executePlugin(Scraper scraper, ScraperContext context) {
        Variable body = executeBody(scraper, context);
        try {
            JSONObject jsonObject = XML.toJSONObject(body.toString());
            return new NodeVariable(jsonObject.toString());
        } catch (JSONException e) {
            throw new PluginException("Error converting XML to JSON: " + e.getMessage());
        }
    }
View Full Code Here


    public Variable executePlugin(Scraper scraper, ScraperContext context) {
        Variable body = executeBody(scraper, context);
        try {
            JSONObject jsonObject = new JSONObject(body.toString());
            return new NodeVariable( XML.toString(jsonObject) );
        } catch (JSONException e) {
            throw new PluginException("Error converting JSON to XML: " + e.getMessage());
        }
    }
View Full Code Here

                    context.put(item, currElement);
                }

                // define current value of index variable
                if ( index != null && !"".equals(index) ) {
                    context.put( index, new NodeVariable(String.valueOf(i)) );
                }

                // execute the loop body
                BaseElementDef bodyDef = loopDef.getLoopBodyDef();
                Variable loopResult = bodyDef != null ? new BodyProcessor(bodyDef).run(scraper, context) : new EmptyVariable();
View Full Code Here

                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        Result domResult = new StreamResult(out);
                        TransformerFactory factory = TransformerFactory.newInstance();
                        Transformer transformer = factory.newTransformer();
                        transformer.transform(source, domResult);
                        result.addVariable(new NodeVariable(out.toByteArray()));
                    } catch (TransformerException e) {
                        log.error(transformError, e);
                        throw new PluginException(e);
                    } catch (IllegalAccessException e) {
                        throw new PluginException(e);
                    } catch (InstantiationException e) {
                        throw new PluginException(e);
                    } catch (Exception e) {
                        if (e instanceof SAXException) {
                            String msg = "Error parsing content retrieved from the url" + documentURI;
                            log.error(msg, e);
                            throw new PluginException(msg, e);
                        } else if(e instanceof IOException) {
                            String msg = "Error retrieving content from the url" + documentURI;
                            log.error(msg, e);
                            throw new PluginException(msg, e);
                        } else if(e instanceof ClassNotFoundException) {
                            log.error(EXCEPTION, e);
                            throw new PluginException(EXCEPTION, e);
                        } else if(e instanceof InvocationTargetException) {
                            log.error(EXCEPTION, e);
                            throw new PluginException(EXCEPTION, e);
                        } else if(e instanceof IllegalAccessException) {
                            log.error(EXCEPTION, e);
                            throw new PluginException(EXCEPTION, e);
                        } else {
                            String msg = "Error occurred with the content of " + documentURI;
                            log.error(msg, e);
                            throw new PluginException(msg, e);
                        }
                    }
                }

            } catch (ClassNotFoundException e) {
                log.error(EXCEPTION, e);
                throw new PluginException(EXCEPTION, e);
            } catch (InstantiationException e) {
                log.error(EXCEPTION, e);
                throw new PluginException(EXCEPTION, e);
            } catch (IllegalAccessException e) {
                log.error(EXCEPTION, e);
                throw new PluginException(EXCEPTION, e);
            } catch (NoSuchMethodException e) {
                log.error(EXCEPTION, e);
                throw new PluginException(EXCEPTION, e);
            } catch (InvocationTargetException e) {
                log.error(EXCEPTION, e);
                throw new PluginException(EXCEPTION, e);
            }

        } else {
            result.addVariable(new NodeVariable(elementDef.getBodyText()));
        }
        return result;
    }
View Full Code Here

TOP

Related Classes of org.webharvest.runtime.variables.NodeVariable

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.