Search in sources :

Example 1 with ModelFactory

use of pcgen.output.base.ModelFactory in project pcgen by PCGen.

the class OutputDB method getIterable.

/**
	 * Returns a specific portion of the PlayerCharacter data model for the
	 * given CharID and selection string.
	 * 
	 * @param id
	 *            The CharID for which the data model should be built
	 * @param keys
	 *            A String (or array) of keys identifying the portion of the
	 *            data model to be built
	 * @return An Iterable for the portion of the data model identified by the
	 *         given Strings and the PlayerCharacter identified by the given
	 *         CharID
	 */
public static Iterable<?> getIterable(CharID id, String... keys) {
    String k1 = keys[0];
    String k2 = (keys.length > 1) ? keys[1] : "";
    ModelFactory modelFactory = outModels.get(k1, k2);
    if (modelFactory == null) {
        return null;
    }
    return modelFactory.generate(id);
}
Also used : ModelFactory(pcgen.output.base.ModelFactory) ModeModelFactory(pcgen.output.base.ModeModelFactory) ItemModelFactory(pcgen.output.factory.ItemModelFactory) SetModelFactory(pcgen.output.factory.SetModelFactory)

Example 2 with ModelFactory

use of pcgen.output.base.ModelFactory in project pcgen by PCGen.

the class OutputDB method registerModelFactory.

/**
	 * Registers a new ModelFactory to be used in output
	 * 
	 * @param name
	 *            The interpolation for the ModelFactory
	 * @param modelFactory
	 *            The ModelFactory to be used to generate the Models when the
	 *            output Map is built
	 */
public static void registerModelFactory(String name, ModelFactory modelFactory) {
    if (modelFactory == null) {
        throw new IllegalArgumentException("Model Factory may not be null");
    }
    String[] locationElements = name.split("\\.");
    if (locationElements.length == 0) {
        throw new IllegalArgumentException("Name may not be null or empty: " + name);
    }
    if (locationElements.length > 2) {
        throw new IllegalArgumentException("Name may only contain zero or one period");
    }
    String secondName = (locationElements.length == 1) ? "" : locationElements[1];
    ModelFactory old = outModels.put(locationElements[0], secondName, modelFactory);
    if (old != null) {
        throw new UnsupportedOperationException("Cannot have two Output Models using the same name: " + name);
    }
}
Also used : ModelFactory(pcgen.output.base.ModelFactory) ModeModelFactory(pcgen.output.base.ModeModelFactory) ItemModelFactory(pcgen.output.factory.ItemModelFactory) SetModelFactory(pcgen.output.factory.SetModelFactory)

Example 3 with ModelFactory

use of pcgen.output.base.ModelFactory in project pcgen by PCGen.

the class OutputDB method buildDataModel.

/**
	 * Builds the PlayerCharacter data model for the given CharID.
	 * 
	 * @param id
	 *            The CharID for which the data model should be built
	 * @return A Map of the data model for the PlayerCharacter identified by the
	 *         given CharID
	 */
public static Map<String, Object> buildDataModel(CharID id) {
    Map<String, Object> input = new HashMap<>();
    for (Object k1 : outModels.getKeySet()) {
        for (Object k2 : outModels.getSecondaryKeySet(k1)) {
            ModelFactory modelFactory = outModels.get(k1, k2);
            TemplateModel model = modelFactory.generate(id);
            String k1String = k1.toString();
            if ("".equals(k2.toString())) {
                input.put(k1String, model);
            } else {
                ensureMap(input, k1String);
                @SuppressWarnings("unchecked") Map<Object, Object> m = (Map<Object, Object>) input.get(k1String);
                m.put(k2.toString(), model);
            }
        }
    }
    return input;
}
Also used : HashMap(java.util.HashMap) ModelFactory(pcgen.output.base.ModelFactory) ModeModelFactory(pcgen.output.base.ModeModelFactory) ItemModelFactory(pcgen.output.factory.ItemModelFactory) SetModelFactory(pcgen.output.factory.SetModelFactory) TemplateModel(freemarker.template.TemplateModel) HashMap(java.util.HashMap) Map(java.util.Map) CaseInsensitiveMap(pcgen.base.util.CaseInsensitiveMap) DoubleKeyMap(pcgen.base.util.DoubleKeyMap)

Aggregations

ModeModelFactory (pcgen.output.base.ModeModelFactory)3 ModelFactory (pcgen.output.base.ModelFactory)3 ItemModelFactory (pcgen.output.factory.ItemModelFactory)3 SetModelFactory (pcgen.output.factory.SetModelFactory)3 TemplateModel (freemarker.template.TemplateModel)1 HashMap (java.util.HashMap)1 Map (java.util.Map)1 CaseInsensitiveMap (pcgen.base.util.CaseInsensitiveMap)1 DoubleKeyMap (pcgen.base.util.DoubleKeyMap)1