All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.enhydra.xml.xmlc.metadata.ElementEdit Maven / Gradle / Ivy

The newest version!
/*
 * Enhydra Java Application Server Project
 * 
 * The contents of this file are subject to the Enhydra Public License
 * Version 1.1 (the "License"); you may not use this file except in
 * compliance with the License. You may obtain a copy of the License on
 * the Enhydra web site ( http://www.enhydra.org/ ).
 * 
 * Software distributed under the License is distributed on an "AS IS"
 * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See 
 * the License for the specific terms governing rights and limitations
 * under the License.
 * 
 * The Initial Developer of the Enhydra Application Server is Lutris
 * Technologies, Inc. The Enhydra Application Server and portions created
 * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
 * All Rights Reserved.
 * 
 * Contributor(s):
 * 
 * $Id: ElementEdit.java,v 1.2 2005/01/26 08:29:24 jkjome Exp $
 */

package org.enhydra.xml.xmlc.metadata;

import org.enhydra.xml.xmlc.XMLCException;
import org.w3c.dom.Document;

/**
 * Abstract type used as a base for all element editing definitions.  This
 * provides for the definition of which attributes and elements are to be
 * operated on by the derived edit definitions.
 */
public abstract class ElementEdit extends MetaDataElement {
    /**
     * Attribute names.
     */
    private static final String ELEMENT_IDS_ATTR = "elementIds";
    private static final String ELEMENT_CLASSES_ATTR = "elementClasses";
    private static final String ELEMENT_TAGS_ATTR = "elementTags";

    /**
     * Cache of parsed attributes.
     */
    private String[] elementIds;
    private String[] elementClasses;
    private String[] elementTags;

    /**
     * Constructor.
     */
    public ElementEdit(Document ownerDoc,
                       String tagName) {
    	super(ownerDoc, tagName);
    }

    /**
     * Get the elementIds attribute value.
     */
    public String[] getElementIds() {
        return getStringArrayAttribute(ELEMENT_IDS_ATTR);
    }

    /**
     * Set the elementIds attribute value.
     */
    public void setElementIds(String[] values) {
        setRemoveStringArrayAttribute(ELEMENT_IDS_ATTR, values);
    }

    /**
     * Add an element ID to the elementIds attribute value.
     */
    public void addElementId(String value) {
        addStringArrayAttribute(ELEMENT_IDS_ATTR, value);
    }

    /**
     * Determine if an id matches the element id constraints on
     * this object.  If there are no id constraints, all elements
     * match.  The id maybe null, which only matches if there are
     * no constraints.
     */
    public boolean matchesElementIdConstraints(String id) {
        if (elementIds == null) {
            elementIds = getElementIds();
        }
        if (elementIds.length == 0) {
            return true;
        }
        if (id == null) {
            return false; 
        }
        for (int idx = 0; idx < elementIds.length; idx++) {
            if (id.equals(elementIds[idx])) {
                return true;
            }
        }
        return false;
    }

    /**
     * Get the elementClasses attribute value.
     */
    public String[] getElementClasses() {
        return getStringArrayAttribute(ELEMENT_CLASSES_ATTR);
    }

    /**
     * Set the elementClasses attribute value.
     */
    public void setElementClasses(String[] values) {
        setRemoveStringArrayAttribute(ELEMENT_CLASSES_ATTR, values);
    }

    /**
     * Add a class to the elementClasses attribute value.
     */
    public void addElementClass(String value) {
        addStringArrayAttribute(ELEMENT_CLASSES_ATTR, value);
    }

    /**
     * Determine if an element class matches the element class constraints on
     * this object.  If there are no class constraints, all elements match.
     * The class maybe null, which only matches if there are no constraints.
     */
    public boolean matchesElementClassConstraints(String elementClass) {
        if (elementClasses == null) {
            elementClasses = getElementClasses();
        }
        if (elementClasses.length == 0) {
            return true;
        }
        if (elementClass == null) {
            return false;
        }
        for (int idx = 0; idx < elementClasses.length; idx++) {
            if (elementClass.equals(elementClasses[idx])) {
                return true;
            }
        }
        return false;
    }

    /**
     * Get the elementTags attribute value.
     */
    public String[] getElementTags() {
        return getStringArrayAttribute(ELEMENT_TAGS_ATTR);
    }

    /**
     * Set the elementTags attribute value.
     */
    public void setElementTags(String[] values) {
        setRemoveStringArrayAttribute(ELEMENT_TAGS_ATTR, values);
    }

    /**
     * Add an element to the elementTags attribute value.
     */
    public void addElementTag(String value) {
        addStringArrayAttribute(ELEMENT_TAGS_ATTR, value);
    }

    /**
     * Determine if a tag name matches the element tag name constraints on
     * this object.  If there are no tag name constraints, all elements
     * match.
     */
    public boolean matchesElementTagConstraints(String tagName,
                                                boolean ignoreCase) {
        if (elementTags == null) {
            elementTags = getElementTags();
        }
        if (elementTags.length == 0) {
            return true;
        }
        if (ignoreCase) {
            for (int idx = 0; idx < elementTags.length; idx++) {
                if (tagName.equalsIgnoreCase(elementTags[idx])) {
                    return true;
                }
            }
        } else {
            for (int idx = 0; idx < elementTags.length; idx++) {
                if (tagName.equals(elementTags[idx])) {
                    return true;
                }
            }
        }
        return false;
    }

    /**
     * Complete modifications to DOM.  This clears cache of parsed
     * attributes.
     */
    protected void completeModifications() throws XMLCException {
        super.completeModifications();
        elementIds = null;
        elementClasses = null;
        elementTags = null;
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy