All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.rhq.enterprise.server.plugins.alertOperations.PrintTokens Maven / Gradle / Ivy

The newest version!
/*
 * RHQ Management Platform
 * Copyright (C) 2005-2010 Red Hat, Inc.
 * All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation version 2 of the License.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */
package org.rhq.enterprise.server.plugins.alertOperations;

import java.io.BufferedOutputStream;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.OutputStream;
import java.util.EnumSet;
import java.util.Set;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

/**
 * Print the available tokens to stdout, for documentation generation purposes
 * @author Heiko W. Rupp
 */
public class PrintTokens {

    private final Log log = LogFactory.getLog(PrintTokens.class);
    private static final String CLOSE = "\">\n";

    public static void main(String[] args) throws Exception {

        OutputStream out;
        if (args.length==0)
            out = new BufferedOutputStream(System.out);
        else {
            File file = new File(args[0]);
            System.err.println("writing to " + file.getAbsolutePath());
            out = new BufferedOutputStream(new FileOutputStream(file));
        }

        try {
            String text = createTokenDescription();
            out.write(text.getBytes());
        } finally {
            out.close();
        }
    }

    /**
     * Do the work and return an xml structure that lists available token classes and
     * tokens along with their descriptions.
     * @return String with an XML representation of the available tokens
     */
    public static String createTokenDescription() {
        EnumSet tokenClasses = EnumSet.allOf(TokenClass.class);

        StringBuilder builder = new StringBuilder("\n");

        for (TokenClass tc : tokenClasses ) {
            builder.append("   tokens = Token.getByTokenClass(tc);
            for (Token token : tokens) {
                builder.append("    ").append(token.getText()).append("\n");
                builder.append("      ").append(token.getDescription()).append("\n");
                builder.append("    \n");

            }

            builder.append("  \n");

        }

        builder.append("\n");
        return builder.toString();
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy