From 57c8e789a57919d1f8dcc1c719ba5d29b0db5da1 Mon Sep 17 00:00:00 2001 From: quasi Date: Fri, 8 Oct 2010 05:36:10 +0000 Subject: [PATCH] RelatedLinks MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * RelatedLinks bzw. Links so erweitert, daß man den gewünschten CT angeben kann git-svn-id: https://svn.libreccm.org/ccm/trunk@562 8810af33-2d31-482b-a856-94f89814c4df --- .../ui/RelatedLinkPropertyForm.java | 128 +++---- .../content-section/RelationAttribute.pdl | 10 +- .../cms/contenttypes/ui/LinkPropertyForm.java | 314 +++++++++--------- 3 files changed, 229 insertions(+), 223 deletions(-) diff --git a/ccm-cms-assets-relatedlink/src/com/arsdigita/cms/contentassets/ui/RelatedLinkPropertyForm.java b/ccm-cms-assets-relatedlink/src/com/arsdigita/cms/contentassets/ui/RelatedLinkPropertyForm.java index 167c01503..c904e721c 100755 --- a/ccm-cms-assets-relatedlink/src/com/arsdigita/cms/contentassets/ui/RelatedLinkPropertyForm.java +++ b/ccm-cms-assets-relatedlink/src/com/arsdigita/cms/contentassets/ui/RelatedLinkPropertyForm.java @@ -25,6 +25,7 @@ import com.arsdigita.bebop.form.TextField; import com.arsdigita.bebop.parameters.StringParameter; import com.arsdigita.cms.ContentItem; import com.arsdigita.cms.ContentSection; +import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.contenttypes.ui.LinkPropertyForm; @@ -45,10 +46,10 @@ import com.arsdigita.util.Assert; * @version $Revision: #3 $ $Date: 2004/03/30 $ * @author Scott Seago (sseago@redhat.com) */ - public class RelatedLinkPropertyForm extends LinkPropertyForm { private static boolean isHideAdditionalResourceFields; + static { isHideAdditionalResourceFields = ContentSection.getConfig().isHideAdditionalResourceFields(); } @@ -61,38 +62,45 @@ public class RelatedLinkPropertyForm extends LinkPropertyForm { * @param link The LinkSelectionModel to use to obtain the * Link to work on */ - public RelatedLinkPropertyForm( ItemSelectionModel itemModel, - LinkSelectionModel link ) { - + public RelatedLinkPropertyForm(ItemSelectionModel itemModel, + LinkSelectionModel link) { + super(itemModel, link); } - - protected void addWidgets() { - - super.addWidgets(); - if ( isHideAdditionalResourceFields ) { - // Do nothing except protect the poor users from themselves. - } else { - //Hack to get the form layout right. - add(new Label("")); - add(new Label( - new GlobalizedMessage("com.arsdigita.cms.contentassets.related_link_resourceSize", - "com.arsdigita.cms.contentassets.RelatedLinkResources"))); - - TextField resSize = new TextField(new StringParameter(RelatedLink.RESOURCE_SIZE)); - add(resSize); - - add(new Label( - new GlobalizedMessage("com.arsdigita.cms.contentassets.related_link_resourceType", - "com.arsdigita.cms.contentassets.RelatedLinkResources"))); + public RelatedLinkPropertyForm(ItemSelectionModel itemModel, + LinkSelectionModel link, ContentType contentType) { - SingleSelect resType = new SingleSelect(new StringParameter(RelatedLink.RESOURCE_TYPE)); - addMimeOptions(resType); - add(resType); - } + super(itemModel, link, contentType); } - + + @Override + protected void addWidgets() { + + super.addWidgets(); + + if (isHideAdditionalResourceFields) { + // Do nothing except protect the poor users from themselves. + } else { + //Hack to get the form layout right. + add(new Label("")); + add(new Label( + new GlobalizedMessage("com.arsdigita.cms.contentassets.related_link_resourceSize", + "com.arsdigita.cms.contentassets.RelatedLinkResources"))); + + TextField resSize = new TextField(new StringParameter(RelatedLink.RESOURCE_SIZE)); + add(resSize); + + add(new Label( + new GlobalizedMessage("com.arsdigita.cms.contentassets.related_link_resourceType", + "com.arsdigita.cms.contentassets.RelatedLinkResources"))); + + SingleSelect resType = new SingleSelect(new StringParameter(RelatedLink.RESOURCE_TYPE)); + addMimeOptions(resType); + add(resType); + } + } + /** * Add mime-type options to the option group by loading all mime * types which match a certain prefix from the database @@ -103,12 +111,12 @@ public class RelatedLinkPropertyForm extends LinkPropertyForm { public static void addMimeOptions(SingleSelect w) { MimeTypeCollection types; types = MimeType.getAllMimeTypes(); - while(types.next()) { + while (types.next()) { MimeType type = types.getMimeType(); w.addOption(new Option(type.getMimeType(), type.getLabel())); } } - + /** * Take care of basic RelatedLink creation steps. Creates the * RelatedLink and sets the linkOwner property. @@ -125,10 +133,10 @@ public class RelatedLinkPropertyForm extends LinkPropertyForm { //link.setName(item.getName() + "_link_" + item.getID()); // set the owner of the link link.setLinkOwner(item); - + return link; } - + /** * Over-ride super class method to initialize addtional fields specific * to RelatedLink content asset. @@ -138,41 +146,41 @@ public class RelatedLinkPropertyForm extends LinkPropertyForm { FormData data = fse.getFormData(); PageState ps = fse.getPageState(); RelatedLink rl; - if ( isHideAdditionalResourceFields ) { + if (isHideAdditionalResourceFields) { // Do nothing except protect the poor users from themselves. } else { - if ( getLinkSelectionModel().isSelected(ps)) { - //We are editing the link , populate our addtional fields. - rl = (RelatedLink) getLinkSelectionModel().getSelectedLink(ps); - data.put(RelatedLink.RESOURCE_SIZE , rl.getResourceSize()); - if(rl.getResourceType() != null){ - data.put(RelatedLink.RESOURCE_TYPE , rl.getResourceType().getMimeType()); - } - } else { - // New Link creation , clear the fields. - data.put(RelatedLink.RESOURCE_SIZE , null); - data.put(RelatedLink.RESOURCE_TYPE , null); + if (getLinkSelectionModel().isSelected(ps)) { + //We are editing the link , populate our addtional fields. + rl = (RelatedLink) getLinkSelectionModel().getSelectedLink(ps); + data.put(RelatedLink.RESOURCE_SIZE, rl.getResourceSize()); + if (rl.getResourceType() != null) { + data.put(RelatedLink.RESOURCE_TYPE, rl.getResourceType().getMimeType()); + } + } else { + // New Link creation , clear the fields. + data.put(RelatedLink.RESOURCE_SIZE, null); + data.put(RelatedLink.RESOURCE_TYPE, null); + } } } - } - + /** * over-ride super class method to set extended properties for * RelatedLink. */ - protected void setLinkProperties(Link link , FormSectionEvent fse){ - RelatedLink rl = (RelatedLink) (link); - FormData data = fse.getFormData(); - if ( isHideAdditionalResourceFields ) { - // We are not using these but let's try to set some reasonable defaults. - rl.setResourceSize( "" ); - rl.setResourceType(MimeType.loadMimeType("text/html")); - } else { - rl.setResourceSize( (String) data.get(RelatedLink.RESOURCE_SIZE)); - String typeName = (String) data.get(RelatedLink.RESOURCE_TYPE); - MimeType mType = MimeType.loadMimeType(typeName); - rl.setResourceType(mType); - } - super.setLinkProperties(link , fse); + protected void setLinkProperties(Link link, FormSectionEvent fse) { + RelatedLink rl = (RelatedLink) (link); + FormData data = fse.getFormData(); + if (isHideAdditionalResourceFields) { + // We are not using these but let's try to set some reasonable defaults. + rl.setResourceSize(""); + rl.setResourceType(MimeType.loadMimeType("text/html")); + } else { + rl.setResourceSize((String) data.get(RelatedLink.RESOURCE_SIZE)); + String typeName = (String) data.get(RelatedLink.RESOURCE_TYPE); + MimeType mType = MimeType.loadMimeType(typeName); + rl.setResourceType(mType); + } + super.setLinkProperties(link, fse); } } diff --git a/ccm-cms/pdl/com/arsdigita/content-section/RelationAttribute.pdl b/ccm-cms/pdl/com/arsdigita/content-section/RelationAttribute.pdl index 6fe50195a..38821d726 100644 --- a/ccm-cms/pdl/com/arsdigita/content-section/RelationAttribute.pdl +++ b/ccm-cms/pdl/com/arsdigita/content-section/RelationAttribute.pdl @@ -24,11 +24,11 @@ import com.arsdigita.cms.*; object type RelationAttribute extends ContentItem { - String[1..1] attribute = cms_contacttypes.attribute VARCHAR(100); - String[1..1] key = cms_contacttypes.key VARCHAR(100); - String[1..1] lang = cms_contacttypes.lang VARCHAR(2); -// String[1..1] name = cms_contacttypes.name VARCHAR(100); - String[0..1] description = cms_contacttypes.description VARCHAR(500); + String[1..1] attribute = cms_relation_attribute.attribute VARCHAR(100); + String[1..1] key = cms_relation_attribute.key VARCHAR(100); + String[1..1] lang = cms_relation_attribute.lang VARCHAR(2); +// String[1..1] name = cms_relation_attribute.name VARCHAR(100); + String[0..1] description = cms_relation_attribute.description VARCHAR(500); unique (attribute, key, lang); reference key(cms_relationAttribute.relationattribute_id); diff --git a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java index cd54eea65..45b864c09 100755 --- a/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java +++ b/ccm-cms/src/com/arsdigita/cms/contenttypes/ui/LinkPropertyForm.java @@ -45,6 +45,7 @@ import com.arsdigita.util.UncheckedWrapperException; import com.arsdigita.web.Web; import com.arsdigita.cms.ContentItem; +import com.arsdigita.cms.ContentType; import com.arsdigita.cms.ItemSelectionModel; import com.arsdigita.cms.contenttypes.Link; import com.arsdigita.cms.ui.ItemSearchWidget; @@ -62,16 +63,14 @@ import org.apache.log4j.Logger; * @version $Revision: #5 $ $Date: 2004/08/17 $ * @author Nobuko Asakai (nasakai@redhat.com) */ - public class LinkPropertyForm extends FormSection - implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { - private static final Logger s_log = Logger.getLogger(LinkPropertyForm.class); + implements FormInitListener, FormProcessListener, FormValidationListener, FormSubmissionListener { + private static final Logger s_log = Logger.getLogger(LinkPropertyForm.class); /** Name of this form */ public static final String ID = "link_edit"; public static final String SSL_PROTOCOL = "https://"; public static final String HTTP_PROTOCOL = "http://"; - private TextArea m_description; private TextField m_title; private TextField m_targetURI; @@ -81,9 +80,9 @@ public class LinkPropertyForm extends FormSection private LinkSelectionModel m_linkModel; private SaveCancelSection m_saveCancelSection; private ItemSearchWidget m_itemSearch; + private ContentType m_contentType; + private final String ITEM_SEARCH = "contentItem"; - private final String ITEM_SEARCH ="contentItem"; - /** * Creates a new form to edit the Link object specified * by the item selection model passed in. @@ -92,12 +91,18 @@ public class LinkPropertyForm extends FormSection * @param link The LinkSelectionModel to use to obtain the * Link to work on */ - public LinkPropertyForm( ItemSelectionModel itemModel, - LinkSelectionModel link ) { + public LinkPropertyForm(ItemSelectionModel itemModel, + LinkSelectionModel link) { + this(itemModel, link, null); + } + + public LinkPropertyForm(ItemSelectionModel itemModel, + LinkSelectionModel link, ContentType contentType) { super(new ColumnPanel(2)); s_log.debug("property form constructor"); m_linkModel = link; m_itemModel = itemModel; + m_contentType = contentType; addWidgets(); addSaveCancelSection(); @@ -122,28 +127,26 @@ public class LinkPropertyForm extends FormSection m_description = new TextArea("description"); m_description.setCols(40); m_description.setRows(5); - add(new Label(GlobalizationUtil. - globalize("cms.contenttypes.ui.description"))); + add(new Label(GlobalizationUtil.globalize("cms.contenttypes.ui.description"))); add(m_description); add(new Label( - "\n", - false - )); + "\n", + false)); - add(new Label( "Choose either a URL or a Content Item", Label.BOLD), - ColumnPanel.FULL_WIDTH); + add(new Label("Choose either a URL or a Content Item", Label.BOLD), + ColumnPanel.FULL_WIDTH); m_linkType = new RadioGroup("linkType"); Option m_external = new Option(Link.EXTERNAL_LINK, "URL"); m_external.setOnClick("toggle_link_fields(false)"); @@ -166,27 +169,26 @@ public class LinkPropertyForm extends FormSection m_targetURI = new TextField("targetURI"); m_targetURI.setOnFocus("toggle_link_fields(false)"); m_targetURI.setHint("Enter a URL such as http://www.example.com/ or /ccm/forum/"); - add( new Label( "URL: " ) ); - add( m_targetURI ); + add(new Label("URL: ")); + add(m_targetURI); add(new Label("Content Item:")); - m_itemSearch = new ItemSearchWidget(ITEM_SEARCH); + m_itemSearch = new ItemSearchWidget(ITEM_SEARCH, m_contentType); m_itemSearch.getSearchButton().setOnFocus("toggle_link_fields(true)"); m_itemSearch.getClearButton().setOnFocus("toggle_link_fields(true)"); add(m_itemSearch); add(new Label( - "\n", - false - )); + "\n", + false)); } /** Adds the saveCancelSection */ @@ -194,29 +196,29 @@ public class LinkPropertyForm extends FormSection m_saveCancelSection = new SaveCancelSection(); try { m_saveCancelSection.getCancelButton().addPrintListener( - new PrintListener() { - public void prepare(PrintEvent e) { - Submit target = (Submit)e.getTarget(); - if (m_linkModel.isSelected(e.getPageState())) { - target.setButtonLabel("Cancel"); - } else { - target.setButtonLabel("Reset"); + new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_linkModel.isSelected(e.getPageState())) { + target.setButtonLabel("Cancel"); + } else { + target.setButtonLabel("Reset"); + } } - } - } - ); + }); m_saveCancelSection.getSaveButton().addPrintListener( - new PrintListener() { - public void prepare(PrintEvent e) { - Submit target = (Submit)e.getTarget(); - if (m_linkModel.isSelected(e.getPageState())) { - target.setButtonLabel("Save"); - } else { - target.setButtonLabel("Create"); + new PrintListener() { + + public void prepare(PrintEvent e) { + Submit target = (Submit) e.getTarget(); + if (m_linkModel.isSelected(e.getPageState())) { + target.setButtonLabel("Save"); + } else { + target.setButtonLabel("Create"); + } } - } - } - ); + }); } catch (TooManyListenersException e) { throw new UncheckedWrapperException("this cannot happen", e); } @@ -227,10 +229,10 @@ public class LinkPropertyForm extends FormSection public SaveCancelSection getSaveCancelSection() { return m_saveCancelSection; } - + /** return selection model for Link that we are dealing with. */ - protected LinkSelectionModel getLinkSelectionModel(){ - return m_linkModel; + protected LinkSelectionModel getLinkSelectionModel() { + return m_linkModel; } /** @@ -238,10 +240,10 @@ public class LinkPropertyForm extends FormSection * * @param e the FormSectionEvent */ - public void submitted(FormSectionEvent e) - throws FormProcessException { + public void submitted(FormSectionEvent e) + throws FormProcessException { if (m_saveCancelSection.getCancelButton().isSelected(e.getPageState())) { - s_log.debug("cancel in submission listener"); + s_log.debug("cancel in submission listener"); m_linkModel.clearSelection(e.getPageState()); init(e); throw new FormProcessException("cancelled"); @@ -253,35 +255,35 @@ public class LinkPropertyForm extends FormSection * * @param event the FormSectionEvent */ - public void validate(FormSectionEvent event) - throws FormProcessException { + public void validate(FormSectionEvent event) + throws FormProcessException { PageState state = event.getPageState(); FormData data = event.getFormData(); - if (Link.EXTERNAL_LINK.equals((String)m_linkType.getValue(state))) { + if (Link.EXTERNAL_LINK.equals((String) m_linkType.getValue(state))) { // The link is external, the URL must be valid and not null - String externalURI = (String)m_targetURI.getValue(state); - if (externalURI == null || externalURI.length() == 0 ) { + String externalURI = (String) m_targetURI.getValue(state); + if (externalURI == null || externalURI.length() == 0) { throw new FormProcessException("The URI field is required for an external link."); } - - String url = (String)m_targetURI.getValue(state); + + String url = (String) m_targetURI.getValue(state); try { // See if it's a valid URL - URL test = new URL( url ); - } catch (MalformedURLException ex ) { - boolean localLink = url.startsWith( "/" ); + URL test = new URL(url); + } catch (MalformedURLException ex) { + boolean localLink = url.startsWith("/"); boolean hasProtocol = url.indexOf("://") != -1; String newURL; - if( localLink ) { + if (localLink) { // For a local link, see if it would be ok if we stuck // "http://servername" on the front - newURL = HTTP_PROTOCOL + Web.getConfig().getHost() + - url; - } else if( !hasProtocol ) { + newURL = HTTP_PROTOCOL + Web.getConfig().getHost() + + url; + } else if (!hasProtocol) { // There's no protocol. See if it would be ok if we // put one on the beginning @@ -289,40 +291,39 @@ public class LinkPropertyForm extends FormSection } else { // No idea, just throw the error - throw new FormProcessException - ( "URL is not valid: " + ex.getMessage() ); + throw new FormProcessException("URL is not valid: " + ex.getMessage()); } try { - URL test = new URL( newURL ); - } catch (MalformedURLException ex2 ) { + URL test = new URL(newURL); + } catch (MalformedURLException ex2) { StringBuffer msg = new StringBuffer(); - if( localLink ) { + if (localLink) { // For local link, report the error after we put a // protocol and servername on it - msg.append( "Local URL is not valid: " ); - msg.append( ex2.getMessage() ); + msg.append("Local URL is not valid: "); + msg.append(ex2.getMessage()); } else { // For external link, report the error before we tried // to munge it - msg.append( "External URL is not valid: " ); - msg.append( ex.getMessage() ); + msg.append("External URL is not valid: "); + msg.append(ex.getMessage()); } - throw new FormProcessException( msg.toString() ); + throw new FormProcessException(msg.toString()); } // If we fixed it by adding a protocol, notify the user to // check that's what they intended - if( !localLink && !hasProtocol ) { - m_targetURI.setValue( state, newURL ); - throw new FormProcessException( "A valid URL starts with a protocol, eg http://" ); + if (!localLink && !hasProtocol) { + m_targetURI.setValue(state, newURL); + throw new FormProcessException("A valid URL starts with a protocol, eg http://"); } } - } else if (Link.INTERNAL_LINK.equals((String)m_linkType.getValue(state))) { + } else if (Link.INTERNAL_LINK.equals((String) m_linkType.getValue(state))) { // The link is internal, the item selected must be not null if (data.get(ITEM_SEARCH) == null) { throw new FormProcessException("Item selection is required for internal link."); @@ -337,7 +338,7 @@ public class LinkPropertyForm extends FormSection * @return the ContentItem */ protected ContentItem getContentItem(PageState s) { - return (ContentItem)m_itemModel.getSelectedObject(s); + return (ContentItem) m_itemModel.getSelectedObject(s); } /** @@ -353,36 +354,35 @@ public class LinkPropertyForm extends FormSection return link; } - /** * Init listener. For edit actions, fills the form with current data * * @param fse the FormSectionEvent */ - public void init( FormSectionEvent fse ) throws FormProcessException { + public void init(FormSectionEvent fse) throws FormProcessException { FormData data = fse.getFormData(); PageState state = fse.getPageState(); s_log.debug("Init"); setVisible(state, true); Link link; - if ( m_linkModel.isSelected(state)) { + if (m_linkModel.isSelected(state)) { s_log.debug("Edit"); link = m_linkModel.getSelectedLink(state); try { m_title.setValue(state, link.getTitle()); m_description.setValue(state, link.getDescription()); m_targetURI.setValue(state, link.getTargetURI()); - if ( com.arsdigita.bebop.Link.NEW_FRAME.equals(link.getTargetWindow()) ) { - m_URIOption.setValue(state, Link.TARGET_WINDOW); + if (com.arsdigita.bebop.Link.NEW_FRAME.equals(link.getTargetWindow())) { + m_URIOption.setValue(state, Link.TARGET_WINDOW); } else { - m_URIOption.setValue(state, null); + m_URIOption.setValue(state, null); } m_linkType.setValue(state, link.getTargetType()); if (Link.INTERNAL_LINK.equals(link.getTargetType())) { data.put(ITEM_SEARCH, link.getTargetItem()); } - } catch (IllegalStateException e ) { + } catch (IllegalStateException e) { s_log.error(e.getMessage()); throw e; } @@ -397,24 +397,23 @@ public class LinkPropertyForm extends FormSection data.put(ITEM_SEARCH, null); } } - /** * Process listener. Saves/creates the new or modified Link * * @param fse the FormSectionEvent */ - public void process( FormSectionEvent fse ) throws FormProcessException { + public void process(FormSectionEvent fse) throws FormProcessException { PageState state = fse.getPageState(); Link link; // save only if save button was pressed - if ( getSaveCancelSection().getCancelButton().isSelected(state) ) { + if (getSaveCancelSection().getCancelButton().isSelected(state)) { // cancel button is selected m_linkModel.clearSelection(state); - s_log.debug("link save canceled"); + s_log.debug("link save canceled"); - } else { + } else { if (m_linkModel.isSelected(state)) { // Editing a link @@ -423,70 +422,69 @@ public class LinkPropertyForm extends FormSection } else { s_log.debug("processing new link"); link = createLink(state); - } + } //call to set various properties of Link. - setLinkProperties(link , fse); - s_log.debug("Created Link with ID: " + link.getOID().toString() - + "Title " + link.getTitle()); + setLinkProperties(link, fse); + s_log.debug("Created Link with ID: " + link.getOID().toString() + + "Title " + link.getTitle()); } // XXX Initialize the form m_linkModel.clearSelection(state); init(fse); } - + /** * Set various properties of the Link.Child clases can over-ride this * method to add additional properties to Link. */ - protected void setLinkProperties(Link link , FormSectionEvent fse){ - PageState state = fse.getPageState(); - FormData data = fse.getFormData(); - // * Set required properties * - link.setTitle((String)m_title.getValue(state)); - link.setDescription( (String) - m_description.getValue(state)); - link.setTargetType((String)m_linkType.getValue(state)); + protected void setLinkProperties(Link link, FormSectionEvent fse) { + PageState state = fse.getPageState(); + FormData data = fse.getFormData(); + // * Set required properties * + link.setTitle((String) m_title.getValue(state)); + link.setDescription((String) m_description.getValue(state)); + link.setTargetType((String) m_linkType.getValue(state)); - // Process internal and external urls - if (Link.EXTERNAL_LINK.equals(m_linkType.getValue(state))) { - link.setTargetURI( - (String) m_targetURI.getValue(state)); - link.setTargetItem(null); - } else { - // Internal - link.setTargetURI(null); - - // Quasimodo: BEGIN - // This is part of the patch to make RelatedLink (and Link) multilanguage compatible - // Here we have to link to the content bundle instead of the content item, if there's one - // else we don't have a proper multilanguage support' - ContentItem ci = (ContentItem) data.get(ITEM_SEARCH); - - // If the selected target item ci has a parent of type ContentBundle - if (ci.getParent() instanceof ContentBundle) { - // Then there a multiple language versions of this content item and we want to - // link to the content bundle, so we can later negotiate the language depending - // on browser settings - ci = (ContentItem) ci.getParent(); - } - - link.setTargetItem(ci); - } - // Process whether link is to be opened in new window - boolean isNewWindow = false; - String[] value = (String[])m_URIOption.getValue(state); - // Technically this isn't really necessary as there is only one box so any - // non-null value means it was checked - if (value != null) { - isNewWindow = link.TARGET_WINDOW.equals(value[0]); - } - if (isNewWindow) { - link.setTargetWindow(com.arsdigita.bebop.Link.NEW_FRAME); - } else { - link.setTargetWindow(""); - } + // Process internal and external urls + if (Link.EXTERNAL_LINK.equals(m_linkType.getValue(state))) { + link.setTargetURI( + (String) m_targetURI.getValue(state)); + link.setTargetItem(null); + } else { + // Internal + link.setTargetURI(null); - link.save(); + // Quasimodo: BEGIN + // This is part of the patch to make RelatedLink (and Link) multilanguage compatible + // Here we have to link to the content bundle instead of the content item, if there's one + // else we don't have a proper multilanguage support' + ContentItem ci = (ContentItem) data.get(ITEM_SEARCH); + + // If the selected target item ci has a parent of type ContentBundle + if (ci.getParent() instanceof ContentBundle) { + // Then there a multiple language versions of this content item and we want to + // link to the content bundle, so we can later negotiate the language depending + // on browser settings + ci = (ContentItem) ci.getParent(); + } + + link.setTargetItem(ci); + } + // Process whether link is to be opened in new window + boolean isNewWindow = false; + String[] value = (String[]) m_URIOption.getValue(state); + // Technically this isn't really necessary as there is only one box so any + // non-null value means it was checked + if (value != null) { + isNewWindow = link.TARGET_WINDOW.equals(value[0]); + } + if (isNewWindow) { + link.setTargetWindow(com.arsdigita.bebop.Link.NEW_FRAME); + } else { + link.setTargetWindow(""); + } + + link.save(); } }