Search in sources :

Example 1 with RESyntaxException

use of org.apache.regexp.RESyntaxException in project ant by apache.

the class JakartaRegexpMatcher method getCompiledPattern.

/**
 * Compile the pattern.
 *
 * @param options the ant regexp options
 * @return a compiled pattern
 * @exception BuildException if an error occurs
 */
protected RE getCompiledPattern(int options) throws BuildException {
    int cOptions = getCompilerOptions(options);
    try {
        RE reg = new RE(pattern);
        reg.setMatchFlags(cOptions);
        return reg;
    } catch (RESyntaxException e) {
        throw new BuildException(e);
    }
}
Also used : RE(org.apache.regexp.RE) BuildException(org.apache.tools.ant.BuildException) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 2 with RESyntaxException

use of org.apache.regexp.RESyntaxException in project convertigo by convertigo.

the class MergeBlocks method canBlockBeSelected.

public boolean canBlockBeSelected(Block block) {
    if ((!bMultilineMerge) || (!bAccumulating)) {
        return super.canBlockBeSelected(block);
    } else {
        Rectangle selectionScreenZone = getSelectionScreenZone();
        int selectionAttribute = getSelectionAttribute();
        String selectionType = getSelectionType();
        if ((selectionScreenZone.y != -1) && (block.line < selectionScreenZone.y)) {
            Engine.logBeans.trace("Block not selected because of wrong selection screen zone (line out of range)");
            return false;
        }
        if ((selectionScreenZone.x != -1) && (block.column < selectionScreenZone.x)) {
            Engine.logBeans.trace("Block not selected because of wrong selection screen zone (column out of range)");
            return false;
        }
        if ((selectionScreenZone.height != -1) && (block.line >= (selectionScreenZone.y + selectionScreenZone.height))) {
            Engine.logBeans.trace("Block not selected because of wrong selection screen zone (height out of range)");
            return false;
        }
        if (selectionAttribute != -1) {
            boolean b1 = ((selectionAttribute & DONT_CARE_FOREGROUND_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_INK) == (selectionAttribute & Javelin.AT_INK));
            boolean b2 = ((selectionAttribute & DONT_CARE_BACKGROUND_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_PAPER) == (selectionAttribute & Javelin.AT_PAPER));
            boolean b3 = ((selectionAttribute & DONT_CARE_INTENSE_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_BOLD) == (selectionAttribute & Javelin.AT_BOLD));
            boolean b4 = ((selectionAttribute & DONT_CARE_UNDERLINED_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_UNDERLINE) == (selectionAttribute & Javelin.AT_UNDERLINE));
            boolean b5 = ((selectionAttribute & DONT_CARE_REVERSE_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_INVERT) == (selectionAttribute & Javelin.AT_INVERT));
            boolean b6 = ((selectionAttribute & DONT_CARE_BLINK_ATTRIBUTE) != 0 ? true : (block.attribute & Javelin.AT_BLINK) == (selectionAttribute & Javelin.AT_BLINK));
            if (!(b1 && b2 && b3 && b4 && b5 && b6)) {
                Engine.logBeans.trace("Block not selected because of wrong attributes\n" + "AT_PAPER=" + b1 + "\n" + "AT_INK=" + b2 + "\n" + "AT_BOLD=" + b3 + "\n" + "AT_INVERT=" + b4 + "\n" + "AT_UNDERLINE=" + b5 + "\n" + "AT_BLINK=" + b6 + "\n");
                return false;
            }
        }
        try {
            RE regexp = new RE(selectionType);
            if (!regexp.match(block.type))
                return false;
        } catch (RESyntaxException e) {
            Engine.logBeans.error("Unable to execute the regular expression for the selection of the block", e);
        }
        return true;
    }
}
Also used : RE(org.apache.regexp.RE) Rectangle(java.awt.Rectangle) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 3 with RESyntaxException

use of org.apache.regexp.RESyntaxException in project jahia by Jahia.

the class PortletRenderTag method drawPortlet.

/**
 * draw portlet node
 *
 * @param jcrPortletNode the corresponding portlet JCR node
 * @param windowId the window ID
 * @param out the current JSP writer instance
 * @param servletContext  the Servlet context instance
 * @throws JahiaException in case of DX specific error
 * @throws IOException in case of an I/O error
 * @throws RepositoryException in case of JCR-related errors
 */
