/* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you under the Apache * License, Version 2.0 (the "License"); you may not use this file * except in compliance with the License. You may obtain a copy of * the License at http://www.apache.org/licenses/LICENSE-2.0 .
*/ package com.sun.star.wizards.common;
/** * This class delivers static convenience methods * to use with ucb SimpleFileAccess service. * You can also instantiate the class, to encapsulate * some functionality of SimpleFileAccess. The instance * keeps a reference to an XSimpleFileAccess and an * XFileIdentifierConverter, saves the permanent * overhead of querying for those interfaces, and delivers * convenience methods for using them. * These Convenience methods include mainly Exception-handling.
*/ publicclass FileAccess
{
/** * Further information on arguments value see in OO Developer Guide, * chapter 6.2.7 * @return the respective path of the office application. A probable following "/" at the end is trimmed.
*/ publicstatic String getOfficePath(XMultiServiceFactory xMSF, String sPath)
{ try
{
String ResultPath = PropertyNames.EMPTY_STRING;
XInterface xInterface = (XInterface) xMSF.createInstance("com.sun.star.util.PathSettings");
ResultPath = com.sun.star.uno.AnyConverter.toString(Helper.getUnoPropertyValue(xInterface, sPath));
ResultPath = deleteLastSlashfromUrl(ResultPath); return ResultPath;
} catch (Exception exception)
{
exception.printStackTrace(System.err); return PropertyNames.EMPTY_STRING;
}
}
/** * Further information on arguments value see in OO Developer Guide, * chapter 6.2.7 * @param sType use "share" or "user". Set to PropertyNames.EMPTY_STRING if not needed eg for the WorkPath; * In the return Officepath a possible slash at the end is cut off
*/ publicstatic String getOfficePath(XMultiServiceFactory xMSF, String sPath, String sType, String sSearchDir) throws NoValidPathException
{ //This method currently only works with sPath="Template"
// if there exists a language in the directory, we try to add the right language
sPath = checkIfLanguagePathExists(xMSF, sPath);
aPathList.add(sPath);
}
aPathList.addAll(Arrays.asList(Template_user));
aPathList.add(Template_writable); // There was a bug here, because we have to search through the whole list of paths
} catch (java.lang.Exception exception)
{
exception.printStackTrace(System.err);
} return aPathList;
}
/** * We search in all given path for a given file
*/ privatestatic String addPath(String _sPath, String _sPath2)
{
String sNewPath; if (!_sPath.endsWith("/"))
{
_sPath += "/";
} if (_sPath2.startsWith("/"))
{
_sPath2 = _sPath2.substring(1);
}
sNewPath = _sPath + _sPath2; return sNewPath;
}
public FileAccess(XMultiServiceFactory xmsf) throws com.sun.star.uno.Exception
{ //get a simple file access...
Object fa = xmsf.createInstance("com.sun.star.ucb.SimpleFileAccess");
fileAccess = UnoRuntime.queryInterface(XSimpleFileAccess2.class, fa); //get the file identifier converter
Object fcv = xmsf.createInstance("com.sun.star.ucb.FileContentProvider");
UnoRuntime.queryInterface(XFileIdentifierConverter.class, fcv);
}
/** * @return the extension of the given filename.
*/ privatestatic String getExtension(String filename)
{ int p = filename.indexOf('.'); if (p == -1)
{ return PropertyNames.EMPTY_STRING;
} else
{ do
{
filename = filename.substring(p + 1);
} while ((p = filename.indexOf('.')) > -1);
} return filename;
}
/** * @param def what to return in case of an exception * @return true if the given file exists or not. * if an exception occurs, returns the default value.
*/ publicboolean exists(String filename, boolean def)
{ try
{ return fileAccess.exists(filename);
} catch (CommandAbortedException e)
{
} catch (Exception e)
{
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.