/** * Reads a file from the class loader and converts it to a String with the specified encoding.<p> * * @param filename the file to read * @param encoding the encoding to use when converting the file content to a String * @return the read file convered to a String * @throws IOException in case of file access errors */ public static String readFile(String filename, String encoding) throws IOException { return new String(readFile(filename), encoding); }
/** * Reads a file from the class loader and converts it to a String with the specified encoding.<p> * * @param filename the file to read * @param encoding the encoding to use when converting the file content to a String * @return the read file convered to a String * @throws IOException in case of file access errors */ public static String readFile(String filename, String encoding) throws IOException { return new String(readFile(filename), encoding); }
/** * Reads the log file and returns the data.<p> * * @param moduleName the module name * @return the log contents * * @throws IOException if something goes wrong */ public synchronized byte[] readLog(String moduleName) throws IOException { File logFile = getLogFile(moduleName); if (logFile.exists()) { return CmsFileUtil.readFile(logFile); } else { return new byte[] {}; } }
/** * Returns the content of the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but outdated.<p> * * @param rfsName the file RFS name to look up in the cache * * @return the content of the requested file in the disk cache, or <code>null</code> */ public byte[] getCacheContent(String rfsName) { try { File f = new File(rfsName); if (f.exists()) { long age = f.lastModified(); if ((System.currentTimeMillis() - age) > 3600000) { // file has not been touched for 1 hour, touch the file with the current date f.setLastModified(System.currentTimeMillis()); } return CmsFileUtil.readFile(f); } } catch (IOException e) { // unable to read content } return null; }
/** * Returns the content of the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but outdated.<p> * * @param rfsName the file RFS name to look up in the cache * * @return the content of the requested file in the disk cache, or <code>null</code> */ public byte[] getCacheContent(String rfsName) { try { File f = new File(rfsName); if (f.exists()) { long age = f.lastModified(); if ((System.currentTimeMillis() - age) > 3600000) { // file has not been touched for 1 hour, touch the file with the current date f.setLastModified(System.currentTimeMillis()); } return CmsFileUtil.readFile(f); } } catch (IOException e) { // unable to read content LOG.debug("Unable to read file " + rfsName, e); } return null; }
/** * Returns the extraction result in the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but out-dated.<p> * * @param rfsName the file RFS name to look up in the cache * * @return the extraction result stored in the requested file in the RFS disk cache, or <code>null</code> */ public CmsExtractionResult getCacheObject(String rfsName) { try { File f = new File(rfsName); if (f.exists()) { long age = f.lastModified(); if ((System.currentTimeMillis() - age) > 3600000) { // file has not been touched for 1 hour, touch the file with the current date f.setLastModified(System.currentTimeMillis()); } byte[] byteContent = CmsFileUtil.readFile(f); return CmsExtractionResult.fromBytes(byteContent); } } catch (IOException e) { // unable to read content } // this code can be reached only in case of an error return null; }
/** * Returns the content of the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but outdated.<p> * * @param rfsName the file RFS name to look up in the cache * @param dateLastModified the date of last modification for the cache * * @return the content of the requested file in the VFS disk cache, or <code>null</code> */ public byte[] getCacheContent(String rfsName, long dateLastModified) { dateLastModified = simplifyDateLastModified(dateLastModified); try { File f = new File(rfsName); if (f.exists()) { if (f.lastModified() != dateLastModified) { // last modification time different, remove cached file in RFS f.delete(); } else { return CmsFileUtil.readFile(f); } } } catch (IOException e) { // unable to read content } return null; }
/** * Returns the extraction result in the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but out-dated.<p> * * @param rfsName the file RFS name to look up in the cache * * @return the extraction result stored in the requested file in the RFS disk cache, or <code>null</code> */ public CmsExtractionResult getCacheObject(String rfsName) { try { File f = new File(rfsName); if (f.exists()) { long age = f.lastModified(); if ((System.currentTimeMillis() - age) > 3600000) { // file has not been touched for 1 hour, touch the file with the current date f.setLastModified(System.currentTimeMillis()); } byte[] byteContent = CmsFileUtil.readFile(f); return CmsExtractionResult.fromBytes(byteContent); } } catch (IOException e) { // unable to read content } // this code can be reached only in case of an error return null; }
/** * Returns the content of the requested file in the disk cache, or <code>null</code> if the * file is not found in the cache, or is found but outdated.<p> * * @param rfsName the file RFS name to look up in the cache * @param dateLastModified the date of last modification for the cache * * @return the content of the requested file in the VFS disk cache, or <code>null</code> */ public byte[] getCacheContent(String rfsName, long dateLastModified) { dateLastModified = simplifyDateLastModified(dateLastModified); try { File f = new File(rfsName); if (f.exists()) { if (f.lastModified() != dateLastModified) { // last modification time different, remove cached file in RFS f.delete(); } else { return CmsFileUtil.readFile(f); } } } catch (IOException e) { // unable to read content } return null; }
/** * Loads a file from the "real" file system to the VFS.<p> * * @param localfile the file upload * @param folder the folder in the VFS to place the file into * @param filename the name of the uploaded file in the VFS * @param type the type of the new file in the VFS * @return the createed file * @throws Exception if something goes wrong * @throws CmsIllegalArgumentException if the concatenation of String arguments * <code>folder</code> and <code>localfile</code> is of length 0 * */ public CmsResource uploadFile(String localfile, String folder, String filename, String type) throws Exception, CmsIllegalArgumentException { I_CmsResourceType t = OpenCms.getResourceManager().getResourceType(type); return m_cms.createResource(folder + filename, t, CmsFileUtil.readFile(new File(localfile)), null); }
/** * Loads a file from the "real" file system to the VFS.<p> * * @param localfile the file upload * @param folder the folder in the VFS to place the file into * @param filename the name of the uploaded file in the VFS * @param type the type of the new file in the VFS * @return the createed file * @throws Exception if something goes wrong * @throws CmsIllegalArgumentException if the concatenation of String arguments * <code>folder</code> and <code>localfile</code> is of length 0 * */ public CmsResource uploadFile(String localfile, String folder, String filename, String type) throws Exception, CmsIllegalArgumentException { int t = OpenCms.getResourceManager().getResourceType(type).getTypeId(); return m_cms.createResource(folder + filename, t, CmsFileUtil.readFile(new File(localfile)), null); }
/** * Convenience method to loads the XML schema definition for this value type from an external file.<p> * * @param schemaUri the schema uri to load the XML schema file from * * @return the loaded XML schema * * @throws CmsRuntimeException if something goes wrong */ protected String readSchemaDefinition(String schemaUri) throws CmsRuntimeException { // the schema definition is located in a separate file for easier editing String schemaDefinition; try { schemaDefinition = CmsFileUtil.readFile(schemaUri, CmsEncoder.ENCODING_UTF_8); } catch (Exception e) { throw new CmsRuntimeException( Messages.get().container(Messages.ERR_XMLCONTENT_LOAD_SCHEMA_1, schemaUri), e); } return schemaDefinition; } }
/** * Convenience method to loads the XML schema definition for this value type from an external file.<p> * * @param schemaUri the schema uri to load the XML schema file from * * @return the loaded XML schema * * @throws CmsRuntimeException if something goes wrong */ protected String readSchemaDefinition(String schemaUri) throws CmsRuntimeException { // the schema definition is located in a separate file for easier editing String schemaDefinition; try { schemaDefinition = CmsFileUtil.readFile(schemaUri, CmsEncoder.ENCODING_UTF_8); } catch (Exception e) { throw new CmsRuntimeException(Messages.get().container(Messages.ERR_XMLCONTENT_LOAD_SCHEMA_1, schemaUri), e); } return schemaDefinition; } }
byte[] content = CmsFileUtil.readFile(currentFile);
/** * Adds a new DTD system id prefix mapping for internal resolution * of external URLs.<p> * * @param dtdSystemLocation the internal system location of the DTD file, e.g. <code>org/opencms/configuration/</code> * @param dtdFilename the name of the DTD file, e.g. <code>opencms-configuration.dtd</code> * @param dtdUrlPrefix the external system id prefix of the DTD file, e.g. <code>http://www.opencms.org/dtd/6.0/</code> * * @see org.opencms.configuration.I_CmsXmlConfiguration */ public void cacheDtdSystemId(String dtdSystemLocation, String dtdFilename, String dtdUrlPrefix) { if (dtdSystemLocation != null) { try { String file = CmsFileUtil.readFile(dtdSystemLocation + dtdFilename, CmsEncoder.ENCODING_UTF_8); CmsXmlEntityResolver.cacheSystemId(dtdUrlPrefix + dtdFilename, file.getBytes(CmsEncoder.ENCODING_UTF_8)); if (LOG.isDebugEnabled()) { LOG.debug(org.opencms.configuration.Messages.get().getBundle().key( org.opencms.configuration.Messages.LOG_CACHE_DTD_SYSTEM_ID_1, new Object[] {dtdUrlPrefix + dtdFilename + " --> " + dtdSystemLocation + dtdFilename})); } } catch (IOException e) { LOG.error(org.opencms.configuration.Messages.get().getBundle().key( org.opencms.configuration.Messages.LOG_CACHE_DTD_SYSTEM_ID_FAILURE_1, new Object[] {dtdSystemLocation + dtdFilename}), e); } } }
/** * Contains the visibility handler configuration for a content field path.<p> */ protected static class VisibilityConfiguration { /** The handler instance. */ private I_CmsXmlContentVisibilityHandler m_handler; /** The handler configuration parameters. */ private String m_params; /** * Constructor.<p> * * @param handler the handler instance * @param params the handler configuration parameteres */ protected VisibilityConfiguration(I_CmsXmlContentVisibilityHandler handler, String params) { m_handler = handler; m_params = params; } /** * Returns the visibility handler instance.<p> * * @return the handler instance */ public I_CmsXmlContentVisibilityHandler getHandler() {
String file = CmsFileUtil.readFile(dtdSystemLocation + dtdFilename, CmsEncoder.ENCODING_UTF_8); CmsXmlEntityResolver.cacheSystemId( dtdUrlPrefix + dtdFilename,
return CmsFileUtil.readFile(file);
String file = CmsFileUtil.readFile( configuration.getDtdSystemLocation() + configuration.getDtdFilename(), CmsEncoder.ENCODING_UTF_8);
/** * Adds a new DTD system id prefix mapping for internal resolution of external URLs.<p> * * @param configuration the configuration to add the mapping from */ private void cacheDtdSystemId(I_CmsXmlConfiguration configuration) { if (configuration.getDtdSystemLocation() != null) { try { String file = CmsFileUtil.readFile(configuration.getDtdSystemLocation() + configuration.getDtdFilename(), CmsEncoder.ENCODING_UTF_8); CmsXmlEntityResolver.cacheSystemId( configuration.getDtdUrlPrefix() + configuration.getDtdFilename(), file.getBytes(CmsEncoder.ENCODING_UTF_8)); if (LOG.isDebugEnabled()) { LOG.debug(Messages.get().getBundle().key( Messages.LOG_CACHE_DTD_SYSTEM_ID_1, configuration.getDtdUrlPrefix() + configuration.getDtdFilename() + " --> " + configuration.getDtdSystemLocation() + configuration.getDtdFilename())); } } catch (IOException e) { LOG.error(Messages.get().getBundle().key( Messages.LOG_CACHE_DTD_SYSTEM_ID_FAILURE_1, configuration.getDtdSystemLocation() + configuration.getDtdFilename()), e); } } }