001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html.
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.util.jna;
013:
014: import java.io.File;
015:
016: import org.tmatesoft.svn.core.internal.wc.SVNFileType;
017: import org.tmatesoft.svn.core.internal.wc.SVNFileUtil;
018:
019: /**
020: * @version 1.1.2
021: * @author TMate Software Ltd.
022: */
023: public class SVNJNAUtil {
024:
025: private static boolean ourIsJNAPresent;
026: private static final String JNA_CLASS_NAME = "com.sun.jna.Library";
027:
028: static {
029: try {
030: ClassLoader loader = SVNJNAUtil.class.getClassLoader();
031: if (loader == null) {
032: loader = ClassLoader.getSystemClassLoader();
033: }
034: if (loader != null
035: && loader.loadClass(JNA_CLASS_NAME) != null) {
036: ourIsJNAPresent = true;
037: }
038: } catch (ClassNotFoundException e) {
039: ourIsJNAPresent = false;
040: }
041: }
042:
043: public static boolean isJNAPresent() {
044: return ourIsJNAPresent;
045: }
046:
047: // linux.
048:
049: public static SVNFileType getFileType(File file) {
050: if (isJNAPresent()) {
051: return SVNLinuxUtil.getFileType(file);
052: }
053: return null;
054: }
055:
056: public static Boolean isExecutable(File file) {
057: if (isJNAPresent()) {
058: return SVNLinuxUtil.isExecutable(file);
059: }
060: return null;
061: }
062:
063: public static String getLinkTarget(File file) {
064: if (isJNAPresent()) {
065: return SVNLinuxUtil.getLinkTarget(file);
066: }
067: return null;
068: }
069:
070: public static boolean setExecutable(File file, boolean set) {
071: if (isJNAPresent()) {
072: return SVNLinuxUtil.setExecutable(file, set);
073: }
074: return false;
075: }
076:
077: public static boolean createSymlink(File file, String linkName) {
078: if (isJNAPresent()) {
079: return SVNLinuxUtil.createSymlink(file, linkName);
080: }
081: return false;
082: }
083:
084: // linux and win32.
085: public static boolean setWritable(File file) {
086: if (isJNAPresent()) {
087: return SVNFileUtil.isWindows ? SVNWin32Util
088: .setWritable(file) : SVNLinuxUtil.setWritable(file);
089: }
090: return false;
091: }
092:
093: // win32
094: public static boolean setHidden(File file) {
095: if (isJNAPresent()) {
096: return SVNWin32Util.setHidden(file);
097: }
098: return false;
099: }
100:
101: public static boolean moveFile(File src, File dst) {
102: if (isJNAPresent()) {
103: return SVNWin32Util.moveFile(src, dst);
104: }
105: return false;
106: }
107:
108: public static String decrypt(String encryptedData) {
109: if (isJNAPresent()) {
110: return SVNWinCrypt.decrypt(encryptedData);
111: }
112: return null;
113: }
114:
115: public static String encrypt(String rawData) {
116: if (isJNAPresent()) {
117: return SVNWinCrypt.encrypt(rawData);
118: }
119: return null;
120: }
121:
122: public synchronized static boolean isWinCryptEnabled() {
123: return isJNAPresent() && SVNWinCrypt.isEnabled();
124: }
125: }
|