Example usage for java.util.regex Pattern DOTALL

List of usage examples for java.util.regex Pattern DOTALL

Introduction

In this page you can find the example usage for java.util.regex Pattern DOTALL.

Prototype

int DOTALL

To view the source code for java.util.regex Pattern DOTALL.

Click Source Link

Document

Enables dotall mode.

Usage

From source file:com.norconex.importer.parser.AbstractParserTest.java

private void assertDefaults(ImporterDocument doc, String testType, String resourcePath, String contentType,
        String contentRegex, String extension, String family) throws IOException {
    Pattern p = Pattern.compile(contentRegex, Pattern.DOTALL | Pattern.MULTILINE);

    Assert.assertNotNull("Document is null", doc);

    String content = IOUtils.toString(doc.getContent());
    Assert.assertEquals(testType + " content-type detection failed for \"" + resourcePath + "\".",
            ContentType.valueOf(contentType), doc.getContentType());

    Assert.assertTrue(/*from   w  w  w .  java 2s.co  m*/
            testType + " content extraction failed for \"" + resourcePath + "\". Content:\n" + content,
            p.matcher(content).find());

    String ext = doc.getContentType().getExtension();
    Assert.assertEquals(testType + " extension detection failed for \"" + resourcePath + "\".", extension, ext);

    String familyEnglish = doc.getContentType().getContentFamily().getDisplayName(Locale.ENGLISH);
    //        System.out.println("FAMILY: " + familyEnglish);
    Assert.assertEquals(testType + " family detection failed for \"" + resourcePath + "\".", family,
            familyEnglish);

}

From source file:org.talend.dataprep.transformation.actions.common.ReplaceOnValueHelper.java

/**
 * @return true if this pattern is valid.
 *//*from w  w w  .j  a va2  s. c  o m*/
private boolean isValid() {
    // regex validity check
    final Boolean regexMode = this.operator.equals(REGEX_MODE);

    if (regexMode && pattern == null) {
        String actualPattern = strict ? this.token : ".*" + this.token + ".*";
        try {
            pattern = Pattern.compile(actualPattern, Pattern.DOTALL);
        } catch (Exception e) {
            return false;
        }
    }

    return true;
}

From source file:de.blizzy.documentr.TestUtil.java

public static void assertRE(String expectedRegExp, String actual) {
    @SuppressWarnings("nls")
    String msg = "text does not match regular expression:\n" + "regular expression:\n" + expectedRegExp + "\n"
            + "text:\n" + actual;
    assertTrue(msg, Pattern.compile(expectedRegExp, Pattern.DOTALL).matcher(actual).matches());
}

From source file:com.rubika.aotalk.util.ItemRef.java

