You are viewing a plain text version of this content. The canonical link for it is here.
Posted to jetspeed-dev@portals.apache.org by dl...@apache.org on 2004/06/05 22:09:51 UTC
cvs commit: jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/impl LocalizedFieldImpl.java GenericMetadataImpl.java UserAttributeRefImpl.java DublinCoreImpl.java
dlestrat 2004/06/05 13:09:51
Added: components/registry/src/java/org/apache/jetspeed/om/impl
LocalizedFieldImpl.java GenericMetadataImpl.java
UserAttributeRefImpl.java DublinCoreImpl.java
Log:
User info J2 extension. See http://nagoya.apache.org/jira/browse/JS2-64
Revision Changes Path
1.1 jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/impl/LocalizedFieldImpl.java
Index: LocalizedFieldImpl.java
===================================================================
/* Copyright 2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.om.impl;
import java.util.Locale;
import org.apache.jetspeed.om.common.LocalizedField;
import org.apache.jetspeed.util.HashCodeBuilder;
import org.apache.jetspeed.util.JetspeedObjectID;
import org.apache.pluto.om.common.ObjectID;
/**
* LocalizedFieldImpl
* <br/>
* Implementation that represents a string value and the locale of that string
*
* @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
* @version $Id: LocalizedFieldImpl.java,v 1.1 2004/06/05 20:09:50 dlestrat Exp $
*
*/
public class LocalizedFieldImpl implements LocalizedField
{
protected String value;
protected String name;
protected Locale locale;
protected long parentId;
protected long id;
public LocalizedFieldImpl()
{
}
public LocalizedFieldImpl(Locale locale, String value)
{
this.locale = locale;
this.value = value;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#getLocale()
*/
public Locale getLocale()
{
return locale;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#setLocale(java.util.Locale)
*/
public void setLocale(Locale locale)
{
this.locale = locale;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#getValue()
*/
public String getValue()
{
return value;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#setValue(java.lang.String)
*/
public void setValue(String value)
{
this.value = value;
}
/**
*
*/
public ObjectID getId()
{
return new JetspeedObjectID(id);
}
/**
*
*/
public void setId(String oid)
{
id = JetspeedObjectID.createFromString(oid).longValue();
}
public void setLanguage(String lang)
{
this.locale = new Locale(lang);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#getName()
*/
public String getName()
{
return name;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.LocalizedField#setName(java.lang.String)
*/
public void setName(String name)
{
this.name = name;
}
public String toString()
{
return "Name: " + name + " Value: " + value + " Locale: " + locale;
}
public boolean equals(Object o)
{
boolean result = false;
if(o instanceof LocalizedFieldImpl && o != null)
{
LocalizedFieldImpl localField = (LocalizedFieldImpl)o;
result = (this.name == null) ? (localField.name == null) : (this.name.equals(localField.name));
result = result && ((this.value == null) ? (localField.value == null) : (this.value.equals(localField.value)));
result = result && ((this.locale == null) ? (localField.locale == null) : (this.locale.equals(localField.locale)));
}
return result;
}
/**
* @see java.lang.Object#hashCode()
*/
public int hashCode()
{
HashCodeBuilder hasher = new HashCodeBuilder(27, 101);
hasher.append(name).append(value);
if(locale != null)
{
hasher.append(locale.getCountry()).append(locale.getLanguage()).append(locale.getVariant());
}
return hasher.toHashCode();
}
}
1.1 jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/impl/GenericMetadataImpl.java
Index: GenericMetadataImpl.java
===================================================================
/* Copyright 2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.om.impl;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.Locale;
import org.apache.commons.collections.MultiHashMap;
import org.apache.jetspeed.om.common.GenericMetadata;
import org.apache.jetspeed.om.common.LocalizedField;
/**
* GenericMetadataImpl
* <br/>
* Implementation that allows retrieving localized information
*
* @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
* @version $Id: GenericMetadataImpl.java,v 1.1 2004/06/05 20:09:50 dlestrat Exp $
*
*/
public abstract class GenericMetadataImpl implements GenericMetadata
{
private Collection fields = null;
private transient MultiHashMap fieldMap = new MultiHashMap();
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#addField(java.util.Locale, java.lang.String, java.lang.String)
*/
public void addField(Locale locale, String name, String value)
{
LocalizedFieldImpl field = new LocalizedFieldImpl();
field.setName(name);
field.setValue(value);
field.setLocale(locale);
addField(field);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#addField(org.apache.jetspeed.om.common.LocalizedField)
*/
public void addField(LocalizedField field)
{
if(fields == null)
{
fields = new ArrayList();
}
fields.add(field);
fieldMap.put(field.getName(), field);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#getFields(java.lang.String)
*/
public Collection getFields(String name)
{
//TODO: return an immutable version?
return (Collection)fieldMap.get(name);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#setFields(java.lang.String, java.util.Collection)
*/
public void setFields(String name, Collection values)
{
fieldMap.remove(name);
Iterator fieldIter = fields.iterator();
while(fieldIter.hasNext())
{
LocalizedField field = (LocalizedField)fieldIter.next();
if(field != null && field.getName() != null && field.getName().equals(name))
{
fieldIter.remove();
}
}
if(values != null)
{
Iterator iter = values.iterator();
while(iter.hasNext())
{
LocalizedField field = (LocalizedField)iter.next();
fieldMap.put(field.getName(), field);
}
fields.addAll(values);
}
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#getFields()
*/
public Collection getFields() {
return fields;
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.GenericMetadata#setField(java.util.Collection)
*/
public void setFields(Collection fields)
{
this.fields = fields;
if(fields != null)
{
Iterator fieldIter = fields.iterator();
while(fieldIter.hasNext())
{
LocalizedField field = (LocalizedField)fieldIter.next();
fieldMap.put(field.getName(), field);
}
}
}
}
1.1 jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/impl/UserAttributeRefImpl.java
Index: UserAttributeRefImpl.java
===================================================================
/* Copyright 2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.om.impl;
import org.apache.jetspeed.om.common.UserAttributeRef;
/**
* <p>User attribute ref implementation.</p>
*
* @author <a href="mailto:dlestrat@apache.org">David Le Strat</a>
*/
public class UserAttributeRefImpl implements UserAttributeRef
{
/** The application id. */
protected long appId;
/**
* <p>Default constructor.</p>
*/
public UserAttributeRefImpl()
{
}
/**
* <p>User attribute ref constructor given a name and name link.</p>
* @param The user attribute ref name.
* @param The user attribute ref name link.
*/
public UserAttributeRefImpl(String name, String nameLink)
{
this.name = name;
this.nameLink = nameLink;
}
private String name;
/**
* @see org.apache.jetspeed.om.common.UserAttributeRef#getName()
*/
public String getName()
{
return name;
}
/**
* @see org.apache.jetspeed.om.common.UserAttributeRef#setName(java.lang.String)
*/
public void setName(String name)
{
this.name = name;
}
private String nameLink;
/**
* @see org.apache.jetspeed.om.common.UserAttributeRef#getNameLink()
*/
public String getNameLink()
{
return nameLink;
}
/**
* @see org.apache.jetspeed.om.common.UserAttributeRef#setNameLink(java.lang.String)
*/
public void setNameLink(String nameLink)
{
this.nameLink = nameLink;
}
/**
* <p>Convert {@link UserAttributeRef} to String.</p>
* @return String value of UserAttributeRef.
*/
public String toString()
{
String userAttributeRef = "[[name, " + this.name + "], [name-link, " + this.nameLink + "]]";
return userAttributeRef;
}
}
1.1 jakarta-jetspeed-2/components/registry/src/java/org/apache/jetspeed/om/impl/DublinCoreImpl.java
Index: DublinCoreImpl.java
===================================================================
/* Copyright 2004 Apache Software Foundation
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.apache.jetspeed.om.impl;
import java.util.Collection;
import java.util.Locale;
import org.apache.jetspeed.om.common.DublinCore;
import org.apache.jetspeed.om.common.GenericMetadata;
import org.apache.jetspeed.om.common.LocalizedField;
/**
* DublinCoreImpl
* <br/>
* Implementation that allows retrieving information according to the
* Dublin Core specification
* (<a href="http://www.dublincore.org">http://www.dublincore.org</a>)
*
* @author <a href="mailto:jford@apache.org">Jeremy Ford</a>
* @version $Id: DublinCoreImpl.java,v 1.1 2004/06/05 20:09:50 dlestrat Exp $
*
*/
public class DublinCoreImpl implements DublinCore
{
public static final String TITLE = "title";
public static final String CONTRIBUTOR = "contributor";
public static final String COVERAGE = "coverage";
public static final String CREATOR = "creator";
public static final String DESCRIPTION = "description";
public static final String FORMAT = "format";
public static final String IDENTIFIER = "identifier";
public static final String LANGUAGE = "language";
public static final String PUBLISHER = "publisher";
public static final String RELATION = "relation";
public static final String RIGHT = "right";
public static final String SOURCE = "source";
public static final String SUBJECT = "subject";
public static final String TYPE = "type";
GenericMetadata metadata = null;
/**
* @param md
*/
public DublinCoreImpl(GenericMetadata md) {
this.metadata = md;
}
/**
* @return Returns the titles
*/
public Collection getTitles()
{
return metadata.getFields(TITLE);
}
/**
* @param titles The titles to set
*/
public void setTitles(Collection titles)
{
metadata.setFields(TITLE, titles);
}
/**
* @return Returns the contributors.
*/
public Collection getContributors() {
return metadata.getFields(CONTRIBUTOR);
}
/**
* @param contributors The contributors to set.
*/
public void setContributors(Collection contributors) {
metadata.setFields(CONTRIBUTOR, contributors);
}
/**
* @return Returns the coverages.
*/
public Collection getCoverages() {
return metadata.getFields(COVERAGE);
}
/**
* @param coverages The coverages to set.
*/
public void setCoverages(Collection coverages) {
metadata.setFields(COVERAGE, coverages);
}
/**
* @return Returns the creators.
*/
public Collection getCreators() {
return metadata.getFields(CREATOR);
}
/**
* @param creators The creators to set.
*/
public void setCreators(Collection creators) {
metadata.setFields(CREATOR, creators);
}
/**
* @return Returns the descriptions.
*/
public Collection getDescriptions() {
return metadata.getFields(DESCRIPTION);
}
/**
* @param descriptions The descriptions to set.
*/
public void setDescriptions(Collection descriptions) {
metadata.setFields(DESCRIPTION, descriptions);
}
/**
* @return Returns the formats.
*/
public Collection getFormats() {
return metadata.getFields(FORMAT);
}
/**
* @param formats The formats to set.
*/
public void setFormats(Collection formats) {
metadata.setFields(FORMAT, formats);
}
/**
* @return Returns the identifiers.
*/
public Collection getIdentifiers() {
return metadata.getFields(IDENTIFIER);
}
/**
* @param identifiers The identifiers to set.
*/
public void setIdentifiers(Collection identifiers) {
metadata.setFields(IDENTIFIER, identifiers);
}
/**
* @return Returns the languages.
*/
public Collection getLanguages() {
return metadata.getFields(LANGUAGE);
}
/**
* @param languages The languages to set.
*/
public void setLanguages(Collection languages) {
metadata.setFields(LANGUAGE, languages);
}
/**
* @return Returns the publishers.
*/
public Collection getPublishers() {
return metadata.getFields(PUBLISHER);
}
/**
* @param publishers The publishers to set.
*/
public void setPublishers(Collection publishers) {
metadata.setFields(PUBLISHER, publishers);
}
/**
* @return Returns the relations.
*/
public Collection getRelations() {
return metadata.getFields(RELATION);
}
/**
* @param relations The relations to set.
*/
public void setRelations(Collection relations) {
metadata.setFields(RELATION, relations);
}
/**
* @return Returns the rights.
*/
public Collection getRights() {
return metadata.getFields(RIGHT);
}
/**
* @param rights The rights to set.
*/
public void setRights(Collection rights) {
metadata.setFields(RIGHT, rights);
}
/**
* @return Returns the sources.
*/
public Collection getSources() {
return metadata.getFields(SOURCE);
}
/**
* @param sources The sources to set.
*/
public void setSources(Collection sources) {
metadata.setFields(SOURCE, sources);
}
/**
* @return Returns the subjects.
*/
public Collection getSubjects() {
return metadata.getFields(SUBJECT);
}
/**
* @param subjects The subjects to set.
*/
public void setSubjects(Collection subjects) {
metadata.setFields(SUBJECT, subjects);
}
/**
* @return Returns the types.
*/
public Collection getTypes() {
return metadata.getFields(TYPE);
}
/**
* @param types The types to set.
*/
public void setTypes(Collection types) {
metadata.setFields(TYPE, types);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addContributor(java.util.Locale, java.lang.String)
*/
public void addContributor(Locale locale, String contributor) {
metadata.addField(locale, CONTRIBUTOR, contributor);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addCoverage(java.util.Locale, java.lang.String)
*/
public void addCoverage(Locale locale, String coverage) {
metadata.addField(locale, COVERAGE, coverage);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addCreator(java.util.Locale, java.lang.String)
*/
public void addCreator(Locale locale, String creator) {
metadata.addField(locale, CREATOR, creator);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addDescription(java.util.Locale, java.lang.String)
*/
public void addDescription(Locale locale, String description) {
metadata.addField(locale, DESCRIPTION, description);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addFormat(java.util.Locale, java.lang.String)
*/
public void addFormat(Locale locale, String format) {
metadata.addField(locale, FORMAT, format);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addIdentifier(java.util.Locale, java.lang.String)
*/
public void addIdentifier(Locale locale, String identifier) {
metadata.addField(locale, IDENTIFIER, identifier);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addLanguage(java.util.Locale, java.lang.String)
*/
public void addLanguage(Locale locale, String language) {
metadata.addField(locale, LANGUAGE, language);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addPublisher(java.util.Locale, java.lang.String)
*/
public void addPublisher(Locale locale, String publisher) {
metadata.addField(locale, PUBLISHER, publisher);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addRelation(java.util.Locale, java.lang.String)
*/
public void addRelation(Locale locale, String relation) {
metadata.addField(locale, RELATION, relation);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addRight(java.util.Locale, java.lang.String)
*/
public void addRight(Locale locale, String right) {
metadata.addField(locale, RIGHT, right);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addSource(java.util.Locale, java.lang.String)
*/
public void addSource(Locale locale, String source) {
metadata.addField(locale, SOURCE, source);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addSubject(java.util.Locale, java.lang.String)
*/
public void addSubject(Locale locale, String subject) {
metadata.addField(locale, SUBJECT, subject);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addDisplayName(java.util.Locale, java.lang.String)
*/
public void addTitle(Locale locale, String title) {
metadata.addField(locale, TITLE, title);
}
/* (non-Javadoc)
* @see org.apache.jetspeed.om.common.DublinCore#addType(java.util.Locale, java.lang.String)
*/
public void addType(Locale locale, String type) {
metadata.addField(locale, TYPE, type);
}
private void addLocalizedFieldToCollection(Collection fields, Locale locale, String value)
{
try
{
LocalizedField localizedField = metadata.createLocalizedField();
//TODO: switch to object creation through another mechanism
//(LocalizedField) JetspeedPortletRegistry.getNewObjectInstance(MutableDescription.TYPE_WEB_APP, true);
localizedField.setLocale(locale);
localizedField.setValue(value);
fields.add(localizedField);
}
catch(Exception e)
{
String msg = "Unable to instantiate LocalizedField implementor, " + e.toString();
//log.error(msg, e);
throw new IllegalStateException(msg);
}
}
}
---------------------------------------------------------------------
To unsubscribe, e-mail: jetspeed-dev-unsubscribe@jakarta.apache.org
For additional commands, e-mail: jetspeed-dev-help@jakarta.apache.org