Package org.webharvest.runtime.variables

Examples of org.webharvest.runtime.variables.Variable


        super(htmlToXmlDef);
        this.htmlToXmlDef = htmlToXmlDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        Variable body = getBodyTextContent(htmlToXmlDef, scraper, context);

        HtmlCleaner cleaner = new HtmlCleaner();
        CleanerProperties properties = cleaner.getProperties();

        final ScriptEngine scriptEngine = scraper.getScriptEngine();

        final String advancedXmlEscape = BaseTemplater.execute( htmlToXmlDef.getAdvancedXmlEscape(), scriptEngine);
        if ( advancedXmlEscape != null) {
            properties.setAdvancedXmlEscape(CommonUtil.isBooleanTrue(advancedXmlEscape) );
        }

        final String cdataForScriptAndStyle = BaseTemplater.execute( htmlToXmlDef.getUseCdataForScriptAndStyle(), scriptEngine);
        if ( cdataForScriptAndStyle != null) {
            properties.setUseCdataForScriptAndStyle(CommonUtil.isBooleanTrue(cdataForScriptAndStyle) );
        }

        final String specialEntities = BaseTemplater.execute( htmlToXmlDef.getTranslateSpecialEntities(), scriptEngine);
        if ( specialEntities != null) {
            properties.setTranslateSpecialEntities(CommonUtil.isBooleanTrue(specialEntities) );
        }

        final String recognizeUnicodeChars = BaseTemplater.execute(htmlToXmlDef.getRecognizeUnicodeChars(), scriptEngine);
        if ( recognizeUnicodeChars != null) {
            properties.setRecognizeUnicodeChars( CommonUtil.isBooleanTrue(recognizeUnicodeChars) );
        }

        final String omitUnknownTags = BaseTemplater.execute(htmlToXmlDef.getOmitUnknownTags(), scriptEngine);
        if ( omitUnknownTags != null) {
            properties.setOmitUnknownTags( CommonUtil.isBooleanTrue(omitUnknownTags) );
        }

        final String useEmptyElementTags = BaseTemplater.execute(htmlToXmlDef.getUseEmptyElementTags(), scriptEngine);
        if ( useEmptyElementTags != null) {
            properties.setUseEmptyElementTags( CommonUtil.isBooleanTrue(useEmptyElementTags) );
        }

        final String treatUnknownTagsAsContent = BaseTemplater.execute(htmlToXmlDef.getTreatUnknownTagsAsContent(), scriptEngine);
        if ( treatUnknownTagsAsContent != null) {
            properties.setTreatUnknownTagsAsContent( CommonUtil.isBooleanTrue(treatUnknownTagsAsContent) );
        }

        final String omitDeprecatedTags = BaseTemplater.execute(htmlToXmlDef.getOmitDeprecatedTags(), scriptEngine);
        if ( omitDeprecatedTags != null) {
            properties.setOmitDeprecatedTags( CommonUtil.isBooleanTrue(omitDeprecatedTags) );
        }

        final String treatDeprTagsAsContent = BaseTemplater.execute(htmlToXmlDef.getTreatDeprecatedTagsAsContent(), scriptEngine);
        if ( treatDeprTagsAsContent != null) {
            properties.setTreatDeprecatedTagsAsContent( CommonUtil.isBooleanTrue(treatDeprTagsAsContent) );
        }

        final String omitXmlDecl = BaseTemplater.execute(htmlToXmlDef.getOmitXmlDecl(), scriptEngine);
        if ( omitXmlDecl != null) {
            properties.setOmitXmlDeclaration( CommonUtil.isBooleanTrue(omitXmlDecl) );
        }

        final String omitComments = BaseTemplater.execute(htmlToXmlDef.getOmitComments(), scriptEngine);
        if ( omitComments != null) {
            properties.setOmitComments( CommonUtil.isBooleanTrue(omitComments) );
        }

        final String omitHtmlEnvelope = BaseTemplater.execute(htmlToXmlDef.getOmitHtmlEnvelope(), scriptEngine);
        if ( omitHtmlEnvelope != null) {
            properties.setOmitHtmlEnvelope( CommonUtil.isBooleanTrue(omitHtmlEnvelope) );
        }

        final String allowMultiWordAttributes = BaseTemplater.execute(htmlToXmlDef.getAllowMultiWordAttributes(), scriptEngine);
        if ( allowMultiWordAttributes != null) {
            properties.setAllowMultiWordAttributes( CommonUtil.isBooleanTrue(allowMultiWordAttributes) );
        }

        final String allowHtmlInsideAttributes = BaseTemplater.execute(htmlToXmlDef.getAllowHtmlInsideAttributes(), scriptEngine);
        if ( allowHtmlInsideAttributes != null) {
            properties.setAllowHtmlInsideAttributes( CommonUtil.isBooleanTrue(allowHtmlInsideAttributes) );
        }

        final String namespacesAware = BaseTemplater.execute(htmlToXmlDef.getNamespacesAware(), scriptEngine);
        if ( namespacesAware != null) {
            properties.setNamespacesAware( CommonUtil.isBooleanTrue(namespacesAware) );
        } else {
            properties.setNamespacesAware(false);
        }

        final String hyphenReplacement = BaseTemplater.execute(htmlToXmlDef.getHyphenReplacement(), scriptEngine);
        if ( hyphenReplacement != null) {
            properties.setHyphenReplacementInComment(hyphenReplacement);
        }

        final String pruneTags = BaseTemplater.execute(htmlToXmlDef.getPrunetags(), scriptEngine);
        if ( pruneTags != null) {
            properties.setPruneTags(pruneTags);
        }

        final String booleanAtts = BaseTemplater.execute(htmlToXmlDef.getBooleanAtts(), scriptEngine);
        if ( booleanAtts != null) {
            properties.setBooleanAttributeValues(booleanAtts);
        }

        String outputType = BaseTemplater.execute(htmlToXmlDef.getOutputType(), scriptEngine);

        try {
            TagNode node = cleaner.clean(body.toString());
            String result;

            if ( "simple".equalsIgnoreCase(outputType) ) {
                result = new SimpleXmlSerializer(properties).getXmlAsString(node);
            } else if ( "pretty".equalsIgnoreCase(outputType) ) {
View Full Code Here


        long contentLength = res.getContentLength();
        if ( scraper.getLogger().isInfoEnabled() ) {
            scraper.getLogger().info("Downloaded: " + url + ", mime type = " + mimeType + ", length = " + contentLength + "B.");
        }

        Variable result;

        String responseCharset = res.getCharset();
        byte[] responseBody = res.getBody();

        if ( mimeType == null || mimeType.indexOf("text") >= 0 || mimeType.indexOf("xml") >= 0 || mimeType.indexOf("javascript") >= 0 ) {
View Full Code Here

        super(xpathDef);
        this.xpathDef = xpathDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        Variable xml = getBodyTextContent(xpathDef, scraper, context);
        String expression = BaseTemplater.execute( xpathDef.getExpression(), scraper.getScriptEngine() );
        this.setProperty("Expression", expression);

        try {
            RuntimeConfig runtimeConfig = scraper.getRuntimeConfig();
            return XmlUtil.evaluateXPath(expression, xml.toString(), runtimeConfig);
        } catch (XPathException e) {
            throw new ScraperXPathException("Error parsing XPath expression (XPath = [" + expression + "])!", e);
        }
    }
View Full Code Here

        super(templateDef);
        this.templateDef = templateDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        Variable body = getBodyTextContent(templateDef, scraper, context);

        String language = BaseTemplater.execute( templateDef.getLanguage(), scraper.getScriptEngine());
        if (language != null) {
            language = language.toLowerCase();
        }
        ScriptEngine scriptEngine = language == null ? scraper.getScriptEngine() : scraper.getScriptEngine(language);

        String result = BaseTemplater.execute(body.toString(), scriptEngine);
       
        return new NodeVariable(result);
    }
View Full Code Here

    public Variable execute(Scraper scraper, ScraperContext context) {
        CallProcessor callProcessor = scraper.getRunningFunction();

        if (callProcessor != null) {
            Variable returnValue = new BodyProcessor(returnDef).execute(scraper, context);
            callProcessor.setFunctionResult( returnValue );
        }

        return new EmptyVariable();
    }
View Full Code Here

    public String getName() {
        return "xml-to-json";
    }

    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 String getName() {
        return "json-to-xml";
    }

    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

        String password = evaluateAttribute("password", scraper);
        int maxRows = evaluateAttributeAsInteger("max", -1, scraper);
        boolean isAutoCommit = evaluateAttributeAsBoolean("autocommit", true, scraper);

        Connection conn = scraper.getConnection(jdbc, connection, username, password);
        Variable body = executeBody(scraper, context);
        String sql = body.toString();

        try {
            conn.setAutoCommit(isAutoCommit);
            PreparedStatement statement = conn.prepareStatement(sql, ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
            int index = 1;
View Full Code Here

        super(varDef);
        this.varDef = varDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        Variable var = new BodyProcessor(varDef).execute(scraper, context);
       
        String name = BaseTemplater.execute( varDef.getName(), scraper.getScriptEngine() );
        String overwrite = BaseTemplater.execute( varDef.getOverwrite(), scraper.getScriptEngine() );
        boolean toOverwrite = overwrite == null || CommonUtil.isBooleanTrue(overwrite);
        if (toOverwrite || context.get(name) == null) {
View Full Code Here

    public Variable execute(Scraper scraper, ScraperContext context) {
        String name = BaseTemplater.execute( varDef.getName(), scraper.getScriptEngine() );
        this.setProperty("Name", name);

        Variable var = context.getVar(name);

        if (var == null) {
            throw new VariableException("Variable '" + name + "' is not defined!");
        }
View Full Code Here

TOP

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

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.