Преглед на файлове

Bugzilla #53065: Restore lookup on Event message lookup field part. Add locale field to Event to enable locale dependent deferred bundle load during lookup field part substitution.

git-svn-id: https://svn.apache.org/repos/asf/xmlgraphics/fop/trunk@1324913 13f79535-47bb-0310-9956-ffa450edef68
tags/fop-1_1rc1old
Glenn Adams преди 12 години
родител
ревизия
9ed2391ac8
променени са 4 файла, в които са добавени 77 реда и са изтрити 51 реда
  1. 27
    4
      src/java/org/apache/fop/events/Event.java
  2. 45
    46
      src/java/org/apache/fop/events/EventFormatter.java
  3. 1
    1
      src/java/org/apache/fop/util/XMLResourceBundle.java
  4. 4
    0
      status.xml

+ 27
- 4
src/java/org/apache/fop/events/Event.java Целия файл

@@ -21,33 +21,47 @@ package org.apache.fop.events;

import java.util.Collections;
import java.util.EventObject;
import java.util.Locale;
import java.util.Map;

import org.apache.fop.events.model.EventSeverity;

/**
* This is the default event class used by this package. Each event has a unique event identifier
* (a String), a severity indicator and a map of name/value pairs.
* (a String), a severity indicator, a locale (for formatting event messages), and a map of
* name/value pairs.
*/
public class Event extends EventObject {

private static final long serialVersionUID = -1310594422868258083L;

private String eventGroupID;

private String eventKey;

private EventSeverity severity;
private Locale locale;
private Map<String, Object> params;

/**
* Creates a new Event.
* Creates a new Event using default locale.
* @param source the object that creates the event
* @param eventID the unique identifier of the event
* @param severity the severity level
* @param params the event parameters (a map of name/value pairs)
*/
public Event(Object source, String eventID, EventSeverity severity, Map<String, Object> params)
{
this ( source, eventID, severity, Locale.getDefault(), params );
}

/**
* Creates a new Event.
* @param source the object that creates the event
* @param eventID the unique identifier of the event
* @param severity the severity level
* @param locale to use when formatting event (or null, which means use default locale)
* @param params the event parameters (a map of name/value pairs)
*/
public Event(Object source, String eventID, EventSeverity severity, Locale locale, Map<String, Object> params)
{
super(source);
int pos = eventID.lastIndexOf('.');
@@ -58,6 +72,7 @@ public class Event extends EventObject {
eventKey = eventID.substring(pos + 1);
}
setSeverity(severity);
this.locale = locale;
this.params = params;
}

@@ -106,6 +121,14 @@ public class Event extends EventObject {
this.severity = severity;
}

/**
* Returns the locale.
* @return the locale
*/
public Locale getLocale() {
return this.locale;
}

/**
* Returns a parameter.
* @param key the key to the parameter

+ 45
- 46
src/java/org/apache/fop/events/EventFormatter.java Целия файл

@@ -47,25 +47,28 @@ public final class EventFormatter {
//utility class
}

private static ResourceBundle getBundle ( String groupID, Locale locale ) {
ResourceBundle bundle;
String baseName = ( groupID != null ) ? groupID : EventFormatter.class.getName();
try {
ClassLoader classLoader = EventFormatter.class.getClassLoader();
bundle = XMLResourceBundle.getXMLBundle ( baseName, locale, classLoader );
} catch ( MissingResourceException e ) {
if ( log.isTraceEnabled() ) {
log.trace ( "No XMLResourceBundle for " + baseName + " available." );
}
bundle = null;
}
return bundle;
}

/**
* Formats an event using the default locale.
* @param event the event
* @return the formatted message
*/
public static String format(Event event) {
ResourceBundle bundle = null;
String groupID = event.getEventGroupID();
if (groupID != null) {
try {
bundle = XMLResourceBundle.getXMLBundle(
groupID,
EventFormatter.class.getClassLoader());
} catch (MissingResourceException mre) {
throw new IllegalStateException("No XMLResourceBundle for " + groupID
+ " available.");
}
}
return format(event, bundle);
public static String format ( Event event ) {
return format ( event, event.getLocale() );
}

/**
@@ -75,31 +78,19 @@ public final class EventFormatter {
* @return the formatted message
*/
public static String format(Event event, Locale locale) {
ResourceBundle bundle = null;
String groupID = event.getEventGroupID();
if (groupID != null) {
try {
bundle = XMLResourceBundle.getXMLBundle(
groupID, locale,
EventFormatter.class.getClassLoader());
} catch (MissingResourceException mre) {
if (log.isTraceEnabled()) {
log.trace("No XMLResourceBundle for " + groupID + " available.");
}
}
}
if (bundle == null) {
bundle = XMLResourceBundle.getXMLBundle(
EventFormatter.class.getName(),
locale,
EventFormatter.class.getClassLoader());
}
return format(event, bundle);
return format ( event, getBundle ( event.getEventGroupID(), locale ) );
}

private static String format(Event event, ResourceBundle bundle) {
String template = bundle.getString(event.getEventKey());
return format(event, processIncludes(template, bundle));
private static String format ( Event event, ResourceBundle bundle ) {
assert event != null;
String key = event.getEventKey();
String template;
if ( bundle != null ) {
template = bundle.getString ( key );
} else {
template = "Missing bundle. Can't lookup event key: '" + key + "'.";
}
return format ( event, processIncludes ( template, bundle ) );
}

private static String processIncludes(String template, ResourceBundle bundle) {
@@ -118,14 +109,16 @@ public final class EventFormatter {
private static int processIncludesInner(CharSequence template, StringBuffer sb,
ResourceBundle bundle) {
int replacements = 0;
Matcher m = INCLUDES_PATTERN.matcher(template);
while (m.find()) {
String include = m.group();
include = include.substring(2, include.length() - 2);
m.appendReplacement(sb, bundle.getString(include));
replacements++;
if ( bundle != null ) {
Matcher m = INCLUDES_PATTERN.matcher(template);
while (m.find()) {
String include = m.group();
include = include.substring(2, include.length() - 2);
m.appendReplacement(sb, bundle.getString(include));
replacements++;
}
m.appendTail(sb);
}
m.appendTail(sb);
return replacements;
}

@@ -141,6 +134,8 @@ public final class EventFormatter {
Map params = new java.util.HashMap(event.getParams());
params.put("source", event.getSource());
params.put("severity", event.getSeverity());
params.put("groupID", event.getEventGroupID());
params.put("locale", event.getLocale());
return format.format(params);
}

@@ -157,8 +152,12 @@ public final class EventFormatter {
}

public void write(StringBuffer sb, Map params) {
// TODO there's no defaultBundle anymore
// sb.append(defaultBundle.getString(getKey(params)));
String groupID = (String) params.get("groupID");
Locale locale = (Locale) params.get("locale");
ResourceBundle bundle = getBundle ( groupID, locale );
if ( bundle != null ) {
sb.append(bundle.getString(getKey(params)));
}
}

private String getKey(Map params) {

+ 1
- 1
src/java/org/apache/fop/util/XMLResourceBundle.java Целия файл

@@ -117,7 +117,7 @@ public class XMLResourceBundle extends ResourceBundle {
if (baseName == null) {
throw new NullPointerException("baseName must not be null");
}
assert locale != null;
ResourceBundle bundle;
if (!locale.equals(Locale.getDefault())) {
bundle = handleGetXMLBundle(baseName, "_" + locale, false, loader);

+ 4
- 0
status.xml Целия файл

@@ -62,6 +62,10 @@
documents. Example: the fix of marks layering will be such a case when it's done.
-->
<release version="FOP Trunk" date="TBD">
<action context="Code" dev="GA" type="fix" fixes-bug="53065">
Restore lookup on Event message lookup field part. Add locale field to Event to
enable locale dependent deferred bundle load during lookup field part substitution.
</action>
<action context="Code" dev="MH" type="fix">
Bug in AFP font metrics that performed integer arithmetic when it should have been
double arithemetic.

Loading…
Отказ
Запис