List of usage examples for org.apache.commons.vfs FileObject exists
public boolean exists() throws FileSystemException;
From source file:com.flywet.platform.bi.mondrian.steps.mondrianinput.MondrianInputMeta.java
/** * Since the exported transformation that runs this will reside in a ZIP file, we can't reference files relatively. * So what this does is turn the name of files into absolute paths OR it simply includes the resource in the ZIP file. * For now, we'll simply turn it into an absolute path and pray that the file is on a shared drive or something like that. // ww w. ja va2s .co m * TODO: create options to configure this behavior */ public String exportResources(VariableSpace space, Map<String, ResourceDefinition> definitions, ResourceNamingInterface resourceNamingInterface, Repository repository) throws KettleException { try { // The object that we're modifying here is a copy of the original! // So let's change the filename from relative to absolute by grabbing the file object... // In case the name of the file comes from previous steps, forget about this! // if (Const.isEmpty(catalog)) { // From : ${Internal.Transformation.Filename.Directory}/../foo/bar.csv // To : /home/matt/test/files/foo/bar.csv // FileObject fileObject = KettleVFS.getFileObject(space.environmentSubstitute(catalog), space); // If the file doesn't exist, forget about this effort too! // if (fileObject.exists()) { // Convert to an absolute path... // catalog = resourceNamingInterface.nameResource(fileObject, space, true); return catalog; } } return null; } catch (Exception e) { throw new KettleException(e); //$NON-NLS-1$ } }
From source file:com.panet.imeta.core.plugins.PluginLoader.java
/** * "Deploys" the plugin jar file./*from ww w . jav a2 s . c o m*/ * * @param parent * @return * @throws FileSystemException */ private FileObject explodeJar(FileObject parent) throws FileSystemException { // By Alex, 7/13/07 // Since the JVM does not support nested jars and // URLClassLoaders, we have to hack it // see // http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=4735639 // // We do so by exploding the jar, sort of like deploying it FileObject dest = VFS.getManager().resolveFile(Const.getKettleDirectory() + File.separator + WORK_DIR); dest.createFolder(); FileObject destFile = dest.resolveFile(parent.getName().getBaseName()); if (!destFile.exists()) destFile.createFolder(); else // delete children for (FileObject child : destFile.getChildren()) child.delete(new AllFileSelector()); // force VFS to treat it as a jar file explicitly with children, // etc. and copy destFile.copyFrom(!(parent instanceof JarFileObject) ? VFS.getManager().resolveFile(JAR + ":" + parent.getName().getURI()) : parent, new AllFileSelector()); return destFile; }
From source file:com.thinkberg.moxo.dav.PutHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { FileObject object = getResourceManager().getFileObject(request.getPathInfo()); try {//from www . j a v a 2s . co m LockManager.getInstance().checkCondition(object, getIf(request)); } catch (LockException e) { if (e.getLocks() != null) { response.sendError(SC_LOCKED); } else { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); } return; } // it is forbidden to write data on a folder if (object.exists() && FileType.FOLDER.equals(object.getType())) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } FileObject parent = object.getParent(); if (!parent.exists()) { response.sendError(HttpServletResponse.SC_FORBIDDEN); return; } if (!FileType.FOLDER.equals(parent.getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); return; } InputStream is = request.getInputStream(); OutputStream os = object.getContent().getOutputStream(); log("PUT sends " + request.getHeader("Content-length") + " bytes"); log("PUT copied " + Util.copyStream(is, os) + " bytes"); os.flush(); object.close(); response.setStatus(HttpServletResponse.SC_CREATED); }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
/** * Override the superclass implementation to make sure GaeVFS "shadows" * exist for local directories./* w w w . j av a 2 s .c o m*/ */ @Override public FileObject getParent() throws FileSystemException { FileObject parent = super.getParent(); if ((parent != null) && !parent.exists()) { // check for existing local directory FileSystemManager manager = getFileSystem().getFileSystemManager(); FileObject localDir = manager.resolveFile("file://" + GaeFileNameParser.getRootPath(manager.getBaseFile().getName()) + parent.getName().getPath()); if (localDir.exists() && localDir.getType().hasChildren()) { parent.createFolder(); // make sure GaeVFS "shadow" folder exists } } return parent; }
From source file:com.panet.imeta.job.entries.filecompare.JobEntryFileCompare.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; result.setResult(false);//w w w . j ava 2 s. c o m String realFilename1 = getRealFilename1(); String realFilename2 = getRealFilename2(); FileObject file1 = null; FileObject file2 = null; try { if (filename1 != null && filename2 != null) { file1 = KettleVFS.getFileObject(realFilename1); file2 = KettleVFS.getFileObject(realFilename2); if (file1.exists() && file2.exists()) { if (equalFileContents(file1, file2)) { result.setResult(true); } else { result.setResult(false); } // add filename to result filenames if (addFilenameToResult && file1.getType() == FileType.FILE && file2.getType() == FileType.FILE) { ResultFile resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file1, parentJob.getJobname(), toString()); resultFile.setComment(Messages.getString("JobWaitForFile.FilenameAdded")); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); resultFile = new ResultFile(ResultFile.FILE_TYPE_GENERAL, file2, parentJob.getJobname(), toString()); resultFile.setComment(Messages.getString("JobWaitForFile.FilenameAdded")); result.getResultFiles().put(resultFile.getFile().toString(), resultFile); } } else { if (!file1.exists()) log.logError(toString(), Messages .getString("JobEntryFileCompare.ERROR_0004_File1_Does_Not_Exist", realFilename1)); //$NON-NLS-1$ if (!file2.exists()) log.logError(toString(), Messages .getString("JobEntryFileCompare.ERROR_0005_File2_Does_Not_Exist", realFilename2)); //$NON-NLS-1$ result.setResult(false); result.setNrErrors(1); } } else { log.logError(toString(), Messages.getString("JobEntryFileCompare.ERROR_0006_Need_Two_Filenames")); //$NON-NLS-1$ } } catch (Exception e) { result.setResult(false); result.setNrErrors(1); log.logError(toString(), Messages.getString("JobEntryFileCompare.ERROR_0007_Comparing_Files", //$NON-NLS-1$ realFilename2, realFilename2, e.getMessage())); } finally { try { if (file1 != null) file1.close(); if (file2 != null) file2.close(); } catch (IOException e) { } } return result; }
From source file:com.newatlanta.appengine.vfs.provider.GaeFileObject.java
private FileObject[] getLocalChildren() throws FileSystemException { if (isCombinedLocal) { GaeFileName fileName = (GaeFileName) getName(); String localUri = "file://" + fileName.getRootPath() + fileName.getPath(); FileObject localFile = getFileSystem().getFileSystemManager().resolveFile(localUri); if (localFile.exists()) { return localFile.getChildren(); }// w ww . jav a2s . c o m } return new FileObject[0]; }
From source file:com.thinkberg.webdav.MkColHandler.java
public void service(HttpServletRequest request, HttpServletResponse response) throws IOException { BufferedReader bufferedReader = request.getReader(); String line = bufferedReader.readLine(); if (line != null) { response.sendError(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); return;/*from w w w .j av a 2 s .c om*/ } FileObject object = VFSBackend.resolveFile(request.getPathInfo()); try { if (!LockManager.getInstance().evaluateCondition(object, getIf(request)).result) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } } catch (LockException e) { response.sendError(SC_LOCKED); return; } catch (ParseException e) { response.sendError(HttpServletResponse.SC_PRECONDITION_FAILED); return; } if (object.exists()) { response.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED); return; } if (!object.getParent().exists() || !FileType.FOLDER.equals(object.getParent().getType())) { response.sendError(HttpServletResponse.SC_CONFLICT); return; } try { object.createFolder(); response.setStatus(HttpServletResponse.SC_CREATED); } catch (FileSystemException e) { response.sendError(HttpServletResponse.SC_FORBIDDEN); } }
From source file:com.fer.hr.service.datasource.ClassPathResourceDatasourceManager.java
private void setPath(String path) { FileSystemManager fileSystemManager; try {//from ww w . j a v a 2 s.c o m fileSystemManager = VFS.getManager(); FileObject fileObject; fileObject = fileSystemManager.resolveFile(path); if (fileObject == null) { throw new IOException("File cannot be resolved: " + path); } if (!fileObject.exists()) { throw new IOException("File does not exist: " + path); } repoURL = fileObject.getURL(); if (repoURL == null) { throw new Exception("Cannot load connection repository from path: " + path); } else { load(); } } catch (Exception e) { e.printStackTrace(); } }
From source file:com.panet.imeta.job.entries.xsdvalidator.JobEntryXSDValidator.java
public Result execute(Result previousResult, int nr, Repository rep, Job parentJob) { LogWriter log = LogWriter.getInstance(); Result result = previousResult; result.setResult(false);//from w ww . jav a2 s.co m String realxmlfilename = getRealxmlfilename(); String realxsdfilename = getRealxsdfilename(); FileObject xmlfile = null; FileObject xsdfile = null; try { if (xmlfilename != null && xsdfilename != null) { xmlfile = KettleVFS.getFileObject(realxmlfilename); xsdfile = KettleVFS.getFileObject(realxsdfilename); if (xmlfile.exists() && xsdfile.exists()) { SchemaFactory factorytXSDValidator_1 = SchemaFactory .newInstance("http://www.w3.org/2001/XMLSchema"); // Get XSD File File XSDFile = new File(KettleVFS.getFilename(xsdfile)); Schema SchematXSD = factorytXSDValidator_1.newSchema(XSDFile); Validator XSDValidator = SchematXSD.newValidator(); // Get XML File File xmlfiletXSDValidator_1 = new File(KettleVFS.getFilename(xmlfile)); Source sourcetXSDValidator_1 = new StreamSource(xmlfiletXSDValidator_1); XSDValidator.validate(sourcetXSDValidator_1); // Everything is OK result.setResult(true); } else { if (!xmlfile.exists()) { log.logError(toString(), Messages.getString("JobEntryXSDValidator.FileDoesNotExist1.Label") + realxmlfilename + Messages.getString("JobEntryXSDValidator.FileDoesNotExist2.Label")); } if (!xsdfile.exists()) { log.logError(toString(), Messages.getString("JobEntryXSDValidator.FileDoesNotExist1.Label") + realxsdfilename + Messages.getString("JobEntryXSDValidator.FileDoesNotExist2.Label")); } result.setResult(false); result.setNrErrors(1); } } else { log.logError(toString(), Messages.getString("JobEntryXSDValidator.AllFilesNotNull.Label")); result.setResult(false); result.setNrErrors(1); } } catch (SAXException ex) { log.logError(toString(), "Error :" + ex.getMessage()); } catch (Exception e) { log.logError(toString(), Messages.getString("JobEntryXSDValidator.ErrorXSDValidator.Label") + Messages.getString("JobEntryXSDValidator.ErrorXML1.Label") + realxmlfilename + Messages.getString("JobEntryXSDValidator.ErrorXML2.Label") + Messages.getString("JobEntryXSDValidator.ErrorXSD1.Label") + realxsdfilename + Messages.getString("JobEntryXSDValidator.ErrorXSD2.Label") + e.getMessage()); result.setResult(false); result.setNrErrors(1); } finally { try { if (xmlfile != null) xmlfile.close(); if (xsdfile != null) xsdfile.close(); } catch (IOException e) { } } return result; }
From source file:com.panet.imeta.trans.steps.xsdvalidator.XsdValidator.java
public boolean processRow(StepMetaInterface smi, StepDataInterface sdi) throws KettleException { meta = (XsdValidatorMeta) smi;// ww w. ja va 2s. c o m data = (XsdValidatorData) sdi; Object[] row = getRow(); if (row == null) // no more input to be expected... { setOutputDone(); return false; } if (first) { first = false; data.outputRowMeta = getInputRowMeta().clone(); meta.getFields(data.outputRowMeta, getStepname(), null, null, this); // Check if XML stream is given if (meta.getXMLStream() != null) { // Try to get XML Field index data.xmlindex = getInputRowMeta().indexOfValue(meta.getXMLStream()); // Let's check the Field if (data.xmlindex < 0) { // The field is unreachable ! logError(Messages.getString("XsdValidator.Log.ErrorFindingField") + "[" + meta.getXMLStream() //$NON-NLS-1$//$NON-NLS-2$ + "]"); throw new KettleStepException( Messages.getString("XsdValidator.Exception.CouldnotFindField", meta.getXMLStream())); //$NON-NLS-1$ //$NON-NLS-2$ } // Let's check that Result Field is given if (meta.getResultfieldname() == null) { // Result field is missing ! logError(Messages.getString("XsdValidator.Log.ErrorResultFieldMissing")); //$NON-NLS-1$ //$NON-NLS-2$ throw new KettleStepException( Messages.getString("XsdValidator.Exception.ErrorResultFieldMissing")); //$NON-NLS-1$ //$NON-NLS-2$ } // Is XSD file is provided? if (meta.getXSDSource().equals(meta.SPECIFY_FILENAME)) { if (meta.getXSDFilename() == null) { logError(Messages.getString("XsdValidator.Log.ErrorXSDFileMissing")); //$NON-NLS-1$ //$NON-NLS-2$ throw new KettleStepException( Messages.getString("XsdValidator.Exception.ErrorXSDFileMissing")); //$NON-NLS-1$ //$NON-NLS-2$ } else { // Is XSD file exists ? FileObject xsdfile = null; try { xsdfile = KettleVFS.getFileObject(environmentSubstitute(meta.getXSDFilename())); if (!xsdfile.exists()) { logError(Messages.getString("XsdValidator.Log.Error.XSDFileNotExists")); throw new KettleStepException( Messages.getString("XsdValidator.Exception.XSDFileNotExists")); } } catch (Exception e) { logError(Messages.getString("XsdValidator.Log.Error.GettingXSDFile")); throw new KettleStepException( Messages.getString("XsdValidator.Exception.GettingXSDFile")); } finally { try { if (xsdfile != null) xsdfile.close(); } catch (IOException e) { } } } } // Is XSD field is provided? if (meta.getXSDSource().equals(meta.SPECIFY_FIELDNAME)) { if (meta.getXSDDefinedField() == null) { logError(Messages.getString("XsdValidator.Log.Error.XSDFieldMissing")); throw new KettleStepException(Messages.getString("XsdValidator.Exception.XSDFieldMissing")); } else { // Let's check if the XSD field exist // Try to get XML Field index data.xsdindex = getInputRowMeta().indexOfValue(meta.getXSDDefinedField()); if (data.xsdindex < 0) { // The field is unreachable ! logError(Messages.getString("XsdValidator.Log.ErrorFindingXSDField", //$NON-NLS-1$ meta.getXSDDefinedField())); //$NON-NLS-2$ throw new KettleStepException(Messages.getString( "XsdValidator.Exception.ErrorFindingXSDField", meta.getXSDDefinedField())); //$NON-NLS-1$ //$NON-NLS-2$ } } } } else { // XML stream field is missing ! logError(Messages.getString("XsdValidator.Log.Error.XmlStreamFieldMissing")); //$NON-NLS-1$ //$NON-NLS-2$ throw new KettleStepException(Messages.getString("XsdValidator.Exception.XmlStreamFieldMissing")); //$NON-NLS-1$ //$NON-NLS-2$ } } boolean sendToErrorRow = false; String errorMessage = null; try { // Get the XML field value String XMLFieldvalue = getInputRowMeta().getString(row, data.xmlindex); boolean isvalid = false; // XSD filename String xsdfilename = null; if (meta.getXSDSource().equals(meta.SPECIFY_FILENAME)) { xsdfilename = environmentSubstitute(meta.getXSDFilename()); } else if (meta.getXSDSource().equals(meta.SPECIFY_FIELDNAME)) { // Get the XSD field value xsdfilename = getInputRowMeta().getString(row, data.xsdindex); } // Get XSD filename FileObject xsdfile = null; String validationmsg = null; try { SchemaFactory factoryXSDValidator = SchemaFactory.newInstance(XMLConstants.W3C_XML_SCHEMA_NS_URI); xsdfile = KettleVFS.getFileObject(xsdfilename); File XSDFile = new File(KettleVFS.getFilename(xsdfile)); // Get XML stream Source sourceXML = new StreamSource(new StringReader(XMLFieldvalue)); if (meta.getXMLSourceFile()) { // We deal with XML file // Get XML File File xmlfileValidator = new File(XMLFieldvalue); if (!xmlfileValidator.exists()) { logError(Messages.getString("XsdValidator.Log.Error.XMLfileMissing", XMLFieldvalue)); //$NON-NLS-1$ //$NON-NLS-2$ throw new KettleStepException( Messages.getString("XsdValidator.Exception.XMLfileMissing", XMLFieldvalue)); //$NON-NLS-1$ //$NON-NLS-2$ } sourceXML = new StreamSource(xmlfileValidator); } // Create XSD schema Schema SchematXSD = factoryXSDValidator.newSchema(XSDFile); if (meta.getXSDSource().equals(meta.NO_NEED)) { // ---Some documents specify the schema they expect to be validated against, // ---typically using xsi:noNamespaceSchemaLocation and/or xsi:schemaLocation attributes //---Schema SchematXSD = factoryXSDValidator.newSchema(); SchematXSD = factoryXSDValidator.newSchema(); } // Create XSDValidator Validator XSDValidator = SchematXSD.newValidator(); // Validate XML / XSD XSDValidator.validate(sourceXML); isvalid = true; } catch (SAXException ex) { validationmsg = ex.getMessage(); logError("SAX Exception : " + ex); } catch (IOException ex) { validationmsg = ex.getMessage(); logError("SAX Exception : " + ex); } finally { try { if (xsdfile != null) xsdfile.close(); } catch (IOException e) { } } Object[] outputRowData = null; Object[] outputRowData2 = null; if (meta.getOutputStringField()) { // Output type=String if (isvalid) outputRowData = RowDataUtil.addValueData(row, getInputRowMeta().size(), environmentSubstitute(meta.getIfXmlValid())); else outputRowData = RowDataUtil.addValueData(row, getInputRowMeta().size(), environmentSubstitute(meta.getIfXmlInvalid())); } else { outputRowData = RowDataUtil.addValueData(row, getInputRowMeta().size(), isvalid); } if (meta.useAddValidationMessage()) outputRowData2 = RowDataUtil.addValueData(outputRowData, getInputRowMeta().size() + 1, validationmsg); else outputRowData2 = outputRowData; if (log.isRowLevel()) logRowlevel( Messages.getString("XsdValidator.Log.ReadRow") + " " + getInputRowMeta().getString(row)); // add new values to the row. putRow(data.outputRowMeta, outputRowData2); // copy row to output rowset(s); } catch (KettleException e) { if (getStepMeta().isDoingErrorHandling()) { sendToErrorRow = true; errorMessage = e.toString(); } if (sendToErrorRow) { // Simply add this row to the error row putError(getInputRowMeta(), row, 1, errorMessage, null, "XSD001"); } else { logError(Messages.getString("XsdValidator.ErrorProcesing" + " : " + e.getMessage())); throw new KettleStepException(Messages.getString("XsdValidator.ErrorProcesing"), e); } } return true; }