modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
| 91 +++++++++-
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
| 4
modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
| 11 +
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
| 55 ++++++
modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
| 2
5 files changed, 159 insertions(+), 4 deletions(-)
New commits:
commit 6abff4105f7a878cb0fb2b8b25a4814c880cc60b
Author: John Sanda <jsanda(a)redhat.com>
Date: Fri Aug 26 22:00:26 2011 -0400
[BZ 732078] Adding support for detecting "viewable" files
This commit introduces a simple approach for determing whether or not a
file is viewable. The approach taken is try and determine whether or not
the file is a binary file. DriftManagerBean uses a hard coded list of
known file extensions for binary files. This is in no way as robust as
it could be but it may be sufficient. Since the solution is not robust,
I think it is important to try and detect if a file is a binary type as
opposed to detecting whether or not it is a text file suitable for
viewing. The rationale behind that is we do not want to prevent a user
from viewing a file or viewing a diff of a file when they should be able
to.
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
index 1dd9e56..31c888d 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/drift/DriftDetailsView.java
@@ -145,8 +145,95 @@ public class DriftDetailsView extends LocatableVLayout {
addMember(changeSetForm);
- // the drift history item itself
+ GWTServiceLookup.getDriftService().isBinaryFile(drift, new
AsyncCallback<Boolean>() {
+ @Override
+ public void onFailure(Throwable caught) {
+ CoreGUI.getErrorHandler().handleError("Failed to look up file
type", caught);
+ }
+
+ @Override
+ public void onSuccess(Boolean isBinary) {
+ if (isBinary) {
+ addMember(createDriftFormForBinaryFile(drift, previousVersion));
+ } else {
+ addMember(createDriftFormForTextFile(drift, previousVersion));
+ }
+ }
+ });
+ }
+
+ private DynamicForm createDriftFormForBinaryFile(Drift drift, DriftChangeSet
previousVersion) {
+ DynamicForm driftForm = new
LocatableDynamicForm(extendLocatorId("form"));
+ driftForm.setIsGroup(true);
+ driftForm.setGroupTitle(MSG.view_drift());
+ driftForm.setWrapItemTitles(false);
+ driftForm.setNumCols(4);
+
+ SpacerItem spacer = new SpacerItem();
+
+ StaticTextItem id = new StaticTextItem("id", MSG.common_title_id());
+ id.setValue(drift.getId());
+
+ StaticTextItem path = new StaticTextItem("path",
MSG.common_title_path());
+ path.setValue(drift.getPath());
+
+ StaticTextItem timestamp = new StaticTextItem("timestamp",
MSG.common_title_timestamp());
+ timestamp.setValue(TimestampCellFormatter.format(drift.getCtime(),
DATE_TIME_FORMAT_FULL));
+
+ StaticTextItem category = new StaticTextItem("category",
MSG.common_title_category());
+
+ LinkedHashMap<String, String> catIconsMap = new LinkedHashMap<String,
String>(3);
+ catIconsMap.put(DriftDataSource.CATEGORY_ICON_ADD,
DriftDataSource.CATEGORY_ICON_ADD);
+ catIconsMap.put(DriftDataSource.CATEGORY_ICON_CHANGE,
DriftDataSource.CATEGORY_ICON_CHANGE);
+ catIconsMap.put(DriftDataSource.CATEGORY_ICON_REMOVE,
DriftDataSource.CATEGORY_ICON_REMOVE);
+ LinkedHashMap<String, String> catValueMap = new LinkedHashMap<String,
String>(3);
+ catValueMap.put(DriftDataSource.CATEGORY_ICON_ADD,
MSG.view_drift_category_fileAdded());
+ catValueMap.put(DriftDataSource.CATEGORY_ICON_CHANGE,
MSG.view_drift_category_fileChanged());
+ catValueMap.put(DriftDataSource.CATEGORY_ICON_REMOVE,
MSG.view_drift_category_fileRemoved());
+ category.setValueMap(catValueMap);
+ category.setValueIcons(catIconsMap);
+ category.setShowIcons(true);
+
+ StaticTextItem oldFile = new StaticTextItem("oldFile",
MSG.view_drift_table_oldFile());
+ FormItem oldFileLink = null;
+
+ StaticTextItem newFile = new StaticTextItem("newFile",
MSG.view_drift_table_newFile());
+ FormItem newFileLink = null;
+
+ switch (drift.getCategory()) {
+ case FILE_ADDED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_ADD);
+ oldFile.setValue(MSG.common_label_none());
+ oldFileLink = spacer;
+ newFile.setValue(drift.getNewDriftFile().getHashId());
+ newFileLink = spacer;
+ break;
+
+ case FILE_CHANGED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_CHANGE);
+ oldFile.setValue(drift.getOldDriftFile().getHashId());
+ oldFileLink = createViewFileLink(drift.getOldDriftFile().getHashId(),
drift.getPath(),
+ previousVersion.getVersion());
+ newFile.setValue(drift.getNewDriftFile().getHashId());
+ newFileLink = spacer;
+ break;
+
+ case FILE_REMOVED:
+ category.setValue(DriftDataSource.CATEGORY_ICON_REMOVE);
+ oldFile.setValue(drift.getOldDriftFile().getHashId());
+ oldFileLink = spacer;
+ newFile.setValue(MSG.common_label_none());
+ newFileLink = spacer;
+ break;
+ }
+
+ driftForm.setItems(id, spacer, path, spacer, category, spacer, timestamp, spacer,
oldFile, oldFileLink,
+ newFile, newFileLink);
+
+ return driftForm;
+ }
+ private DynamicForm createDriftFormForTextFile(Drift drift, DriftChangeSet
previousVersion) {
DynamicForm driftForm = new
LocatableDynamicForm(extendLocatorId("form"));
driftForm.setIsGroup(true);
driftForm.setGroupTitle(MSG.view_drift());
@@ -232,7 +319,7 @@ public class DriftDetailsView extends LocatableVLayout {
newFile, newFileLink);
}
- addMember(driftForm);
+ return driftForm;
}
private LinkItem createViewFileLink(final String hash, final String path, final int
version) {
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
index f8e2b20..9b96231 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/client/gwt/DriftGWTService.java
@@ -111,6 +111,8 @@ public interface DriftGWTService extends RemoteService {
String getDriftFileBits(String hash) throws RuntimeException;
- FileDiffReport generateUnifiedDiff(Drift drift);
+ FileDiffReport generateUnifiedDiff(Drift drift) throws RuntimeException;
+
+ boolean isBinaryFile(Drift drift) throws RuntimeException;
}
\ No newline at end of file
diff --git
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
index a71bba2..e8531be 100644
---
a/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
+++
b/modules/enterprise/gui/coregui/src/main/java/org/rhq/enterprise/gui/coregui/server/gwt/DriftGWTServiceImpl.java
@@ -151,11 +151,20 @@ public class DriftGWTServiceImpl extends AbstractGWTServiceImpl
implements Drift
}
@Override
- public FileDiffReport generateUnifiedDiff(Drift drift) {
+ public FileDiffReport generateUnifiedDiff(Drift drift) throws RuntimeException {
try {
return driftManager.generateUnifiedDiff(drift);
} catch (Throwable t) {
throw getExceptionToThrowToClient(t);
}
}
+
+ @Override
+ public boolean isBinaryFile(Drift drift) throws RuntimeException {
+ try {
+ return driftManager.isBinaryFile(drift);
+ } catch (Throwable t) {
+ throw getExceptionToThrowToClient(t);
+ }
+ }
}
\ No newline at end of file
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
index 3f8ffa7..b1a7415 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerBean.java
@@ -20,7 +20,9 @@ package org.rhq.enterprise.server.drift;
import java.io.File;
import java.io.InputStream;
+import java.util.HashSet;
import java.util.List;
+import java.util.Set;
import javax.ejb.EJB;
import javax.ejb.Stateless;
@@ -92,6 +94,47 @@ import static javax.ejb.TransactionAttributeType.REQUIRES_NEW;
@Stateless
public class DriftManagerBean implements DriftManagerLocal, DriftManagerRemote {
+ private static Set<String> binaryFileTypes = new HashSet<String>();
+
+ static {
+ binaryFileTypes.add("jar");
+ binaryFileTypes.add("war");
+ binaryFileTypes.add("ear");
+ binaryFileTypes.add("sar"); // jboss service
+ binaryFileTypes.add("har"); // hibernate archive
+ binaryFileTypes.add("rar"); // resource adapter
+ binaryFileTypes.add("wsr"); // jboss web service archive
+ binaryFileTypes.add("zip");
+ binaryFileTypes.add("tar");
+ binaryFileTypes.add("bz2");
+ binaryFileTypes.add("gz");
+ binaryFileTypes.add("rpm");
+ binaryFileTypes.add("so");
+ binaryFileTypes.add("dll");
+ binaryFileTypes.add("exe");
+ binaryFileTypes.add("jpg");
+ binaryFileTypes.add("png");
+ binaryFileTypes.add("jpeg");
+ binaryFileTypes.add("pdf");
+ binaryFileTypes.add("swf");
+ binaryFileTypes.add("bpm");
+ binaryFileTypes.add("tiff");
+ binaryFileTypes.add("svg");
+ binaryFileTypes.add("doc");
+ binaryFileTypes.add("mp3");
+ binaryFileTypes.add("wav");
+ binaryFileTypes.add("m4a");
+ binaryFileTypes.add("mov");
+ binaryFileTypes.add("mpeg");
+ binaryFileTypes.add("avi");
+ binaryFileTypes.add("mp4");
+ binaryFileTypes.add("wmv");
+ binaryFileTypes.add("deb");
+ binaryFileTypes.add("sit");
+ binaryFileTypes.add("iso");
+ binaryFileTypes.add("dmg");
+ }
+
// TODO Should security checks be handled here instead of delegating to the drift
plugin?
// Currently any security checks that need to be performed are delegated to the
plugin.
// This is fine *so far* since the only plugin is the default which is our existing
SLSB
@@ -440,6 +483,18 @@ public class DriftManagerBean implements DriftManagerLocal,
DriftManagerRemote {
}
}
+ @Override
+ public boolean isBinaryFile(Drift drift) {
+ String path = drift.getPath();
+ int index = path.lastIndexOf('.');
+
+ if (index == -1 || index == path.length() - 1) {
+ return false;
+ }
+
+ return binaryFileTypes.contains(path.substring(index + 1, path.length()));
+ }
+
private DriftServerPluginFacet getServerPlugin() {
MasterServerPluginContainer masterPC =
LookupUtil.getServerPluginService().getMasterPluginContainer();
if (masterPC == null) {
diff --git
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
index c6fc043..663b626 100644
---
a/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
+++
b/modules/enterprise/server/jar/src/main/java/org/rhq/enterprise/server/drift/DriftManagerLocal.java
@@ -129,4 +129,6 @@ public interface DriftManagerLocal extends DriftServerPluginFacet,
DriftManagerR
* referenced by drift
*/
FileDiffReport generateUnifiedDiff(Drift drift);
+
+ boolean isBinaryFile(Drift drift);
}