org.opencms.search.documents
Class CmsDocumentDependency

java.lang.Object
  extended by org.opencms.search.documents.CmsDocumentDependency

public final class CmsDocumentDependency
extends java.lang.Object

Provides the dependency information about one search result document, used to generate the list of document search results.

Since:
8.5.0

Nested Class Summary
static class CmsDocumentDependency.DependencyType
          Defines the possible dependency types.
 
Field Summary
static java.util.regex.Pattern DOC_PATTERN_LOCALE
          Pattern to determine the document locale.
static java.util.regex.Pattern DOC_PATTERN_NUMBER
          Pattern to determine the document attachment number.
 
Method Summary
 void addAttachment(CmsDocumentDependency dep)
          Adds another document attachment dependency to this document.
 void addDependency(CmsDocumentDependency dep)
          Adds another document dependency to this document.
 void addVariant(CmsDocumentDependency dep)
          Adds another language version document dependency to this document.
 boolean equals(java.lang.Object obj)
           
static CmsDocumentDependency fromDependencyString(java.lang.String input, java.lang.String rootPath)
          Creates a dependency object from a String representation.
 void fromJSON(JSONObject json, java.lang.String rootPath)
          Read the information out of the given JSON object to fill the values of the document.
 int getAttachmentNumber()
          Returns the attachment number.
 java.util.List<CmsDocumentDependency> getAttachments()
          Returns the attachments.
 java.util.List<CmsDocumentDependency> getDependencies()
          Returns the list of resources the main resource depends on, including the main resource itself.
 java.lang.String getDocumentName()
          Returns the file name of the document without attachment or locale suffixes.
 java.lang.String getDocumentSuffix()
          Returns the suffix of the document.
 java.util.Locale getLocale()
          Returns the locale of this document container.
static java.util.Locale getLocale(java.lang.String rootPath)
          Returns the locale (language) of the given resource based on the resource root path.
 CmsDocumentDependency getMainDocument()
          Returns the main document in case this document is an attachment.
 CmsPublishedResource getResource()
          Returns the VFS resource for which the dependencies are calculated.
 java.lang.String getRootPath()
          Returns the root path of this dependency.
 CmsDocumentDependency.DependencyType getType()
          Returns the type.
 java.util.List<CmsDocumentDependency> getVariants()
          Returns the variants.
 int hashCode()
           
 boolean hasLocaleFileName()
          Returns the locale file name flag.
 boolean isAttachment()
          Returns true if this document is an attachment, i.e. an attachment number is provided.
static CmsDocumentDependency load(CmsObject cms, CmsPublishedResource pubRes)
          Loads or creates a dependency object for the given parameters.
static CmsDocumentDependency load(CmsObject cms, CmsResource res)
          Loads or creates a dependency object for the given parameters.
static CmsDocumentDependency load(CmsObject cms, CmsResource res, java.util.List<CmsResource> resources)
          Loads or creates a dependency object for the given parameters.
protected static CmsDocumentDependency loadForTest(java.lang.String rootPath)
          Creates a dependency object for the given root path, to be used only for test cases.
 void readDependencies(CmsObject cms)
          Reads all dependencies that exist for this main resource in the OpenCms VFS.
 void readDependencies(CmsObject cms, java.util.List<CmsResource> folderContent)
          Reads all dependencies that exist for this main resource in provided list of resources.
