Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-17781

Attachments don't appear anymore in the picker of the Office Document Viewer macro

    XMLWordPrintable

Details

    • Bug
    • Resolution: Fixed
    • Blocker
    • 12.8-rc-1
    • 12.7.1
    • Office
    • XWiki 12.7.1 with MySQL 8.0 and IE 11
    • Unknown
    • N/A
    • N/A

    Description

      Steps to reproduce:

      1. Attach a document to a page (word/powerpoint/excel)
      2. Click on Insert > Other Macros
      3. Search for Office Document Viewer macro
      4. Click Select
      5. Select the document from the drop down list under Reference
      6. Click Submit

      Expected results: The document is shown in the page.

      Actual results: No document appears in the drop-down list. Errors appear in the XWiki and browser console.

      Working in XWiki 12.6.2

      XWiki console:

      2020-09-11 10:47:26,271 [qtp668849042-22 - http://localhost:8080/xwiki/bin/skin/resources/uicomponents/suggest/suggestAttachments.min.js?cache-version=1599204144000&language=en&_=1599810404339] ERROR c.x.x.XWiki                    - Error while parsing velocity template namespace [/resources/uicomponents/suggest/suggestAttachments.min.js] with content:
      [/*
       #set ($discard = "#mimetypeimg('' '')")
       #set ($discard = $mimetypeMap.put('attachment', ['attach', 'attachment']))
       #foreach ($map in [$mimetypeMap, $extensionMap])
         #foreach ($entry in $map.entrySet())
           #set ($discard = $entry.value.set(0, $services.icon.getMetaData($entry.value.get(0))))
           #set ($translationKey = "core.viewers.attachments.mime.$entry.value.get(1)")
           #set ($discard = $entry.value.set(1, $services.localization.render($translationKey)))
         #end
       #end
      */
      'use strict';require.config({paths:{"xwiki-selectize":"$xwiki.getSkinFile('uicomponents/suggest/xwiki.selectize.js', true)?v=$escapetool.url($xwiki.version)"}});
      define("xwiki-attachments-store",["jquery"],function(c){var g=function(b,e){var a=["$request.contextPath","rest"];b.getReversedReferenceChain().forEach(function(f){var c=f.type===XWiki.EntityType.DOCUMENT?"page":XWiki.EntityType.getName(f.type);a.push(c+"s",encodeURIComponent(f.name))});b.type===XWiki.EntityType.ATTACHMENT?a.push("metadata"):a.push("attachments");b=c.param(c.extend({prettyNames:!0},e),!0);return a.join("/")+"?"+b};return{get:function(b,e){return c.getJSON(g(b),e)},upload:function(b,
      e){var a=new FormData;a.append("file",e);a.append("filename",b.name);var f=c.Deferred();c.post({url:g(b.parent,{createPage:!0}),data:a,processData:!1,contentType:!1,dataType:"json",xhr:function(){var a=c.ajaxSettings.xhr();a.upload&&a.upload.addEventListener("progress",function(a){a.lengthComputable&&f.notify({loaded:a.loaded,total:a.total,percent:Math.round(100*a.loaded/a.total)})},!1);return a}}).done(c.proxy(f,"resolve")).fail(c.proxy(f,"reject"));return f.promise()},create:function(b,e){var a=
      (new XWiki.Document(b.parent)).getURL("download")+"/"+encodeURIComponent(b.name),f=b.getReversedReferenceChain().map(function(a){return{type:XWiki.EntityType.getName(a.type),name:a.name,label:a.name}});b={id:XWiki.Model.serialize(b),name:b.name,xwikiRelativeUrl:a,hierarchy:{items:f}};e&&c.extend(b,{mimeType:e.type,file:e});return b}}});
      define("xwiki-attachments-icon",["jquery"],function(c){var g=function(a){var f=c.Deferred();if("undefined"!==typeof FileReader){var b=new FileReader;b.onload=function(a){f.resolve(a.target.result)};b.readAsDataURL(a)}return f.promise()},b=$jsontool.serialize($mimetypeMap),e=$jsontool.serialize($extensionMap),a=function(a,c){c=c.substring(c.lastIndexOf(".")+1);if(b.hasOwnProperty(a))return b[a][0];if(e.hasOwnProperty(c))return e[c][0];a=a.substring(0,a.indexOf("/")+1);return b.hasOwnProperty(a)?b[a][0]:
      b.attachment[0]};return{getIcon:function(c){if("string"===typeof c.mimeType&&"image/"===c.mimeType.substring(0,6)){var b=c.xwikiRelativeUrl;if("/"===b.substring(0,1)||"http://"===b.substring(0,7))b+=(0>b.indexOf("?")?"?":"&")+"width=48";var f={iconSetType:"IMAGE",url:b};c.file&&(f.promise=g(c.file).done(function(a){f.url=a}));return f}return a(c.mimeType,c.name)},loadIcon:function(a){var b=c.Deferred();if("IMAGE"===a.icon.iconSetType){var f=new Image;f.onload=function(){b.resolve(a)};f.src=a.icon.url}else b.resolve(a);
      return b.promise()}}});define("xwiki-attachments-filter",["jquery"],function(c){return{filter:function(c,b){var e=[];"string"===typeof b&&(e=b.split(/\s*,\s*/).filter(function(a){return 0<a.length}));return c.filter(function(a){a:{for(var c=e,b=0;b<c.length;b++){var g=c[b];if("."===g.substring(0,1)){if(a.name.substring(a.name.length-g.length)===g){a=!0;break a}}else if("string"===typeof a.mimeType&&0<=a.mimeType.indexOf(g)){a=!0;break a}}a=0===c.length}return a})}}});
      define("xwiki-file-picker",["jquery"],function(c){return{pickLocalFiles:function(g){var b=c.Deferred(),e;c(window).one("focus.filePicker",function(a){e=setTimeout(function(){b.reject()},1E3)});var a=c('<input type="file" class="hidden"/>').prop("multiple",!!g.multiple).appendTo("body");"string"===typeof g.accept&&a.attr("accept",g.accept.replace(/\/(\s*(,|$))/g,"/*$1"));a.change(function(f){c(window).off("focus.filePicker");clearTimeout(e);b.resolve(this.files);a.remove()}).click();return b.promise()}}});
      define("xwiki-suggestAttachments","jquery xwiki-attachments-store xwiki-attachments-icon xwiki-attachments-filter xwiki-file-picker xwiki-selectize".split(" "),function(c,g,b,e,a){var f=function(d){return{maxOptions:10,documentReference:d.data("documentReference"),searchScope:d.data("searchScope"),useAttachmentName:!1,uploadAllowed:"true"===d.data("uploadAllowed")||!0===d.data("uploadAllowed"),accept:d.data("accept"),load:function(d,a){var h=this.settings,b=h.searchScope;""!==d||b&&!h.documentReference.hasParent(b)||
      (b=h.documentReference);g.get(b,{name:d,types:h.accept,number:h.maxOptions}).then(c.proxy(k,null,h)).done(a).fail(a)},loadSelected:function(d,a){p(d,this.settings).done(a).fail(a)},create:function(d,b){if(0<d.length)return b={},b[this.settings.labelField]=d,b[this.settings.valueField]=d,b;a.pickLocalFiles({accept:this.settings.accept,multiple:1!==this.settings.maxItems}).then(c.proxy(m,null,this)).done(b).fail(b)}}},n=function(d){d.documentReference&&"string"!==typeof d.documentReference||(d.documentReference=
      XWiki.Model.resolve(d.documentReference,XWiki.EntityType.DOCUMENT,XWiki.currentDocument.documentReference));a:{var a=d.searchScope||"wiki:"+XWiki.currentWiki;if("string"===typeof a)try{var b=XWiki.Model.resolve(a,null,XWiki.currentDocument.documentReference);break a}catch(A){b=null;break a}b=a}d.searchScope=b;return d},p=function(d,a){d=q(d,a);return g.get(d).then(c.proxy(l,null,a)).then(function(d){return[d]})},k=function(d,a){return c.isArray(a.attachments)?a.attachments.map(c.proxy(l,null,d)):
      []},l=function(a,c){var d=XWiki.Model.resolve(c.id,XWiki.EntityType.ATTACHMENT),h=c.name;a=a.useAttachmentName&&a.searchScope&&a.searchScope.type===XWiki.EntityType.DOCUMENT?d.name:d.parent.equals(a.documentReference)?XWiki.Model.serialize(d.relativeTo(a.documentReference)):XWiki.Model.serialize(d.relativeTo(a.documentReference.getRoot()));return{label:h,value:a,url:c.xwikiRelativeUrl,icon:b.getIcon(c),hint:r(c),data:c}},q=function(a,c){return c.useAttachmentName&&c.searchScope&&c.searchScope.type===
      XWiki.EntityType.DOCUMENT?new XWiki.AttachmentReference(a,c.searchScope):XWiki.Model.resolve(a,XWiki.EntityType.ATTACHMENT,c.documentReference)},r=function(a){return a.hierarchy.items.filter(function(a){return"space"===a.type||"document"===a.type&&"WebHome"!==a.name}).map(function(a){return a.label}).join(" / ")},u=function(a){a.$wrapper.addClass("async-create");var d=a.canCreate;a.canCreate=function(a){return 0===a.length||d.apply(this,arguments)};var b=a.settings.render.option_create;a.settings.render.option_create=
      function(a,d){if(0<a.input.length)return b.apply(this,arguments);var h=$jsontool.serialize($services.localization.render("web.uicomponents.suggest.attachments.upload"));return c('<div class="create upload option"/>').text(h)};var e=a.settings.render.item;a.settings.render.item=function(a){var c=e.apply(this,arguments);a.data&&a.data.upload&&(c.addClass("upload create-"+a.data.upload.status),"running"===a.data.upload.status&&c.css("background","linear-gradient(90deg, #dff0d8 "+a.data.upload.progress.percent+
      "%, #efefef 0)"));return c};t(a)},m=function(a,b){b=v(b,a.settings);b=e.filter(b,a.settings.accept);1===a.settings.maxItems&&(b=b.slice(0,1));b=k(a.settings,{attachments:b});a.addOption(b);var d=c.Deferred(),f=d;b.forEach(function(b){a.addItem(b.value);b.icon.promise&&b.icon.promise.done(function(){a.updateOption(b.value,b)});var d=c.proxy(w,null,b,a);f=f.then(d,d)});d.resolve();return b},v=function(a,b){for(var c=[],d=0;d<a.length;d++){var f=a.item(d),e=new XWiki.EntityReference(f.name,XWiki.EntityType.ATTACHMENT,
      b.documentReference);c.push(g.create(e,f))}return c},w=function(a,f){var d="<em>"+c("<em/>").text(a.label).html()+"</em>",e=new XWiki.widgets.Notification($jsontool.serialize($services.localization.render("web.uicomponents.suggest.attachments.uploading",["{0}"])).replace("{0}",d),"inprogress");a.data.upload={status:"pending",progress:{loaded:0,total:a.data.file.size,percent:0}};return x(a.data).then(c.proxy(l,null,f.settings)).then(b.loadIcon).progress(function(b){a.data.upload.status="running";a.data.upload.progress=
      b;f.updateOption(a.value,a)}).done(function(a){a.data.upload={status:"done"};f.updateOption(a.value,a);e.replace(new XWiki.widgets.Notification($jsontool.serialize($services.localization.render("web.uicomponents.suggest.attachments.uploadDone",["{0}"])).replace("{0}",d),"done"))}).fail(function(){a.data.upload.status="failed";f.updateOption(a.value,a);e.replace(new XWiki.widgets.Notification($jsontool.serialize($services.localization.render("web.uicomponents.suggest.attachments.uploadFailed",["{0}"])).replace("{0}",
      d),"error"))})},x=function(a){var b=XWiki.Model.resolve(a.id,XWiki.EntityType.ATTACHMENT);return g.upload(b,a.file)},t=function(a){a.$wrapper.on("drag dragstart dragend dragover dragenter dragleave drop",function(a){a.preventDefault();a.stopPropagation()}).on("dragover dragenter",function(){c(this).addClass("is-dragover")}).on("dragleave dragend drop",function(){c(this).removeClass("is-dragover")}).on("drop",function(b){b=b.originalEvent.dataTransfer;0<b.files.length?m(a,b.files):y(a,b.getData("text/html"))})},
      y=function(a,b){c(b).find('[data-entity-type="ATTACHMENT"][data-entity-reference]').each(function(){var b=XWiki.Model.resolve(c(this).data("entityReference"),XWiki.EntityType.ATTACHMENT);g.get(b).done(function(b){b=k(a.settings,{attachments:e.filter([b],a.settings.accept)});a.addOption(b);b.forEach(function(b){a.addItem(b.value)})})})},z=function(a){var b=a.settings.render.option;a.settings.render.option=function(d){var f=b.apply(this,arguments),e=f.find(".xwiki-selectize-option-hint");a.settings.searchScope.type===
      XWiki.EntityType.DOCUMENT?e.remove():1===e.length&&(c('<div class="xwiki-selectize-option-label-wrapper"/>').append(f.find(".xwiki-selectize-option-label")).append(e).appendTo(f),f.find(".xwiki-selectize-option-icon-wrapper").addClass("pull-left"));return f}};c.fn.suggestAttachments=function(a){return this.each(function(){var b=c.extend(f(c(this)),a);c(this).xwikiSelectize(n(b));this.selectize.settings.uploadAllowed&&u(this.selectize);z(this.selectize)})}});
      define("xwiki-attachmentResourcePicker",["jquery","xwiki-suggestAttachments"],function(c){var g=function(){b(this.selectize);var c=this.selectize.settings.loadSelected;this.selectize.settings.loadSelected=function(a,b){var f=this.options[a];f&&f.data?b(a):c.apply(this,arguments)}},b=function(b){Object.keys(b.options).forEach(function(a){var c=b.options[a];a:{var e=b.settings.supportedResourceTypes;var g=a.indexOf(":");if(0<=g){var k=a.substring(0,g).toLowerCase();if(0<=e.indexOf(k)){e={type:k,reference:a.substring(g+
      1)};break a}}e={type:"attach",reference:a}}"attach"===e.type?a!==e.reference&&(c[b.settings.valueField]=e.reference,b.updateOption(a,c)):c.data||(c.data.resourceReference=e)})};c.fn.pickAttachmentResource=function(b){return this.on("initialize",g).each(function(){var a=c.extend({supportedResourceTypes:c(this).data("supportedResourceTypes")||"attach, data, url, path, unc"},b);"string"===typeof a.supportedResourceTypes&&(a.supportedResourceTypes=a.supportedResourceTypes.split(/\s*,\s*/).filter(function(a){return 0<
      a.length}).map(function(a){return a.toLowerCase()}));c(this).suggestAttachments(a)})}});require(["jquery","xwiki-suggestAttachments","xwiki-attachmentResourcePicker","xwiki-events-bridge"],function(c){var g=function(b,e){b=c(e&&e.elements||document);b.find(".suggest-attachments").suggestAttachments();b.find(".pick-attachment-resource").pickAttachmentResource()};c(document).on("xwiki:dom:updated",g);XWiki.domIsLoaded&&g()});
      
      //# sourceMappingURL=suggestAttachments.min.js.map
      ]
      org.xwiki.velocity.XWikiVelocityException: Failed to evaluate content with namespace [/resources/uicomponents/suggest/suggestAttachments.min.js]
              at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:292)
              at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:249)
              at com.xpn.xwiki.internal.velocity.DefaultVelocityEvaluator.evaluateVelocity(DefaultVelocityEvaluator.java:72)
              at com.xpn.xwiki.XWiki.evaluateVelocity(XWiki.java:6343)
              at com.xpn.xwiki.XWiki.evaluateVelocity(XWiki.java:6362)
              at com.xpn.xwiki.web.SkinAction.lambda$evaluateVelocity$0(SkinAction.java:385)
              at com.xpn.xwiki.internal.security.authorization.DefaultAuthorExecutor.call(DefaultAuthorExecutor.java:98)
              at com.xpn.xwiki.web.SkinAction.evaluateVelocity(SkinAction.java:385)
              at com.xpn.xwiki.web.SkinAction.renderFileFromFilesystem(SkinAction.java:282)
              at com.xpn.xwiki.web.SkinAction.render(SkinAction.java:157)
              at com.xpn.xwiki.web.SkinAction.render(SkinAction.java:83)
              at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:560)
              at com.xpn.xwiki.web.XWikiAction.execute(XWikiAction.java:250)
              at org.apache.struts.action.RequestProcessor.processActionPerform(RequestProcessor.java:425)
              at org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:228)
              at org.apache.struts.action.ActionServlet.process(ActionServlet.java:1913)
              at org.apache.struts.action.ActionServlet.doGet(ActionServlet.java:449)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:687)
              at javax.servlet.http.HttpServlet.service(HttpServlet.java:790)
              at org.eclipse.jetty.servlet.ServletHolder$NotAsyncServlet.service(ServletHolder.java:1411)
              at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:763)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1631)
              at com.xpn.xwiki.web.ActionFilter.doFilter(ActionFilter.java:122)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
              at org.xwiki.wysiwyg.filter.ConversionFilter.doFilter(ConversionFilter.java:109)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
              at org.xwiki.container.servlet.filters.internal.SetHTTPHeaderFilter.doFilter(SetHTTPHeaderFilter.java:63)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
              at org.xwiki.container.servlet.filters.internal.SavedRequestRestorerFilter.doFilter(SavedRequestRestorerFilter.java:208)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
              at org.xwiki.container.servlet.filters.internal.SetCharacterEncodingFilter.doFilter(SetCharacterEncodingFilter.java:111)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1618)
              at org.xwiki.resource.servlet.RoutingFilter.doFilter(RoutingFilter.java:132)
              at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1610)
              at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:549)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)
              at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:602)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:235)
              at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:1610)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextHandle(ScopedHandler.java:233)
              at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1369)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:188)
              at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:489)
              at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:1580)
              at org.eclipse.jetty.server.handler.ScopedHandler.nextScope(ScopedHandler.java:186)
              at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1284)
              at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)
              at org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:221)
              at org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:146)
              at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:127)
              at org.eclipse.jetty.server.Server.handle(Server.java:501)
              at org.eclipse.jetty.server.HttpChannel.lambda$handle$1(HttpChannel.java:383)
              at org.eclipse.jetty.server.HttpChannel.dispatch(HttpChannel.java:556)
              at org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:375)
              at org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:273)
              at org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:311)
              at org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:103)
              at org.eclipse.jetty.io.ChannelEndPoint$1.run(ChannelEndPoint.java:104)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.runTask(EatWhatYouKill.java:336)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.doProduce(EatWhatYouKill.java:313)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.tryProduce(EatWhatYouKill.java:171)
              at org.eclipse.jetty.util.thread.strategy.EatWhatYouKill.run(EatWhatYouKill.java:129)
              at org.eclipse.jetty.util.thread.ReservedThreadExecutor$ReservedThread.run(ReservedThreadExecutor.java:375)
              at org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:806)
              at org.eclipse.jetty.util.thread.QueuedThreadPool$Runner.run(QueuedThreadPool.java:938)
              at java.lang.Thread.run(Unknown Source)
      Caused by: org.apache.velocity.exception.ParseErrorException: Lexical error,   Encountered: "(" (40), after : "" at /resources/uicomponents/suggest/suggestAttachments.min.js[line 29, column 213]
              at org.apache.velocity.Template.process(Template.java:154)
              at org.xwiki.velocity.internal.DefaultVelocityEngine.evaluate(DefaultVelocityEngine.java:281)
              ... 66 common frames omitted
      

      Attachments

        Issue Links

          Activity

            People

              mflorea Marius Dumitru Florea
              ganechitoaei Gabriela Anechitoaei
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: