
org.glassfish.admingui.common.handlers.LogViewHandlers Maven / Gradle / Ivy
/*
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
*
* Copyright (c) 1997-2011 Oracle and/or its affiliates. All rights reserved.
*
* The contents of this file are subject to the terms of either the GNU
* General Public License Version 2 only ("GPL") or the Common Development
* and Distribution License("CDDL") (collectively, the "License"). You
* may not use this file except in compliance with the License. You can
* obtain a copy of the License at
* https://glassfish.dev.java.net/public/CDDL+GPL_1_1.html
* or packager/legal/LICENSE.txt. See the License for the specific
* language governing permissions and limitations under the License.
*
* When distributing the software, include this License Header Notice in each
* file and include the License file at packager/legal/LICENSE.txt.
*
* GPL Classpath Exception:
* Oracle designates this particular file as subject to the "Classpath"
* exception as provided by Oracle in the GPL Version 2 section of the License
* file that accompanied this code.
*
* Modifications:
* If applicable, add the following below the License Header, with the fields
* enclosed by brackets [] replaced by your own identifying information:
* "Portions Copyright [year] [name of copyright owner]"
*
* Contributor(s):
* If you wish your version of this file to be governed by only the CDDL or
* only the GPL Version 2, indicate your decision by adding "[Contributor]
* elects to include this software in this distribution under the [CDDL or GPL
* Version 2] license." If you don't indicate a single choice of license, a
* recipient has the option to distribute your version of this file under
* either the CDDL, the GPL Version 2 or to extend the choice of license to
* its licensees as provided above. However, if you add GPL Version 2 code
* and therefore, elected the GPL Version 2 license, then the option applies
* only if the new code is made subject to such option by the copyright
* holder.
*/
/*
* CommonHandlers.java
*
* Created on August 30, 2006, 4:21 PM
*
* To change this template, choose Tools | Template Manager
* and open the template in the editor.
*/
package org.glassfish.admingui.common.handlers;
import com.sun.jsftemplating.annotation.Handler;
import com.sun.jsftemplating.annotation.HandlerInput;
import com.sun.jsftemplating.annotation.HandlerOutput;
import com.sun.jsftemplating.layout.descriptors.handler.HandlerContext;
import com.sun.jsftemplating.util.Util;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.text.ParseException;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.logging.Level;
import org.glassfish.admingui.common.util.GuiUtil;
public class LogViewHandlers {
/** Creates a new instance of LogViewHandlers */
public LogViewHandlers() {
}
/**
* This handler creates a Map<String, String> which contains
* the QUERY_STRING parameters that should be passed to the REST
* logging endpoint to make a query with the given constraints.
*
* @param context The HandlerContext.
*/
@Handler(id="gf.getLogQueryAttributes",
input={
@HandlerInput(name="InstanceName", type=String.class, required=true),
@HandlerInput(name="LogFileName", type=String.class, required=true),
@HandlerInput(name="LogLevel", type=String.class, required=true),
@HandlerInput(name="FromRecord", type=Integer.class),
@HandlerInput(name="AfterRecord", type=Boolean.class),
@HandlerInput(name="DateEnabled", type=String.class),
@HandlerInput(name="FromDate", type=Object.class),
@HandlerInput(name="FromTime", type=Object.class),
@HandlerInput(name="ToDate", type=Object.class),
@HandlerInput(name="ToTime", type=Object.class),
@HandlerInput(name="Loggers", type=Object.class),
@HandlerInput(name="CustomLoggers", type=Object.class),
@HandlerInput(name="anySearch", type = String.class),
@HandlerInput(name="NumToDisplay", type=Integer.class),
@HandlerInput(name="OnlyLevel", type=Boolean.class, defaultValue="false"),
@HandlerInput(name="LogDateSortDirection", type=Boolean.class)},
output={
@HandlerOutput(name="attributes", type=Map.class)})
public static void getLogQueryAttributes(HandlerContext handlerCtx) {
// Create a Map to hold the attributes
Map attMap = new HashMap();
// Attempt to read values passed in
String logFileName = (String) handlerCtx.getInputValue("LogFileName");
Integer fromRecord = (Integer) handlerCtx.getInputValue("FromRecord");
Boolean after = (Boolean) handlerCtx.getInputValue("AfterRecord");
String dateEnabledString = (String) handlerCtx.getInputValue("DateEnabled");
Object fromDate = handlerCtx.getInputValue("FromDate");
Object fromTime = handlerCtx.getInputValue("FromTime");
Object toDate = handlerCtx.getInputValue("ToDate");
Object toTime = handlerCtx.getInputValue("ToTime");
Object loggers = handlerCtx.getInputValue("Loggers");
String logLevel = (String) handlerCtx.getInputValue("LogLevel");
Object customLoggers = handlerCtx.getInputValue("CustomLoggers");
String anySearch = (String) handlerCtx.getInputValue("anySearch");
Integer numberToDisplay = (Integer) handlerCtx.getInputValue("NumToDisplay");
Boolean onlyLevel = (Boolean) handlerCtx.getInputValue("OnlyLevel");
Boolean direction = (Boolean) handlerCtx.getInputValue("LogDateSortDirection");
String instanceName = (String) handlerCtx.getInputValue("InstanceName");
notNullStringPut(attMap, "instanceName", instanceName);
Date from = null, to = null;
if ((instanceName != null)) {
notNullStringPut(attMap, "instanceName", instanceName);
if (logFileName != null) {
// Convert Date/Time fields
if ((dateEnabledString != null) &&
("enabled".equalsIgnoreCase(dateEnabledString)
|| "true".equalsIgnoreCase(dateEnabledString))) {
// Date is enabled, figure out what the values are
from = convertDateTime(handlerCtx, fromDate, fromTime);
to = convertDateTime(handlerCtx, toDate, toTime);
if ((from == null)) {
GuiUtil.handleError(handlerCtx, "Specific Date Range was chosen, however, date fields are incomplete.");
}
if (to != null && from != null) {
if (from.after(to)) {
GuiUtil.handleError(handlerCtx, "Timestamp value of 'From: ' field " + fromDate +
" must not be greater than 'To: ' field value " + toDate);
}
}
} else {
// Date not enabled, ignore from/to dates
from = null;
to = null;
}
if ((logLevel != null) && (logLevel.trim().length() == 0)) {
logLevel = null;
}
// Convert module array to List
//List moduleList = null;
//Set moduleList = new HashSet();
Set moduleList = null;
if (loggers != null) {
int len = ((Object[]) loggers).length;
if (len > 0) {
moduleList = new HashSet();
Object val;
for (int count = 0; count < len; count++) {
val = (((Object[]) loggers)[count]);
if ((val == null) || (val.toString().trim().length() == 0)) {
continue;
}
moduleList.add(val);
}
}
}
// Add custom loggers
if ((customLoggers != null) &&
(customLoggers.toString().trim().length() != 0)) {
StringTokenizer tok = new StringTokenizer(
customLoggers.toString(),
CUSTOM_LOGGER_DELIMITERS);
String token;
if (moduleList == null) {
moduleList = new HashSet();
}
while (tok.hasMoreTokens()) {
token = tok.nextToken();
if ((token == null) || (token.length() == 0)) {
continue;
}
moduleList.add(token);
}
}
// Get the number to Display
if (numberToDisplay == null) {
numberToDisplay = DEFAULT_NUMBER_TO_DISPLAY;
}
// Get the direction
if (direction == null) {
direction = Boolean.FALSE;
}
// Get AfterRecord flag
if (after == null) {
// Not supplied, use direction
after = direction;
}
notNullStringPut(attMap, "logFileName", logFileName);
notNullStringPut(attMap, "startIndex", fromRecord);
notNullStringPut(attMap, "searchForward", after);//direction
notNullStringPut(attMap, "maximumNumberOfResults", numberToDisplay);
notNullStringPut(attMap, "onlyLevel", onlyLevel);
if (from != null)
notNullStringPut(attMap,"fromTime", Long.valueOf(from.getTime()));
if (to != null)
notNullStringPut(attMap, "toTime", Long.valueOf(to.getTime()));
notNullStringPut(attMap, "anySearch", anySearch);
notNullStringPut(attMap, "logLevel", logLevel);
notNullStringPut(attMap, "instanceName", instanceName);
notNullStringPut(attMap, "logFileRefresh", "true");
if (moduleList != null) {
attMap.put("listOfModules", moduleList);
}
//notNullStringPut(attMap, "logFileRefresh", logFileName);
}
}
handlerCtx.setOutputValue("attributes", attMap);
}
/**
* This handler creates a Map<String, String> which contains
* the QUERY_STRING parameters that should be passed to the REST
* logging endpoint to make a query with the given constraints.
*
* @param context The HandlerContext.
*/
@Handler(id="gf.processLogRecords",
input={
@HandlerInput(name="logRecords", type=List.class, required=true),
@HandlerInput(name="truncate", type=Boolean.class, defaultValue="true"),
@HandlerInput(name="truncateLength", type=Integer.class, defaultValue="100")},
output={
@HandlerOutput(name="result", type=List.class),
@HandlerOutput(name="firstRecord", type=Integer.class),
@HandlerOutput(name="lastRecord", type=Integer.class)})
public static void processLogRecords(HandlerContext handlerCtx) {
// Get the input...
List
© 2015 - 2025 Weber Informatics LLC | Privacy Policy