KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > core > internal > registry > RegistrySupport


1 /*******************************************************************************
2  * Copyright (c) 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.core.internal.registry;
12
13 import java.util.ResourceBundle JavaDoc;
14 import org.eclipse.core.runtime.IStatus;
15
16 /**
17  * Simple implementation if the registry support functionality.
18  * The logging output is done onto System.out (for both specific and generic logs)
19  * in the following format:
20  *
21  * [Error|Warning|Log]: Main error message
22  * [Error|Warning|Log]: Child error message 1
23  * ...
24  * [Error|Warning|Log]: Child error message N
25  *
26  * The translation routine assumes that keys are prefixed with '%'. If no resource
27  * bundle is present, the key itself (without leading '%') is returned. There is
28  * no decoding for the leading '%%'.
29  */

30 public class RegistrySupport {
31
32     static public String JavaDoc translate(String JavaDoc key, ResourceBundle JavaDoc resources) {
33         if (key == null)
34             return null;
35         if (resources == null)
36             return key;
37         String JavaDoc trimmedKey = key.trim();
38         if (trimmedKey.length() == 0)
39             return key;
40         if (trimmedKey.charAt(0) != '%')
41             return key;
42         return resources.getString(trimmedKey.substring(1));
43     }
44
45     static public void log(IStatus status, String JavaDoc prefix) {
46         String JavaDoc message = status.getMessage();
47         int severity = status.getSeverity();
48
49         String JavaDoc statusMsg;
50         switch (severity) {
51             case IStatus.ERROR :
52                 statusMsg = RegistryMessages.log_error;
53                 break;
54             case IStatus.WARNING :
55                 statusMsg = RegistryMessages.log_warning;
56                 break;
57             default :
58                 statusMsg = RegistryMessages.log_log;
59                 break;
60         }
61         statusMsg += message;
62
63         if (prefix != null)
64             statusMsg = prefix + statusMsg;
65         System.out.println(statusMsg);
66
67         // print out children as well
68
IStatus[] children = status.getChildren();
69         if (children.length != 0) {
70             String JavaDoc newPrefix;
71             if (prefix == null)
72                 newPrefix = "\t"; //$NON-NLS-1$
73
else
74                 newPrefix = prefix + "\t"; //$NON-NLS-1$
75
for (int i = 0; i < children.length; i++) {
76                 log(children[i], newPrefix);
77             }
78         }
79     }
80 }
81
Popular Tags