/******************************************************************************* * Copyright (c) 2003, 2004 IBM Corporation and others. * All rights reserved. This program and the accompanying materials * are made available under the terms of the Eclipse Public License v1.0 * which accompanies this distribution, and is available at * http://www.eclipse.org/legal/epl-v10.html * * Contributors: * IBM Corporation - initial API and implementation *******************************************************************************/ /* * Created on Mar 9, 2004 * * To change the template for this generated file go to * Window - Preferences - Java - Code Generation - Code and Comments */ package org.eclipse.jst.j2ee.internal.web.operations; import java.util.List; import org.eclipse.core.runtime.IStatus; import org.eclipse.jst.j2ee.internal.J2EEVersionConstants; import org.eclipse.jst.j2ee.internal.common.operations.J2EEModelModifierOperationDataModel; import org.eclipse.jst.j2ee.jsp.JSPConfig; import org.eclipse.jst.j2ee.jsp.TagLibRefType; import org.eclipse.jst.j2ee.webapplication.TagLibRef; import org.eclipse.jst.j2ee.webapplication.WebApp; import org.eclipse.wst.common.frameworks.operations.WTPOperation; import org.eclispe.wst.common.frameworks.internal.plugin.WTPCommonPlugin; /** * @author jialin * * To change the template for this generated type comment go to Window - Preferences - Java - Code * Generation - Code and Comments */ public class AddTagLibRefDataModel extends J2EEModelModifierOperationDataModel { public static final String URL = "AddTagLibRefDataModel.URL"; //$NON-NLS-1$ public static final String LOCATION = "AddTagLibRefDataModel.LOCATION"; //$NON-NLS-1$ /* * (non-Javadoc) * * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#getDefaultOperation() */ public WTPOperation getDefaultOperation() { return new AddTagLibRefOperation(this); } /* * (non-Javadoc) * * @see org.eclipse.wst.common.internal.emfworkbench.operation.ModelModifierOperationDataModel#initValidBaseProperties() */ protected void initValidBaseProperties() { super.initValidBaseProperties(); addValidBaseProperty(URL); addValidBaseProperty(LOCATION); } /* * (non-Javadoc) * * @see org.eclipse.wst.common.frameworks.internal.operation.WTPOperationDataModel#doValidateProperty(java.lang.String) */ protected IStatus doValidateProperty(String propertyName) { if (propertyName.equals(URL)) return validateURL(getStringProperty(propertyName)); return super.doValidateProperty(propertyName); } private IStatus validateURL(String name) { if (name == null || name.trim().length() == 0) { String msg = WebMessages.getResourceString(WebMessages.ERR_TAGLIBREF_URL_EMPTY, new String[]{name}); return WTPCommonPlugin.createErrorStatus(msg); } WebApp webApp = (WebApp) getDeploymentDescriptorRoot(); boolean exists = false; List list = null; if (webApp.getJ2EEVersionID() >= J2EEVersionConstants.J2EE_1_4_ID) { JSPConfig jspConfig = webApp.getJspConfig(); if (jspConfig != null) { list = jspConfig.getTagLibs(); int size = list.size(); for (int i = 0; i < size; i++) { TagLibRefType refType = (TagLibRefType) list.get(i); String url = refType.getTaglibURI(); if (name.equals(url)) { exists = true; break; } } } } else { list = webApp.getTagLibs(); if (list != null && list.size() > 0) { int size = list.size(); for (int i = 0; i < size; i++) { TagLibRef ref = (TagLibRef) list.get(i); String url = ref.getTaglibURI(); if (name.equals(url)) { exists = true; break; } } } } if (exists) { String msg = WebMessages.getResourceString(WebMessages.ERR_TAGLIBREF_URL_EXIST, new String[]{name}); return WTPCommonPlugin.createErrorStatus(msg); } return WTPCommonPlugin.OK_STATUS; } }