Author: akazakov
Date: 2011-11-11 19:45:29 -0500 (Fri, 11 Nov 2011)
New Revision: 36312
Removed:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/JSF2ComponentModelManager.java
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/project/JSF2Util.java
Log:
https://issues.jboss.org/browse/JBIDE-10137 Close input and output stream in all places
where it used
Modified: trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml
===================================================================
--- trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2011-11-12 00:17:34 UTC (rev 36311)
+++ trunk/jsf/plugins/org.jboss.tools.jsf/plugin.xml 2011-11-12 00:45:29 UTC (rev 36312)
@@ -545,207 +545,8 @@
<adapter type="org.eclipse.core.resources.IProject"/>
</factory>
</extension>
- <!--extension
- id="jsf2"
- name="%JSF2_ComponentsValidator.name"
- point="org.eclipse.wst.validation.validatorV2">
- <validator
- build="true"
-
class="org.jboss.tools.jsf.web.validation.jsf2.JSF2ComponentsValidator"
- manual="true"
- markerId="org.jboss.tools.jsf.jsf2problemmarker"
-
sourceid="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML"
- version="4">
- <include>
- <rules>
- <contentType
- id="org.eclipse.wst.html.core.htmlsource">
- </contentType>
- <contentType
- id="org.eclipse.jst.jsp.core.jspfragmentsource">
- </contentType>
- <contentType
- id="org.eclipse.jst.jsp.core.tagsource">
- </contentType>
- <fileext
- caseSensitive="false"
- ext="xhtml">
- </fileext>
- <fileext
- caseSensitive="false"
- ext="jsp">
- </fileext>
- <contentType
- id="org.eclipse.jst.jsp.core.jspsource">
- </contentType>
- <contentType
- id="org.jboss.tools.jst.jsp.jspincludesource">
- </contentType>
- </rules>
- </include>
- </validator>
- </extension>
- <extension
- point="org.eclipse.ui.ide.markerResolution">
- <markerResolutionGenerator
-
class="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2ComponentResolutionGenerator"
- markerType="org.jboss.tools.jsf.jsf2problemmarker">
- </markerResolutionGenerator>
- </extension>
-
- <extension
- id="jsf2problemmarker"
- name="%JSF2ProblemName"
- point="org.eclipse.core.resources.markers">
- <super
- type="org.eclipse.core.resources.problemmarker">
- </super>
- <persistent
- value="true">
- </persistent>
- <attribute
- name="problemType">
- </attribute>
- <attribute
- name="baseElement">
- </attribute>
- <super
- type="org.eclipse.core.resources.textmarker">
- </super>
- </extension -->
-
- <!--extension
- point="org.eclipse.wst.sse.ui.sourcevalidation">
- <validator
- class="org.jboss.tools.jsf.web.validation.jsf2.JSF2SourceValidator"
- id="org.jboss.tools.jsf.jsf2sourcevalidator"
- scope="total">
- <contentTypeIdentifier
- id="jsf.facelet">
- <partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.eclipse.wst.html.core.htmlsource">
- <partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.eclipse.jst.jsp.core.jspsource">
- <partitionType id="org.eclipse.jst.jsp.DEFAULT_JSP"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.jboss.tools.jst.jsp.jspincludesource">
- <partitionType id="org.eclipse.jst.jsp.DEFAULT_JSP"/>
- </contentTypeIdentifier>
- </validator>
- </extension-->
-<!--
- <extension
- point="org.eclipse.ui.ide.markerResolution">
- <markerResolutionGenerator
-
class="org.jboss.tools.jsf.web.validation.i18n.I18nMarkerResolutionGenerator"
- markerType="org.jboss.tools.jsf.i18nproblemmarker">
- </markerResolutionGenerator>
- </extension>
-
- <extension
- id="i18nproblemmarker"
- name="%i18nProblemName"
- point="org.eclipse.core.resources.markers">
- <super
- type="org.eclipse.core.resources.problemmarker">
- </super>
- <persistent
- value="true">
- </persistent>
- <attribute
- name="problemType">
- </attribute>
- <attribute
- name="baseElement">
- </attribute>
- <super
- type="org.eclipse.core.resources.textmarker">
- </super>
- </extension>
-
<extension
- point="org.eclipse.wst.sse.ui.sourcevalidation">
- <validator
- class="org.jboss.tools.jsf.web.validation.i18n.I18nValidator"
- id="org.jboss.tools.jsf.externalize.source.validator"
- scope="total">
- <contentTypeIdentifier
- id="jsf.facelet">
- <partitionType id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.eclipse.wst.html.core.htmlsource">
- <partitionType
- id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.eclipse.jst.jsp.core.jspsource">
- <partitionType
- id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- <contentTypeIdentifier
- id="org.jboss.tools.jst.jsp.jspincludesource">
- <partitionType
- id="org.eclipse.wst.html.HTML_DEFAULT"/>
- </contentTypeIdentifier>
- </validator>
- </extension>
-
- <extension
- id="i18n"
- name="%I18nValidator.name"
- point="org.eclipse.wst.validation.validatorV2">
- <validator
- build="true"
- class="org.jboss.tools.jsf.web.validation.i18n.I18nValidator"
- manual="true"
- markerId="org.jboss.tools.jsf.i18nproblemmarker"
-
sourceid="org.eclipse.wst.xml.ui.internal.validation.DelegatingSourceValidatorForXML"
- version="4">
- <include>
- <rules>
- <contentType
- id="org.eclipse.wst.html.core.htmlsource">
- </contentType>
- <contentType
- id="org.eclipse.jst.jsp.core.jspfragmentsource">
- </contentType>
- <contentType
- id="org.eclipse.jst.jsp.core.tagsource">
- </contentType>
- <fileext
- caseSensitive="false"
- ext="xhtml">
- </fileext>
- <fileext
- caseSensitive="false"
- ext="jsp">
- </fileext>
- <contentType
- id="org.eclipse.jst.jsp.core.jspsource">
- </contentType>
- <contentType
- id="org.jboss.tools.jst.jsp.jspincludesource">
- </contentType>
- </rules>
- </include>
- </validator>
- </extension>
--->
- <!--extension
- point="org.eclipse.wst.sse.ui.quickFixProcessor">
- <quickFixProcessor
-
class="org.jboss.tools.jsf.web.validation.jsf2.action.JSF2QuickFixProcessor"
- problemType="org.jboss.tools.jsf.jsf2problemmarker">
- </quickFixProcessor>
- </extension-->
- <extension
point="org.eclipse.ui.editors.annotationTypes">
<type
markerSeverity="1"
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/JSF2ComponentModelManager.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/JSF2ComponentModelManager.java 2011-11-12
00:17:34 UTC (rev 36311)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/jsf2/model/JSF2ComponentModelManager.java 2011-11-12
00:45:29 UTC (rev 36312)
@@ -313,7 +313,7 @@
public static IDOMDocument getReadableDOMDocument(JarEntryFile file) {
IDOMDocument document = null;
IStructuredModel model = null;
- InputStream inputStream;
+ InputStream inputStream = null;
try {
inputStream = file.getContents();
if (inputStream != null) {
@@ -333,6 +333,13 @@
} catch (CoreException e) {
JSFModelPlugin.getPluginLog().logError(e);
} finally {
+ if(inputStream!=null) {
+ try {
+ inputStream.close();
+ } catch (IOException e) {
+ // Ignore
+ }
+ }
model = null;
}
return document;
Modified:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/project/JSF2Util.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/project/JSF2Util.java 2011-11-12
00:17:34 UTC (rev 36311)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/project/JSF2Util.java 2011-11-12
00:45:29 UTC (rev 36312)
@@ -151,5 +151,4 @@
}
return false;
}
-
-}
+}
\ No newline at end of file
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java 2011-11-12
00:17:34 UTC (rev 36311)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2ComponentsValidator.java 2011-11-12
00:45:29 UTC (rev 36312)
@@ -1,149 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2010 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.jsf.web.validation.jsf2;
-
-import java.io.InputStream;
-import java.util.Scanner;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IProject;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.core.runtime.IProgressMonitor;
-import org.eclipse.wst.validation.ValidationResult;
-import org.eclipse.wst.validation.ValidationState;
-import org.eclipse.wst.validation.internal.provisional.core.IMessage;
-import org.eclipse.wst.xml.core.internal.validation.core.NestedValidatorContext;
-import org.eclipse.wst.xml.core.internal.validation.core.ValidationMessage;
-import org.eclipse.wst.xml.core.internal.validation.core.ValidationReport;
-import org.eclipse.wst.xml.core.internal.validation.eclipse.Validator;
-import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
-import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2AttrTempComponent;
-import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2CompositeTempComponent;
-import org.jboss.tools.jsf.web.validation.jsf2.components.JSF2URITempComponent;
-import org.jboss.tools.jsf.web.validation.jsf2.util.JSF2ValidatorConstants;
-import org.jboss.tools.jst.web.kb.IKbProject;
-import org.jboss.tools.jst.web.kb.KbProjectFactory;
-
-/**
- * Validates full file, when we click validate in Context menu
- *
- * @author yzhishko
- * @author mareshkau
- *
- */
-
-@SuppressWarnings("restriction")
-public class JSF2ComponentsValidator extends Validator {
-
- private IKbProject kbProject;
- private IFile file;
-
- @Override
- public ValidationResult validate(IResource resource, int kind,
- ValidationState state, IProgressMonitor monitor) {
- ValidationResult result = new ValidationResult();
- if (resource instanceof IFile) {
- IFile file = (IFile) resource;
- if (!isValidate(file)) {
- return result;
- }
- this.file = file;
- return super.validate(resource, kind, state, monitor);
- }
- return result;
- }
-
- @Override
- public ValidationReport validate(String uri, InputStream inputstream,
- NestedValidatorContext context, ValidationResult result) {
- JSF2XMLValidator validator = JSF2XMLValidator.getInstance();
- return validator.validate(file, uri);
- }
-
- protected boolean isValidate(IFile file) {
- if (!file.isAccessible() || !file.isSynchronized(IResource.DEPTH_ZERO) ||
file.getProject() == null
- || !file.getProject().isAccessible()) {
- return false;
- }
- IProject project = file.getProject();
- kbProject = KbProjectFactory.getKbProject(project, false);
- if (kbProject == null) {
- return false;
- }
- boolean isValidate = false;
- try {
- InputStream is = file.getContents();
- Scanner scanner = new Scanner(is);
- while (scanner.hasNextLine()) {
- if (scanner.nextLine()
- .indexOf(JSF2ResourceUtil.JSF2_URI_PREFIX) != -1) {
- isValidate = true;
- scanner.close();
- break;
- }
- }
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- return isValidate;
- }
- return isValidate;
- }
-
- @Override
- protected void addInfoToMessage(ValidationMessage validationMessage,
- IMessage message) {
- Object[] args = validationMessage.getMessageArguments();
- if (args == null) {
- return;
- }
- if (args[0] instanceof JSF2CompositeTempComponent) {
- JSF2CompositeTempComponent component = (JSF2CompositeTempComponent) args[0];
- message.setAttribute(JSF2ValidatorConstants.JSF2_TYPE_KEY,
- component.getType());
- message.setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
- component.getComponentResourceLocation());
- message.setAttribute(JSF2ResourceUtil.JSF2_COMPONENT_NAME,
component.getElement().getLocalName());
- String[] attrNames = component.getAttrNames();
- if (attrNames != null) {
- for (int i = 0; i < attrNames.length; i++) {
- message.setAttribute(
- JSF2ValidatorConstants.JSF2_ATTR_NAME_KEY
- + String.valueOf(i), attrNames[i]);
- }
- }
- return;
- }
- if (args[0] instanceof JSF2AttrTempComponent) {
- JSF2AttrTempComponent component = (JSF2AttrTempComponent) args[0];
- message.setAttribute(JSF2ValidatorConstants.JSF2_TYPE_KEY,
- component.getType());
- message.setAttribute(JSF2ValidatorConstants.JSF2_ATTR_NAME_KEY,
- component.getName());
- message.setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
- component.getComponentResourceLocation());
- message.setAttribute(JSF2ResourceUtil.JSF2_COMPONENT_NAME,
component.getElementName());
- return;
- }
- if (args[0] instanceof JSF2URITempComponent) {
- JSF2URITempComponent component = (JSF2URITempComponent) args[0];
- message.setAttribute(JSF2ValidatorConstants.JSF2_TYPE_KEY,
- JSF2ValidatorConstants.JSF2_URI_TYPE);
- message.setAttribute(JSF2ValidatorConstants.JSF2_URI_NAME_KEY,
- component.getURI());
- message.setAttribute(JSF2ResourceUtil.COMPONENT_RESOURCE_PATH_KEY,
- component.getResourcesFolder());
- }
- }
-
-}
Deleted:
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java
===================================================================
---
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2011-11-12
00:17:34 UTC (rev 36311)
+++
trunk/jsf/plugins/org.jboss.tools.jsf/src/org/jboss/tools/jsf/web/validation/jsf2/JSF2SourceValidator.java 2011-11-12
00:45:29 UTC (rev 36312)
@@ -1,92 +0,0 @@
-/*******************************************************************************
- * Copyright (c) 2007-2010 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
- *
- * Contributors:
- * Red Hat, Inc. - initial API and implementation
- ******************************************************************************/
-
-package org.jboss.tools.jsf.web.validation.jsf2;
-
-import org.eclipse.core.resources.IFile;
-import org.eclipse.core.resources.IMarker;
-import org.eclipse.core.resources.IResource;
-import org.eclipse.core.runtime.CoreException;
-import org.eclipse.jface.text.IDocument;
-import org.eclipse.jface.text.IRegion;
-import org.eclipse.wst.sse.ui.internal.reconcile.validator.ISourceValidator;
-import org.eclipse.wst.validation.internal.core.Message;
-import org.eclipse.wst.validation.internal.core.ValidationException;
-import org.eclipse.wst.validation.internal.provisional.core.IReporter;
-import org.eclipse.wst.validation.internal.provisional.core.IValidationContext;
-import org.eclipse.wst.validation.internal.provisional.core.IValidator;
-import org.eclipse.wst.xml.core.internal.provisional.document.IDOMDocument;
-import org.jboss.tools.jsf.JSFModelPlugin;
-import org.jboss.tools.jsf.jsf2.model.JSF2ComponentModelManager;
-import org.jboss.tools.jsf.jsf2.util.JSF2ResourceUtil;
-import org.jboss.tools.jsf.web.validation.IJSFValidationComponent;
-import org.jboss.tools.jsf.web.validation.LocalizedMessage;
-
-/**
- * Validates when we change smth in file
- *
- * @author yzhishko
- * @author mareshkau
- *
- */
-
-@SuppressWarnings("restriction")
-public class JSF2SourceValidator implements IValidator, ISourceValidator {
-
- private IDOMDocument document;
- private IFile validateFile;
-
- public void cleanup(IReporter reporter) {
- }
-
- public void validate(IValidationContext helper, IReporter reporter)
- throws ValidationException {
- if (document != null) {
- IResource resource = JSF2ResourceUtil.getValidatingResource(helper);
- if (resource instanceof IFile) {
- validateFile = (IFile) resource;
- reportProblems(reporter,
- JSF2XMLValidator.getValidationComponents(document,
- (IFile) resource),resource);
- }
- }
- }
-
- public void connect(IDocument document) {
- this.document = JSF2ComponentModelManager
- .getReadableDOMDocument(document);
- }
-
- public void disconnect(IDocument document) {
- document = null;
- validateFile = null;
- }
-
- public void validate(IRegion dirtyRegion, IValidationContext helper,
- IReporter reporter) {
- }
-
- private void reportProblems(IReporter reporter,
- IJSFValidationComponent[] validationComponents,IResource resource) {
- try {
- resource.deleteMarkers(JSF2XMLValidator.JSF2_PROBLEM_ID, false,
IResource.DEPTH_INFINITE);
- for (int i = 0; i < validationComponents.length; i++) {
- Message locMessage =
LocalizedMessage.createJSF2LocalizedMessage(validationComponents[i], validateFile);
- reporter.addMessage(this, locMessage);
- IMarker marker = resource.createMarker(JSF2XMLValidator.JSF2_PROBLEM_ID);
- marker.setAttributes(locMessage.getAttributes());
- }
- } catch (CoreException e) {
- JSFModelPlugin.getPluginLog().logError(e);
- }
-
- }
-}
\ No newline at end of file