Author: dgolovin
Date: 2009-04-14 20:53:23 -0400 (Tue, 14 Apr 2009)
New Revision: 14748
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/DefaultProblemReporter.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemBuffer.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemReportingHelper.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/Submit.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/DtdResolver.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SAXValidator.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SafeDocumentBuilderFactory.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolver.java
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLUtilities.java
Log:
code clean-up
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/DefaultProblemReporter.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/DefaultProblemReporter.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/DefaultProblemReporter.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -20,7 +20,9 @@
public class DefaultProblemReporter implements IProblemReporter {
public void reportProblem(IStatus status) {
- if(status != null)
Platform.getLog(Platform.getBundle("org.jboss.tools.common")).log(status);
+ if(status != null) {
+ Platform.getLog(Platform.getBundle("org.jboss.tools.common")).log(status);
+ }
}
}
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemBuffer.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemBuffer.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemBuffer.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -11,14 +11,15 @@
package org.jboss.tools.common.reporting;
import java.io.File;
+
import org.eclipse.core.internal.runtime.PlatformLogWriter;
import org.eclipse.core.runtime.ILogListener;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.core.runtime.Platform;
import org.eclipse.core.runtime.adaptor.EclipseLog;
import org.eclipse.osgi.framework.log.FrameworkLog;
+import org.jboss.tools.common.util.FileUtil;
import org.osgi.framework.Bundle;
-import org.jboss.tools.common.util.FileUtil;
/**
* This class is intended only to be called by Report Problem Framework.
@@ -43,7 +44,9 @@
*/
public int getSize() {
String s = getContent();
- if(s.length() == 0) return 0;
+ if(s.length() == 0) {
+ return 0;
+ }
int i = 0;
int c = 0;
while(i < s.length()) {
@@ -51,7 +54,9 @@
if(i >= 0) {
++c;
++i;
- } else break;
+ } else {
+ break;
+ }
}
return c;
}
@@ -72,7 +77,9 @@
public void clean() {
File f = getLogFile();
- if(f.exists()) f.delete();
+ if(f.exists()) {
+ f.delete();
+ }
}
/**
@@ -88,7 +95,9 @@
if(other != null && other.length() > 0) {
sb.append("Other=" + other + "\n");
}
- if(text != null) sb.append(text);
+ if(text != null) {
+ sb.append(text);
+ }
String reportText = sb.toString();
Submit.getInstance().submit(reportText, cleanBuffer);
}
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemReportingHelper.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemReportingHelper.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/ProblemReportingHelper.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -35,7 +35,9 @@
* @param throwable
*/
public static void reportProblem(String plugin, String message, Throwable throwable) {
- if(message==null) throw new IllegalArgumentException("Message parameter cannot be
null");
+ if(message==null) {
+ throw new IllegalArgumentException("Message parameter cannot be null");
+ }
IStatus status = new Status(IStatus.ERROR, plugin, 0, message, throwable);
reportProblem(status);
}
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/Submit.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/Submit.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/reporting/Submit.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -53,6 +53,7 @@
*/
public void submit(final String reportText, final boolean cleanBuffer) {
Job job = new Job(JOB_NAME) {
+ @Override
public IStatus run(IProgressMonitor monitor) {
try {
submitReport(reportText);
@@ -62,7 +63,7 @@
if(exceptionMessage!=null && exceptionMessage.trim().length()>0) {
message = message + ".\r\n" + e.getClass().getName() + ": " +
exceptionMessage;
}
- Status status = new Status(Status.WARNING, CommonPlugin.PLUGIN_ID, Status.WARNING,
message, e);
+ Status status = new Status(IStatus.WARNING, CommonPlugin.PLUGIN_ID, IStatus.WARNING,
message, e);
return status;
}
if(cleanBuffer) {
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/DtdResolver.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/DtdResolver.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/DtdResolver.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -23,14 +23,13 @@
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.Platform;
import org.eclipse.wst.xml.core.internal.XMLCorePlugin;
+import org.jboss.tools.common.CommonPlugin;
+import org.jboss.tools.common.util.HttpUtil;
+import org.osgi.framework.Bundle;
import org.xml.sax.EntityResolver;
import org.xml.sax.InputSource;
import org.xml.sax.SAXException;
-import org.jboss.tools.common.CommonPlugin;
-import org.jboss.tools.common.util.HttpUtil;
-import org.osgi.framework.Bundle;
-
/**
* @author igels
*/
@@ -39,9 +38,13 @@
public InputStream getInputStream(String publicId, String systemId) throws
SAXException, IOException {
String location =
XMLCorePlugin.getDefault().getDefaultXMLCatalog().resolvePublic(publicId, systemId);
- if(location == null) location =
XMLCorePlugin.getDefault().getDefaultXMLCatalog().resolveSystem(systemId);
- if(location == null) location =
XMLCorePlugin.getDefault().getDefaultXMLCatalog().resolveURI(systemId);
if(location == null) {
+ location = XMLCorePlugin.getDefault().getDefaultXMLCatalog().resolveSystem(systemId);
+ }
+ if(location == null) {
+ location = XMLCorePlugin.getDefault().getDefaultXMLCatalog().resolveURI(systemId);
+ }
+ if(location == null) {
if(systemId != null && systemId.startsWith("file:") &&
systemId.endsWith(".xsd")) {
int i = systemId.replace('\\', '/').lastIndexOf('/');
String systemId2 = systemId.substring(i + 1);
@@ -56,11 +59,15 @@
String s = systemId.substring(q + 1);
URL u = b.getEntry("/dtdsAndSchemas/" + s);
try {
- if(u != null) u = FileLocator.resolve(u);
+ if(u != null) {
+ u = FileLocator.resolve(u);
+ }
} catch (IOException ee) {
u = null;
}
- if(u != null) location = u.toString();
+ if(u != null) {
+ location = u.toString();
+ }
}
}
if(location == null) {
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SAXValidator.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SAXValidator.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SAXValidator.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -122,9 +122,10 @@
ErrorHandlerImpl h = new ErrorHandlerImpl();
try {
XMLReader parser = createParser();
- if(parser==null)
- // TODO - Move to NLS bundle
+ if(parser==null) {
+ // TODO - Move to NLS bundle
return new String[]{ "error: Unable to instantiate parser
("+DEFAULT_SAX_PARSER_CLASS_NAME+")"};
+ }
parser.setErrorHandler(h);
parser.parse(is);
} catch (SAXException e) {
@@ -140,7 +141,7 @@
} finally {
// Thread.currentThread().setContextClassLoader(cc);
}
- return (String[])h.errors.toArray(new String[0]);
+ return h.errors.toArray(new String[0]);
}
/**
@@ -161,13 +162,17 @@
Bundle b = Platform.getBundle(CommonPlugin.PLUGIN_ID);
String location = Platform.getStateLocation(b).toString().replace('\\',
'/');
- if(!location.endsWith("/")) location += "/";
+ if(!location.endsWith("/")) {
+ location += "/";
+ }
String urlString = null;
URL url = null;
try {
url = Platform.resolve(b.getEntry("/"));
urlString = url.toString();
- if(!urlString.endsWith("/")) urlString += "/";
+ if(!urlString.endsWith("/")) {
+ urlString += "/";
+ }
urlString += "schemas";
} catch (IOException e) {
CommonPlugin.getPluginLog().logError(e);
@@ -203,7 +208,8 @@
/**
*
*/
- public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) throws
IOException {
+ @Override
+ public String resolveIdentifier(XMLResourceIdentifier resourceIdentifier) throws
IOException {
String literal = resourceIdentifier.getLiteralSystemId();
if(literal != null && !literals.contains(literal)) {
literals.add(literal);
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SafeDocumentBuilderFactory.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SafeDocumentBuilderFactory.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/SafeDocumentBuilderFactory.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -38,12 +38,15 @@
this.validate = validate;
}
+ @Override
public void run () {
ClassLoader loader = Thread.currentThread().getContextClassLoader();
Thread.currentThread().setContextClassLoader(getClass().getClassLoader());
try {
DocumentBuilderFactory f = DocumentBuilderFactory.newInstance();
- if(validate) f.setValidating(validate);
+ if(validate) {
+ f.setValidating(validate);
+ }
/// f.setExpandEntityReferences(false);
d = f.newDocumentBuilder();
if(!validate) {
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolver.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolver.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLEntityResolver.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -10,7 +10,9 @@
import java.util.Properties;
import org.eclipse.core.runtime.FileLocator;
-import org.xml.sax.*;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
/**
* @author valera
@@ -26,7 +28,9 @@
public static void registerPublicEntity(String publicId, Class<?> loader,
String resourceName) throws IOException {
URL url = resolve(loader, resourceName);
- if(url != null) registerPublicEntity(publicId, url.toString());
+ if(url != null) {
+ registerPublicEntity(publicId, url.toString());
+ }
}
public static void registerSystemEntity(String systemId, String url) {
@@ -35,7 +39,9 @@
public static void registerSystemEntity(String systemId, Class<?> loader,
String resourceName) throws IOException {
URL url = resolve(loader, resourceName);
- if(url != null) registerSystemEntity(systemId, url.toString());
+ if(url != null) {
+ registerSystemEntity(systemId, url.toString());
+ }
}
static URL resolve(Class<?> loader, String resourceName) throws IOException {
Modified:
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLUtilities.java
===================================================================
---
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLUtilities.java 2009-04-14
22:53:02 UTC (rev 14747)
+++
trunk/common/plugins/org.jboss.tools.common/src/org/jboss/tools/common/xml/XMLUtilities.java 2009-04-15
00:53:23 UTC (rev 14748)
@@ -10,13 +10,36 @@
******************************************************************************/
package org.jboss.tools.common.xml;
-import java.io.*;
-import java.util.*;
+import java.io.BufferedWriter;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.FileWriter;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.Reader;
+import java.io.Writer;
+import java.util.ArrayList;
+
import javax.xml.parsers.DocumentBuilder;
-import org.apache.xml.serialize.*;
+
+import org.apache.xml.serialize.LineSeparator;
+import org.apache.xml.serialize.Method;
+import org.apache.xml.serialize.OutputFormat;
+import org.apache.xml.serialize.XMLSerializer;
import org.jboss.tools.common.CommonPlugin;
-import org.w3c.dom.*;
-import org.xml.sax.*;
+import org.w3c.dom.Comment;
+import org.w3c.dom.DOMException;
+import org.w3c.dom.DOMImplementation;
+import org.w3c.dom.Document;
+import org.w3c.dom.DocumentType;
+import org.w3c.dom.Element;
+import org.w3c.dom.Node;
+import org.w3c.dom.NodeList;
+import org.w3c.dom.Text;
+import org.xml.sax.EntityResolver;
+import org.xml.sax.InputSource;
+import org.xml.sax.SAXException;
public class XMLUtilities {
public static boolean hasAttribute(Element e, String s) {
@@ -68,7 +91,9 @@
public static Element[] getAncestors(Element parent, String name) {
int i = name.indexOf('.');
- if(i < 0) return getChildren(parent, name);
+ if(i < 0) {
+ return getChildren(parent, name);
+ }
Element p = getUniqueChild(parent, name.substring(0, i));
return (p == null) ? new Element[0] : getAncestors(p, name.substring(i + 1));
}
@@ -126,7 +151,9 @@
}
public static Element getElement(File file, EntityResolver resolver) {
- if(file == null || !file.isFile()) return null;
+ if(file == null || !file.isFile()) {
+ return null;
+ }
java.io.FileReader fr = null;
try {
fr = new java.io.FileReader(file);
@@ -140,7 +167,9 @@
CommonPlugin.getPluginLog().logError(e);
} finally {
try {
- if (fr != null) fr.close();
+ if (fr != null) {
+ fr.close();
+ }
} catch (IOException e) {
CommonPlugin.getPluginLog().logError(e);
}
@@ -181,7 +210,9 @@
public static Document getDocument(InputSource is, EntityResolver resolver) throws
SAXException, IOException{
DocumentBuilder builder = createDocumentBuilder(false);
- if(resolver != null) builder.setEntityResolver(resolver);
+ if(resolver != null) {
+ builder.setEntityResolver(resolver);
+ }
return builder.parse(is);
}
@@ -202,21 +233,31 @@
ErrorHandlerImpl h = new ErrorHandlerImpl();
try {
DocumentBuilder builder = createDocumentBuilder(checkDTD);
- if(resolver != null) builder.setEntityResolver(resolver);
+ if(resolver != null) {
+ builder.setEntityResolver(resolver);
+ }
builder.setErrorHandler(h);
builder.parse(is);
} catch (IOException e) {
- if(h.errors.isEmpty()) return new String[]{"Unexpected parser
error:0:0",e.toString()};
+ if(h.errors.isEmpty()) {
+ return new String[]{"Unexpected parser error:0:0",e.toString()};
+ }
} catch (SAXException e) {
- if(h.errors.isEmpty()) return new String[]{"Unexpected parser
error:0:0",e.toString()};
+ if(h.errors.isEmpty()) {
+ return new String[]{"Unexpected parser error:0:0",e.toString()};
+ }
}
return h.errors.toArray(new String[0]);
}
public static final void serialize(Element element, String filename) throws
IOException {
File f = new File(filename);
- if(f.exists() && !f.canWrite()) return;
- if(!f.exists()) f.createNewFile();
+ if(f.exists() && !f.canWrite()) {
+ return;
+ }
+ if(!f.exists()) {
+ f.createNewFile();
+ }
FileWriter fw = new FileWriter(f);
serialize(element, new BufferedWriter(fw));
fw.close();
@@ -226,10 +267,14 @@
public static String getEncoding(String body) {
int i = body.indexOf(ENCODING);
- if(i < 0) return UTF8;
+ if(i < 0) {
+ return UTF8;
+ }
i = i + ENCODING.length();
int j = body.indexOf('"', i);
- if(j < 0) return UTF8;
+ if(j < 0) {
+ return UTF8;
+ }
return body.substring(i, j);
}
@@ -241,14 +286,18 @@
}
public static final boolean serialize(Element element, Writer w) throws IOException
{
- if(element == null) return false;
+ if(element == null) {
+ return false;
+ }
serialize(element, new XMLSerializer(w, createOutputFormat(UTF8)));
w.close();
return true;
}
public static final boolean serialize(Element element, OutputStream w) throws
IOException {
- if(element == null) return false;
+ if(element == null) {
+ return false;
+ }
serialize(element, new XMLSerializer(w, createOutputFormat(UTF8)));
w.close();
return true;
@@ -260,7 +309,9 @@
}
public static void serialize(Document document, XMLSerializer serial) throws
IOException {
- if(serial == null || document == null) return;
+ if(serial == null || document == null) {
+ return;
+ }
serial.asDOMSerializer();
serial.serialize(document);
}
@@ -270,7 +321,9 @@
}
public static final boolean serialize(Document document, Writer w, String encoding)
throws IOException {
- if(document == null) return false;
+ if(document == null) {
+ return false;
+ }
serialize(document, new XMLSerializer(w, createOutputFormat(encoding)));
w.close();
return true;
@@ -289,7 +342,9 @@
sb.append(((Text) nc).getData());
} else if (nc.getNodeType() == Node.TEXT_NODE) {
String txt = ((Text) nc).getData();
- if(trim) txt = txt.trim();
+ if(trim) {
+ txt = txt.trim();
+ }
sb.append(txt);
}
}
@@ -300,7 +355,9 @@
StringBuffer sb = new StringBuffer();
Node node = elem.getPreviousSibling();
while (node != null) {
- if (node.getNodeType() == Node.ELEMENT_NODE) break;
+ if (node.getNodeType() == Node.ELEMENT_NODE) {
+ break;
+ }
if (node.getNodeType() == Node.COMMENT_NODE) {
if (sb.length() > 0) {
sb.insert(0, '\n');