1 Reply Latest reply on Mar 20, 2013 7:11 PM by beew71493

    com.day.cq.commons.DownloadResource Illegal call to setSelector() after source already calculated

    beew71493

      Hello I'm having trouble getting a smart image to crop the proper preportions.  I've added a smart image tab to the a form.  The dialog.xml file goes something like this

       

      -----------------------------------

      <?xml version="1.0" encoding="UTF-8"?>

      <jcr:root xmlns:cq="http://www.day.com/jcr/cq/1.0" xmlns:jcr="http://www.jcp.org/jcr/1.0" xmlns:nt="http://www.jcp.org/jcr/nt/1.0"

          jcr:primaryType="cq:Dialog"

          height="600"

          title="dialog"

          width="700"

          xtype="dialog">

          <items

              jcr:primaryType="cq:TabPanel"

              title=""

              xtype="">

              <items jcr:primaryType="cq:WidgetCollection">

                  <titleTab

                      jcr:primaryType="cq:Panel"

                      title="Title">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <documentNumber

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Document Number"

                              name="./document_number"

                              title="Document Number"

                              xtype="textfield"/>

                          <series

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Series"

                              name="./series"

                              options="/etc/rand/scripts/dialogUtils/seriesOptions.json"

                              type="select"

                              xtype="selection"/>

                          <title

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Title"

                              name="./document_title"

                              title="Document Title"

                              xtype="textfield"/>

                          <subtitle

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Subtitle"

                              name="./document_subtitle"

                              title="Document Subtitle"

                              xtype="textfield"/>

                          <authors

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Authors"

                              name="./authors"

                              processRecord="function(record, path) { var authArray = new Array(); var authors=new Array(); var author_types=new Array(); var authorsVal=record.get('./authors'); if(authorsVal instanceof Array){authors=authorsVal;}else{authors[0]=authorsVal;} var authorTypesVal = record.get('./author_types'); if(authorTypesVal instanceof Array){author_types=authorTypesVal;}else{author_types[0]=authorTypesVal;} for(i=0; i &lt; authors.length; i++) { if(authors[i]==undefined){continue;} authArray[i] = authors[i] +'|'+ author_types[i]; } this.setValue(authArray); }"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  xtype="randmultiauthor"/>

                          </authors>

                          <authorsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./authors@TypeHint"

                              xtype="hidden"/>

                          <authorTypesTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./author_types@TypeHint"

                              xtype="hidden"/>

                          <coverDate

                              jcr:primaryType="cq:Widget"

                                    dateFormat="m/d/Y"

                              fieldLabel="Publish Date"

                              name="../../cover_date"

                              processRecord="function(record, path) { var date=document.data.cover_date.value; this.setValue(date); }"

                              title="Publish Date"

                              xtype="datetime"/>

                          <printDate

                              jcr:primaryType="cq:Widget"

                                    dateFormat="m/d/Y"

                              fieldLabel="Print Date"

                                    fieldSubLabel="EPs only. Use when journal print date differs from RAND publish date."

                              name="./print_date"

                              title="Print Date"

                              xtype="datetime"/>

                          <pubYear

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Publish Year"

                              name="./product_date"

                              title="Product Date"

                              xtype="textfield"/>

                          <publisher

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Publisher"

                              name="./publisher"

                              title="Publisher"

                              xtype="textfield"/>

                          <copyrightHolder

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Copyright Holder"

                              name="./copyright_holder"

                              title="Copyright Holder"

                              xtype="textfield"/>

                          <indicia

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Indicia"

                              name="./indicia"

                              title="Indicia"

                              xtype="textfield"/>

                          <primaryResearchArea

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Primary Research Area"

                              name="./primary_research_area"

                              options="/apps/rand/components/content/product/primaryResearchAreas.json"

                              type="select"

                              xtype="selection"/>

                          <divisions

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Divisions"

                              name="../../divisions"

                              processRecord="function(record, path) { var divisionString=document.data.divisions.value; var divs=new Array(); divs=divisionString.split('|'); this.setValue(divs); }"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  hideTrigger="true"

                                  options="/apps/rand/components/content/product/divisionOptions.json"

                                  type="select"

                                  width="400"

                                  xtype="selection"/>

                          </divisions>

                          <divisionsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="../../divisions@TypeHint"

                              xtype="hidden"/>

                      </items>

                  </titleTab>

          <image

                  jcr:primaryType="cq:Widget"

                  cropParameter="./imageCrop"

                  ddGroups="[media]"

                  fileNameParameter="./fileName"

                  fileReferenceParameter="./fileReference"

                  mapParameter="./imageMap"

                  name="./file"

                  requestSuffix=".img.png"

                  rotateParameter="./imageRotate"

                  sizeLimit="100"

                  title="Smart Image"

                  uploadUrl="/tmp/upload_test/*"

                  xtype="smartimage">

                    <cropConfig

                      jcr:primaryType="cq:Widget">

                      <aspectRatios

                        jcr:primaryType="cq:Widget">

                          <teaser

                            jcr:primaryType="cq:Widget"

                            checked="true"

                            text="Teaser"

                            value="63,47"/>

                          <teaserRE

                            jcr:primaryType="cq:Widget"

                            text="Teaser (RAND Europe)"

                            value="91,66"/>

                      </aspectRatios>

                    </cropConfig>

                </image>

              <settings

                  jcr:primaryType="cq:Widget"

                  title="Smart Image Settings"

                  xtype="panel">

                  <items jcr:primaryType="cq:WidgetCollection">

                      <alt

                          jcr:primaryType="cq:Widget"

                          fieldDescription="will override alt set on original DAM asset"

                          fieldLabel="Smart Image Alt Text"

                          name="./alt"

                          xtype="textfield"/>

                      <title

                          jcr:primaryType="cq:Widget"

                          fieldDescription="will override title set on original DAM asset"

                          fieldLabel="Smart Image Title"

                          name="./jcr:title"

                          xtype="textfield"/>

                  </items>

              </settings>

       

       

                  <assetTab

                      jcr:primaryType="cq:Panel"

                      title="Assets">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <assets

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Assets"

                              name="./asset_links_path"

                              processRecord="function(record, path) {var linkArray=new Array();var labels=new Array();var paths=new Array();var notes=new Array();var pathsVal=record.get('./asset_links_path'); if(pathsVal instanceof Array){paths=pathsVal;}else{paths[0]=pathsVal;} var labelsVal=record.get('./asset_links_label'); if(labelsVal instanceof Array){labels=labelsVal;}else{labels[0]=labelsVal;} var notesVal=record.get('./asset_links_note'); if(notesVal instanceof Array){notes=notesVal;}else{notes[0]=notesVal;} for(i=0; i &lt; paths.length; i++) {if(paths==undefined || paths[i]==undefined){continue;} if(labels==undefined || labels[i]==undefined){label=''}else{label=labels[i]} if(notes==undefined || notes[i]==undefined){note=''}else{note=notes[i]} linkArray[i]=label+'|'+paths[i]+'|'+note;}this.setValue(linkArray); }"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  xtype="randmultiproductasset"/>

                          </assets>

                          <assetLinksLabelTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./asset_links_label@TypeHint"

                              xtype="hidden"/>

                          <assetLinksNoteTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./asset_links_note@TypeHint"

                              xtype="hidden"/>

                          <assetLinksPathTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./asset_links_path@TypeHint"

                              xtype="hidden"/>

                          <htmlLink

                              jcr:primaryType="cq:Widget"

                              fieldLabel="HTML Page Link"

                              name="./html_link"

                              title="HTML Page Link"

                              xtype="textfield"/>

                          <htmlLinkText

                              jcr:primaryType="cq:Widget"

                              fieldLabel="HTML Page Link Text"

                              fieldSubLabel="default is 'Full Document'"

                              name="./html_link_text"

                              title="HTML Page Link Text"

                              xtype="textfield"/>

                      </items>

                  </assetTab>

                  <abstractsTab

                      jcr:primaryType="cq:Panel"

                      title="Abstracts">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <webAbstract

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Web Summary"

                              height="80"

                              name="./web_abstract"

                              title="Web Summary"

                              xtype="textarea"/>

                          <jcr_description

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Meta Description"

                              fieldSubLabel="(aka 'one-liner'/'250')"

                              name="../../jcr:description"

                              processRecord="function(record, path) { var desc=document.data.description.value; this.setValue(desc); }"

                              title="Meta Description"

                              xtype="textfield"/>

                          <shortAbstract

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Short Abstract"

                              fieldSubLabel="(aka '450')"

                              height="100"

                              name="./short_abstract"

                              title="Short Abstract"

                              xtype="textarea"/>

                          <longAbstract

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Long Abstract"

                              fieldSubLabel="(aka 'Full Abstract')"

                              height="150"

                              name="./long_abstract"

                              title="Long Abstract"

                              xtype="textarea"/>

                          <hideMicrocontent

                              jcr:primaryType="cq:Widget"

                              default="n"

                              fieldDescription="(check to hide microcontent in display)"

                              fieldLabel="Hide Microcontent"

                              name="./hideMicrocontent"

                              type="checkbox"

                              xtype="selection">

                              <options jcr:primaryType="cq:WidgetCollection">

                                  <y

                                      jcr:primaryType="nt:unstructured"

                                      value="y"/>

                              </options>

                          </hideMicrocontent>

                      </items>

                  </abstractsTab>

                  <bookstoreTab

                      jcr:primaryType="cq:Panel"

                      title="Bookstore">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <invStatus

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Inventory Status"

                              hideTrigger="true"

                              name="./inv_status"

                              type="select"

                              validateOnBlur="true"

                              xtype="selection">

                              <options jcr:primaryType="cq:WidgetCollection">

                                  <available

                                      jcr:primaryType="nt:unstructured"

                                      text="Available"

                                      value="Available"/>

                                  <webonly

                                      jcr:primaryType="nt:unstructured"

                                      text="Web-Only"

                                      value="Web-Only"/>

                                  <prepublication

                                      jcr:primaryType="nt:unstructured"

                                      text="Pre-Publication"

                                      value="Pre-Publication"/>

                                  <withdrawn

                                      jcr:primaryType="nt:unstructured"

                                      text="Withdrawn"

                                      value="Withdrawn"/>

                                  <superseded

                                      jcr:primaryType="nt:unstructured"

                                      text="Superseded"

                                      value="Superseded"/>

                                  <outofprint

                                      jcr:primaryType="nt:unstructured"

                                      text="Out Of Print"

                                      value="Out Of Print"/>

                                  <nonrand

                                      jcr:primaryType="nt:unstructured"

                                      text="Non-RAND"

                                      value="Non-RAND"/>

                              </options>

                          </invStatus>

                          <supersededLink

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Superseded Link"

                              name="./superseded_link"

                              rootPath="/content/rand/pubs"

                              title="Superseded Link"

                              xtype="pathfield"/>

                          <embargoed

                              jcr:primaryType="cq:Widget"

                              default="n"

                              fieldDescription="(if embargoed document, check box)"

                              fieldLabel="Embargoed Document"

                              name="./embargoed"

                              type="checkbox"

                              xtype="selection">

                              <options jcr:primaryType="cq:WidgetCollection">

                                  <y

                                      jcr:primaryType="nt:unstructured"

                                      value="y"/>

                              </options>

                          </embargoed>

                          <invStatusNote

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Status Text"

                              name="./inv_status_note"

                              xtype="textarea"/>

                          <discountPct

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Discount Percentage"

                              name="./discount_pct"

                              regex="/^[0-9][0-9]$/"

                              regexText="Discount percentage must be 2-digit numeric"

                              title="Discount Percentage"

                              xtype="textfield"/>

                          <product_formats

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Product Formats"

                              fieldSubLabel="binding|price|ISBN|pages"

                              name="./product_formats"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  xtype="textfield"/>

                          </product_formats>

                          <productFormatsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./product_formats@TypeHint"

                              xtype="hidden"/>

                      </items>

                  </bookstoreTab>

                  <tocTab

                      jcr:primaryType="cq:Panel"

                      title="TOC">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <toc

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Table of Contents"

                              fieldSubLabel="rich text format"

                              name="./toc"

                              title="TOC"

                              xtype="textarea"/>

                          <tocxml

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Table of Contents"

                              fieldSubLabel="XML format"

                              height="200"

                              name="./tocxml"

                              title="TOCXML"

                              xtype="textarea"/>

                      </items>

                  </tocTab>

                  <awardsReviewsTab

                      jcr:primaryType="cq:Panel"

                      title="Awards/Reviews">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <awards

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Awards"

                              name="./awardTitles"

                              processRecord="function(record, path) { var awardsArray=new Array(); var titles=new Array(); var subtitles=new Array(); var titlesVal=record.get('./awardTitles'); if(titlesVal instanceof Array){titles=titlesVal;}else{titles[0]=titlesVal;} var subtitlesVal=record.get('./awardSubtitles'); if(subtitlesVal instanceof Array){subtitles=subtitlesVal;}else{subtitles[0]=subtitlesVal;} for(i=0; i &lt; titles.length; i++) { if(titles==undefined || titles[i]==undefined){continue;} if(subtitles==undefined || subtitles[i]==undefined){subtitle='';}else{subtitle=subtitles[i];} awardsArray[i] = titles[i] + &quot;|&quot; + subtitle; } this.setValue(awardsArray); }"

                              title="Awards"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  hideTrigger="true"

                                  text1FieldLabel="Award Title"

                                  text1Property="awardTitles"

                                  text2FieldLabel="Award Subtitle"

                                  text2Property="awardSubtitles"

                                  width="400"

                                  xtype="randMultiText"/>

                          </awards>

                          <awardTitlesTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./awardTitles@TypeHint"

                              xtype="hidden"/>

                          <awardSubtitlesTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./awardSubtitles@TypeHint"

                              xtype="hidden"/>

                          <bookReviews

                              jcr:primaryType="cq:Widget"

                              anchor="100%"

                              fieldLabel="Book Reviews"

                              name="./sources"

                              processRecord="function(record, path) { var reviewsArray=new Array(); var reviews=new Array(); var sources=new Array(); var reviewsVal=record.get('./reviews'); if(reviewsVal instanceof Array){reviews=reviewsVal;}else{reviews[0]=reviewsVal;} var sourcesVal=record.get('./sources'); if(sourcesVal instanceof Array){sources=sourcesVal;}else{sources[0]=sourcesVal;} for(i=0; i &lt; sources.length; i++) { if(sources==undefined || sources[i]==undefined || reviews==undefined || reviews[i]==undefined){continue;} reviewsArray[i] = sources[i]+'|'+ reviews[i]; } this.setValue(reviewsArray); }"

                              title="Book Reviews"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  hideTrigger="true"

                                  textAreaFieldLabel="Review"

                                  textAreaProperty="reviews"

                                  textFieldLabel="Source"

                                  textProperty="sources"

                                  width="600"

                                  xtype="randMultiTextAndTextArea"/>

                          </bookReviews>

                          <sourcesTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./sources@TypeHint"

                              xtype="hidden"/>

                          <reviewsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./reviews@TypeHint"

                              xtype="hidden"/>

                      </items>

                  </awardsReviewsTab>

                  <tagsTab

                      jcr:primaryType="cq:Panel"

                      hideMode="offsets"

                      title="Tags/Links">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <tags

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Tags"

                              name="../../cq:tags"

                              processRecord="function(record, path) { var tagString=document.data.tags.value; var tags=new Array(); tags=tagString.split('|'); this.setValue(tags); }"

                              xtype="tags"/>

                          <relatedLinks

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Related Links"

                              name="./related_links"

                              processRecord="function(record, path) {var link = record.get('./related_links');var styles = record.get('./styles');var texts = record.get('./texts');if (link !== undefined) { if(link instanceof Array){ for (var i = 0; i &lt; link.length; i++) { if(styles==undefined || i >= styles.length || styles[i]=='undefined'){style=''}else{style=styles[i]} if(texts==undefined || i >= texts.length || texts[i]=='undefined'){text=''}else{text=texts[i]} link[i] = link[i]+'|'+style+'|'+text; this.setValue(link); }} else {if(styles==undefined){styles='';}if(texts==undefined){texts='';}link = link +'|'+styles+'|'+texts; this.setValue(link); }}}"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  xtype="randlinkbar"/>

                          </relatedLinks>

                          <relatedLinksTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./related_links@TypeHint"

                              xtype="hidden"/>

                          <stylesTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./styles@TypeHint"

                              xtype="hidden"/>

                          <textsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./texts@TypeHint"

                              xtype="hidden"/>

                          <relatedReports

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Related Reports"

                              name="./related_reports"

                              xtype="multifield">

                              <fieldConfig

                                  jcr:primaryType="cq:Widget"

                                  hideTrigger="true"

                                  width="400"

                                  xtype="textfield"/>

                          </relatedReports>

                          <relatedReportsTypeHint

                              jcr:primaryType="cq:Widget"

                              defaultValue="String[]"

                              name="./related_reports@TypeHint"

                              xtype="hidden"/>

                      </items>

                  </tagsTab>

                  <commentsTab

                      jcr:primaryType="cq:Panel"

                      title="Comments">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <comments

                              jcr:primaryType="cq:Widget"

                              fieldLabel="Comments"

                              name="./comments"

                              title="Comments"

                              xtype="textarea"/>

                      </items>

                  </commentsTab>

                  <imageTab

                      jcr:primaryType="cq:Panel"

                      title="Legacy Image">

                      <items jcr:primaryType="cq:WidgetCollection">

                          <coverImage

                              jcr:primaryType="cq:Widget"

                              autoUploadDelay="1"

                              ddGroups="[media]"

                              fieldLabel="Cover Image"

                              fileNameParameter="./cover_image_name"

                              fileReferenceParameter="./cover_link"

                              height="150"

                              mimeTypes="*.jpg;*.jpeg;*.gif;*.png"

                              mimeTypesDescription="Images"

                              name="./cover_image"

                              sizeLimit="100"

                              title="Cover Image"

                              uploadUrl="/tmp/upload_test/*"

                              xtype="smartfile"/>

                      </items>

                  </imageTab>

              </items>

          </items>

      </jcr:root>

      ------------------------------------------------------------------------------------------ ------

       

      I've also created a productImg.GET.java servlet to handle this form.  And in my code I'm doing 2 things.

      1.  Create an image

      2.  Load the currentStyle

        3.  Set the selector to refer to the product image servlet

       

       

      image = new Image(resourceResolver.resolve(currentNode.getPath()));

      if (!"".equals(image.getFileName())) {

        image.setSelector("." + AssetConstants.TEASER_IMAGE_GRID_SELECTOR);

        image.draw(out);

      }

       

      This will display the image (without cropping / rotating affects).

       

      I looked at my logs but it keeps saying

      -------------------------------------------------------------

      com.day.cq.commons.DownloadResource Illegal call to setSelector() after source already calculated.

      ------------------------------------------------------------

       

       

      Now I've tried to set this code at the earliest possible call and it seems, short of calling the code before my include and import code, to provide me with the same error.

       

      Any help as to what this is and why it somehow decided to lock onto a resource without the ability to change it?  I know this code works for a teaser codebase that I've modeled after.

       

      my includes are as follows

       

      ----------------------------------------

        com.day.cq.wcm.api.WCMMode,

                                    java.text.SimpleDateFormat,

                                    java.util.ArrayList,

                                    java.util.Calendar,

                                    java.util.Date,

                                    org.rand.common.utils.NodeUtils,

                                    org.rand.common.utils.RANDUtils,

                                    org.rand.common.utils.RANDHTMLUtils,

                                    org.rand.constants.CQ,

                                    org.rand.constants.Constants,

                                    org.rand.constants.Paths,

                                    org.rand.people.PeopleFactory,

                                    org.rand.pubs.Pub,

                                    org.rand.pubs.PubFactory,

                                    org.rand.pubs.PubUtil,

                                    org.rand.pubs.Series,

                                    com.day.cq.wcm.foundation.Image,

                                    org.apache.sling.api.resource.Resource,

                                    org.rand.constants.AssetConstants,

        com.day.cq.wcm.api.components.EditConfig,

        com.day.cq.wcm.commons.WCMUtils

      --------------------------------------------

       

       

      Thanks!