/*
 * Licensed to the Apache Software Foundation (ASF) under one or more
 * contributor license agreements. See the NOTICE file distributed with
 * this work for additional information regarding copyright ownership.
 * The ASF licenses this file to You under the Apache license, Version 2.0
 * (the "License"); you may not use this file except in compliance with
 * the License. You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the license for the specific language governing permissions and
 * limitations under the license.
 */
package org.apache.logging.log4j.core.lookup;

import java.util.Locale;

import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.config.plugins.Plugin;
import org.apache.logging.log4j.util.Strings;

/**
 * Looks up keys related to Java: Java version, JRE version, VM version, and so on.
 */
@Plugin(name = "java", category = StrLookup.CATEGORY)
public class JavaLookup extends AbstractLookup {

    private final SystemPropertiesLookup spLookup = new SystemPropertiesLookup();

    /**
     * Accessible through the Lookup key {@code hw}.
     * @return hardware processor information.
     */
    public String getHardware() {
        return "processors: " + Runtime.getRuntime().availableProcessors() + ", architecture: "
                + getSystemProperty("os.arch") + this.getSystemProperty("-", "sun.arch.data.model")
                + this.getSystemProperty(", instruction sets: ", "sun.cpu.isalist");
    }

    /**
     * Accessible through the Lookup key {@code locale}.
     * @return system locale and file encoding information.
     */
    public String getLocale() {
        return "default locale: " + Locale.getDefault() + ", platform encoding: " + getSystemProperty("file.encoding");
    }

    /**
     * Accessible through the Lookup key {@code os}.
     * @return operating system information.
     */
    public String getOperatingSystem() {
        return getSystemProperty("os.name") + " " + getSystemProperty("os.version")
                + getSystemProperty(" ", "sun.os.patch.level") + ", architecture: " + getSystemProperty("os.arch")
                + getSystemProperty("-", "sun.arch.data.model");
    }

    /**
     * Accessible through the Lookup key {@code runtime}.
     * @return Java Runtime Environment information.
     */
    public String getRuntime() {
        return getSystemProperty("java.runtime.name") + " (build " + getSystemProperty("java.runtime.version")
                + ") from " + getSystemProperty("java.vendor");
    }

    private String getSystemProperty(final String name) {
        return spLookup.lookup(name);
    }

    private String getSystemProperty(final String prefix, final String name) {
        final String value = getSystemProperty(name);
        if (Strings.isEmpty(value)) {
            return Strings.EMPTY;
        }
        return prefix + value;
    }

    /**
     * Accessible through the Lookup key {@code vm}.
     * @return Java Virtual Machine information.
     */
    public String getVirtualMachine() {
        return getSystemProperty("java.vm.name") + " (build " + getSystemProperty("java.vm.version") + ", "
                + getSystemProperty("java.vm.info") + ")";
    }

    /**
     * Looks up the value of the environment variable.
     *
     * @param event
     *        The current LogEvent (is ignored by this StrLookup).
     * @param key
     *        the key to be looked up, may be null
     * @return The value of the environment variable.
     */
    @Override
    public String lookup(final LogEvent event, final String key) {
        // TODO Use a Java 7 switch
        if ("version".equals(key)) {
            return "Java version " + getSystemProperty("java.version");
        } else if ("runtime".equals(key)) {
            return getRuntime();
        } else if ("vm".equals(key)) {
            return getVirtualMachine();
        } else if ("os".equals(key)) {
            return getOperatingSystem();
        } else if ("hw".equals(key)) {
            return getHardware();
        } else if ("locale".equals(key)) {
            return getLocale();
        }
        throw new IllegalArgumentException(key);
    }
}

@@ -3867,35 +3867,22 @@
     
-// TODO Use a Java 7 switch
+switch (key) %7B
 %0A   
@@ -3886,20 +3886,21 @@
         
-if (
+case 
 %22version
@@ -3900,31 +3900,17 @@
 version%22
-.equals(key)) %7B
+:
 %0A       
@@ -3986,43 +3986,23 @@
     
-%7D else if (%22runtime%22.equals(key)) %7B
+case %22runtime%22:
 %0A   
@@ -4043,38 +4043,18 @@
     
-%7D else if (%22vm%22.equals(key)) %7B
+case %22vm%22:
 %0A   
@@ -4102,38 +4102,18 @@
     
-%7D else if (%22os%22.equals(key)) %7B
+case %22os%22:
 %0A   
@@ -4162,38 +4162,18 @@
     
-%7D else if (%22hw%22.equals(key)) %7B
+case %22hw%22:
 %0A   
@@ -4215,42 +4215,22 @@
     
-%7D else if (%22locale%22.equals(key)) %7B
+case %22locale%22:
 %0A   
@@ -4258,34 +4258,45 @@
 cale();%0A        
-%7D%0A
+default:%0A    
         throw ne
@@ -4328,16 +4328,26 @@
 n(key);%0A
+        %7D%0A
     %7D%0A%7D%0A

Update Java platform from Java 6 to 7. Reuse stock Java 7 method. Use Java 7 String switch.