public List<Object> getData(String lowId, String highId, String ql) {
    List<Object> result = new ArrayList<Object>();

    EasyTracker.getInstance().setContext(AOTalk.getContext());
    Tracker tracker = EasyTracker.getTracker();
    long loadTime = System.currentTimeMillis();

    String xml = null;// ww w . j a  v a2s.com
    Document doc = null;

    String icon = "";
    String name = "";
    String description = "";
    String flaglist = "";
    String flags = "";
    String requirements = "";
    String can = "";
    String events = "";
    String attributes = "";
    String attacks = "";
    String defenses = "";
    String level = "";

    int lowQL = 0;
    int highQL = 0;

    String xyphosUrl = String.format(Statics.XYPHOS_ITEM_QL_URL, lowId, ql);
    Logging.log(APP_TAG, xyphosUrl);

    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpPost httpPost = new HttpPost(xyphosUrl);
        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        xml = EntityUtils.toString(httpEntity);
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    } catch (ClientProtocolException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }

    if (xml != null) {
        if (xml.contains("<item>")) {
            xml = xml.substring(xml.indexOf("<item>"));
        }

        Pattern pattern = Pattern.compile("<description>(.*?)</description>", Pattern.DOTALL);
        Matcher matcher = pattern.matcher(xml);

        while (matcher.find()) {
            xml = xml.replace(matcher.group(1),
                    matcher.group(1).replaceAll("<", "&lt;").replaceAll(">", "&gt;"));
        }

        pattern = Pattern.compile(" name=\"(.*?)\" />", Pattern.DOTALL);
        matcher = pattern.matcher(xml);

        while (matcher.find()) {
            xml = xml.replace(matcher.group(1), matcher.group(1).replaceAll("<b>", "").replaceAll("</b>", ""));
        }

        Logging.log(APP_TAG, xml);

        DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();

        try {
            DocumentBuilder db = dbf.newDocumentBuilder();

            InputSource is = new InputSource();
            is.setCharacterStream(new StringReader(xml));
            doc = db.parse(is);
        } catch (ParserConfigurationException e) {
            Logging.log(APP_TAG, e.getMessage());
            return null;
        } catch (SAXException e) {
            Logging.log(APP_TAG, e.getMessage());
            return null;
        } catch (IOException e) {
            Logging.log(APP_TAG, e.getMessage());
            return null;
        }

        if (doc != null) {
            NodeList nl = doc.getElementsByTagName("item");

            for (int i = 0; i < nl.getLength(); i++) {
                Element e = (Element) nl.item(i);

                name = getValue(e, "name");
                description = getValue(e, "description").replaceAll("\n", "<br />");
            }

            nl = doc.getElementsByTagName("low");
            for (int x = 0; x < nl.getLength(); x++) {
                Element item = (Element) nl.item(x);
                lowQL = Integer.parseInt(item.getAttribute("ql"));
            }

            nl = doc.getElementsByTagName("high");
            for (int x = 0; x < nl.getLength(); x++) {
                Element item = (Element) nl.item(x);
                highQL = Integer.parseInt(item.getAttribute("ql"));
            }

            nl = doc.getElementsByTagName("attribute");

            int equipmentPageID = -1;
            for (int x = 0; x < nl.getLength(); x++) {
                Element item = (Element) nl.item(x);
                int value = Integer.parseInt(item.getAttribute("value"));

                if (item != null) {
                    if (item.getAttribute("stat") != null) {
                        if (item.getAttribute("stat").equals("79")) {
                            icon = item.getAttribute("value");
                        } else if (item.getAttribute("stat").equals("76")) {
                            equipmentPageID = value;
                        } else if (item.getAttribute("stat").equals("298")) {
                            String slots = ItemValues.getSlot(value, equipmentPageID);

                            if (slots.length() > 0) {
                                attributes += item.getAttribute("name") + " <b>" + slots + "</b><br />";
                            }
                        } else if (item.getAttribute("stat").equals("0")) {
                            flaglist = item.getAttribute("extra") + "<br />";
                        } else if (item.getAttribute("stat").equals("30")) {
                            can = item.getAttribute("extra");
                        } else if (item.getAttribute("stat").equals("54")) {
                            level = String.valueOf(value);
                        } else {
                            if (!item.getAttribute("stat").equals("88")
                                    && !item.getAttribute("stat").equals("2")
                                    && !item.getAttribute("stat").equals("209")
                                    && !item.getAttribute("stat").equals("353")
                                    && !item.getAttribute("stat").equals("12")
                                    && !item.getAttribute("stat").equals("74")
                                    && !item.getAttribute("stat").equals("272")
                                    && !item.getAttribute("stat").equals("270")
                                    && !item.getAttribute("stat").equals("269")
                                    && !item.getAttribute("stat").equals("428")
                                    && !item.getAttribute("stat").equals("419")) {
                                if (item.getAttribute("extra").equals("")) {
                                    attributes += item.getAttribute("name") + " " + item.getAttribute("value")
                                            + "<br />";
                                } else {
                                    attributes += item.getAttribute("name") + " " + item.getAttribute("extra")
                                            + "<br />";
                                }
                            }
                        }
                    }
                }
            }

            nl = doc.getElementsByTagName("attack");

            for (int i = 0; i < nl.getLength(); i++) {
                Element item = (Element) nl.item(i);
                attacks += item.getAttribute("name") + " " + item.getAttribute("percent") + "%<br />";
            }

            nl = doc.getElementsByTagName("defense");

            for (int i = 0; i < nl.getLength(); i++) {
                Element item = (Element) nl.item(i);
                defenses += item.getAttribute("name") + " " + item.getAttribute("percent") + "%<br />";
            }

            nl = doc.getElementsByTagName("action");

            for (int i = 0; i < nl.getLength(); i++) {
                Element item = (Element) nl.item(i);
                NodeList nreq = item.getElementsByTagName("requirement");

                requirements += "<br /><b><i>" + item.getAttribute("name") + "</i></b><br />";

                for (int p = 0; p < nreq.getLength(); p++) {
                    Element ritem = (Element) nreq.item(p);
                    NodeList reqList = ritem.getChildNodes();

                    String req = "%s %s %s %s %s<br />";
                    String target = "";
                    String stat = "";
                    String op = "";
                    String value = "";
                    String subop = "";

                    for (int y = 0; y < reqList.getLength(); y++) {
                        Node reqItem = reqList.item(y);

                        if (!(reqItem instanceof Text)) {

                            Element e = (Element) reqItem;

                            if (e.getNodeName().equals("target")) {
                                target = e.getAttribute("name");
                            }

                            if (e.getNodeName().equals("stat")) {
                                stat = e.getAttribute("name");
                            }

                            if (e.getNodeName().equals("op")) {
                                op = e.getAttribute("name");
                            }

                            if (e.getNodeName().equals("value")) {
                                value = e.getAttribute("num");

                                if (stat.equals("WornItem")) {
                                    value = ItemValues.getWornItem(Integer.parseInt(value));
                                }

                                if (stat.equals("Expansion")) {
                                    value = ItemValues.getExpansion(Integer.parseInt(value));
                                }

                                if (stat.equals("Breed")) {
                                    value = ItemValues.getBreed(Integer.parseInt(value));
                                }

                                if (stat.equals("ExpansionPlayfield")) {
                                    value = ItemValues.getExpansionPlayfield(Integer.parseInt(value));
                                }

                                if (stat.equals("CurrentPlayfield")) {
                                    value = ItemValues.getCurrentPlayfield(Integer.parseInt(value));
                                }

                                if (stat.equals("Faction")) {
                                    value = ItemValues.getFaction(Integer.parseInt(value));
                                }

                                if (stat.equals("Flags")) {
                                    if (op.equals("HasPerk")) {
                                        value = ItemValues.getPerk(Integer.parseInt(value));
                                    }
                                    if (op.equals("HasNotWornItem")) {
                                        value = ItemValues.getHasNotWornItem(Integer.parseInt(value));
                                    }
                                }

                                if (stat.equals("Profession") || stat.equals("VisualProfession")) {
                                    value = ItemValues.getProfession(Integer.parseInt(value));
                                }
                            }

                            if (e.getNodeName().equals("subop")) {
                                subop = e.getAttribute("name");
                            }
                        }
                    }

                    requirements += String.format(req, target, stat, op, value, subop);
                }
            }

            nl = doc.getElementsByTagName("event");

            for (int x = 0; x < nl.getLength(); x++) {
                Element item = (Element) nl.item(x);

                if (item != null) {
                    events += "<br /><b><i>" + item.getAttribute("name") + "</i></b><br />";

                    NodeList nwear = item.getElementsByTagName("function");
                    String funcName = "";

                    for (int y = 0; y < nwear.getLength(); y++) {
                        Element wear = (Element) nwear.item(y);
                        NodeList ntarget = wear.getElementsByTagName("target");
                        NodeList nfunc = wear.getElementsByTagName("func");
                        NodeList nparam = wear.getElementsByTagName("parameters");

                        for (int z = 0; z < ntarget.getLength(); z++) {
                            Element target = (Element) ntarget.item(z);
                            events += target.getAttribute("name") + " ";
                        }

                        for (int z = 0; z < nfunc.getLength(); z++) {
                            Element func = (Element) nfunc.item(z);
                            events += func.getAttribute("name") + " ";
                            funcName = func.getAttribute("name");
                        }

                        for (int z = 0; z < nparam.getLength(); z++) {
                            Element params = (Element) nparam.item(z);
                            NodeList nparams = params.getElementsByTagName("param");

                            for (int i = 0; i < nparams.getLength(); i++) {
                                Element param = (Element) nparams.item(i);

                                if (nparams.getLength() > 1) {
                                    if (i == 0) {
                                        if (funcName.equals("Modify") || funcName.equals("LockSkill")
                                                || funcName.equals("Skill") || funcName.equals("Hit")
                                                || funcName.equals("ChangeVariable")
                                                || funcName.equals("TimedEffect")) {
                                            events += ItemValues.getSkill(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else if (funcName.equals("CastStunNano")
                                                || funcName.equals("AreaCastNano")) {
                                            events += ItemValues.lookupItemName(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else if (funcName.equals("ResistNanoStrain")) {
                                            events += ItemValues.getNanoStrain(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else if (funcName.equals("SetFlag")) {
                                            events += ItemValues.getFlag(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else {
                                            events += param.getFirstChild().getNodeValue();
                                        }
                                    } else if (i == 3) {
                                        if (funcName.equals("Teleport")) {
                                            events += ItemValues.getCurrentPlayfield(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else if (funcName.equals("HasNotFormula")) {
                                            events += ItemValues.getNano(
                                                    Integer.parseInt(param.getFirstChild().getNodeValue()));
                                        } else {
                                            events += param.getFirstChild().getNodeValue();
                                        }
                                    } else {
                                        if (funcName.equals("AddSkill") || funcName.equals("ChangeVariable")
                                                || funcName.equals("Set")) {
                                            int num = Integer.parseInt(param.getFirstChild().getNodeValue());
                                            events += ItemValues.getSkill(num);
                                        } else {
                                            events += param.getFirstChild().getNodeValue();
                                        }
                                    }
                                } else {
                                    if (funcName.equals("UploadNano") || funcName.equals("CastNano")
                                            || funcName.equals("TeamCastNano")) {
                                        events += ItemValues.lookupItemName(
                                                Integer.parseInt(param.getFirstChild().getNodeValue()));
                                    } else if (funcName.equals("RemoveNanoStrain")) {
                                        events += ItemValues.getNanoStrain(
                                                Integer.parseInt(param.getFirstChild().getNodeValue()));
                                    } else {
                                        events += param.getFirstChild().getNodeValue();
                                    }
                                }

                                events += " ";
                            }
                        }

                        events += "<br />";
                    }
                }
            }
        }

        if (flaglist.contains("NoDrop")) {
            flags += "NODROP";
        }

        if (flaglist.contains("Unique")) {
            if (flags.length() > 0) {
                flags += ", ";
            }
            flags += "UNIQUE";
        }

        if (!flags.equals("")) {
            flags = "<br /><font color=#999999>" + flags + "</font>";
        }

        retval += "<img src=\"" + Statics.ICON_PATH + icon + "\" class=\"item\">" + "<b>" + name + "</b>"
                + flags + "<br /><br />" + "<b>Quality level:</b> " + level + "<br /><br />"
                + "<b>Description</b><br />" + description;

        if (can.length() > 0) {
            retval += "<br /><br /><b>Can</b><br />" + can;
        }

        if (flaglist.length() > 0) {
            retval += "<br /><br /><b>Flags</b><br />" + flaglist;
        }

        if (attributes.length() > 0) {
            retval += "<br /><b>Attributes</b><br />";
            retval += attributes;
        }

        if (attacks.length() > 0) {
            retval += "<br /><b>Attacks</b><br />";
            retval += attacks;
        }

        if (defenses.length() > 0) {
            retval += "<br /><b>Defenses</b><br />";
            retval += defenses;
        }

        if (requirements.length() > 0) {
            requirements = requirements.replace("EqualTo", "=").replace("NotBitAnd", "!=")
                    .replace("BitAnd", "=").replace("Unequal", "!=").replace("LessThan", "<")
                    .replace("GreaterThan", ">");
            retval += "<br /><b>Reqirements</b><br />" + requirements;
        }

        if (events.length() > 0) {
            retval += "<br /><b>Events</b><br />";
            retval += events;
        }

        /*
        retval += "<br /><br />";
        retval += "<font color=#999999>Guides from AO-Universe</font>";
        retval += "<br />";
        retval += "<a href=\"gitem://" + name + "\">Check for guides</a>";
        retval += "<br /><br />";
        retval += "<font color=#999999>Recipes from AO RecipeBook</font>";
        retval += "<br />";
        retval += "<a href=\"aorbid://" + lowId + "\">Check for recipes</a>";
         */
        retval += "<br /><br />";
        retval += "<font color=#999999>Data from Xyphos.org</font>";
        retval += "<br />";
        retval += "<a href=\"chatcmd:///start http://www.xyphos.com/ao/aodb.php?id=" + lowId + "&ql=" + ql
                + "\">Show on web page</a>";

        if (retval.startsWith("<br />")) {
            retval = retval.replaceFirst("<br />", "");
        }
    }

    result.add(retval);
    result.add(lowQL);
    result.add(highQL);
    try {
        result.add(Integer.parseInt(level));
    } catch (NumberFormatException e) {
        Logging.log(APP_TAG, e.getMessage());
        result.add(0);
    }
    result.add(name);

    if (retval != null && retval.length() > 0) {
        tracker.sendTiming("Loading", System.currentTimeMillis() - loadTime, "Item", null);
    }

    return result;
}

From source file:de.dfki.km.perspecting.obie.model.Document.java

/***************************************************************************
 * Gets the pure plain text out of a html text. All html tags are replaced
 * by spaces. To do so, the head is replaced, all remaining javascript tags
 * (including the content) and finally all remaining html tags. Thus,
 * absolute positioning is possible./* w ww . j  a  v  a  2 s. co  m*/
 * 
 * @param text
 *            content of the html document as text
 * @return text where all html was replaced by spaces
 */
private String extractPlainTextFromHtml(String text) {
    Collection<Pattern> patterns = new ArrayList<Pattern>(3);
    // Delete the head, then all remaining javascript items that might exist
    // in the body, then all remaining html tags.
    patterns.add(
            Pattern.compile("<head.*/head>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL));
    // .*? makes it non greedy -> take the shortes match
    // DOTALL does also include new lines
    patterns.add(Pattern.compile("<script.*?/script>",
            Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE | Pattern.DOTALL));
    patterns.add(Pattern.compile("<.+?>", Pattern.CASE_INSENSITIVE | Pattern.UNICODE_CASE));
    StringBuffer s = new StringBuffer(text);

    // Go for all patterns.
    for (Pattern p : patterns) {
        Matcher matcher = p.matcher(s);

        // As long as the matcher finds another occurance of the pattern we
        // replace it by the same number of spaces but keep new lines.
        while (matcher.find())
            s.replace(matcher.start(), matcher.end(), matcher.group().replaceAll(".", " "));
    }
    return s.toString();
}

From source file:Main.java

/**
 * Converts the string flags to their pattern constants
 * @param flags//from  w w w .  j a v  a 2s.co  m
 * @return
 */
public static int convertFlagsToConstants(ArrayList<String> flags) {
    int ret = 0;
    for (String s : flags) {
        if (s.equals("i")) {
            ret |= Pattern.CASE_INSENSITIVE;
        } else if (s.equals("m")) {
            ret |= Pattern.MULTILINE;
        } else {
            ret |= Pattern.DOTALL;
        }
    }
    return ret;
}

From source file:mobi.jenkinsci.server.core.net.ProxyUtil.java

private String resolveImages(final String userAgent, final String pluginName, final String url,
        String resultString) {//from  w  w  w .  j a  v a 2 s.c o  m
    resultString = resolveImages(userAgent, pluginName,
            Pattern.compile("<(img|image)[^>]*src=[\"']([^\"']+\\.[a-zA-Z]+)[\"'][^>]*/>", Pattern.DOTALL), 2,
            url, resultString);
    resultString = resolveImages(userAgent, pluginName,
            Pattern.compile(CSS_BACKGROUND_IMAGE_PATTERN, Pattern.DOTALL), 2, url, resultString);
    return resultString;
}

From source file:org.limy.eclipse.qalab.mark.CheckCreator.java

private InputStream supportEncoding(LimyQalabEnvironment env, File configFile) throws IOException {
    String lines = FileUtils.readFileToString(configFile, "UTF-8");

    Matcher matcherTree = Pattern
            .compile(".*<module name=\"TreeWalker\">(.*)", Pattern.MULTILINE | Pattern.DOTALL).matcher(lines);
    if (matcherTree.matches()) {
        int pos = matcherTree.start(1);
        StringBuilder buff = new StringBuilder(lines);
        try {/*from ww w  .j a v a2  s  . c  om*/
            buff.insert(pos,
                    "<property name=\"charset\" value=\"" + env.getProject().getDefaultCharset() + "\"/>");
            lines = buff.toString();
        } catch (CoreException e) {
            LimyEclipsePluginUtils.log(e);
        }
    }

    return new StringInputStream(lines);
}

From source file:com.md87.charliebravo.commands.IssueCommand.java

protected void executeOldIssue(InputHandler handler, Response response, String line) throws Exception {
    final List<String> result = Downloader.getPage("http://bugs.dmdirc.com/view.php?id=" + line);
    final StringBuilder builder = new StringBuilder();

    for (String resline : result) {
        builder.append(resline);//from  www .  j a  v  a 2  s .  c om
    }

    if (builder.indexOf("APPLICATION ERROR #1100") > -1) {
        response.sendMessage("That issue was not found", true);
    } else if (builder.indexOf("<p>Access Denied.</p>") > -1) {
        response.sendMessage("that issue is private. Please see " + "http://bugs.dmdirc.com/view/" + line);
    } else {
        final Map<String, String> data = new HashMap<String, String>();

        final Pattern pattern = Pattern.compile(
                "<td class=\"category\".*?>\\s*(.*?)\\s*"
                        + "</td>\\s*(?:<!--.*?-->\\s*)?<td.*?>\\s*(.*?)\\s*</td>",
                Pattern.CASE_INSENSITIVE + Pattern.DOTALL);
        final Matcher matcher = pattern.matcher(builder);

        while (matcher.find()) {
            data.put(matcher.group(1).toLowerCase(), matcher.group(2));
        }

        response.sendMessage("issue " + data.get("id") + " is \"" + data.get("summary").substring(9)
                + "\". Current " + "status is " + data.get("status") + " (" + data.get("resolution")
                + "). See http://bugs.dmdirc.com/view/" + data.get("id"));
        response.addFollowup(new IssueFollowup(data));
    }
}

From source file:com.icesoft.faces.webapp.parser.JspPageToDocument.java

/**
 * @param input//from ww w .j  a v a2s .  c o m
 * @return String
 */
public static String transform(String input) {
    String result = input;

    Pattern jspDeclarationPattern = Pattern.compile(JSP_DECL_PATTERN, Pattern.DOTALL);
    Matcher jspDeclarationMatcher = jspDeclarationPattern.matcher(result);
    if (!jspDeclarationMatcher.find()) {
        //no JSP declarations, must be a JSP Document, not a page
        return (preprocessJspDocument(result));
    }

    result = performStaticInclude(STATIC_INCLUDE_PATTERN, input);

    result = toLowerHTML(result);

    Pattern jspTaglibPattern = Pattern.compile(JSP_TAGLIB_PATTERN, Pattern.DOTALL);
    Pattern openTagPattern = Pattern.compile(OPEN_TAG_PATTERN, Pattern.DOTALL);
    Pattern attributePattern = Pattern.compile(ATTRIBUTE_PATTERN, Pattern.DOTALL);
    Pattern prefixPattern = Pattern.compile(PREFIX_PATTERN, Pattern.DOTALL);
    Pattern uriPattern = Pattern.compile(URI_PATTERN, Pattern.DOTALL);

    Hashtable declarationsTable = new Hashtable();
    Matcher jspTaglibMatcher = jspTaglibPattern.matcher(result);
    declarationsTable.put("xmlns:jsp", "jsp");
    declarationsTable.put("xmlns:icefaces", "http://www.icesoft.com/icefaces");

    while (jspTaglibMatcher.find()) {
        String attributes = jspTaglibMatcher.group(1);
        Matcher prefixMatcher = prefixPattern.matcher(attributes);
        Matcher uriMatcher = uriPattern.matcher(attributes);
        prefixMatcher.find();
        uriMatcher.find();
        String prefix = prefixMatcher.group(1);
        String url = uriMatcher.group(1);
        declarationsTable.put("xmlns:" + prefix, url);
    }

    Matcher openTagMatcher = openTagPattern.matcher(result);
    openTagMatcher.find();
    String tag = openTagMatcher.group(1);
    String attributes = openTagMatcher.group(2);

    Matcher attributeMatcher = attributePattern.matcher(attributes);
    while (attributeMatcher.find()) {
        String name = attributeMatcher.group(1);
        String value = attributeMatcher.group(2);
        declarationsTable.put(name, value);
    }

    Enumeration declarations = declarationsTable.keys();
    String namespaceDeclarations = "";
    while (declarations.hasMoreElements()) {
        String prefix = (String) declarations.nextElement();
        String url = (String) declarationsTable.get(prefix);
        namespaceDeclarations += prefix + "=\"" + url + "\" ";
    }

    jspDeclarationMatcher = jspDeclarationPattern.matcher(result);
    result = jspDeclarationMatcher.replaceAll("");

    //ensure single root tag for all JSPs as per bug 361
    result = "<icefaces:root " + namespaceDeclarations + ">" + result + "</icefaces:root>";

    Pattern jspIncludePattern = Pattern.compile(JSP_INCLUDE_PATTERN);
    Matcher jspIncludeMatcher = jspIncludePattern.matcher(result);
    StringBuffer jspIncludeBuf = new StringBuffer();
    while (jspIncludeMatcher.find()) {
        String args = jspIncludeMatcher.group(1);
        jspIncludeMatcher.appendReplacement(jspIncludeBuf,
                "<icefaces:include" + args + " isDynamic=\"#{true}\" />");
    }
    jspIncludeMatcher.appendTail(jspIncludeBuf);
    result = jspIncludeBuf.toString();

    //Fix HTML
    result = toSingletonTag(P_TAG_PATTERN, result);
    result = toSingletonTag(LINK_TAG_PATTERN, result);
    result = toSingletonTag(META_TAG_PATTERN, result);
    result = toSingletonTag(IMG_TAG_PATTERN, result);
    result = toSingletonTag(INPUT_TAG_PATTERN, result);

    Pattern brTagPattern = Pattern.compile(BR_TAG_PATTERN);
    Matcher brTagMatcher = brTagPattern.matcher(result);
    result = brTagMatcher.replaceAll("<br/>");

    Pattern hrTagPattern = Pattern.compile(HR_TAG_PATTERN);
    Matcher hrTagMatcher = hrTagPattern.matcher(result);
    result = hrTagMatcher.replaceAll("<hr/>");

    Pattern nbspEntityPattern = Pattern.compile(NBSP_ENTITY_PATTERN);
    Matcher nbspEntityMatcher = nbspEntityPattern.matcher(result);
    //  result = nbspEntityMatcher.replaceAll("&nbsp;");
    result = nbspEntityMatcher.replaceAll("&amp;nbsp");

    Pattern copyEntityPattern = Pattern.compile(COPY_ENTITY_PATTERN);
    Matcher copyEntityMatcher = copyEntityPattern.matcher(result);
    result = copyEntityMatcher.replaceAll("&#169;");

    Pattern docDeclPattern = Pattern.compile(DOC_DECL_PATTERN);
    Matcher docDeclMatcher = docDeclPattern.matcher(result);
    result = docDeclMatcher.replaceAll("");

    result = unescapeBackslash(result);

    return result;
}