return newNode;
}
private AbstractQOMNode getNewPropertyBasedNodeIfRequired(String selectorName,
String propertyName, AbstractQOMNode node) throws RepositoryException {
Selector selector = getSelector(getOriginalSource(), selectorName);
if (selector == null) {
return node;
}
try {
if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE
|| getModificationInfo().getMode() == MODIFY_MODE) {
// check for language dependent modifications and use the translation selector on
// jnt:translation node if user specified it in query
if (getSelectorsJoinedWithTranslation().get(selector.getSelectorName()) != null) {
selector = getSelectorsJoinedWithTranslation().get(selector.getSelectorName());
}
Set<String> languageCodes = getLanguagesPerSelector().get(
selector.getSelectorName());
if ((languageCodes == null || languageCodes.isEmpty()) && session != null
&& session.getLocale() != null) {
if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE) {
Set<String> newLanguageCodes = getNewLanguagesPerSelector().get(
selector.getSelectorName());
if (newLanguageCodes == null) {
newLanguageCodes = new HashSet<String>();
newLanguageCodes.add(session.getLocale().toString());
newLanguageCodes.add(NO_LOCALE);
getNewLanguagesPerSelector().put(selector.getSelectorName(),
newLanguageCodes);
}
if (newLanguageCodes.contains(NO_LOCALE)) {
ExtendedNodeType nodeType = NodeTypeRegistry.getInstance()
.getNodeType(selector.getNodeTypeName());
boolean isFulltextIncludingMultilingualProperties = (propertyName == null && node instanceof FullTextSearch) ? isFulltextIncludingMultilingualProperties(
nodeType, selector) : false;
ExtendedPropertyDefinition propDef = propertyName != null ? getPropertyDefinition(
nodeType, selector, propertyName) : null;
if (propDef != null && propDef.isInternationalized()
|| isFulltextIncludingMultilingualProperties) {
newLanguageCodes.remove(NO_LOCALE);
}
}
getModificationInfo().setModificationNecessary(true);
} else {
QueryObjectModelFactory qomFactory = getModificationInfo()
.getQueryObjectModelFactory();
Set<String> newLanguageCodes = getNewLanguagesPerSelector().get(
selector.getSelectorName());
if (newLanguageCodes != null) {
Constraint langConstraint = null;
for (String newLanguageCode : newLanguageCodes) {
Constraint currentConstraint = NO_LOCALE
.equals(newLanguageCode) ? qomFactory.not(qomFactory
.propertyExistence(selector.getSelectorName(),
Constants.JCR_LANGUAGE))
: qomFactory
.comparison(
qomFactory.propertyValue(
selector.getSelectorName(),
Constants.JCR_LANGUAGE),
QueryObjectModelConstants.JCR_OPERATOR_EQUAL_TO,
qomFactory.literal(getValueFactory()
.createValue(newLanguageCode)));
langConstraint = langConstraint == null ? currentConstraint
: qomFactory.or(langConstraint, currentConstraint);
}
getModificationInfo().getNewConstraints().add(langConstraint);
if (languageCodes == null) {
languageCodes = new HashSet<String>();
getLanguagesPerSelector().put(selector.getSelectorName(),
languageCodes);
}
languageCodes.addAll(newLanguageCodes);
}
}
}
if (node instanceof Column) {
String columnName = ((Column) node).getColumnName();
if (StringUtils.startsWith(columnName, "rep:facet(")
&& !StringUtils.contains(columnName, "locale=")) {
ExtendedNodeType nodeType = NodeTypeRegistry.getInstance().getNodeType(
selector.getNodeTypeName());
ExtendedPropertyDefinition propDef = propertyName != null ? getPropertyDefinition(
nodeType, selector, propertyName) : null;
if (propDef != null && propDef.isInternationalized()) {
if (getModificationInfo().getMode() == CHECK_FOR_MODIFICATION_MODE) {
getModificationInfo().setModificationNecessary(true);
} else {
String facetOptions = columnName.substring("rep:facet("
.length());
if (languageCodes == null) {
languageCodes = getNewLanguagesPerSelector().get(
selector.getSelectorName());
}
String languageCode = null;
for (String currentLanguageCode : languageCodes) {
if (!NO_LOCALE.equals(currentLanguageCode)) {
languageCode = currentLanguageCode;
break;
}
}
if (!StringUtils.isEmpty(languageCode)) {
columnName = "rep:facet(locale=" + languageCode
+ (facetOptions.trim().length() > 1 ? "&" : "")
+ facetOptions;
QueryObjectModelFactory qomFactory = getModificationInfo()
.getQueryObjectModelFactory();
node = (AbstractQOMNode) qomFactory.column(
selector.getSelectorName(), propertyName,
columnName);
}
}
}
}
}
}
} catch (NoSuchNodeTypeException e) {
logger.debug("Type " + selector.getNodeTypeName() + " not found in registry", e);
}
return node;
}