@@ -0,0 +1,3264 @@
+/*%0A * #%25L%0A * ACS AEM Commons Bundle%0A * %25%25%0A * Copyright (C) 2015 Adobe%0A * %25%25%0A * Licensed under the Apache License, Version 2.0 (the %22License%22);%0A * you may not use this file except in compliance with the License.%0A * You may obtain a copy of the License at%0A *%0A *      http://www.apache.org/licenses/LICENSE-2.0%0A *%0A * Unless required by applicable law or agreed to in writing, software%0A * distributed under the License is distributed on an %22AS IS%22 BASIS,%0A * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.%0A * See the License for the specific language governing permissions and%0A * limitations under the License.%0A * #L%25%0A */%0Apackage com.adobe.acs.commons.util.impl;%0A%0Aimport java.util.Set;%0A%0Aimport javax.jcr.Node;%0Aimport javax.jcr.RepositoryException;%0A%0Aimport org.apache.commons.lang.StringUtils;%0Aimport org.apache.felix.scr.annotations.Component;%0Aimport org.apache.felix.scr.annotations.Service;%0Aimport org.apache.jackrabbit.JcrConstants;%0A%0Aimport com.adobe.cq.dialogconversion.AbstractDialogRewriteRule;%0Aimport com.adobe.cq.dialogconversion.DialogRewriteException;%0Aimport com.adobe.cq.dialogconversion.DialogRewriteUtils;%0A%0A/**%0A * DialogRewriteRule which handles rewriting of the 'graphiciconselection' xtype.%0A */%0A@Component%0A@Service%0Apublic final class GraphicIconSelectionDialogRewriteRule extends AbstractDialogRewriteRule %7B%0A%0A    private static final String PN_OPTIONS = %22options%22;%0A    private static final String XTYPE = %22graphiciconselection%22;%0A    private static final String%5B%5D PROPERTIES_TO_COPY = %7B %22name%22, %22fieldLabel%22, %22fieldDescription%22 %7D;%0A    private static final String PN_SLING_RESOURCE_TYPE = %22sling:resourceType%22;%0A%0A    @Override%0A    public Node applyTo(final Node root, final Set%3CNode%3E finalNodes)%0A            throws DialogRewriteException, RepositoryException %7B%0A        final Node parent = root.getParent();%0A        final String name = root.getName();%0A        DialogRewriteUtils.rename(root);%0A%0A        // add node for multifield%0A        final Node newRoot = parent.addNode(name, JcrConstants.NT_UNSTRUCTURED);%0A        finalNodes.add(newRoot);%0A        for (final String propertyName : PROPERTIES_TO_COPY) %7B%0A            DialogRewriteUtils.copyProperty(root, propertyName, newRoot, propertyName);%0A        %7D%0A%0A        newRoot.setProperty(PN_SLING_RESOURCE_TYPE, %22acs-commons/components/authoring/graphiciconselect%22);%0A%0A        if (root.hasProperty(PN_OPTIONS)) %7B%0A            final String options = root.getProperty(PN_OPTIONS).getString();%0A            if (options.startsWith(%22/etc/acs-commons/lists%22)) %7B%0A                final Node dataSource = newRoot.addNode(%22datasource%22, JcrConstants.NT_UNSTRUCTURED);%0A                dataSource.setProperty(PN_SLING_RESOURCE_TYPE, %22acs-commons/components/utilities/genericlist/datasource%22);%0A                // assuming the options property is something like /etc/acs-commons/lists/font-awesome-icons/_jcr_content.list.json, we want /etc/acs-commons/lists/font-awesome-icons%0A                dataSource.setProperty(%22path%22, StringUtils.substringBeforeLast(options, %22/%22));%0A            %7D%0A        %7D%0A%0A        root.remove();%0A        return newRoot;%0A    %7D%0A%0A    @Override%0A    public boolean matches(final Node root) throws RepositoryException %7B%0A        return DialogRewriteUtils.hasXtype(root, XTYPE);%0A    %7D%0A%0A%7D%0A

add dialog rewrite rule for graphiciconselection widget