8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Copyright (c) 2007 Sun Microsystems Inc. All Rights Reserved
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The contents of this file are subject to the terms
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * of the Common Development and Distribution License
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * (the License). You may not use this file except in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * compliance with the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * You can obtain a copy of the License at
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * https://opensso.dev.java.net/public/CDDLv1.0.html or
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * See the License for the specific language governing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * permission and limitations under the License.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * When distributing Covered Code, include this CDDL
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Header Notice in each file and include the License file
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * If applicable, add the following below the CDDL Header,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * with the fields enclosed by brackets [] replaced by
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * your own identifying information:
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * "Portions Copyrighted [year] [name of copyright owner]"
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * $Id: PropertyXMLBuilderBase.java,v 1.20 2009/12/11 23:23:55 veiming Exp $
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted 2011-2016 ForgeRock AS.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Portions Copyrighted 2013-2014 Nomura Research Institute, Ltd
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport static com.sun.identity.sm.AttributeSchema.UIType.*;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.console.base.model.AMAdminConstants;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.console.base.model.AMModel;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.console.service.model.SubConfigModel;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport com.sun.identity.sm.ServiceSchemaManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.forgerock.openam.console.ui.taglib.propertysheet.CCPropertySheetTag;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Fosterimport org.forgerock.openam.utils.CollectionUtils;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Map mapSchemaTypeToName = new HashMap(8);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static List orderDisplaySchemaType = new ArrayList(4);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Map mapUITypeToName = new HashMap(8);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Map mapTypeToName = new HashMap(8);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected static Map mapSyntaxToName = new HashMap(20);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSchemaTypeToName.put(SchemaType.GLOBAL, "schemaType.global");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSchemaTypeToName.put(SchemaType.ORGANIZATION,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "schemaType.organization");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSchemaTypeToName.put(SchemaType.USER, "schemaType.user");
0503f9abf9d0469a149d3aa0d009409f328a6e59Phill Cunnington mapSchemaTypeToName.put(SchemaType.DYNAMIC, "schemaType.dynamic");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orderDisplaySchemaType.add(SchemaType.ORGANIZATION);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster orderDisplaySchemaType.add(SchemaType.DYNAMIC);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.BUTTON, "button");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.LINK, "link");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.ADDREMOVELIST, "addremove");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.NAME_VALUE_LIST,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "namevaluelist");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.RADIO, "radio");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.UNORDEREDLIST,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "unorderedlist");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.ORDEREDLIST,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "orderedlist");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.MAPLIST, "maplist");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.GLOBALMAPLIST,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "globalmaplist");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapUITypeToName.put(AttributeSchema.UIType.SCRIPTSELECT, "scriptSelect");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapTypeToName.put(AttributeSchema.Type.LIST, "list");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapTypeToName.put(AttributeSchema.Type.MULTIPLE_CHOICE,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "multiple_choice");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapTypeToName.put(AttributeSchema.Type.SINGLE_CHOICE, "single_choice");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapTypeToName.put(AttributeSchema.Type.SINGLE, "single");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.BOOLEAN, "boolean");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.PASSWORD, "password");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.ENCRYPTED_PASSWORD,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "password");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.PARAGRAPH, "paragraph");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.XML, "xml");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.SCRIPT, "script");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.STRING, "string");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.NUMERIC, "numeric");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.NUMBER_RANGE,"number_range");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.NUMBER, "number");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.DN, "dn");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster mapSyntaxToName.put(AttributeSchema.Syntax.URL, "url");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected ServiceSchemaManager svcSchemaManager;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String VALIDATE_LABEL = "label.validate";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private static final String UPLOAD_LABEL = "label.upload";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster static String getTagClassName(AttributeSchema as) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.UIType uitype = as.getUIType();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String val = (String)mapUITypeToName.get(uitype);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String valType = (String)mapTypeToName.get(type);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((tagClassName == null) && (valType != null)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.Syntax syntax = as.getSyntax();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String valSyntax = (String)mapSyntaxToName.get(syntax);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tagClassName = properties.getString(valType + ".whatever");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // do nothing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((tagClassName != null) && (tagClassName.trim().length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes hidden attribute schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeSchemas Set of Attribute Schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void filterHiddenAttributes(Set attributeSchemas) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster removeAttributeSchemaWithoutI18nKey(attributeSchemas);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema as = (AttributeSchema)iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes attribute schema that does not have <code>i18nKey</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeSchemas Set of Attribute Schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void removeAttributeSchemaWithoutI18nKey(Set attributeSchemas)
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema as = (AttributeSchema)iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((i18n == null) || (i18n.trim().length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Removes the attributes that do not match a specified set of any
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * display strings.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attributeSchemas Set of Attribute Schemas.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static void filterAttributes(Set attributeSchemas, String a[]) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster removeAttributeSchemaWithoutI18nKey(attributeSchemas);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = attributeSchemas.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema as = (AttributeSchema)iter.next();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean found = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public static boolean hasAnyAttribute(String any, String attribute) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean has = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((any != null) && (any.trim().length() > 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringTokenizer st = new StringTokenizer(any, "|");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a replaced XML. This method replaces a property element.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml XML to operate on.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propertyName Name of the property (attribute) that is going to be
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propertyXML XML to replace.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a replaced XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String ccHead = "<cc name=\"" + propertyName + "\"";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PropertyTemplate.PROPERTY_START_OPEN_TAG, start);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Inserts XML to a property XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml Original property XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param insertXML XML to be inserted to <code>xml</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param marker A marker where <code>insertXML</code> will be inserted.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param afterMarker <code>true</code> to insert XML after marker.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the modified XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int start = (afterMarker) ? idx + marker.length() : idx;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Inserts XML to a property XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml Original property XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param insertXML XML to be inserted to <code>xml</code>.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param marker A marker where <code>insertXML</code> will be inserted.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the modified XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns true if sub configuration is supported.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return true if sub configuration is supported.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set support sub configuration state.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param state <code>true</code> to support sub configuration.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public void setSupportSubConfig(boolean state) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Set name of view bean.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param name Name of view bean.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns name of view bean.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Name of view bean.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String rbName = svcSchemaManager.getI18NFileName();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceBundle = ResourceBundle.getBundle(rbName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "PropertyXMLBuilderBase.getServiceResourceBundle " +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns a set of attributeSchemas that are displayed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return Set of attribute names that are displayed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Collection values = mapTypeToAttributeSchema.values();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = values.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster protected void getServiceResourceBundle(ServiceSchema ss) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster serviceBundle = ResourceBundle.getBundle(rbName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster "PropertyXMLBuilderBase.getServiceResourceBundle", e);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(READONLY_START_TAG, param));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster param[0] = name + PropertyTemplate.PASSWORD_VALUE_TAG;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(READONLY_START_TAG, param));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean editableList = tagClassName.equals(TAGNAME_EDITABLE_LIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean orderedList = tagClassName.equals(TAGNAME_ORDERED_LIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean unorderedList = tagClassName.equals(TAGNAME_UNORDERED_LIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean mapList = tagClassName.equals(TAGNAME_MAP_LIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean globalMapList = tagClassName.equals(TAGNAME_GLOBAL_MAP_LIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.UIType uitype = as.getUIType();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster type.equals(AttributeSchema.Type.MULTIPLE_CHOICE) &&
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster uitype.equals(AttributeSchema.UIType.ADDREMOVELIST);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean listTyped = editableList || orderedList || unorderedList ||
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * create a subsection without a title to hold the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * editable list component.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(GROUP_START_TAG).append(PROPERTY_START_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendAddRemoveListComponent(as, xml, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster //need to handle link specially.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String editString = model.getLocalizedString("label.edit");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] pLink = {"'" + name + "'", editString};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tagClassName.equals(TAGNAME_HREF)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String editString = model.getLocalizedString("label.edit");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PropertyTemplate.PARAM_ATTR_NAME + "=" + name +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster PropertyTemplate.PARAM_PROPERTIES_VIEW_BEAN_URL +
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tagClassName.equals(TAGNAME_CHECKBOX)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * putting the editable list component wihin a group tag
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * to help isolate the list box and text box together on the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * page. Otherwise the list component blends in with other
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * components on the page.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.getLocalizedString("label.current.value"),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(GROUP_START_TAG).append(PROPERTY_START_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (mapList) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendChoiceValues(as, xml, model, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(COMPONENT_START_TAG,param));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * if its a textarea component add the no localize attribute
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * set the size of the text field based on its syntax
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(TEXTBOX_SIZE_TAG,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tagClassName.equals(TAGNAME_TEXTAREA)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final Map<String, String> sizeMap = getTextAreaSize(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] textAreaSize = {sizeMap.get("columns"), sizeMap.get("rows")};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(TEXTAREA_SIZE_TAG, textAreaSize));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (tagClassName.equals(TAGNAME_PASSWORD)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendChoiceValues(as, xml, model, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (type.equals(AttributeSchema.Type.MULTIPLE_CHOICE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster !uitype.equals(AttributeSchema.UIType.ADDREMOVELIST)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendMultipleChoiceCheckboxes(as, xml, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // close off the group and subsection tags for the editable list
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This will get the syntax of the attribute, and compute an appropriate
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * size for the length of the text field. This will help the user
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * understand what the expected value is for the field. The field sizes
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * are set in amProperty.properties so the customer can change the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * defaults as necessary.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private String getStringFieldSize(AttributeSchema as) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.Syntax syntax = as.getSyntax();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String valSyntax = (String)mapSyntaxToName.get(syntax);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size = properties.getString("textfield." + valSyntax);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster size = properties.getString("textfield.default");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This will get the syntax of the attribute and retrieve the desired size for the text area.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * The text area rows and columns are set in amProperty.properties and can be configured as required.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param as the attribute schema holding the text area properties.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return a Map with keys "columns" and "rows" as specified in the properties
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * file or an empty map if nothing was specified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map<String, String> getTextAreaSize(AttributeSchema as) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final Map<String, String> sizeMap = new HashMap<String, String>();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final AttributeSchema.Syntax syntax = as.getSyntax();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final String valSyntax = (String)mapSyntaxToName.get(syntax);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final String columnsKey = "textarea." + valSyntax + ".columns";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final String rowsKey = "textarea." + valSyntax + ".rows";
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (properties.containsKey(columnsKey) && properties.containsKey(rowsKey)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sizeMap.put("columns", properties.getString(columnsKey));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster sizeMap.put("rows", properties.getString(rowsKey));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.Syntax syntax = as.getSyntax();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (syntax.equals(AttributeSchema.Syntax.DATE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(PropertyTemplate.DATE_MARKER, arg));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster addPasswordConfirmLabel(as, xml, serviceBundle, model);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(COMPONENT_PWD_START_TAG, param));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Adds a file upload button below the last attribute added. This will dynamically upload a file and then paste
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the contents back into the field of the previous attribute on the form.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param as The attribute that describes this UI element.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml The XML document to add the element to.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param model The AMModel that stores admin constants.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void buildFileUploadXML(AttributeSchema as, StringBuffer xml, AMModel model) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster final String label = model.getLocalizedString(UPLOAD_LABEL);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(MessageFormat.format(COMPONENT_UPLOAD_BUTTON_START_TAG, name, label))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void buildScriptSelectXML(AttributeSchema as, StringBuffer xml, AMModel model, ResourceBundle bundle,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String attrName = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(COMPONENT_START_TAG, attrName, TAGNAME_DROPDOWN_MENU));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map<String, String> choiceValues = getSortedChoiceValueMap(as, model);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Map.Entry<String, String> entry : choiceValues.entrySet()) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(OPTION_TAG, escapeSpecialChars(model.getLocalizedString(entry.getValue())),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster .append(MessageFormat.format(COMPONENT_ACTION_BUTTON_START_TAG, "refresh", attrName, "",
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // Users can't create global scripts
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(COMPONENT_ACTION_BUTTON_START_TAG, "create", attrName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster as.getPropertiesViewBeanURL(), model.getLocalizedString("button.create")))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(COMPONENT_ACTION_BUTTON_START_TAG, "edit", attrName,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster as.getPropertiesViewBeanURL(), model.getLocalizedString("button.edit")))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster escapeSpecialChars(com.sun.identity.shared.locale.Locale.getString(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(LABEL_TAG, params));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster escapeSpecialChars(com.sun.identity.shared.locale.Locale.getString(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String label = MessageFormat.format(model.getLocalizedString(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(LABEL_TAG, params));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((i18nKey == null) || (i18nKey.length() < 1)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String helpString = CCPropertySheetTag.getDynamicHelp(serviceBundle, i18nKey + ".help");
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] params = {as.getName(), escapeSpecialChars(helpString)};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(HELP_TAG, params));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // no-op, assumption here is help is not defined for this attr.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public String escapeSpecialChars(String text) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((text != null) && (text.trim().length() > 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster StringBuilder sb = new StringBuilder(text.length());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster switch (c) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (type.equals(AttributeSchema.Type.SINGLE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster AttributeSchema.UIType uitype = as.getUIType();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((uitype != null) && uitype.equals(AttributeSchema.UIType.RADIO))
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster model.getLocalizedString("label.Yes"), "true"};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(OPTION_TAG, p1));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] p2 = {model.getLocalizedString("label.No"), "false"};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(OPTION_TAG, p2));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (type.equals(AttributeSchema.Type.SINGLE_CHOICE)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendChoiceValueForSelectableComponent(as, xml, serviceBundle, true, OPTION_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster } else if (type.equals(AttributeSchema.Type.LIST)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster appendChoiceValueForSelectableComponent(as, xml, serviceBundle, false, VALUE_OPTION_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set sorted = getSortedChoiceValues(as, map, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String name = getAttributeNameForPropertyXML(as);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(DYN_GUI_MULTIPLE_LIST_MARKER_XML,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster name, (String)map.get(localizedName), localizedName};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(DYN_GUI_MULTIPLE_LIST_CHECKBOX_XML,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set sorted = getSortedChoiceValues(as, map, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(ADD_REMOVE_COMPONENT_XML, nameArg));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] params = {localizedName, (String)map.get(localizedName)};
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(OPTION_TAG, params));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = choices.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster MessageFormat.format(DYN_GUI_MULTIPLE_LIST_CHECKBOX_XML,
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Sets the value for the current realm name being used to build the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * property sheet xml page.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param value the name of the realm
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns the current realm name value which can be used for constructing
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * the xml page. If the realm name has not been set the default location
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * which is stored in <code>AMModelBase</code> will be returned. If no
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * location has been set in the model the realm where the user logged in
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * is returned.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return name of the realm used for building the page.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return (currentRealm != null) ? currentRealm : model.getLocationDN();
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if (AttributeSchema.ListOrder.INSERTION.equals(as.getListOrder())) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster tmp.put(Constants.ORGANIZATION_NAME, getCurrentRealm());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((choices != null) && (choices.length > 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster String i18nKey = as.getChoiceValueI18NKey(val);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster if ((i18nKey == null) || (i18nKey.trim().length() == 0)) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster com.sun.identity.shared.locale.Locale.getString(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private Map<String, String> getSortedChoiceValueMap(AttributeSchema as, AMModel model) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster env.put(Constants.CONFIGURATION_NAME, ((SubConfigModel)model).getName());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster env.put(Constants.ORGANIZATION_NAME, getCurrentRealm());
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Map<String, String> choiceValues = as.getChoiceValuesMap(env);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return CollectionUtils.sortMapByValue(choiceValues);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster private void appendChoiceValueForSelectableComponent(
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster boolean defaultValue = false;
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Set sorted = getSortedChoiceValues(as, map, serviceBundle);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster for (Iterator iter = sorted.iterator(); iter.hasNext(); ) {
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster Object[] params = {escapeSpecialChars(localizedName),
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append("<attribute name=\"defaultValue\" value=\"")
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml.append(MessageFormat.format(template, params));
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * This will remove an entire subsection which surrounds the
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * specified attribute. The subsection will be replaced with a
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * <code><property></code> tag.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param original xml string to be modified.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param attribute name which is going to be removed.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param insert string with new xml.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return new xml string without subsection.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the attribute is not within a subsection
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster // the end of the subsection is missing. invalid xml perhaps.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns an altered XML. This method prepends a property element.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml XML to operate on.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propertyXML XML to replace.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the altered XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx = xml.indexOf(PropertyTemplate.START_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster return xml.substring(0, idx) + propertyXML + xml.substring(idx);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns an altered XML. This method appends a property element.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param xml XML to operate on.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @param propertyXML XML to replace.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return the altered XML.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster int idx = xml.lastIndexOf(PropertyTemplate.SECTION_END_TAG);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster xml = xml.substring(0, idx) + propertyXML + xml.substring(idx);
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * Returns service schema manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster * @return service schema manager.
8af80418ba1ec431c8027fa9668e5678658d3611Allan Foster public ServiceSchemaManager getServiceSchemaManager() {
buildSchemaTypeXML(schemaTypeName, attributeSchemas, xml, model, serviceBundle, readonly, true, true);
boolean section,
boolean addSubSection
if (section) {
protected Set<AttributeSchema> getAttributeSchemaForSection(Set<AttributeSchema> attributeSchemas, List<String> sectionList) {
return result;
boolean addSection
return (addSection)
return template;