Author: mareshkau
Date: 2009-07-15 09:02:21 -0400 (Wed, 15 Jul 2009)
New Revision: 16579
Removed:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDData.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDParser.java
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java
Log:
https://jira.jboss.org/jira/browse/JBIDE-3197
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-07-15
09:56:07 UTC (rev 16578)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeController.java 2009-07-15
13:02:21 UTC (rev 16579)
@@ -255,7 +255,7 @@
}
sourceModel.addModelLifecycleListener(this);
- IEditorInput editorInput = pageContext.getEditPart().getEditorInput();
+// IEditorInput editorInput = pageContext.getEditPart().getEditorInput();
//commented by Maksim Areshkau, as fix for
https://jira.jboss.org/jira/browse/JBIDE-4534
// if(editorInput instanceof IFileEditorInput) {
// XModel xm = null;
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-07-15
09:56:07 UTC (rev 16578)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeTemplateManager.java 2009-07-15
13:02:21 UTC (rev 16579)
@@ -385,15 +385,17 @@
}
String sourceNodeUri = sourceNodeTaglib.getUri();
- if(sourceNodeUri!=null &&
CustomTLDReference.isExistInCustomTlds(pageContext,sourceNodeUri)){
- return VpeTemplateManager.CUSTOM_TEMPLATE_NAME;
- }
+
String templateTaglibPrefix = getTemplateTaglibPrefix(sourceNodeUri);
if(templateTaglibPrefix != null) {
return templateTaglibPrefix + ":" + sourceNode.getLocalName();
//$NON-NLS-1$
}
+
+ if(sourceNodeUri!=null &&
CustomTLDReference.isExistInCustomTlds(pageContext,sourceNodeUri)){
+ return VpeTemplateManager.CUSTOM_TEMPLATE_NAME;
+ }
return null;
default :
return null;
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDData.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDData.java 2009-07-15
09:56:07 UTC (rev 16578)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDData.java 2009-07-15
13:02:21 UTC (rev 16579)
@@ -1,48 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template.custom;
-
-import org.eclipse.core.runtime.IPath;
-
-/**
- * Class which contains information about
- * @author mareshkau
- *
- */
-public class CustomTLDData {
-
- private IPath tldFilePath;
- private String namespace;
-
- /**
- *
- * @param tldFilePath
- */
- public CustomTLDData(IPath tldFilePath, String namespace) {
- this.tldFilePath=tldFilePath;
- this.namespace=namespace;
- }
-
- /**
- * @return the tldFilePath
- */
- public IPath getTldFilePath() {
- return this.tldFilePath;
- }
-
- /**
- * @return the namespace
- */
- public String getNamespace() {
- return this.namespace;
- }
-
-}
Deleted:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDParser.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDParser.java 2009-07-15
09:56:07 UTC (rev 16578)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDParser.java 2009-07-15
13:02:21 UTC (rev 16579)
@@ -1,105 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2008 Red Hat, Inc.
- * Distributed under license by Red Hat, Inc. All rights reserved.
- * This program is 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
- *
- * Contributor:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-package org.jboss.tools.vpe.editor.template.custom;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.ResourcesPlugin;
-import org.eclipse.core.runtime.IPath;
-import org.jboss.tools.vpe.VpePlugin;
-import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
-import org.w3c.dom.Document;
-import org.w3c.dom.Element;
-import org.w3c.dom.Node;
-import org.w3c.dom.NodeList;
-
-
-/**
- *
- * Class which created for parsing custom class definitions
- * @author mareshkau
- *
- */
-public class CustomTLDParser {
-
- private static final String NAMESPACE="namespace"; //$NON-NLS-1$
- private static final String TAG="tag"; //$NON-NLS-1$
- private static final String TAG_NAME="tag-name"; //$NON-NLS-1$
- private static final String SOURCE="source"; //$NON-NLS-1$
-
- /**
- * Looks for namespace, defined for custom template definition file
- *
- * @param absolute path for template definition file
- * @return namespace element if such was founded or null otherwise
- */
- public static final String getNameSpace(IPath pathToFile){
-
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(pathToFile);
- if(file!=null && file.exists()) {
- Document document=null;
- try {
- document = VpeCreatorUtil.getDocumentForRead(file);
- Element rootElement = document.getDocumentElement();
- NodeList nodeList = rootElement.getElementsByTagName(NAMESPACE);
- return nodeList.item(0).getFirstChild().getNodeValue();
- } finally {
- if(document!=null) {
- VpeCreatorUtil.releaseDocumentFromRead(document);
- }
- }
- }
- return null;
- }
- /**
- * Looks for source value like in example bellow
- <tag>
- <tag-name>paginator</tag-name>
- <source>components/paginator.xhtml</source>
- </tag>
- * @param pathToFile
- * @param name of tag
- * @return source value if exists or null otherwise
- */
- public static final String getSourceValuetInTag(IPath pathToFile, String name){
- IFile file = ResourcesPlugin.getWorkspace().getRoot().getFile(pathToFile);
- Document document=null;
- if(file!=null &&file.exists()) {
- try{
- document= VpeCreatorUtil.getDocumentForRead(file);
- Element rootElement = document.getDocumentElement();
- NodeList nodeList = rootElement.getElementsByTagName(TAG);
- for(int i=0;i<nodeList.getLength();i++) {
- Node child = nodeList.item(i);
- if(!(child instanceof Element)) {
- continue;
- }
- NodeList tagsList =((Element)child).getElementsByTagName(TAG_NAME);
- for(int j=0;j<tagsList.getLength();j++) {
- if(name.equals(tagsList.item(j).getFirstChild().getNodeValue())){
- NodeList sourceList =((Element)child).getElementsByTagName(SOURCE);
- //no source element has been founded
- if(sourceList.getLength()==0) {
- return null;
- }
- return sourceList.item(0).getFirstChild().getNodeValue();
- }
- }
- }
-
- } finally {
- if(document!=null) {
- VpeCreatorUtil.releaseDocumentFromRead(document);
- }
- }
- }
- return null;
- }
-}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java 2009-07-15
09:56:07 UTC (rev 16578)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/custom/CustomTLDReference.java 2009-07-15
13:02:21 UTC (rev 16579)
@@ -10,24 +10,20 @@
******************************************************************************/
package org.jboss.tools.vpe.editor.template.custom;
-import java.util.HashMap;
+
import java.util.List;
-import java.util.Map;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.IPath;
-import org.eclipse.core.runtime.Path;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.jboss.tools.common.model.XModel;
import org.jboss.tools.common.model.XModelObject;
+import org.jboss.tools.common.model.filesystems.impl.SimpleFileImpl;
import org.jboss.tools.common.model.project.IModelNature;
import org.jboss.tools.common.model.util.EclipseResourceUtil;
-import org.jboss.tools.jst.web.model.helpers.WebAppHelper;
+import org.jboss.tools.jst.web.project.WebProject;
import org.jboss.tools.jst.web.tld.TaglibData;
import org.jboss.tools.vpe.editor.context.VpePageContext;
-import org.jboss.tools.vpe.editor.util.VpeStyleUtil;
import org.jboss.tools.vpe.editor.util.XmlUtil;
import org.w3c.dom.Node;
@@ -39,12 +35,9 @@
*/
public class CustomTLDReference {
- private static final String FACELETS_LIBS_PARAMETER = "facelets.LIBRARIES";
//$NON-NLS-1$
-
- private static final String PARAM_VALUE = "param-value"; //$NON-NLS-1$
-
/**
- * Returns absolute path to custom template file, if such exist or null otherwise
+ * Returns absolute path to custom template file, if such exist or null
+ * otherwise
*
* @param sourceNode
* @return full path to custom template if exist or null if not exist
@@ -56,99 +49,66 @@
TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourceNode
.getPrefix(), taglibs);
String uri = sourceNodeTaglib.getUri();
- CustomTLDData customTLDData = getCustomTLDDataMap(pageContext).get(uri);
- if (customTLDData == null) {
- return null;
+ XModelObject xmodel = getCustomTaglibObject(pageContext,uri);
+
+ XModelObject o = xmodel.getChildByPath(sourceNode.getLocalName()
+ + "/declaration"); //$NON-NLS-1$
+ String sourceAttributeValue = null;
+ if (o != null) {
+ sourceAttributeValue = o.getAttributeValue("source"); //$NON-NLS-1$
}
- IPath pathToSourceFile = customTLDData.getTldFilePath();
- pathToSourceFile = pathToSourceFile.removeLastSegments(1);
- String sourceParamValue = CustomTLDParser.getSourceValuetInTag(
- customTLDData.getTldFilePath(), sourceNode.getLocalName());
- if (sourceParamValue == null) {
+
+ if (sourceAttributeValue == null) {
return null;
}
- pathToSourceFile = pathToSourceFile.append(sourceParamValue);
- return pathToSourceFile;
+ if (xmodel instanceof SimpleFileImpl) {
+ IPath pathToSourceFile = ((SimpleFileImpl) xmodel).getFile()
+ .getFullPath();
+ // pathToSourceFile now smth like this
+ // /customFaceletsTestProject/WebContent/tags/facelets.taglib.xml
+ // so we remove facelet taglib name now
+ pathToSourceFile = pathToSourceFile.removeLastSegments(1);
+ pathToSourceFile = pathToSourceFile.append(sourceAttributeValue);
+ return pathToSourceFile;
+ }
+ return null;
}
+
/**
*
* @param pageContext
- * @param uri node namespace uri
- * @return true if such template defined in facelets lib or falce if not defined
+ * @param uri
+ * node namespace uri
+ * @return true if such template defined in facelets lib or falce if not
+ * defined
*/
public static boolean isExistInCustomTlds(VpePageContext pageContext,
String uri) {
- return getCustomTLDDataMap(pageContext).containsKey(uri);
+ return getCustomTaglibObject(pageContext,uri)!=null?true:false;
}
/**
- * Looks for taglibs library
- * @param pageContext
- * @param sourceNode node for which we look for taglib library
- * @return path to taglibs, if such exists or null otherwise
- */
- public static IPath getCustomTLDPath(VpePageContext pageContext, Node sourceNode) {
- List<TaglibData> taglibs = XmlUtil.getTaglibsForNode(sourceNode,
- pageContext);
- TaglibData sourceNodeTaglib = XmlUtil.getTaglibForPrefix(sourceNode
- .getPrefix(), taglibs);
- String uri = sourceNodeTaglib.getUri();
- CustomTLDData customTLDData = getCustomTLDDataMap(pageContext).get(uri);
- if(customTLDData!=null) {
- return customTLDData.getTldFilePath();
- }
- return null;
- }
- /**
* Looks for custom taglib library map
+ *
* @return the customTLDDataMap
*/
- private static Map<String, CustomTLDData> getCustomTLDDataMap(
- VpePageContext pageContext) {
+ private static XModelObject getCustomTaglibObject(
+ VpePageContext pageContext, String uri) {
+ IEditorInput editorInput = pageContext.getEditPart().getEditorInput();
- Map<String, CustomTLDData> customTLDMap = new HashMap<String,
CustomTLDData>();
-
- IEditorInput iEditorInput = pageContext.getEditPart().getEditorInput();
-
- if (iEditorInput instanceof IFileEditorInput) {
-
- IFileEditorInput iFileEditorInput = (IFileEditorInput) iEditorInput;
-
- IFile iFile = iFileEditorInput.getFile();
-
- IProject project = iFile.getProject();
- IModelNature nature = EclipseResourceUtil.getModelNature(project);
- if (nature != null) {
- XModel model = nature.getModel();
- XModelObject webXML = WebAppHelper.getWebApp(model);
- XModelObject param = WebAppHelper.findWebAppContextParam(
- webXML, CustomTLDReference.FACELETS_LIBS_PARAMETER);
- if (param != null) {
- String value = param.getAttributeValue(PARAM_VALUE);
- if (value != null) {
- String[] libs = value.split(";");//$NON-NLS-1$
- for (String faceletLib : libs) {
- IPath rootPath = VpeStyleUtil
- .getRootPath(iEditorInput);
- IPath projectPath =
((IFileEditorInput)iEditorInput).getFile().getProject().getLocation();
-
- IPath pathToCustonTld = new Path(faceletLib);
-
- pathToCustonTld = rootPath.append(pathToCustonTld);
- pathToCustonTld = pathToCustonTld.makeRelativeTo(projectPath);
- pathToCustonTld =
((IFileEditorInput)iEditorInput).getFile().getProject().getFile(pathToCustonTld).getFullPath();
- CustomTLDData customTLDData = new CustomTLDData(
- pathToCustonTld, CustomTLDParser
- .getNameSpace(pathToCustonTld));
- if (customTLDData.getNamespace() != null) {
- customTLDMap.put(customTLDData.getNamespace(),
- customTLDData);
- }
- }
- }
- }
+ if (editorInput instanceof IFileEditorInput) {
+ XModel xm = null;
+ IProject project = ((IFileEditorInput) editorInput).getFile()
+ .getProject();
+ IModelNature mn = EclipseResourceUtil.getModelNature(project);
+ if (mn != null) {
+ xm = mn.getModel();
}
+ if (xm != null) {
+ return WebProject.getInstance(xm).getTaglibMapping().getTaglibObject(uri);
+ }
}
- return customTLDMap;
+ return null;
}
+
}