Examples of BaseElementDef


Examples of org.webharvest.definition.BaseElementDef

                    return ifResult;
                }
          }
        }

        BaseElementDef elseDef = caseDef.getElseDef();
        if (elseDef != null) {
          Variable elseResult = new BodyProcessor(elseDef).run(scraper, context);
            debug(elseDef, scraper, elseResult);
            return elseResult;
        }
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        ScriptEngine scriptEngine = scraper.getScriptEngine();

        BaseElementDef patternDef = regexpDef.getRegexpPatternDef();
        Variable patternVar = getBodyTextContent(patternDef, scraper, context, true);
        debug(patternDef, scraper, patternVar);

        BaseElementDef sourceDef = regexpDef.getRegexpSourceDef();
        Variable source = new BodyProcessor(sourceDef).run(scraper, context);
        debug(sourceDef, scraper, source);
       
        String replace = BaseTemplater.execute( regexpDef.getReplace(), scriptEngine);
        boolean isReplace = CommonUtil.isBooleanTrue(replace);

        boolean flagCaseInsensitive = CommonUtil.getBooleanValue( BaseTemplater.execute(regexpDef.getFlagCaseInsensitive(), scriptEngine), false );
        boolean flagMultiline = CommonUtil.getBooleanValue( BaseTemplater.execute(regexpDef.getFlagMultiline(), scriptEngine), false );
        boolean flagDotall = CommonUtil.getBooleanValue( BaseTemplater.execute(regexpDef.getFlagDotall(), scriptEngine), true );
        boolean flagUnicodecase = CommonUtil.getBooleanValue( BaseTemplater.execute(regexpDef.getFlagUnicodecase(), scriptEngine), true );
        boolean flagCanoneq = CommonUtil.getBooleanValue( BaseTemplater.execute(regexpDef.getFlagCanoneq(), scriptEngine), false );

        this.setProperty("Is replacing", String.valueOf(isReplace));
        this.setProperty("Flag CaseInsensitive", String.valueOf(flagCaseInsensitive));
        this.setProperty("Flag MultiLine", String.valueOf(flagMultiline));
        this.setProperty("Flag DotAll", String.valueOf(flagDotall));
        this.setProperty("Flag UnicodeCase", String.valueOf(flagUnicodecase));
        this.setProperty("Flag CanonEq", String.valueOf(flagCanoneq));

        String maxLoopsString = BaseTemplater.execute( regexpDef.getMax(), scriptEngine);
        double maxLoops = Constants.DEFAULT_MAX_LOOPS;
        if (maxLoopsString != null && !"".equals(maxLoopsString.trim())) {
            maxLoops = Double.parseDouble(maxLoopsString);
        }

        this.setProperty("Max loops", String.valueOf(maxLoops));

        int flags = 0;
        if (flagCaseInsensitive) {
            flags |= Pattern.CASE_INSENSITIVE;
        }
        if (flagMultiline) {
            flags |= Pattern.MULTILINE;
        }
        if (flagDotall) {
            flags |= Pattern.DOTALL;
        }
        if (flagUnicodecase) {
            flags |= Pattern.UNICODE_CASE;
        }
        if (flagCanoneq) {
            flags |= Pattern.CANON_EQ;
        }

        Pattern pattern = Pattern.compile(patternVar.toString(), flags);
       
        List resultList = new ArrayList();
       
        List bodyList = source.toList();
        Iterator it = bodyList.iterator();
        while (it.hasNext()) {
          Variable currVar = (Variable) it.next();
          String text = currVar.toString();
           
            Matcher matcher = pattern.matcher(text);
            int groupCount = matcher.groupCount();
           
            StringBuffer buffer = new StringBuffer();
           
            int index = 0;
            while ( matcher.find() ) {
              index++;

              // if index exceeds maximum number of matching sequences exists the loop
                if (maxLoops < index) {
                    break;
                }

              for (int i = 0; i <= groupCount; i++) {
                context.put("_"+i, new NodeVariable(matcher.group(i)));
              }

                BaseElementDef resultDef = regexpDef.getRegexpResultDef();
                Variable result = getBodyTextContent(resultDef, scraper, context, true);
                debug(resultDef, scraper, result);
               
                String currResult = (result == null) ? matcher.group(0) : result.toString();
              if (isReplace) {
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

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

    public Variable execute(Scraper scraper, ScraperContext context) {
        BaseElementDef xsltElementDef = xsltDef.getXmlDef();
        Variable xmlStr = getBodyTextContent(xsltElementDef, scraper, context, true);
        debug(xsltElementDef, scraper, xmlStr);

        BaseElementDef stylesheetElementDef = xsltDef.getStylesheetDef();
        Variable stylesheetStr = getBodyTextContent(stylesheetElementDef, scraper, context, true);
        debug(stylesheetElementDef, scraper, stylesheetStr);
     
        try {
        TransformerFactory xformFactory = TransformerFactory.newInstance();
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

        this.tryDef = tryDef;
    }

    public Variable execute(Scraper scraper, ScraperContext context) {
        try {
            BaseElementDef tryBodyDef = tryDef.getTryBodyDef();
            Variable result = new BodyProcessor(tryBodyDef).run(scraper, context);
            debug(tryBodyDef, scraper, result);

            return result;
        } catch(BaseException e) {
            if ( scraper.getLogger().isInfoEnabled() ) {
                scraper.getLogger().info("Exception caught with try processor: " + e.getMessage());
            }
            BaseElementDef catchValueDef = tryDef.getCatchValueDef();
            Variable result = new BodyProcessor(catchValueDef).run(scraper, context);
            debug(catchValueDef, scraper, result);

            return result;
        }
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

            tree.expandRow(row);
        }
    }

    public void onNewProcessorExecution(Scraper scraper, BaseProcessor processor) {
        BaseElementDef elementDef = processor.getElementDef();
        if (elementDef != null) {
            TreeNodeInfo nodeInfo = (TreeNodeInfo) this.nodeInfos.get(elementDef);
            if (nodeInfo != null) {
                nodeInfo.increaseExecutionCount();
                setExecutingNode(nodeInfo);
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

        // releases scraper in order help garbage collector
//        releaseScraper();
    }

    public void onProcessorExecutionFinished(Scraper scraper, BaseProcessor processor, Map properties) {
        BaseElementDef elementDef = processor.getElementDef();
        if (elementDef != null) {
            TreeNodeInfo nodeInfo = (TreeNodeInfo) this.nodeInfos.get(elementDef);
            if (nodeInfo != null) {
                nodeInfo.setProperties(properties);
                if ( nodeInfo == this.selectedNodeInfo ) {
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

    private int locateInSource(DefaultMutableTreeNode treeNode, boolean locateAtLineBeginning) {
        if (treeNode != null) {
            Object userObject = treeNode.getUserObject();
            if (userObject instanceof TreeNodeInfo) {
                TreeNodeInfo treeNodeInfo = (TreeNodeInfo) userObject;
                BaseElementDef elementDef = (BaseElementDef) treeNodeInfo.getElementDef();
                int lineNumber = elementDef.getLineNumber();
                int columnNumber = elementDef.getColumnNumber();

                String content = null;
                try {
                    content = this.xmlPane.getDocument().getText( 0, this.xmlPane.getDocument().getLength() );
                    String[] lines = content.split("\n");
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

        double maxLoops = Constants.DEFAULT_MAX_LOOPS;
        if (maxLoopsString != null && !"".equals(maxLoopsString.trim())) {
            maxLoops = Double.parseDouble(maxLoopsString);
        }

        BaseElementDef loopValueDef = loopDef.getLoopValueDef();
        Variable loopValue = new BodyProcessor(loopValueDef).run(scraper, context);
        debug(loopValueDef, scraper, loopValue);

        List resultList = new ArrayList();

        List list = loopValue != null ? loopValue.toList() : null;
        if (list != null) {
            Variable itemBeforeLoop = (Variable) context.get(item);
            Variable indexBeforeLoop = (Variable) context.get(index);

            List filteredList = filter != null ? createFilteredList(list, filter) : list;
            Iterator it = filteredList.iterator();

            for (int i = 1; it.hasNext() && i <= maxLoops; i++) {
                Variable currElement = (Variable) it.next();

                // define current value of item variable
                if ( item != null && !"".equals(item) ) {
                    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();
                debug(bodyDef, scraper, loopResult);
                if (!isEmpty) {
                    resultList.addAll( loopResult.toList() );
                }
View Full Code Here

Examples of org.webharvest.definition.BaseElementDef

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

    public Variable execute(Scraper scraper, ScraperContext context) {
        BaseElementDef xqueryElementDef = xqueryDef.getXqDef();
        Variable xq = getBodyTextContent(xqueryElementDef, scraper, context, true);
        debug(xqueryElementDef, scraper, xq);

        String xqExpression = xq.toString().trim();
        XQueryExternalParamDef[] externalParamDefs = xqueryDef.getExternalParamDefs();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.