/** * Returns the root path of the given resource.<p> * * @see javax.activation.DataSource#getName() */ public String getName() { return m_file.getRootPath(); }
/** * Returns the root path of the given resource.<p> * * @see javax.activation.DataSource#getName() */ public String getName() { return m_file.getRootPath(); }
/** * 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()); }
/** * @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 { if (matchParentPath(IMPORT_PATH, resource.getRootPath())) { OpenCms.getModuleManager().getImportExportRepository().importModule( CmsResource.getName(resource.getRootPath()), resource.getContents()); m_importFileUpdateCache.put(resource.getRootPath(), Long.valueOf(System.currentTimeMillis())); m_importDataCache.put(resource.getRootPath(), resource); return resource; } else { return super.writeFile(cms, resource); } }
/** * JTidy sometimes erroneouslsy produces HTML containing 'null' characters (Unicode code point 0), which are * invalid in an XML document. Until we find a way to prevent JTidy doing that, we remove the null characters * from the HTML, and log a warning.<p> * * @param jtidyOutput the JTidy output * @return the output with null characters removed */ protected String fixNullCharacters(String jtidyOutput) { String outputWithoutNullChars = jtidyOutput.replaceAll("\u0000", ""); if (jtidyOutput.length() != outputWithoutNullChars.length()) { String context = ""; if (m_document.getFile() != null) { context = "(file=" + m_document.getFile().getRootPath() + ")"; } LOG.warn("HTML cleanup produced invalid null characters in output. " + context); LOG.debug("HTML cleanup output = " + jtidyOutput); } return outputWithoutNullChars; }
/** * 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()); }
/** * 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); }
/** * Returns the required version of the user accepted agreement.<p> * * @return the required version of the user accepted agreement */ public double getRequiredVersion() { if (m_requiredVersion == 0) { String versionStr = getConfigurationContentStringValue(NODE_VERSION); try { m_requiredVersion = Double.parseDouble(versionStr); } catch (Exception e) { // the version number is not in the correct format LOG.error( Messages.get().getBundle().key( Messages.LOG_USERAGREEMENT_WRONG_VERSION_2, versionStr, getConfigurationContent().getFile().getRootPath())); } } return m_requiredVersion; }
/** * @see org.opencms.relations.I_CmsLinkParseable#parseLinks(org.opencms.file.CmsObject, org.opencms.file.CmsFile) */ public List<CmsLink> parseLinks(CmsObject cms, CmsFile file) { CmsJspLinkMacroResolver macroResolver = new CmsJspLinkMacroResolver(cms, file.getRootPath(), false); String encoding = CmsLocaleManager.getResourceEncoding(cms, file); String content = CmsEncoder.createString(file.getContents(), encoding); macroResolver.resolveMacros(content); // ignore return value return macroResolver.getLinks(); }
/** * @see org.opencms.relations.I_CmsLinkParseable#parseLinks(org.opencms.file.CmsObject, org.opencms.file.CmsFile) */ public List parseLinks(CmsObject cms, CmsFile file) { CmsJspLinkMacroResolver macroResolver = new CmsJspLinkMacroResolver(cms, file.getRootPath(), false); String encoding = CmsLocaleManager.getResourceEncoding(cms, file); String content = CmsEncoder.createString(file.getContents(), encoding); macroResolver.resolveMacros(content); // ignore return value return macroResolver.getLinks(); }
/** * @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; }
/** * Writes the xml content to the vfs and re-initializes the member variables.<p> * * @param cms the cms context * @param file the file to write to * @param content the content * @param encoding the file encoding * * @return the content * * @throws CmsException if writing the file fails */ private CmsXmlContent writeContent(CmsObject cms, CmsFile file, CmsXmlContent content, String encoding) throws CmsException { String decodedContent = content.toString(); try { file.setContents(decodedContent.getBytes(encoding)); } catch (UnsupportedEncodingException e) { throw new CmsException( org.opencms.workplace.editors.Messages.get().container( org.opencms.workplace.editors.Messages.ERR_INVALID_CONTENT_ENC_1, file.getRootPath()), e); } // the file content might have been modified during the write operation file = cms.writeFile(file); return CmsXmlContentFactory.unmarshal(cms, file); }
/** * @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 references = getReferencingStrongLinks(cms, resource); CmsFile file = super.writeFile(cms, securityManager, resource); removeReferencingFromCache(references); return file; }
/** * @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 { if (checkTypeId(resource.getTypeId())) { CmsWrappedResource wrap = new CmsWrappedResource(resource); wrap.setRootPath(CmsResourceWrapperUtils.removeFileExtension(cms, resource.getRootPath(), getExtension())); return cms.writeFile(wrap.getFile()); } return null; }
/** * @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 { if (checkTypeId(resource.getTypeId())) { CmsWrappedResource wrap = new CmsWrappedResource(resource); wrap.setRootPath(CmsResourceWrapperUtils.removeFileExtension(cms, resource.getRootPath(), getExtension())); return cms.writeFile(wrap.getFile()); } return null; }
if (resType instanceof CmsResourceTypeXmlPage) { String path = getSubPath(cms, xmlPage, cms.getRequestContext().removeSiteRoot(resource.getRootPath()));
/** * Builds the diff view for the XML text.<p> * * @param cms the CMS context * @param file1 the first file * @param file2 the second file * * @return the diff view */ private Component buildWholeFileDiffView(CmsObject cms, CmsFile file1, CmsFile file2) { String encoding = "UTF-8"; try { CmsXmlContent content1 = CmsXmlContentFactory.unmarshal(cms, file1); encoding = content1.getEncoding(); } catch (CmsException e) { String rootPath = file1.getRootPath(); LOG.error( "Could not unmarshal file " + rootPath + " for determining encoding: " + e.getLocalizedMessage(), e); } String text1 = decode(file1.getContents(), encoding); String text2 = decode(file2.getContents(), encoding); CmsTextDiffPanel diffPanel = new CmsTextDiffPanel(text1, text2, false, true); return diffPanel; }
if (resType instanceof CmsResourceTypeXmlPage) { String path = getSubPath(cms, xmlPage, cms.getRequestContext().removeSiteRoot(resource.getRootPath()));
CmsImageScaler downScaler = getDownScaler(cms, resource.getRootPath()); resource.getRootPath(), null, downScaler);
getStructureId(), getResourceId(), getRootPath(), getTypeId(), getFlags(),