/** * @return the locale of this reference */ public Locale getLocale() { return (Locale) getParameter(LOCALE); }
/** * Create a new EntityReference. * * @param name name for the newly created entity reference, could not be null. * @param type type for the newly created entity reference, could not be null. * @param locale the {@link Locale} of the entity. */ public AbstractLocalizedEntityReference(String name, EntityType type, Locale locale) { this(name, type); setLocale(locale); }
/** * Set the locale of this reference. * * @param locale the locale of this document reference */ protected void setLocale(Locale locale) { setParameter(LOCALE, locale); }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed type. * </p> * * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType) * @exception IllegalArgumentException if the passed type is not a document type */ @Override protected void setType(EntityType type) { if (type != EntityType.DOCUMENT) { throw new IllegalArgumentException("Invalid type [" + type + "] for a document reference"); } super.setType(EntityType.DOCUMENT); }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed parent. * </p> * * @see org.xwiki.model.reference.EntityReference#setParent(EntityReference) * @exception IllegalArgumentException if the passed parent is not a valid document reference parent (ie a space * reference) */ @Override protected void setParent(EntityReference parent) { if (parent instanceof SpaceReference) { super.setParent(parent); return; } if (parent == null || parent.getType() != EntityType.SPACE) { throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in a document reference"); } super.setParent(new SpaceReference(parent)); }
@Override protected void serializeEntityReference(EntityReference currentReference, StringBuilder representation, boolean isLastReference, Object... parameters) { // Append name String name = currentReference.getName(); representation.append(name.length()).append(':').append(name); // Append Locale if (currentReference instanceof AbstractLocalizedEntityReference) { Locale locale = ((AbstractLocalizedEntityReference) currentReference).getLocale(); if (locale != null) { String localeString = locale.toString(); if (!localeString.isEmpty()) { representation.append(localeString.length()).append(':').append(localeString); } } } } }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed type. * </p> * * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType) * @exception IllegalArgumentException if the passed type is not a page type */ @Override protected void setType(EntityType type) { if (type != EntityType.PAGE) { throw new IllegalArgumentException("Invalid type [" + type + "] for a page reference"); } super.setType(type); }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed parent. * </p> * * @see org.xwiki.model.reference.EntityReference#setParent(EntityReference) * @exception IllegalArgumentException if the passed parent is not a valid page reference parent (ie either a page * reference or null) */ @Override protected void setParent(EntityReference parent) { if (parent != null && parent.getType() != EntityType.PAGE) { throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in a local page reference"); } super.setParent(parent != null ? new LocalPageReference(parent) : null); }
/** * @param name name for the newly created entity reference, could not be null. * @param type type for the newly created entity reference, could not be null. * @param parent parent reference for the newly created entity reference, may be null. * @param locale the {@link Locale} of the entity. */ public AbstractLocalizedEntityReference(String name, EntityType type, EntityReference parent, Locale locale) { super(name, type, parent); setLocale(locale); }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed type. * </p> * * @see org.xwiki.model.reference.EntityReference#setType(org.xwiki.model.EntityType) * @exception IllegalArgumentException if the passed type is not a page type */ @Override protected void setType(EntityType type) { if (type != EntityType.PAGE) { throw new IllegalArgumentException("Invalid type [" + type + "] for a page reference"); } super.setType(type); }
/** * {@inheritDoc} * <p> * Overridden in order to verify the validity of the passed parent. * </p> * * @see org.xwiki.model.reference.EntityReference#setParent(EntityReference) * @exception IllegalArgumentException if the passed parent is not a valid page reference parent (ie either a page * reference or a wiki reference) */ @Override protected void setParent(EntityReference parent) { if (parent instanceof PageReference || parent instanceof WikiReference) { super.setParent(parent); return; } if (parent == null || (parent.getType() != EntityType.PAGE && parent.getType() != EntityType.WIKI)) { throw new IllegalArgumentException("Invalid parent reference [" + parent + "] in a page reference"); } if (parent.getType() == EntityType.PAGE) { super.setParent(new PageReference(parent)); } else { super.setParent(new WikiReference(parent)); } }
/** * Clone an EntityReference and change/add the passed Locale. * * @param reference the reference to clone * @param locale the {@link Locale} of the new reference */ public AbstractLocalizedEntityReference(EntityReference reference, Locale locale) { super(reference); setLocale(locale); }