Author: mareshkau
Date: 2008-07-28 13:43:59 -0400 (Mon, 28 Jul 2008)
New Revision: 9371
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeIncludeTemplate.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
Log:
JBIDE-2434, some code adjustment
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java 2008-07-28
16:36:42 UTC (rev 9370)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeCreatorUtil.java 2008-07-28
17:43:59 UTC (rev 9371)
@@ -104,7 +104,11 @@
}
return null;
}
-
+ /**
+ * Releases document model from read
+ * @see VpeCreatorUtil#getDocumentForRead(IFile)
+ * @param document
+ */
public static void releaseDocumentFromRead(Document document) {
if (document instanceof IDOMNode) {
IDOMModel wtpModel = ((IDOMNode)document).getModel();
@@ -145,8 +149,13 @@
}
return null;
}
-
- public static Document getDocumentForRead(IFile file, VpePageContext pageContext) {
+ /**
+ * Return dom document for read, document shoud be released from read
+ * @see VpeCreatorUtil#releaseDocumentFromRead(Document)
+ * @param file
+ * @return dom document for read
+ */
+ public static Document getDocumentForRead(IFile file) {
IDOMModel wtpModel = null;
try {
wtpModel = (IDOMModel)StructuredModelManager.getModelManager().getModelForRead(file);
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeIncludeTemplate.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeIncludeTemplate.java 2008-07-28
16:36:42 UTC (rev 9370)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/template/VpeIncludeTemplate.java 2008-07-28
17:43:59 UTC (rev 9371)
@@ -62,7 +62,7 @@
if (!pageContext.getVisualBuilder().isFileInIncludeStack(file)) {
Document document =
pageContext.getVisualBuilder().getIncludeDocuments().get(file);
if (document == null) {
- document = VpeCreatorUtil.getDocumentForRead(file, pageContext);
+ document = VpeCreatorUtil.getDocumentForRead(file);
if (document != null)
pageContext.getVisualBuilder().getIncludeDocuments().put(file, document);
}
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java 2008-07-28
16:36:42 UTC (rev 9370)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java 2008-07-28
17:43:59 UTC (rev 9371)
@@ -1,7 +1,6 @@
package org.jboss.tools.vpe.editor.util;
import java.io.File;
-import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
@@ -18,14 +17,15 @@
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IFileEditorInput;
import org.eclipse.ui.editors.text.ILocationProvider;
-import org.eclipse.wst.sse.core.StructuredModelManager;
import org.eclipse.wst.sse.core.internal.FileBufferModelManager;
import org.eclipse.wst.sse.core.internal.provisional.text.IStructuredDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocumentType;
import org.eclipse.wst.xml.core.internal.provisional.document.IDOMModel;
import org.jboss.tools.vpe.VpePlugin;
+import org.jboss.tools.vpe.editor.template.VpeCreatorUtil;
import org.w3c.dom.Attr;
+import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.NodeList;
@@ -64,6 +64,8 @@
IPath path = ((ILocationProvider) editorInput).getPath(editorInput);
if (path == null || path.segmentCount() < 1)
return null;
+ //TODO SDzmitrovich Fix This Method, convert to IPath to IFile,
+ //or smht. else, should be only one getDoctype(IFile, List<IFile>);
return getDoctype(path.toFile());
}
return null;
@@ -81,7 +83,10 @@
String docTypeValue = null;
// get document
- IDOMDocument document = getDocument(file);
+ Document document = null;
+ try {
+
+ document = VpeCreatorUtil.getDocumentForRead(file);
if (document != null) {
@@ -144,6 +149,11 @@
}
}
+ } finally {
+ if(document!=null) {
+ VpeCreatorUtil.getDocumentForRead(file);
+ }
+ }
return docTypeValue != null ? docTypeValue.trim() : ""; //$NON-NLS-1$
}
@@ -153,7 +163,7 @@
* @param file
* @return
*/
- static public String getDoctype(File file) {
+ private static String getDoctype(File file) {
String docTypeValue = null;
@@ -216,44 +226,6 @@
}
/**
- * get document by {@link IFile}
- *
- * @param file
- * @return
- */
- static private IDOMDocument getDocument(IFile file) {
-
- IDOMDocument document = null;
-
- IDOMModel model = null;
-
- if (file != null) {
- try {
-
- // get model
- model = (IDOMModel) StructuredModelManager
- .getModelManager().getModelForRead(file);
-
- if (model != null)
- document = model.getDocument();
-
- } catch (IOException e) {
- VpePlugin.getPluginLog().logError(e);
- } catch (CoreException e) {
- VpePlugin.getPluginLog().logError(e);
- } finally {
- //see JBIDE-2219
- if(model!=null) {
-
- model.releaseFromRead();
- }
- }
- }
-
- return document;
- }
-
- /**
* get document by {@link File}
*
* @param file
@@ -304,7 +276,7 @@
}
}
} catch (CoreException e) {
- e.printStackTrace();
+ VpePlugin.getPluginLog().logError(e);
}
return model.getDocument();
Show replies by date