Author: mareshkau
Date: 2009-06-24 08:17:30 -0400 (Wed, 24 Jun 2009)
New Revision: 16185
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java
Log:
Fixing PMD code violations
Modified:
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java
===================================================================
---
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2009-06-24
11:46:14 UTC (rev 16184)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/VpeVisualKeyHandler.java 2009-06-24
12:17:30 UTC (rev 16185)
@@ -793,7 +793,7 @@
}
private Node getNextFlatNode (Node node) {
for (Node next = FlatIterator.next(node); next != null; next = FlatIterator.next(next))
{
- if (getVisualNode(next) != null || next.getNodeType() == Node.TEXT_NODE);
+ if (getVisualNode(next) != null || next.getNodeType() == Node.TEXT_NODE)
return next;
}
return null;
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 2009-06-24
11:46:14 UTC (rev 16184)
+++
trunk/vpe/plugins/org.jboss.tools.vpe/src/org/jboss/tools/vpe/editor/util/DocTypeUtil.java 2009-06-24
12:17:30 UTC (rev 16185)
@@ -18,7 +18,6 @@
import java.net.URISyntaxException;
import java.util.ArrayList;
import java.util.List;
-
import org.eclipse.core.filebuffers.FileBuffers;
import org.eclipse.core.filebuffers.ITextFileBuffer;
import org.eclipse.core.filebuffers.ITextFileBufferManager;
@@ -237,7 +236,9 @@
*/
private static String getDoctype(File file) {
String docTypeValue = Constants.EMPTY;
- IDOMDocument document = getDocument(file);
+ IDOMDocument document= null;
+ try {
+ document = getDocument(file);
if (document != null) {
// find "component" element
Element componentElement = FaceletUtil
@@ -274,10 +275,19 @@
docTypeValue = documentType.getSource();
}
}
+ }finally {
+ //added by Max Areshkau, we should always release document
+ if(document!=null) {
+ FileBufferModelManager.getInstance().releaseModel(document.getStructuredDocument());
+ }
+ }
return (docTypeValue != null) ? docTypeValue.trim() : Constants.EMPTY;
}
/**
+ * Maksim Areshkau
+ * After using document model should be always released!
+ *
* get document by {@link File}
*
* @param file
@@ -285,24 +295,6 @@
*/
static private IDOMDocument getDocument(File file) {
- // if (file.exists()) {
- //
- // String content = org.jboss.tools.common.util.FileUtil
- // .readFile(file);
- //
- // IStructuredDocument newStructuredDocument = StructuredDocumentFactory
- // .getNewStructuredDocumentInstance(new JSPSourceParser());
- //
- // newStructuredDocument.set(content);
- //
- // IDOMModel modelForJSP = new DOMModelForJSP();
- // modelForJSP.setStructuredDocument(newStructuredDocument);
- //
- // return modelForJSP.getDocument();
- //
- // }
- // return null;
-
IDOMModel model = null;
ITextFileBufferManager bufferManager = FileBuffers
.getTextFileBufferManager();
@@ -325,7 +317,7 @@
} catch (CoreException e) {
VpePlugin.getPluginLog().logError(e);
}
- return model.getDocument();
+ return model==null?null:model.getDocument();
}
/**
@@ -347,7 +339,10 @@
* @return
*/
public static String getContentInitFile(File initFile) {
- IDOMDocument document = getDocument(initFile);
+ IDOMDocument document = null;
+ String result = Constants.EMPTY;
+ try {
+ document = getDocument(initFile);
if (document != null) {
// for each tag's name
for (String tag : urlTags) {
@@ -372,8 +367,13 @@
}
}
}
- return document.getSource();
+ result = document.getSource();
}
- return Constants.EMPTY;
+ } finally {
+ if(document!=null) {
+ FileBufferModelManager.getInstance().releaseModel(document.getStructuredDocument());
+ }
+ }
+ return result;
}
}
Show replies by date