public void doTag()

in jelly-tags/junit/src/main/java/org/apache/commons/jelly/tags/junit/AssertFileContainsTag.java [47:102]


    public void doTag(XMLOutput output) throws JellyTagException
    {
        if (match == null)
        {
            throw new MissingAttributeException("match");
        }
        String message = getBodyText();
        if (message == null || message.length() == 0)
        {
            message = "File does not contain '" + match + "'";
        }

        
        if (file == null)
        {
            throw new MissingAttributeException("file");
        }
        else
        {
            if (file.exists() && file.canRead())
            {
                try
                {
                    BufferedReader br = new BufferedReader(new FileReader(file));
                    String line;
                    boolean found = false;
                    while ((line = br.readLine()) != null)
                    {
                        if (line.indexOf(match) != -1)
                        {
                            found = true;
                            break;
                        }
                    }
                    br.close();
                    assertTrue(message, found);
                }
                catch (IOException fnfe)
                {
                    throw new JellyTagException(fnfe);
                }
            }
            else
            {
                try
                {
                    throw new JellyTagException("File '" + file.getCanonicalPath() 
                        + "' can't be read.");
                }
                catch (IOException e)
                {
                    throw new JellyTagException(e);
                }
            }
        }
    }