public Object clone() { byte[] newContent = new byte[getContents().length]; System.arraycopy(getContents(), 0, newContent, 0, getContents().length); getStructureId(), getResourceId(), getRootPath(), getTypeId(), getFlags(), getProjectLastModified(), getState(), getDateCreated(), getUserCreated(), getDateLastModified(), getUserLastModified(), getDateReleased(), getDateExpired(), getSiblingCount(), getLength(), getDateContent(), getVersion(), newContent); if (isTouched()) { clone.setDateLastModified(getDateLastModified());
/** * Rewrites the content of the given file.<p> * * @param resource the resource to rewrite the content for * * @throws CmsException if something goes wrong */ private static void hardTouch(CmsObject cms, CmsResource resource) throws CmsException { CmsFile file = cms.readFile(resource); file.setContents(file.getContents()); cms.writeFile(file); }
/** * @see org.opencms.file.CmsResource#isTemporaryFile() */ @Override public boolean isTemporaryFile() { return ((getFlags() & CmsResource.FLAG_TEMPFILE) > 0) || isTemporaryFileName(getName()); }
/** * Returns a scaled version of the given image file according this image scalers parameters.<p> * * @param file the image file to scale * * @return a scaled version of the given image file according to the provided scaler parameters */ public byte[] scaleImage(CmsFile file) { return scaleImage(file.getContents(), file.getRootPath()); }
public Object clone() { byte[] newContent = new byte[this.getContents().length]; System.arraycopy(getContents(), 0, newContent, 0, getContents().length); CmsFile clone = new CmsFile( getStructureId(), getResourceId(), getRootPath(), getTypeId(), getFlags(), getProjectLastModified(), getState(), getDateCreated(), getUserCreated(), getDateLastModified(), newContent); if (isTouched()) { clone.setDateLastModified(getDateLastModified());
/** * Returns the virtual resource as a file.<p> * * @return the virtual resource as a file */ public CmsFile getFile() { if (m_base instanceof CmsFile) { CmsFile file = (CmsFile)m_base; return new CmsFile( file.getStructureId(), file.getResourceId(), m_rootPath, m_typeId, file.getFlags(), file.getProjectLastModified(), file.getState(), file.getDateCreated(), file.getUserCreated(), file.getDateLastModified(), file.getUserLastModified(), file.getDateReleased(), file.getDateExpired(), file.getSiblingCount(), file.getLength(), file.getDateContent(), file.getVersion(), file.getContents()); } return new CmsFile(getResource()); }
/** * @see org.opencms.file.types.A_CmsResourceType#writeFile(org.opencms.file.CmsObject, org.opencms.db.CmsSecurityManager, org.opencms.file.CmsFile) */ @Override public CmsFile writeFile(CmsObject cms, CmsSecurityManager securityManager, CmsFile resource) throws CmsException { // actualize the link paths and/or ids CmsJspLinkMacroResolver macroResolver = new CmsJspLinkMacroResolver(cms, resource.getRootPath(), false); String encoding = CmsLocaleManager.getResourceEncoding(cms, resource); String content = CmsEncoder.createString(resource.getContents(), encoding); content = macroResolver.resolveMacros(content); try { resource.setContents(content.getBytes(encoding)); } catch (UnsupportedEncodingException e) { // this should usually never happen since the encoding is already used before resource.setContents(content.getBytes()); } // write the content with the 'right' links Set<String> references = getReferencingStrongLinks(cms, resource); CmsFile file = super.writeFile(cms, securityManager, resource); removeReferencingFromCache(references); return file; }
/** * Returns an input stream baded on the file contents.<p> * * @see javax.activation.DataSource#getInputStream() */ public InputStream getInputStream() { return new ByteArrayInputStream(m_file.getContents()); }
public CmsFile writeFile(CmsObject cms, CmsFile resource) throws CmsException { CmsResource xmlPage = cms.readResource(resource.getStructureId()); if (resType instanceof CmsResourceTypeXmlPage) { String path = getSubPath(cms, xmlPage, cms.getRequestContext().removeSiteRoot(resource.getRootPath())); String content = getStringValue(cms, file, resource.getContents()); content = CmsStringUtil.extractHtmlBody(content).trim(); xml.setStringValue(cms, name, new Locale(tokens[0]), content); file.setContents(xml.marshal()); cms.writeFile(file);
/** * Returns the virtual resource as a file.<p> * * @return the virtual resource as a file */ public CmsFile getFile() { if (m_base instanceof CmsFile) { CmsFile file = (CmsFile)m_base; return new CmsFile( file.getStructureId(), file.getResourceId(), m_rootPath, m_typeId, file.getFlags(), file.getProjectLastModified(), file.getState(), file.getDateCreated(), file.getUserCreated(), file.getDateLastModified(), file.getUserLastModified(), file.getDateReleased(), file.getDateExpired(), file.getSiblingCount(), file.getLength(), file.getDateContent(), file.getVersion(), file.getContents()); } return new CmsFile(getResource()); }
resource.setUserLastModified(dbc.currentUser().getId()); resource.setContents(resource.getContents()); // to be sure the content date is updated byte[] contents = resource.getContents(); m_vfsDriver.writeContent(dbc, resource.getResourceId(), contents); resource = new CmsFile(readResource(dbc, resource.getStructureId(), CmsResourceFilter.ALL)); resource.setContents(contents);
CmsImageScaler scaler = new CmsImageScaler(tempFile.getContents(), tempFile.getRootPath()); + "_" + System.currentTimeMillis() + getSuffix(tempFile.getName()); CmsObject adminCms = OpenCms.initCmsObject(m_adminCms); CmsProject tempProject = adminCms.createTempfileProject(); imageFile.setContents(content); adminCms.writeFile(imageFile); adminCms.writePropertyObject(
/** * Save the values to the bundle descriptor. * @throws CmsException thrown if saving fails. */ private void saveToBundleDescriptor() throws CmsException { if (null != m_descFile) { m_removeDescriptorOnCancel = false; updateBundleDescriptorContent(); m_descFile.getFile().setContents(m_descContent.marshal()); m_cms.writeFile(m_descFile.getFile()); } }
/** * Decodes a file's contents and return the content string and the encoding to use for writing the file * back to the VFS.<p> * * @param file the file to decode * @return a pair (content, encoding) * @throws CmsException if something goes wrong */ protected CmsPair<String, String> decode(CmsFile file) throws CmsException { String content = null; String encoding = getConfiguredEncoding(m_cms, file); I_CmsResourceType resType = OpenCms.getResourceManager().getResourceType(file.getTypeId()); if (resType instanceof CmsResourceTypeJsp) { content = decode(file.getContents(), encoding); } else { try { CmsXmlEntityResolver resolver = new CmsXmlEntityResolver(m_cms); // parse the XML and serialize it back to a string with the configured encoding Document doc = CmsXmlUtils.unmarshalHelper(file.getContents(), resolver); content = CmsXmlUtils.marshal(doc, encoding); } catch (Exception e) { // invalid xml structure, just use the configured encoding content = decode(file.getContents(), encoding); } } return CmsPair.create(content, encoding); }
onlineResource.getResourceId()); CmsFile restoredFile = new CmsFile( onlineResource.getStructureId(), onlineResource.getResourceId(), restoredFile.setDateLastModified(onlineResource.getDateLastModified()); restoredFile.getRootPath(), restoredFile, restoredFile.getContents(), properties, false);
/** * @see org.opencms.file.wrapper.A_CmsResourceWrapper#writeFile(org.opencms.file.CmsObject, org.opencms.file.CmsFile) */ @Override public CmsFile writeFile(CmsObject cms, CmsFile resource) throws CmsException { CmsResource res = getResource(cms, resource.getStructureId()); if (res != null) { CmsResourceWrapperUtils.writePropertyFile( cms, cms.getRequestContext().removeSiteRoot(res.getRootPath()), resource.getContents()); return resource; } return null; }
restoredFile.setDateLastModified(onlineResource.getDateLastModified()); restoredFile.getRootPath(), restoredFile, restoredFile.getContents(), properties, false);
/** * Rewrites the links included in the content itself.<p> * * @param file the file for which the links should be replaced * @param relations the original relations * * @throws CmsException if something goes wrong */ protected void rewriteContent(CmsFile file, Collection<CmsRelation> relations) throws CmsException { LOG.info("Rewriting in-content links for " + file.getRootPath()); CmsPair<String, String> contentAndEncoding = decode(file); String content = contentAndEncoding.getFirst(); String encodingForSave = contentAndEncoding.getSecond(); String newContent = rewriteContentString(content); byte[] newContentBytes; try { newContentBytes = newContent.getBytes(encodingForSave); } catch (UnsupportedEncodingException e) { newContentBytes = newContent.getBytes(); } file.setContents(newContentBytes); m_cms.writeFile(file); }
/** * Writes a single OpenCms VFS file to the ZIP export.<p> * * @param file the OpenCms VFS file to write * @param name the name of the file in the export * * @throws IOException in case of file access issues */ protected void writeFile2Zip(CmsFile file, String name) throws IOException { ZipEntry entry = new ZipEntry(name); // save the time of the last modification in the zip entry.setTime(file.getDateLastModified()); m_exportZipStream.putNextEntry(entry); m_exportZipStream.write(file.getContents()); m_exportZipStream.closeEntry(); }
+ locale + " of file " + file.getRootPath() + " because it is not configured as available locale. Using locale " + replacementLocale + " instead."); locale = replacementLocale; entityId = CmsContentDefinition.uuidToEntityId(file.getStructureId(), locale.toString()); entityId = CmsContentDefinition.uuidToEntityId(file.getStructureId(), locale.toString()); CmsGallerySearchResult searchResult = CmsGallerySearch.searchById(cms, file.getStructureId(), locale); title = searchResult.getTitle(); } catch (CmsException e) { LOG.warn(e.getLocalizedMessage(), e); String typeName = OpenCms.getResourceManager().getResourceType(file.getTypeId()).getTypeName(); boolean autoUnlock = OpenCms.getWorkplaceManager().shouldAcaciaUnlock(); Map<String, CmsEntity> entities = new HashMap<String, CmsEntity>();