001/*
002 * Licensed to the Apache Software Foundation (ASF) under one
003 * or more contributor license agreements.  See the NOTICE file
004 * distributed with this work for additional information
005 * regarding copyright ownership.  The ASF licenses this file
006 * to you under the Apache License, Version 2.0 (the
007 * "License"); you may not use this file except in compliance
008 * with the License.  You may obtain a copy of the License at
009 *
010 *   http://www.apache.org/licenses/LICENSE-2.0
011 *
012 * Unless required by applicable law or agreed to in writing,
013 * software distributed under the License is distributed on an
014 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
015 * KIND, either express or implied.  See the License for the
016 * specific language governing permissions and limitations
017 * under the License.
018 */
019package org.apache.maven.doxia.macro;
020
021import java.util.Map;
022
023import org.apache.maven.doxia.sink.SinkEventAttributes;
024import org.apache.maven.doxia.sink.impl.SinkEventAttributeSet;
025
026/**
027 * Abstract base class to execute <code>Macro</code>.
028 *
029 * @author <a href="mailto:jason@maven.org">Jason van Zyl</a>
030 * @since 1.0
031 */
032public abstract class AbstractMacro implements Macro {
033    /**
034     * Convert the Map of macro parameters to an AttributeSet.
035     * No check of validity is done, all parameters are added.
036     *
037     * @param parameters the macro parameters.
038     * @return a SinkEventAttributeSet containing the same parameters,
039     *  or null if parameters is null.
040     * @since 1.1.1.
041     */
042    protected static SinkEventAttributes getAttributesFromMap(Map<?, ?> parameters) {
043        if (parameters == null) {
044            return null;
045        }
046
047        final int count = parameters.size();
048
049        if (count <= 0) {
050            return null;
051        }
052
053        final SinkEventAttributeSet atts = new SinkEventAttributeSet(count);
054
055        for (Map.Entry<?, ?> entry : parameters.entrySet()) {
056            atts.addAttribute(entry.getKey(), entry.getValue());
057        }
058
059        return atts;
060    }
061}