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

com.sun.webui.jsf.util.ComponentUtilities Maven / Gradle / Ivy

There is a newer version: 4.4.0.1
Show newest version
/*
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
 *
 * Copyright (c) 2007-2018 Oracle and/or its affiliates. All rights reserved.
 *
 * The contents of this file are subject to the terms of either the GNU
 * General Public License Version 2 only ("GPL") or the Common Development
 * and Distribution License("CDDL") (collectively, the "License").  You
 * may not use this file except in compliance with the License.  You can
 * obtain a copy of the License at
 * https://oss.oracle.com/licenses/CDDL+GPL-1.1
 * or LICENSE.txt.  See the License for the specific
 * language governing permissions and limitations under the License.
 *
 * When distributing the software, include this License Header Notice in each
 * file and include the License file at LICENSE.txt.
 *
 * GPL Classpath Exception:
 * Oracle designates this particular file as subject to the "Classpath"
 * exception as provided by Oracle in the GPL Version 2 section of the License
 * file that accompanied this code.
 *
 * Modifications:
 * If applicable, add the following below the License Header, with the fields
 * enclosed by brackets [] replaced by your own identifying information:
 * "Portions Copyright [year] [name of copyright owner]"
 *
 * Contributor(s):
 * If you wish your version of this file to be governed by only the CDDL or
 * only the GPL Version 2, indicate your decision by adding "[Contributor]
 * elects to include this software in this distribution under the [CDDL or GPL
 * Version 2] license."  If you don't indicate a single choice of license, a
 * recipient has the option to distribute your version of this file under
 * either the CDDL, the GPL Version 2 or to extend the choice of license to
 * its licensees as provided above.  However, if you add GPL Version 2 code
 * and therefore, elected the GPL Version 2 license, then the option applies
 * only if the new code is made subject to such option by the copyright
 * holder.
 */

/*
 * $Id: ComponentUtilities.java,v 1.1.6.1 2009-12-29 04:59:21 jyeary Exp $
 */
package com.sun.webui.jsf.util;

import javax.faces.component.UIComponent;

/**
 * Methods for general component manipulation.
 */
public class ComponentUtilities {

    private final static String USCORE = "_"; //NOI18N

    /** Creates a new instance of ComponentUtilities. */
    public ComponentUtilities() {
    }

    /**
     * Store an internally created component utilizing the 
     * internal facet naming convention by mapping the facet
     * to the name returned by createPrivateFacetName().
     * Add the component to the parent's facets map.
     *
     * @param parent the component that created the facet
     * @param facetName the public facet name
     * @param facet the private facet component instance
     */
    public static void putPrivateFacet(UIComponent parent,
            String facetName, UIComponent facet) {

        if (parent == null || facet == null || facetName == null) {
            return;
        }
        parent.getFacets().put(createPrivateFacetName(facetName), facet);
    }

    /**
     * Remove an internally created component utilizing the 
     * internal facet naming convention by mapping the facet
     * to the name returned by createPrivateFacetName().
     * Remove the component from the parent's facets map.
     *
     * @param parent the component that created the facet
     * @param facetName the public facet name
     */
    public static void removePrivateFacet(UIComponent parent,
            String facetName) {

        if (parent == null || facetName == null) {
            return;
        }
        parent.getFacets().remove(createPrivateFacetName(facetName));
    }

    /**
     * Return a private facet from the the parent component's facet map.
     * Look for a private facet name by calling
     * createPrivateFacetName() on the facetName parameter.
     * 

* If the matchId parameter is true, verify that the facet that is found * has an id that matches the value of * getPrivateFacetId(parent.getId(), facetName). * If the id's do not match return null and remove the existing facet.
* If matchId is false, return the facet if found or null. * * @param parent the component that contains the facet * @param facetName the public facet name * @parem matchId verify a the id of the facet * @return a UIComponent if the facet is found else null. */ public static UIComponent getPrivateFacet(UIComponent parent, String facetName, boolean matchId) { if (parent == null || facetName == null) { return null; } String pfacetName = createPrivateFacetName(facetName); UIComponent facet = (UIComponent) parent.getFacets().get(pfacetName); if (facet == null) { return null; } if (matchId == false) { return facet; } // Will never be null as long as facetName is not null. // String id = createPrivateFacetId(parent, facetName); if (!id.equals(facet.getId())) { parent.getFacets().remove(pfacetName); return null; } return facet; } /** * Prefix the facetName parameter with an "_". * * @param facetName the public facet name * @return a private facet name */ public static String createPrivateFacetName(String facetName) { return USCORE.concat(facetName); } /** * Return an id using the convention
* parent.getId() + "_" + facetName * If parent.getId() is null, "_" + facetName * is returned. * * @param parent the component that contains the facet * @param facetName the public facet name * @return an id for a private facet. */ public static String createPrivateFacetId(UIComponent parent, String facetName) { String pfacetName = createPrivateFacetName(facetName); String id = parent.getId(); if (id != null) { pfacetName = id.concat(pfacetName); } return pfacetName; } }





© 2015 - 2024 Weber Informatics LLC | Privacy Policy