/* * CDDL HEADER START * * The contents of this file are subject to the terms of the * Common Development and Distribution License, Version 1.0 only * (the "License"). You may not use this file except in compliance * with the License. * * You can obtain a copy of the license at * trunk/opends/resource/legal-notices/OpenDS.LICENSE * or https://OpenDS.dev.java.net/OpenDS.LICENSE. * See the License for the specific language governing permissions * and limitations under the License. * * When distributing Covered Code, include this CDDL HEADER in each * file and include the License file at * trunk/opends/resource/legal-notices/OpenDS.LICENSE. If applicable, * add the following below this CDDL HEADER, with the fields enclosed * by brackets "[]" replaced with your own identifying information: * Portions Copyright [yyyy] [name of copyright owner] * * CDDL HEADER END * * * Copyright 2008 Sun Microsystems, Inc. */ package com.sun.opends.sdk.build.tools; import static com.sun.opends.sdk.build.tools.Utilities.*; import java.io.*; import java.util.*; import java.util.regex.Matcher; import java.util.regex.Pattern; import org.apache.tools.ant.BuildException; import org.apache.tools.ant.Location; import org.apache.tools.ant.Project; import org.apache.tools.ant.Task; /** * Generates a Java class containing representations of messages found * in a properties file. */ public class GenerateMessageFile extends Task { /** * The maximum number of arguments that can be handled by a specific * subclass. If you define more subclasses be sure to increment this * number appropriately. */ static public final int DESCRIPTOR_MAX_ARG_HANDLER = 11; /** * The base name of the specific argument handling subclasses defined * below. The class names consist of the base name followed by a * number indicating the number of arguments that they handle when * creating messages or the letter "N" meaning any number of * arguments. */ public static final String DESCRIPTOR_CLASS_BASE_NAME = "Arg"; private File source; private File dest; private boolean overwrite; static private final String MESSAGES_FILE_STUB = "resource/Messages.java.stub"; /** * When true generates messages that have no ordinals. */ static private final String GLOBAL_ORDINAL = "global.ordinal"; static private final Set DIRECTIVE_PROPERTIES = new HashSet(); static { DIRECTIVE_PROPERTIES.add(GLOBAL_ORDINAL); } static private final String SPECIFIER_REGEX = "%(\\d+\\$)?([-#+ 0,(\\<]*)?(\\d+)?(\\.\\d+)?([tT])?([a-zA-Z%])"; private final Pattern SPECIFIER_PATTERN = Pattern .compile(SPECIFIER_REGEX); /** * LocalizableMessage giving formatting rules for string keys. */ static public String KEY_FORM_MSG; static { KEY_FORM_MSG = new StringBuilder().append( ".\n\nOpenDS message property keys must be of the form\n\n") .append("\t\'[DESCRIPTION]_[ORDINAL]\'\n\n") .append("where\n\n").append( "\n\nDESCRIPTION is a descriptive string composed ") .append("of uppercase character, digits and underscores ") .append("describing the purpose of the message ").append( "\n\nORDINAL is an integer between 0 and 65535 that is ") .append("unique to other messages defined in this file.\n\n") .toString(); } /* * ISO_LANGUAGES contains all official supported languages for i18n */ private static final List ISO_LANGUAGES = Arrays .asList(Locale.getISOLanguages()); /* * ISO_COUNTRIES contains all official supported countries for i18n */ private static final List ISO_COUNTRIES = Arrays .asList(Locale.getISOCountries()); /* * A Pattern instance that matches * "