shuber 2004/10/14 20:12:41 CEST
Modified files: (Branch: JAHIA-4-0-BRANCH)
src/java/org/jahia/services/fields
ContentApplicationField.java
ContentField.java
ContentPageField.java
Log:
JAHIA-195 : On fields, mandatory language check should only be done if field was
initialized
- Added check to see if fields are initialized. If not, mandatory language checks
are not done.
Revision Changes Path
1.23.4.2 +14 -0
jahia/src/java/org/jahia/services/fields/ContentApplicationField.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/fields/ContentApplicationField.java.diff?r1=1.23.4.1&r2=1.23.4.2&f=h
1.113.2.11 +99 -39 jahia/src/java/org/jahia/services/fields/ContentField.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/fields/ContentField.java.diff?r1=1.113.2.10&r2=1.113.2.11&f=h
1.74.4.6 +14 -0 jahia/src/java/org/jahia/services/fields/ContentPageField.java
http://jahia.mine.nu:8080/cgi-bin/cvsweb.cgi/jahia/src/java/org/jahia/services/fields/ContentPageField.java.diff?r1=1.74.4.5&r2=1.74.4.6&f=h
Index: ContentApplicationField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/fields/Attic/ContentApplicationField.java,v
retrieving revision 1.23.4.1
retrieving revision 1.23.4.2
diff -u -r1.23.4.1 -r1.23.4.2
--- ContentApplicationField.java 12 Oct 2004 13:18:04 -0000 1.23.4.1
+++ ContentApplicationField.java 14 Oct 2004 18:12:40 -0000 1.23.4.2
@@ -220,4 +220,18 @@
xmlWriter.writeCData ("NOT YET IMPLEMENTED");
}
+ protected boolean isEntryInitialized (ContentObjectEntryState curEntryState)
+ throws JahiaException {
+ String entryValue = getDBValue(curEntryState);
+ if (entryValue == null) {
+ return false;
+ }
+ if (!entryValue.equals("") &&
+ !entryValue.equals("<empty>")) {
+ return true;
+ }
+ return false;
+ }
+
+
}
Index: ContentField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/fields/Attic/ContentField.java,v
retrieving revision 1.113.2.10
retrieving revision 1.113.2.11
diff -u -r1.113.2.10 -r1.113.2.11
--- ContentField.java 7 Oct 2004 17:27:22 -0000 1.113.2.10
+++ ContentField.java 14 Oct 2004 18:12:40 -0000 1.113.2.11
@@ -64,6 +64,7 @@
import java.io.IOException;
import java.io.Serializable;
import java.util.*;
+import org.jahia.registries.JahiaContainerDefinitionsRegistry;
/**
* This class represents a Field in Jahia (it should replace JahiaFields in the
@@ -660,49 +661,80 @@
// first we must test if we have all the mandatory languages in our
// field
JahiaSite theSite = jParams.getSite();
- Vector languageSettings = theSite.getLanguageSettings();
- Enumeration languageSettingsEnum = languageSettings.elements();
- while (languageSettingsEnum.hasMoreElements()) {
- SiteLanguageSettings curSettings = (SiteLanguageSettings)
- languageSettingsEnum.nextElement();
- if (curSettings.isMandatory()) {
- // we found a mandatory language, let's check that there at
- // least an active or a staged entry for this field.
- boolean foundLanguage = false;
- Enumeration activeAndStagingEntriesEnum =
- activeAndStagingEntryStates.elements();
- while ( (foundLanguage == false) &&
- (activeAndStagingEntriesEnum.hasMoreElements())) {
- ContentObjectEntryState curEntryState = (
- ContentObjectEntryState)
- activeAndStagingEntriesEnum.nextElement();
- if ( (curEntryState.getLanguageCode().equals(
- curSettings.getCode())) ||
- (curEntryState.getLanguageCode().equals(
- ContentField.SHARED_LANGUAGE))) {
- foundLanguage = true;
- break;
- }
- }
- if (!foundLanguage) {
- activationTestResults.setStatus(
- ActivationTestResults.FAILED_OPERATION_STATUS);
- try {
- IsValidForActivationResults activationResults = new
- IsValidForActivationResults(
- ContentFieldKey.FIELD_TYPE, getID(),
- curSettings.getCode(),
- "A mandatory language is missing for a content
field.");
- activationTestResults.appendError(activationResults);
+ // first let's check if all the languages have unitialized values,
+ // in which case we do not need to do mandatory language checks.
+ boolean allEntriesUninitialized = true;
+ Enumeration activeAndStagingEntryEnum =
+ activeAndStagingEntryStates.elements();
+ while ( (allEntriesUninitialized == true) &&
+ (activeAndStagingEntryEnum.hasMoreElements())) {
+ ContentObjectEntryState curEntryState = (ContentObjectEntryState)
+
activeAndStagingEntryEnum.nextElement();
+ if (isEntryInitialized(curEntryState)) {
+ allEntriesUninitialized = false;
+ }
+ }
+
+ if (!allEntriesUninitialized) {
+ Vector languageSettings = theSite.getLanguageSettings();
+ Enumeration languageSettingsEnum = languageSettings.elements();
+ while (languageSettingsEnum.hasMoreElements()) {
+ SiteLanguageSettings curSettings = (SiteLanguageSettings)
+ languageSettingsEnum.nextElement();
+ if (curSettings.isMandatory()) {
+ // we found a mandatory language, let's check that there at
+ // least an active or a staged entry for this field.
+ boolean foundLanguage = false;
+ Enumeration activeAndStagingEntriesEnum =
+ activeAndStagingEntryStates.elements();
+ while ( (foundLanguage == false) &&
+ (activeAndStagingEntriesEnum.hasMoreElements())) {
+ ContentObjectEntryState curEntryState = (
+ ContentObjectEntryState)
+ activeAndStagingEntriesEnum.nextElement();
+ if ( (curEntryState.getLanguageCode().equals(
+ curSettings.getCode())) ||
+ (curEntryState.getLanguageCode().equals(
+ ContentField.SHARED_LANGUAGE))) {
+ foundLanguage = true;
+ break;
+ }
}
- catch (ClassNotFoundException cnfe) {
- logger.debug(
- "Error while creating activation test node result",
- cnfe);
+
+ if (!foundLanguage) {
+ activationTestResults.setStatus(
+ ActivationTestResults.FAILED_OPERATION_STATUS);
+ try {
+ JahiaFieldDefinition fieldDefinition =
JahiaFieldDefinitionsRegistry.getInstance().getDefinition(getFieldDefID());
+ String fieldTitle = null;
+ if (fieldDefinition != null) {
+ try {
+ fieldTitle = fieldDefinition.getTitle(
+ getPage().getPageTemplate(jParams.
+ getEntryLoadRequest()).getID(),
+ jParams.getLocale());
+ } catch (NullPointerException npe) {
+ // if we can't solve the title, let's
+ // just do nothing.
+ ;
+ }
+ }
+ IsValidForActivationResults activationResults = new
+ IsValidForActivationResults(
+ ContentFieldKey.FIELD_TYPE, getID(),
+ curSettings.getCode(),
+ "A mandatory language is missing for field [" +
fieldTitle + "]");
+ activationTestResults.appendError(
+ activationResults);
+ } catch (ClassNotFoundException cnfe) {
+ logger.debug(
+ "Error while creating activation test node
result",
+ cnfe);
+ }
}
- }
+ }
}
}
}
@@ -714,6 +746,34 @@
}
/**
+ * This method is used to check if the field has been initialized for
+ * a specific entry state. This is mostly used to figure out whether we
+ * must perform mandatory language check. If all entry states are un-
+ * initialized, we must not perform mandatory language checks.
+ *
+ * You will want to redefine this method in subclasses in order to check
+ * for other empty value markers.
+ *
+ * @param curEntryState ContentObjectEntryState the entry state for which
+ * to check if the entry's value has been initialized.
+ * @throws JahiaException
+ * @return boolean true if the field has been initialized with a value,
+ * false otherwise.
+ */
+ protected boolean isEntryInitialized (ContentObjectEntryState curEntryState)
+ throws JahiaException {
+ String entryValue = getValue(curEntryState);
+ if (entryValue == null) {
+ return false;
+ }
+ if (!entryValue.equals("") &&
+ !entryValue.equals("<empty>")) {
+ return true;
+ }
+ return false;
+ }
+
+ /**
* This method removes all the data related to the staging mode of this
* field, effectively "undoing" all the changes and returning to the
* active values.
Index: ContentPageField.java
===================================================================
RCS file:
/home/cvs/repository/jahia/src/java/org/jahia/services/fields/Attic/ContentPageField.java,v
retrieving revision 1.74.4.5
retrieving revision 1.74.4.6
diff -u -r1.74.4.5 -r1.74.4.6
--- ContentPageField.java 1 Oct 2004 16:54:47 -0000 1.74.4.5
+++ ContentPageField.java 14 Oct 2004 18:12:40 -0000 1.74.4.6
@@ -982,4 +982,18 @@
return opResult;
}
+ protected boolean isEntryInitialized (ContentObjectEntryState curEntryState)
+ throws JahiaException {
+ String entryValue = getDBValue(curEntryState);
+ if (entryValue == null) {
+ return false;
+ }
+ if (!entryValue.equals("") &&
+ !entryValue.equals("<empty>") &&
+ !entryValue.equals("-1")) {
+ return true;
+ }
+ return false;
+ }
+
}