/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param pubRes the published resource to get the dependency object for * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsPublishedResource pubRes) { CmsDocumentDependency result = readFromContext(cms, pubRes.getRootPath()); if (result == null) { result = new CmsDocumentDependency(pubRes); result.readDependencies(cms); } return result; }
if (att.getAttachmentNumber() == dep.getAttachmentNumber()) { if (m_locale.equals(dep.getLocale())) { for (CmsDocumentDependency langAtt : att.getVariants()) { dep.addVariant(langAtt); dep.addVariant(att); m_attachments.remove(att); } else { exist = true; att.addVariant(dep); dep.setType(DependencyType.attachment); m_attachments.add(dep); } else { dep.setType(DependencyType.variant); addDependency(dep);
/** * Returns the locale (language) of the given resource based on the resource root path.<p> * * @param rootPath the resource name to check for the locale information * * @return the locale of the given resource based on the resource root path */ public static Locale getLocale(String rootPath) { return (new CmsDocumentDependency(null, rootPath)).getLocale(); }
/** * Adds another language version document dependency to this document.<p> * * @param dep the language version document dependency to add */ public void addVariant(CmsDocumentDependency dep) { // check if already exists for (CmsDocumentDependency lang : m_variants) { if (lang.getLocale().equals(dep.getLocale())) { return; } } dep.setType(DependencyType.variant); m_variants.add(dep); addDependency(dep); }
if (isAttachment()) { attachments.put(new Integer(getAttachmentNumber()), this); if (r.isFile() && !getResource().getRootPath().equals(r.getRootPath())) { CmsPublishedResource pubRes = new CmsPublishedResource( r, getResource().getPublishTag(), CmsResourceState.STATE_CHANGED); CmsDocumentDependency dep = new CmsDocumentDependency(pubRes); if (getDocumentName().equals(dep.getDocumentName())) { if (isAttachment()) { if (dep.isAttachment()) { if ((getAttachmentNumber() == dep.getAttachmentNumber()) && dep.hasLocaleFileName()) { addVariant(dep); if (getAttachmentNumber() == dep.getAttachmentNumber()) { dep.setMainDocument(dep); } else { Integer attNum = new Integer(dep.getAttachmentNumber()); CmsDocumentDependency att = attachments.get(attNum); if (att != null) { att.addVariant(dep); } else { attachments.put(attNum, dep); setMainDocument(dep);
CmsDocumentDependency result = new CmsDocumentDependency(null, rootPath); if (input != null) { if (input.startsWith("{")) { JSONObject jsonDoc = new JSONObject(input); result.fromJSON(jsonDoc, rootPath); CmsDocumentDependency main = new CmsDocumentDependency(null, jsonMain.getString(JSON_PATH)); main.fromJSON(jsonMain, rootPath); result.setMainDocument(main); result.setLocale(loc); } else { String rp = doc.substring(3); CmsDocumentDependency dep = new CmsDocumentDependency(null, rp); if (!loc.equals(result.getLocale())) { dep.setLocale(new Locale(lang)); result.addVariant(dep);
/** * Adds the given document dependency to this document.<p> * * @param cms the current CmsObject * @param resDeps the dependency */ public void addDocumentDependency(CmsObject cms, CmsDocumentDependency resDeps) { if (resDeps != null) { m_doc.addField(CmsSearchField.FIELD_DEPENDENCY_TYPE, resDeps.getType()); if ((resDeps.getMainDocument() != null) && (resDeps.getType() != null)) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + resDeps.getType().toString(), resDeps.getMainDocument().toDependencyString(cms)); } for (CmsDocumentDependency dep : resDeps.getVariants()) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + dep.getType().toString(), dep.toDependencyString(cms)); } for (CmsDocumentDependency dep : resDeps.getAttachments()) { m_doc.addField( CmsSearchField.FIELD_PREFIX_DEPENDENCY + dep.getType().toString(), dep.toDependencyString(cms)); } } }
JSONObject jsonDoc = toJSON(cms, true); if ((!isAttachment()) && (m_attachments != null)) { JSONObject jsonAttachment = att.toJSON(cms, true); jsonAttachments.put(jsonAttachment); } else if (isAttachment()) { CmsDocumentDependency main = getMainDocument(); if (main != null) { JSONObject jsonMain = main.toJSON(cms, true); List<CmsDocumentDependency> attachments = main.getAttachments(); if (attachments != null) { JSONArray jsonAttachments = new JSONArray(); for (CmsDocumentDependency att : attachments) { JSONObject jsonAttachment = att.toJSON(cms, true); jsonAttachments.put(jsonAttachment);
JSONObject jsonLang = (JSONObject)jsonLanguages.get(i); CmsDocumentDependency lang = new CmsDocumentDependency(null, jsonLang.getString(JSON_PATH)); lang.fromJSON(jsonLang, rootPath); addVariant(lang); JSONObject jsonAttachment = (JSONObject)jsonAttachments.get(i); CmsDocumentDependency att = new CmsDocumentDependency( null, jsonAttachment.getString(JSON_PATH)); att.fromJSON(jsonAttachment, rootPath); JSONObject jsonAttLanguage = (JSONObject)jsonAttLanguages.get(j); CmsDocumentDependency attLang = new CmsDocumentDependency( null, jsonAttLanguage.getString(JSON_PATH)); attLang.fromJSON(jsonAttLanguage, rootPath); att.addVariant(attLang); addAttachment(att); } catch (Exception e) { LOG.error(e);
CmsDocumentDependency dep = CmsDocumentDependency.load(m_cms, pub); List<CmsDocumentDependency> depsAvailable = dep.getDependencies(); Iterator<CmsDocumentDependency> depIt = depsAvailable.iterator(); do { if (!pub.getState().isDeleted()) { dep.storeInContext(m_cms); pub = depIt.next().getResource(); } else { dep = null;
} else { if (mainDocument.getLocale().equals(getLocale())) { int pos1 = locales.indexOf(m_mainDocument.getLocale()); if (pos1 > 0) { int pos2 = locales.indexOf(mainDocument.getLocale()); if (pos2 < pos1) { mainDocument.addVariant(m_mainDocument); m_mainDocument.addVariant(mainDocument);
/** * Stores this dependency object for a published resource in the OpenCms runtime context.<p> * * This done to optimize indexing speed. When the index update information is calculated, * all dependencies for a resource must be calculated also. The same information is later needed when * the Lucene document is created, for example in order to store the list of other available languages.<p> * * @param cms the current OpenCms user context */ public void storeInContext(CmsObject cms) { cms.getRequestContext().setAttribute(getAttributeKey(getResource().getRootPath()), this); }
/** * Reads the dependency object for the given root path in the OpenCms runtime context.<p> * * @param cms the current OpenCms user context * @param rootPath the root path to look up the dependency object for * * @return the deps */ private static CmsDocumentDependency readFromContext(CmsObject cms, String rootPath) { return (CmsDocumentDependency)cms.getRequestContext().getAttribute(getAttributeKey(rootPath)); }
/** * Creates a dependency object for the given root path, to be used only for test cases.<p> * * @param rootPath the root path to create the dependency object for * * @return a dependency object for the given parameters */ protected static CmsDocumentDependency loadForTest(String rootPath) { return new CmsDocumentDependency(null, rootPath); }
/** * Removes the dependency object for a published resource from the OpenCms * runtime context.<p> * * <b>Please note:</b> This must be used with caution since the information * may be required to generate documents for several configured indexes. It * must be ensured that this is called only when all indexes have been * updated.<p> * * @param cms the current OpenCms user context * @param pubRes the published resource info * * @see #storeInContext(CmsObject) */ protected static void removeFromContext(CmsObject cms, CmsPublishedResource pubRes) { cms.getRequestContext().removeAttribute(getAttributeKey(pubRes.getRootPath())); }
/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param res the VFS resource to get the dependency object for * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsResource res) { CmsDocumentDependency result = readFromContext(cms, res.getRootPath()); if (result == null) { result = new CmsDocumentDependency(res); result.readDependencies(cms); } return result; }
/** * Loads or creates a dependency object for the given parameters.<p> * * @param cms the current OpenCms user context * @param res the VFS resource to get the dependency object for * @param resources the resource folder data to check for dependencies * * @return a dependency object for the given parameters */ public static CmsDocumentDependency load(CmsObject cms, CmsResource res, List<CmsResource> resources) { CmsDocumentDependency result = readFromContext(cms, res.getRootPath()); if (result == null) { result = new CmsDocumentDependency(res); result.readDependencies(cms, resources); } return result; }