protected static void removeFromContext(CmsObject cms, CmsPublishedResource pubRes)
          Removes the dependency object for a published resource from the OpenCms runtime context.
 void setAttachmentNumber(java.lang.Integer attachmentNumber)
          Sets the attachment number.
 void setDocumentName(java.lang.String documentName)
          Sets the file name of the document without attachment or locale suffixes.
 void setDocumentSuffix(java.lang.String documentSuffix)
          Sets the suffix (.pdf, .doc etc.) of the document.
 void setLocale(java.util.Locale locale)
          Sets the locale of this document container.
 void setMainDocument(CmsDocumentDependency mainDocument)
          Sets the main document in case this document is an attachment.
 void setType(CmsDocumentDependency.DependencyType type)
          Sets the type for this dependency.
 void storeInContext(CmsObject cms)
          Stores this dependency object for a published resource in the OpenCms runtime context.
 java.lang.String toDependencyString(CmsObject cms)
          Creates the String representation of this dependency object.
 JSONObject toJSON(CmsObject cms, boolean includeLang)
          Returns a JSON object describing this dependency document.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Field Detail

DOC_PATTERN_LOCALE

public static final java.util.regex.Pattern DOC_PATTERN_LOCALE
Pattern to determine the document locale.


DOC_PATTERN_NUMBER

public static final java.util.regex.Pattern DOC_PATTERN_NUMBER
Pattern to determine the document attachment number.

Method Detail

fromDependencyString

public static CmsDocumentDependency fromDependencyString(java.lang.String input,
                                                         java.lang.String rootPath)
Creates a dependency object from a String representation.

Parameters:
input - the String representation
rootPath - the root path of the base document of which the dependencies are encoded
Returns:
the dependency object created from a String representation

getLocale

public static java.util.Locale getLocale(java.lang.String rootPath)
Returns the locale (language) of the given resource based on the resource root path.

Parameters:
rootPath - the resource name to check for the locale information
Returns:
the locale of the given resource based on the resource root path

load

public static CmsDocumentDependency load(CmsObject cms,
                                         CmsPublishedResource pubRes)
Loads or creates a dependency object for the given parameters.

Parameters:
cms - the current OpenCms user context
pubRes - the published resource to get the dependency object for
Returns:
a dependency object for the given parameters

load

public static CmsDocumentDependency load(CmsObject cms,
                                         CmsResource res)
Loads or creates a dependency object for the given parameters.

Parameters:
cms - the current OpenCms user context
res - the VFS resource to get the dependency object for
Returns:
a dependency object for the given parameters

load

public static CmsDocumentDependency load(CmsObject cms,
                                         CmsResource res,
                                         java.util.List<CmsResource> resources)
Loads or creates a dependency object for the given parameters.

Parameters:
cms - the current OpenCms user context
res - the VFS resource to get the dependency object for
resources - the resource folder data to check for dependencies
Returns:
a dependency object for the given parameters

loadForTest

protected static CmsDocumentDependency loadForTest(java.lang.String rootPath)
Creates a dependency object for the given root path, to be used only for test cases.

Parameters:
rootPath - the root path to create the dependency object for
Returns:
a dependency object for the given parameters

removeFromContext

protected static void removeFromContext(CmsObject cms,
                                        CmsPublishedResource pubRes)
Removes the dependency object for a published resource from the OpenCms runtime context.

Please note: 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.

Parameters:
cms - the current OpenCms user context
pubRes - the published resource info
See Also:
storeInContext(CmsObject)

addAttachment

public void addAttachment(CmsDocumentDependency dep)
Adds another document attachment dependency to this document.

Parameters:
dep - the document attachment dependency to add

addDependency

public void addDependency(CmsDocumentDependency dep)
Adds another document dependency to this document.

Parameters:
dep - the document dependency to add

addVariant

public void addVariant(CmsDocumentDependency dep)
Adds another language version document dependency to this document.

Parameters:
dep - the language version document dependency to add

equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object
See Also:
Object.equals(java.lang.Object)

fromJSON

public void fromJSON(JSONObject json,
                     java.lang.String rootPath)
Read the information out of the given JSON object to fill the values of the document.

Parameters:
json - the JSON object with the information about this document
rootPath - the current path the home division

getAttachmentNumber

public int getAttachmentNumber()
Returns the attachment number.

Returns:
the attachment number

getAttachments

public java.util.List<CmsDocumentDependency> getAttachments()
Returns the attachments.

