001/* 002 * (C) Copyright 2010 Nuxeo SA (http://nuxeo.com/) and others. 003 * 004 * Licensed under the Apache License, Version 2.0 (the "License"); 005 * you may not use this file except in compliance with the License. 006 * You may obtain a copy of the License at 007 * 008 * http://www.apache.org/licenses/LICENSE-2.0 009 * 010 * Unless required by applicable law or agreed to in writing, software 011 * distributed under the License is distributed on an "AS IS" BASIS, 012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 013 * See the License for the specific language governing permissions and 014 * limitations under the License. 015 * 016 * Contributors: 017 * Anahide Tchertchian 018 */ 019package org.nuxeo.ecm.platform.contentview.jsf; 020 021import java.util.ArrayList; 022import java.util.List; 023import java.util.Map; 024 025import org.nuxeo.common.xmap.annotation.XNode; 026import org.nuxeo.common.xmap.annotation.XNodeList; 027import org.nuxeo.common.xmap.annotation.XObject; 028import org.nuxeo.ecm.platform.query.core.CoreQueryPageProviderDescriptor; 029import org.nuxeo.ecm.platform.query.core.GenericPageProviderDescriptor; 030import org.nuxeo.ecm.platform.query.core.ReferencePageProviderDescriptor; 031 032/** 033 * Descriptor for content view registration. 034 * 035 * @author Anahide Tchertchian 036 * @since 5.4 037 */ 038@XObject("contentView") 039public class ContentViewDescriptor { 040 041 @XNode("@name") 042 String name; 043 044 @XNode("@enabled") 045 boolean enabled = true; 046 047 @XNode("title") 048 String title; 049 050 @XNode("translateTitle") 051 Boolean translateTitle; 052 053 @XNode("emptySentence") 054 String emptySentence; 055 056 /** 057 * @since 7.4 058 */ 059 @XNode("waitForExecutionSentence") 060 String waitForExecutionSentence; 061 062 @XNode("translateEmptySentence") 063 Boolean translateEmptySentence; 064 065 @XNode("iconPath") 066 String iconPath; 067 068 @XNode("coreQueryPageProvider") 069 CoreQueryPageProviderDescriptor coreQueryPageProvider; 070 071 @XNode("genericPageProvider") 072 GenericPageProviderDescriptor genericPageProvider; 073 074 @XNode("pageProvider") 075 ReferencePageProviderDescriptor referencePageProvider; 076 077 @XNode("selectionList") 078 String selectionList; 079 080 @XNode("pagination") 081 String pagination; 082 083 @XNodeList(value = "actions@category", type = ArrayList.class, componentType = String.class) 084 List<String> actionCategories; 085 086 @XNode("searchDocument") 087 String searchDocument; 088 089 @XNode("searchLayout") 090 ContentViewLayoutImpl searchLayout; 091 092 @XNode("resultLayouts@append") 093 Boolean appendResultLayouts; 094 095 @XNodeList(value = "resultLayouts/layout", type = ArrayList.class, componentType = ContentViewLayoutImpl.class) 096 List<ContentViewLayout> resultLayouts; 097 098 @XNode("resultColumns") 099 String resultColumns; 100 101 /** 102 * @since 6.0 103 */ 104 @XNode("resultLayout") 105 String resultLayout; 106 107 @XNodeList(value = "flags/flag", type = ArrayList.class, componentType = String.class) 108 List<String> flags; 109 110 @XNode("cacheKey") 111 String cacheKey; 112 113 @XNode("cacheSize") 114 Integer cacheSize; 115 116 @XNode("useGlobalPageSize") 117 Boolean useGlobalPageSize; 118 119 @XNode("showTitle") 120 Boolean showTitle; 121 122 @XNode("showPageSizeSelector") 123 Boolean showPageSizeSelector; 124 125 @XNode("showRefreshCommand") 126 Boolean showRefreshCommand; 127 128 @XNode("showFilterForm") 129 Boolean showFilterForm; 130 131 /** 132 * @since 7.4 133 */ 134 @XNode("waitForExecution") 135 Boolean waitForExecution; 136 137 @XNodeList(value = "refresh/event", type = ArrayList.class, componentType = String.class) 138 List<String> refreshEventNames; 139 140 @XNodeList(value = "reset/event", type = ArrayList.class, componentType = String.class) 141 List<String> resetEventNames; 142 143 public String getName() { 144 return name; 145 } 146 147 public CoreQueryPageProviderDescriptor getCoreQueryPageProvider() { 148 return coreQueryPageProvider; 149 } 150 151 public GenericPageProviderDescriptor getGenericPageProvider() { 152 return genericPageProvider; 153 } 154 155 public ReferencePageProviderDescriptor getReferencePageProvider() { 156 return referencePageProvider; 157 } 158 159 // @since 6.0 160 protected String pageProviderName; 161 162 // @since 6.0 163 protected Map<String, String> pageProviderProperties; 164 165 public String getSelectionListName() { 166 return selectionList; 167 } 168 169 public String getPagination() { 170 return pagination; 171 } 172 173 public List<String> getActionCategories() { 174 return actionCategories; 175 } 176 177 public ContentViewLayoutImpl getSearchLayout() { 178 return searchLayout; 179 } 180 181 public Boolean getAppendResultLayouts() { 182 return appendResultLayouts; 183 } 184 185 public List<ContentViewLayout> getResultLayouts() { 186 return resultLayouts; 187 } 188 189 public String getCacheKey() { 190 return cacheKey; 191 } 192 193 public Integer getCacheSize() { 194 return cacheSize; 195 } 196 197 public List<String> getRefreshEventNames() { 198 return refreshEventNames; 199 } 200 201 public List<String> getResetEventNames() { 202 return resetEventNames; 203 } 204 205 public Boolean getUseGlobalPageSize() { 206 return useGlobalPageSize; 207 } 208 209 public String getIconPath() { 210 return iconPath; 211 } 212 213 public String getTitle() { 214 return title; 215 } 216 217 public Boolean getTranslateTitle() { 218 return translateTitle; 219 } 220 221 public String getSearchDocumentBinding() { 222 return searchDocument; 223 } 224 225 public String getResultColumnsBinding() { 226 return resultColumns; 227 } 228 229 /** 230 * @since 6.0 231 */ 232 public String getResultLayoutBinding() { 233 return resultLayout; 234 } 235 236 public List<String> getFlags() { 237 return flags; 238 } 239 240 public boolean isEnabled() { 241 return enabled; 242 } 243 244 public void setEnabled(boolean enabled) { 245 this.enabled = enabled; 246 } 247 248 /** 249 * @since 5.4.2 250 */ 251 public Boolean getShowTitle() { 252 return showTitle; 253 } 254 255 /** 256 * @since 5.4.2 257 */ 258 public Boolean getShowPageSizeSelector() { 259 if (showPageSizeSelector == null) { 260 // default value 261 return Boolean.TRUE; 262 } 263 return showPageSizeSelector; 264 } 265 266 /** 267 * @since 5.4.2 268 */ 269 public Boolean getShowRefreshCommand() { 270 if (showRefreshCommand == null) { 271 // default value 272 return Boolean.TRUE; 273 } 274 return showRefreshCommand; 275 } 276 277 /** 278 * @since 5.4.2 279 */ 280 public Boolean getShowFilterForm() { 281 return showFilterForm; 282 } 283 284 /** 285 * @since 5.4.2 286 */ 287 public String getEmptySentence() { 288 return emptySentence; 289 } 290 291 /** 292 * @since 7.4 293 */ 294 public String getWaitForExecutionSentence() { 295 return waitForExecutionSentence; 296 } 297 298 /** 299 * @since 5.4.2 300 */ 301 public Boolean getTranslateEmptySentence() { 302 return translateEmptySentence; 303 } 304 305 /** 306 * @since 6.0 307 */ 308 public String getPageProviderName() { 309 if (pageProviderName == null) { 310 if (referencePageProvider != null && referencePageProvider.isEnabled()) { 311 pageProviderName = referencePageProvider.getName(); 312 } else if (coreQueryPageProvider != null && coreQueryPageProvider.isEnabled() 313 && coreQueryPageProvider.getName() != null) { 314 pageProviderName = coreQueryPageProvider.getName(); 315 } else if (genericPageProvider != null && genericPageProvider.isEnabled() 316 && genericPageProvider.getName() != null) { 317 pageProviderName = genericPageProvider.getName(); 318 } else { 319 pageProviderName = getName(); 320 } 321 } 322 return pageProviderName; 323 } 324 325 /** 326 * @since 6.0 327 */ 328 public Map<String, String> getPageProviderProperties() { 329 if (pageProviderProperties == null) { 330 if (referencePageProvider != null && referencePageProvider.isEnabled()) { 331 pageProviderProperties = referencePageProvider.getProperties(); 332 } else if (coreQueryPageProvider != null && coreQueryPageProvider.isEnabled()) { 333 pageProviderProperties = coreQueryPageProvider.getProperties(); 334 335 } else if (genericPageProvider != null && genericPageProvider.isEnabled()) { 336 pageProviderProperties = genericPageProvider.getProperties(); 337 } 338 } 339 return pageProviderProperties; 340 } 341 342 /** 343 * @since 7.4 344 */ 345 public Boolean getWaitForExecution() { 346 return waitForExecution; 347 } 348 349 /** 350 * @since 7.4 351 */ 352 public void merge(ContentViewDescriptor newDesc) { 353 this.setEnabled(newDesc.isEnabled()); 354 355 String title = newDesc.getTitle(); 356 if (title != null) { 357 this.title = title; 358 } 359 360 Boolean translateTitle = newDesc.getTranslateTitle(); 361 if (translateTitle != null) { 362 this.translateTitle = translateTitle; 363 } 364 365 String emptySentence = newDesc.getEmptySentence(); 366 if (emptySentence != null) { 367 this.emptySentence = emptySentence; 368 } 369 370 String waitForExecutionSentence = newDesc.getWaitForExecutionSentence(); 371 if (waitForExecutionSentence != null) { 372 this.waitForExecutionSentence = waitForExecutionSentence; 373 } 374 375 Boolean translateEmptySentence = newDesc.getTranslateEmptySentence(); 376 if (translateEmptySentence != null) { 377 this.translateEmptySentence = translateEmptySentence; 378 } 379 380 String iconPath = newDesc.getIconPath(); 381 if (iconPath != null) { 382 this.iconPath = iconPath; 383 } 384 385 List<String> actions = newDesc.getActionCategories(); 386 if (actions != null && !actions.isEmpty()) { 387 this.actionCategories = actions; 388 } 389 390 String cacheKey = newDesc.getCacheKey(); 391 if (cacheKey != null) { 392 this.cacheKey = cacheKey; 393 } 394 395 Integer cacheSize = newDesc.getCacheSize(); 396 if (cacheSize != null) { 397 this.cacheSize = cacheSize; 398 } 399 400 CoreQueryPageProviderDescriptor coreDesc = newDesc.getCoreQueryPageProvider(); 401 if (coreDesc != null && coreDesc.isEnabled()) { 402 this.coreQueryPageProvider = coreDesc; 403 // make sure other page providers are reset 404 this.genericPageProvider = null; 405 this.referencePageProvider = null; 406 } 407 408 GenericPageProviderDescriptor genDesc = newDesc.getGenericPageProvider(); 409 if (genDesc != null && genDesc.isEnabled()) { 410 this.genericPageProvider = genDesc; 411 // make sure other page providers are reset 412 this.coreQueryPageProvider = null; 413 this.referencePageProvider = null; 414 } 415 416 ReferencePageProviderDescriptor refDesc = newDesc.getReferencePageProvider(); 417 if (refDesc != null && refDesc.isEnabled()) { 418 this.referencePageProvider = refDesc; 419 // make sure other page providers are reset 420 this.coreQueryPageProvider = null; 421 this.genericPageProvider = null; 422 } 423 424 String pagination = newDesc.getPagination(); 425 if (pagination != null) { 426 this.pagination = pagination; 427 } 428 429 List<String> events = newDesc.getRefreshEventNames(); 430 if (events != null && !events.isEmpty()) { 431 this.refreshEventNames = events; 432 } 433 events = newDesc.getResetEventNames(); 434 if (events != null && !events.isEmpty()) { 435 this.resetEventNames = events; 436 } 437 438 ContentViewLayoutImpl searchLayout = newDesc.getSearchLayout(); 439 if (searchLayout != null) { 440 this.searchLayout = searchLayout; 441 } 442 443 List<ContentViewLayout> resultLayouts = newDesc.getResultLayouts(); 444 if (resultLayouts != null) { 445 Boolean appendResultLayout = newDesc.getAppendResultLayouts(); 446 if (Boolean.TRUE.equals(appendResultLayout) || resultLayouts.isEmpty()) { 447 List<ContentViewLayout> allLayouts = new ArrayList<ContentViewLayout>(); 448 if (this.resultLayouts != null) { 449 allLayouts.addAll(this.resultLayouts); 450 } 451 allLayouts.addAll(resultLayouts); 452 this.resultLayouts = allLayouts; 453 } else { 454 this.resultLayouts = resultLayouts; 455 } 456 } 457 458 List<String> flags = newDesc.getFlags(); 459 if (flags != null && !flags.isEmpty()) { 460 this.flags = flags; 461 } 462 463 String selectionList = newDesc.getSelectionListName(); 464 if (selectionList != null) { 465 this.selectionList = selectionList; 466 } 467 468 Boolean useGlobalPageSize = newDesc.getUseGlobalPageSize(); 469 if (useGlobalPageSize != null) { 470 this.useGlobalPageSize = useGlobalPageSize; 471 } 472 473 Boolean showTitle = newDesc.getShowTitle(); 474 if (showTitle != null) { 475 this.showTitle = showTitle; 476 } 477 478 // avoid override when setting the default value => use the field, not 479 // the API, for merge 480 Boolean showPageSizeSelector = newDesc.showPageSizeSelector; 481 if (showPageSizeSelector != null) { 482 this.showPageSizeSelector = showPageSizeSelector; 483 } 484 485 Boolean showRefreshCommand = newDesc.showRefreshCommand; 486 if (showRefreshCommand != null) { 487 this.showRefreshCommand = showRefreshCommand; 488 } 489 490 Boolean showFilterForm = newDesc.getShowFilterForm(); 491 if (showFilterForm != null) { 492 this.showFilterForm = showFilterForm; 493 } 494 495 String searchDocument = newDesc.getSearchDocumentBinding(); 496 if (searchDocument != null) { 497 this.searchDocument = searchDocument; 498 } 499 500 String resultCols = newDesc.getResultColumnsBinding(); 501 if (resultCols != null) { 502 this.resultColumns = resultCols; 503 } 504 505 String resultLayout = newDesc.getResultLayoutBinding(); 506 if (resultLayout != null) { 507 this.resultLayout = resultLayout; 508 } 509 510 Boolean waitForFilter = newDesc.getWaitForExecution(); 511 if (waitForFilter != null) { 512 this.waitForExecution = waitForFilter; 513 } 514 515 } 516 517 @Override 518 public ContentViewDescriptor clone() { 519 ContentViewDescriptor clone = new ContentViewDescriptor(); 520 clone.name = getName(); 521 clone.enabled = isEnabled(); 522 clone.title = getTitle(); 523 clone.translateTitle = getTranslateTitle(); 524 clone.emptySentence = getEmptySentence(); 525 clone.waitForExecutionSentence = getWaitForExecutionSentence(); 526 clone.translateEmptySentence = getTranslateEmptySentence(); 527 clone.iconPath = getIconPath(); 528 CoreQueryPageProviderDescriptor cpp = getCoreQueryPageProvider(); 529 if (cpp != null) { 530 clone.coreQueryPageProvider = cpp.clone(); 531 } 532 GenericPageProviderDescriptor gpp = getGenericPageProvider(); 533 if (gpp != null) { 534 clone.genericPageProvider = gpp.clone(); 535 } 536 ReferencePageProviderDescriptor rpp = getReferencePageProvider(); 537 if (rpp != null) { 538 clone.referencePageProvider = rpp.clone(); 539 } 540 clone.selectionList = getSelectionListName(); 541 clone.pagination = getPagination(); 542 List<String> actionCats = getActionCategories(); 543 if (actionCats != null) { 544 clone.actionCategories = new ArrayList<String>(); 545 clone.actionCategories.addAll(actionCats); 546 } 547 clone.searchDocument = getSearchDocumentBinding(); 548 ContentViewLayoutImpl searchLayout = getSearchLayout(); 549 if (searchLayout != null) { 550 clone.searchLayout = searchLayout.clone(); 551 } 552 clone.appendResultLayouts = getAppendResultLayouts(); 553 List<ContentViewLayout> resultLayouts = getResultLayouts(); 554 if (resultLayouts != null) { 555 clone.resultLayouts = new ArrayList<ContentViewLayout>(); 556 for (ContentViewLayout item : resultLayouts) { 557 clone.resultLayouts.add(item.clone()); 558 } 559 } 560 clone.resultColumns = getResultColumnsBinding(); 561 clone.resultLayout = getResultLayoutBinding(); 562 List<String> flags = getFlags(); 563 if (flags != null) { 564 clone.flags = new ArrayList<String>(); 565 clone.flags.addAll(flags); 566 } 567 clone.cacheKey = getCacheKey(); 568 clone.cacheSize = getCacheSize(); 569 clone.useGlobalPageSize = getUseGlobalPageSize(); 570 clone.showTitle = getShowTitle(); 571 clone.showPageSizeSelector = getShowPageSizeSelector(); 572 clone.showRefreshCommand = getShowRefreshCommand(); 573 clone.showFilterForm = getShowFilterForm(); 574 List<String> refresh = getRefreshEventNames(); 575 if (refresh != null) { 576 clone.refreshEventNames = new ArrayList<String>(); 577 clone.refreshEventNames.addAll(refresh); 578 } 579 List<String> reset = getResetEventNames(); 580 if (reset != null) { 581 clone.resetEventNames = new ArrayList<String>(); 582 clone.resetEventNames.addAll(reset); 583 } 584 clone.waitForExecution = getWaitForExecution(); 585 return clone; 586 } 587}