public void drawPortlet(JCRPortletNode jcrPortletNode, int windowId, final JspWriter out, ServletContext servletContext) throws JahiaException, IOException, RepositoryException {
    String appID = null;
    try {
        appID = jcrPortletNode.getUUID();
    } catch (RepositoryException e) {
        throw new JahiaException("Error rendering portlet", "Error rendering portlet", JahiaException.APPLICATION_ERROR, JahiaException.ERROR_SEVERITY, e);
    }
    logger.debug("Dispatching to portlet for appID=" + appID + "...");
    String portletOutput = ServicesRegistry.getInstance().getApplicationsDispatchService().getAppOutput(windowId, appID, getRenderContext().getUser(), getRenderContext().getRequest(), getRenderContext().getResponse(), servletContext, jcrPortletNode.getSession().getWorkspace().getName());
    // remove <html> tags that can break the page
    if (portletOutput != null) {
        try {
            portletOutput = (new RE("</?html>", RE.MATCH_CASEINDEPENDENT)).subst(portletOutput, "");
        } catch (RESyntaxException e) {
            logger.debug(".getValue, exception : " + e.toString());
        }
    } else {
        portletOutput = "";
    }
    out.print(portletOutput);
}
Also used : RE(org.apache.regexp.RE) JahiaException(org.jahia.exceptions.JahiaException) RepositoryException(javax.jcr.RepositoryException) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 4 with RESyntaxException

use of org.apache.regexp.RESyntaxException in project convertigo by convertigo.

the class Record method execute.

public JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    Block curBlock = block, eorBlock = block, temp;
    boolean found = false;
    // recreate the regular expression object.
    if (borRE == null) {
        try {
            setBorType(borType);
        } catch (RESyntaxException e) {
            Engine.logBeans.error("Unable to create the regular expression object for BOR type", e);
        }
    }
    if (eorRE == null) {
        try {
            setEorType(eorType);
        } catch (RESyntaxException e) {
            Engine.logBeans.error("Unable to create the regular expression object for EOR type", e);
        }
    }
    if (perPage) {
        Engine.logBeans.trace("Applying Record rule to the current page");
        // Test if it's the first block of the page
        if (blockFactory.getPreviousBlock(block) != null) {
            Engine.logBeans.trace("The block isn't the first block of the page, aborting ...");
            xrs.hasMatched = false;
            xrs.newCurrentBlock = block;
            return xrs;
        }
        // Creation and initialisation of the parent bloc of the record
        Block record = new Block();
        Engine.logBeans.trace("Creation du bloc parent");
        record.type = "record";
        record.setText("");
        record.name = "";
        if (this.tagName.length() != 0)
            record.tagName = this.tagName;
        else
            record.tagName = "record";
        // Insert the main bloc in the blockFactory in first position
        blockFactory.insertBlock(record, null);
        Engine.logBeans.trace("Insertion du bloc parent");
        // After being added, each block is deleted
        while (curBlock != null) {
            record.addOptionalChildren(curBlock);
            Engine.logBeans.trace("appending child " + curBlock.tagName + " to record " + record.tagName);
            temp = blockFactory.getNextBlock(curBlock);
            blockFactory.removeBlock(curBlock);
            curBlock = temp;
        }
        xrs.hasMatched = true;
        xrs.newCurrentBlock = record;
        return xrs;
    } else {
        Engine.logBeans.trace("Applying Record rule to block " + block.name);
        // Tests if the block is in the specified zone and if it's a bor block
        if (isBor(block)) {
            // we look for an eor block
            while ((curBlock = blockFactory.getNextBlock(curBlock)) != null) {
                if (!canBlockBeSelected(curBlock))
                    continue;
                if (isEor(curBlock)) {
                    eorBlock = curBlock;
                    found = true;
                    break;
                }
            }
            // If the end of the screen has been reached, set the 'found' flag to true.
            if (curBlock == null) {
                found = true;
            }
        }
        // of the main block of the record
        if (found) {
            Engine.logBeans.trace("Begining and End of Record " + this.tagName + " found");
            Block recordBlock;
            recordBlock = new Block();
            Engine.logBeans.trace("Creation du bloc BOR");
            recordBlock.type = "record";
            recordBlock.setText("");
            recordBlock.name = "";
            recordBlock.line = block.line;
            recordBlock.column = block.column;
            if (this.tagName.length() != 0)
                recordBlock.tagName = this.tagName;
            // Insert the main block in the blockFactory in first position
            blockFactory.insertBlock(recordBlock, blockFactory.getPreviousBlock(block));
            Engine.logBeans.trace("BOR block inserted ...");
            // Starts the block just after the bor
            curBlock = blockFactory.getNextBlock(recordBlock);
            Block nextBlock = null;
            if (eorBlock != null) {
                nextBlock = blockFactory.getNextBlock(eorBlock);
            }
            // and deleted from memory
            while (curBlock != null) {
                if (isEor(curBlock)) {
                    if (bor.equals(eor)) {
                        if (recordBlock.hasOptionalChildren()) {
                            break;
                        }
                    } else {
                        break;
                    }
                }
                recordBlock.addOptionalChildren(curBlock);
                Engine.logBeans.trace("Appending child " + curBlock.tagName + " to record " + recordBlock.tagName);
                temp = blockFactory.getNextBlock(curBlock);
                blockFactory.removeBlock(curBlock);
                curBlock = temp;
            }
            // Deletes the eor separator only if it's followed  by a bor separator
            // and sets the new current block
            xrs.newCurrentBlock = recordBlock;
            if (isBor(nextBlock) || (nextBlock == null)) {
                if (eorBlock != null) {
                    blockFactory.removeBlock(eorBlock);
                }
            }
            xrs.hasMatched = true;
            return xrs;
        }
    }
    xrs.hasMatched = false;
    xrs.newCurrentBlock = block;
    return xrs;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) Block(com.twinsoft.convertigo.beans.core.Block) RESyntaxException(org.apache.regexp.RESyntaxException)