Returns:
the attachments

getDependencies

public java.util.List<CmsDocumentDependency> getDependencies()
Returns the list of resources the main resource depends on, including the main resource itself.

Returns:
the list of resources the main resource depends on, including the main resource itself

getDocumentName

public java.lang.String getDocumentName()
Returns the file name of the document without attachment or locale suffixes.

Returns:
the file name of the document without attachment or locale suffixes

getDocumentSuffix

public java.lang.String getDocumentSuffix()
Returns the suffix of the document.

Returns:
the suffix of the document

getLocale

public java.util.Locale getLocale()
Returns the locale of this document container.

Returns:
the locale of this document container

getMainDocument

public CmsDocumentDependency getMainDocument()
Returns the main document in case this document is an attachment.

Returns:
the main document in case this document is an attachment

getResource

public CmsPublishedResource getResource()
Returns the VFS resource for which the dependencies are calculated.

Returns:
the VFS resource for which the dependencies are calculated

getRootPath

public java.lang.String getRootPath()
Returns the root path of this dependency.

Returns:
the root path

getType

public CmsDocumentDependency.DependencyType getType()
Returns the type.

Returns:
the type

getVariants

public java.util.List<CmsDocumentDependency> getVariants()
Returns the variants.

Returns:
the variants

hashCode

public int hashCode()
Overrides:
hashCode in class java.lang.Object
See Also:
Object.hashCode()

hasLocaleFileName

public boolean hasLocaleFileName()
Returns the locale file name flag.

Returns:
the locale file name flag

isAttachment

public boolean isAttachment()
Returns true if this document is an attachment, i.e. an attachment number is provided.

Returns:
true if this document is an attachment, otherwise false

readDependencies

public void readDependencies(CmsObject cms)
Reads all dependencies that exist for this main resource in the OpenCms VFS.

To be used when incremental updating an index.

Parameters:
cms - the current users OpenCms context

readDependencies

public void readDependencies(CmsObject cms,
                             java.util.List<CmsResource> folderContent)
Reads all dependencies that exist for this main resource in provided list of resources.

Parameters:
cms - the current users OpenCms context
folderContent - the contents of the folder to check the dependencies for

setAttachmentNumber

public void setAttachmentNumber(java.lang.Integer attachmentNumber)
Sets the attachment number.

Parameters:
attachmentNumber - the attachment number

setDocumentName

public void setDocumentName(java.lang.String documentName)
Sets the file name of the document without attachment or locale suffixes.

Parameters:
documentName - the file name of the document without attachment or locale suffixes

setDocumentSuffix

public void setDocumentSuffix(java.lang.String documentSuffix)
Sets the suffix (.pdf, .doc etc.) of the document.

Parameters:
documentSuffix - the suffix to set

setLocale

public void setLocale(java.util.Locale locale)
Sets the locale of this document container.

Parameters:
locale - the locale of this document container

setMainDocument

public void setMainDocument(CmsDocumentDependency mainDocument)
Sets the main document in case this document is an attachment.

Parameters:
mainDocument - the main document to set

setType

public void setType(CmsDocumentDependency.DependencyType type)
Sets the type for this dependency.

Parameters:
type - the type to set

storeInContext

public void storeInContext(CmsObject cms)
Stores this dependency object for a published resource in the OpenCms runtime context.

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.

Parameters:
cms - the current OpenCms user context

toDependencyString

public java.lang.String toDependencyString(CmsObject cms)
Creates the String representation of this dependency object.

Parameters:
cms - the current OpenCms user context
Returns:
the String representation of this dependency object

toJSON

public JSONObject toJSON(CmsObject cms,
                         boolean includeLang)
Returns a JSON object describing this dependency document.

Parameters:
cms - the current cms object
includeLang - flag if language versions should be included
Returns:
a JSON object describing this dependency document

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object
See Also:
Object.toString()