public void doTag()

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


    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");
        }
        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.contains(match))
                    {
                        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);
            }
        }
    }