public void doTag()

in jelly-tags/util/src/main/java/org/apache/commons/jelly/tags/util/LoadTextTag.java [55:103]


    public void doTag(XMLOutput output) throws MissingAttributeException, JellyTagException {
        if (var == null) {
            throw new MissingAttributeException("var");
        }
        if (file == null && uri == null) {
            throw new JellyTagException( "This tag must have a 'file' or 'uri' specified" );
        }
        
        InputStream in = null;
        if (file != null) {
            if (! file.exists()) {
                throw new JellyTagException( "The file: " + file + " does not exist" );
            }

            try {
                in = new FileInputStream(file);
            } catch (FileNotFoundException e) {
                throw new JellyTagException("could not find the file",e);
            }
        }
        else {
            in = context.getResourceAsStream(uri);
            if (in == null) {
                throw new JellyTagException( "Could not find uri: " + uri );
            }
        }

        Reader reader = null;
        if (encoding != null) {
            try {
                reader = new InputStreamReader(in, encoding);
            } catch (UnsupportedEncodingException e) {
                throw new JellyTagException("unsupported encoding",e);
            }
        } else {
            reader = new InputStreamReader(in);
        }

        String text = null;

        try {
            text = loadText(reader);
        }
        catch (IOException e) {
            throw new JellyTagException(e);
        }

        context.setVariable(var, text);
    }