Example 5 with RESyntaxException

use of org.apache.regexp.RESyntaxException in project convertigo by convertigo.

the class RemoveBlocks method execute.

/**
 * Applies the extraction rule to the current iJavelin object.
 *
 * @param javelin the Javelin object.
 * @param block the current block to analyze.
 * @param blockFactory the block context of the current block.
 * @param dom the XML DOM.
 *
 * @return an ExtractionRuleResult object containing the result of
 * the query.
 */
protected JavelinExtractionRuleResult execute(iJavelin javelin, Block block, BlockFactory blockFactory, org.w3c.dom.Document dom) {
    JavelinExtractionRuleResult xrs = new JavelinExtractionRuleResult();
    Block curBlock;
    Block tempBlock;
    int blockLen;
    xrs.hasMatched = false;
    // recreate the regular expression object.
    if (regexp == null) {
        try {
            Engine.logBeans.debug("Setting regular expression to : " + regularExpression);
            setRegularExpression(regularExpression);
        } catch (RESyntaxException e) {
            Engine.logBeans.error("Unable to create the regular expression object", e);
        }
    }
    curBlock = block;
    do {
        tempBlock = blockFactory.getNextBlock(curBlock);
        if (canBlockBeSelected(curBlock)) {
            if ((blockTag.length() == 0) || blockTag.equalsIgnoreCase(curBlock.tagName)) {
                blockLen = curBlock.getText().trim().length();
                if ((length == -1) || (blockLen == length)) {
                    // Avoid to try to match on empty strings
                    if (blockLen != 0) {
                        if (regexp.match(curBlock.getText())) {
                            blockFactory.removeBlock(curBlock);
                            xrs.hasMatched = true;
                        }
                    } else {
                        blockFactory.removeBlock(curBlock);
                        xrs.hasMatched = true;
                    }
                }
            }
        }
        if (tempBlock == null)
            break;
        curBlock = tempBlock;
    } while (true);
    xrs.newCurrentBlock = curBlock;
    return xrs;
}
Also used : JavelinExtractionRuleResult(com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult) Block(com.twinsoft.convertigo.beans.core.Block) RESyntaxException(org.apache.regexp.RESyntaxException)

Aggregations

RESyntaxException (org.apache.regexp.RESyntaxException)6 RE (org.apache.regexp.RE)4 Block (com.twinsoft.convertigo.beans.core.Block)2 JavelinExtractionRuleResult (com.twinsoft.convertigo.beans.extractionrules.JavelinExtractionRuleResult)2 FindString (com.twinsoft.convertigo.beans.common.FindString)1 EngineException (com.twinsoft.convertigo.engine.EngineException)1 DevicePool (com.twinsoft.util.DevicePool)1 Rectangle (java.awt.Rectangle)1 IOException (java.io.IOException)1 NoSuchElementException (java.util.NoSuchElementException)1 RepositoryException (javax.jcr.RepositoryException)1 BuildException (org.apache.tools.ant.BuildException)1 JahiaException (org.jahia.exceptions.JahiaException)1 EvaluatorException (org.mozilla.javascript.EvaluatorException)1 JavaScriptException (org.mozilla.javascript.JavaScriptException)1