📄 fieldxrefmanager.java
字号:
package org.jahia.content;import java.util.*;import org.jahia.utils.JahiaConsole;/** * Title: Jahia * Description: The purpose of this class is to provide a cross reference * system between fields and pages, in order to know which pages reference * a field. This is necessary since currently this information is defined * only by template developpers and is useful for the HTML cache system when a * field modification is done. This class allows lookups such as : "which * pages access this field via the absolute field reference system?" * Copyright: Copyright (c) 2002 * Company: Jahia Ltd * @author Serge Huber * @version 1.0 */public class FieldXRefManager { private static final String NAME_SEPARATOR = "_"; private static FieldXRefManager theObject = null; protected FieldXRefManager() { JahiaConsole.println("FieldXRefManager", "Initializing..."); } /** * Returns a singleton instance of this service * Note : this is a synchronized access method so it might affect performance * if a lot of threads must access it simultaneously. * @returns the singleton instance. */ public static synchronized FieldXRefManager getInstance() { if (theObject == null) { theObject = new FieldXRefManager(); } return theObject; } // end getInstance /** * Retrieves a list of pageIDs that contain references to a specific * absolute field. * @param fieldName the name of the field referenced in a * absolute way * @param fieldSourcePageID the source page on which we are accessing * the field * @returns a Set of Integers containing pageIDs */ public Set getAbsoluteFieldPageIDs(String siteName, String fieldName, int fieldSourcePageID) { FieldKey fieldKey = new FieldKey(siteName, fieldName + NAME_SEPARATOR + Integer.toString(fieldSourcePageID)); Set objectRefs = CrossReferenceManager.getInstance().getObjectXRefs(fieldKey); Set pageIDs = new TreeSet(); if (objectRefs == null) { return pageIDs; } Iterator objectRefIter = objectRefs.iterator(); while (objectRefIter.hasNext()) { Object ref = objectRefIter.next(); if (ref instanceof ObjectKey) { ObjectKey refKey = (ObjectKey) ref; if (PageKey.PAGE_TYPE.equals(refKey.getType())) { PageKey pageRefKey = (PageKey) refKey; Integer pageID = new Integer(pageRefKey.getPageID()); pageIDs.add(pageID); } else { JahiaConsole.println("FieldXRefManager.getAbsoluteFieldPageIDs", "Expected page type in cross reference list, ignoring value... "); } } else { JahiaConsole.println("FieldXRefManager.getAbsoluteFieldPageIDs", "Invalid key object in cross reference list, ignoring... "); } } return pageIDs; } /** * Adds or updates a cross reference between an absolute field and * a page * @param fieldName the name of the field referenced on a * absolute way * @param fieldSourcePageID the source page on which we are accessing * the field * @param pageID the page identifier */ public void setAbsoluteFieldPageID(String siteName, String fieldName, int fieldSourcePageID, int referencePageID) { FieldKey fieldKey = new FieldKey(siteName, fieldName + NAME_SEPARATOR + Integer.toString(fieldSourcePageID)); PageKey pageKey = new PageKey(siteName, referencePageID); CrossReferenceManager.getInstance().setObjectXRef(fieldKey, pageKey); } /** * Removes all the cross references for a specified absolute field * @param fieldName the name of the field referenced in a * absolute way * @param fieldSourcePageID the source page on which we are accessing * the field */ public void removeAbsoluteField(String siteName, String fieldName, int fieldSourcePageID) { FieldKey fieldKey = new FieldKey(siteName, fieldName + NAME_SEPARATOR + Integer.toString(fieldSourcePageID)); CrossReferenceManager.getInstance().removeObjectXRefs(fieldKey); }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -