0001: /**********************************************************************************
0002: * $URL: https://source.sakaiproject.org/svn/content/tags/sakai_2-4-1/content-tool/tool/src/java/org/sakaiproject/content/tool/ResourcesEditItem.java $
0003: * $Id: ResourcesEditItem.java 22584 2007-03-14 03:26:07Z jimeng@umich.edu $
0004: ***********************************************************************************
0005: *
0006: * Copyright (c) 2007 The Sakai Foundation.
0007: *
0008: * Licensed under the Educational Community License, Version 1.0 (the "License");
0009: * you may not use this file except in compliance with the License.
0010: * You may obtain a copy of the License at
0011: *
0012: * http://www.opensource.org/licenses/ecl1.php
0013: *
0014: * Unless required by applicable law or agreed to in writing, software
0015: * distributed under the License is distributed on an "AS IS" BASIS,
0016: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
0017: * See the License for the specific language governing permissions and
0018: * limitations under the License.
0019: *
0020: **********************************************************************************/package org.sakaiproject.content.tool;
0021:
0022: import java.io.UnsupportedEncodingException;
0023: import java.util.Collection;
0024: import java.util.HashSet;
0025: import java.util.Hashtable;
0026: import java.util.Iterator;
0027: import java.util.List;
0028: import java.util.Map;
0029: import java.util.Set;
0030: import java.util.SortedSet;
0031: import java.util.TreeSet;
0032: import java.util.Vector;
0033:
0034: import org.sakaiproject.content.api.GroupAwareEntity.AccessMode;
0035: import org.sakaiproject.entity.api.ResourceProperties;
0036: import org.sakaiproject.event.cover.NotificationService;
0037: import org.sakaiproject.site.api.Group;
0038: import org.sakaiproject.time.api.Time;
0039: import org.sakaiproject.time.cover.TimeService;
0040: import org.sakaiproject.util.ResourceLoader;
0041: import org.sakaiproject.util.Validator;
0042:
0043: /**
0044: * Inner class encapsulates information about resources (folders and items) for editing
0045: * This is being phased out as we switch to the resources type registry.
0046: */
0047: public class ResourcesEditItem extends ResourcesBrowseItem {
0048: /** Resource bundle using current language locale */
0049: private static ResourceLoader rb = new ResourceLoader("content");
0050:
0051: protected String m_copyrightStatus;
0052: protected String m_copyrightInfo;
0053: // protected boolean m_copyrightAlert;
0054:
0055: protected String m_filename;
0056: protected byte[] m_content;
0057: protected String m_encoding = ResourcesAction.UTF_8_ENCODING;
0058:
0059: protected String m_mimetype;
0060: protected String m_description;
0061: protected Map m_metadata;
0062: protected boolean m_hasQuota;
0063: protected boolean m_canSetQuota;
0064: protected String m_quota;
0065: protected boolean m_isUrl;
0066: protected boolean m_contentHasChanged;
0067: protected boolean m_contentTypeHasChanged;
0068: protected int m_notification = NotificationService.NOTI_NONE;
0069:
0070: protected String m_formtype;
0071: protected String m_rootname;
0072: protected Map m_structuredArtifact;
0073: protected List m_properties;
0074:
0075: protected Set m_metadataGroupsShowing;
0076:
0077: protected Set m_missingInformation;
0078: protected boolean m_hasBeenAdded;
0079: protected ResourcesMetadata m_form;
0080: protected boolean m_isBlank;
0081: protected String m_instruction;
0082: protected String m_ccRightsownership;
0083: protected String m_ccLicense;
0084: protected String m_ccCommercial;
0085: protected String m_ccModification;
0086: protected String m_ccRightsOwner;
0087: protected String m_ccRightsYear;
0088:
0089: protected boolean m_hidden;
0090: protected Time m_releaseDate;
0091: protected Time m_retractDate;
0092: protected boolean m_useReleaseDate;
0093: protected boolean m_useRetractDate;
0094: private boolean m_isInUserSite;
0095:
0096: /**
0097: * @param id
0098: * @param name
0099: * @param type
0100: */
0101: public ResourcesEditItem(String id, String name, String type) {
0102: super (id, name, type);
0103:
0104: m_filename = "";
0105: m_contentHasChanged = false;
0106: m_contentTypeHasChanged = false;
0107: m_metadata = new Hashtable();
0108: m_structuredArtifact = new Hashtable();
0109: m_metadataGroupsShowing = new HashSet();
0110: m_mimetype = type;
0111: m_content = null;
0112: m_encoding = ResourcesAction.UTF_8_ENCODING;
0113: m_notification = NotificationService.NOTI_NONE;
0114: m_hasQuota = false;
0115: m_canSetQuota = false;
0116: m_formtype = "";
0117: m_rootname = "";
0118: m_missingInformation = new HashSet();
0119: m_hasBeenAdded = false;
0120: m_properties = new Vector();
0121: m_isBlank = true;
0122: m_instruction = "";
0123: m_ccRightsownership = "";
0124: m_ccLicense = "";
0125: // m_copyrightStatus = ServerConfigurationService.getString("default.copyright");
0126:
0127: m_hidden = false;
0128: m_releaseDate = TimeService.newTime();
0129: m_retractDate = TimeService.newTime();
0130: m_useReleaseDate = false;
0131: m_useRetractDate = false;
0132:
0133: }
0134:
0135: public void setInWorkspace(boolean isInUserSite) {
0136: m_isInUserSite = isInUserSite;
0137: }
0138:
0139: public boolean isInWorkspace() {
0140: return m_isInUserSite;
0141: }
0142:
0143: public void setHidden(boolean hidden) {
0144: this .m_hidden = hidden;
0145: }
0146:
0147: public boolean isHidden() {
0148: return this .m_hidden;
0149: }
0150:
0151: public SortedSet convertToRefs(Collection groupIds) {
0152: SortedSet groupRefs = new TreeSet();
0153: Iterator it = groupIds.iterator();
0154: while (it.hasNext()) {
0155: String groupId = (String) it.next();
0156: Group group = (Group) this .m_allSiteGroupsMap.get(groupId);
0157: if (group != null) {
0158: groupRefs.add(group.getReference());
0159: }
0160: }
0161: return groupRefs;
0162:
0163: }
0164:
0165: public void setRightsowner(String ccRightsOwner) {
0166: m_ccRightsOwner = ccRightsOwner;
0167: }
0168:
0169: public String getRightsowner() {
0170: return m_ccRightsOwner;
0171: }
0172:
0173: public void setRightstyear(String ccRightsYear) {
0174: m_ccRightsYear = ccRightsYear;
0175: }
0176:
0177: public String getRightsyear() {
0178: return m_ccRightsYear;
0179: }
0180:
0181: public void setAllowModifications(String ccModification) {
0182: m_ccModification = ccModification;
0183: }
0184:
0185: public String getAllowModifications() {
0186: return m_ccModification;
0187: }
0188:
0189: public void setAllowCommercial(String ccCommercial) {
0190: m_ccCommercial = ccCommercial;
0191: }
0192:
0193: public String getAllowCommercial() {
0194: return m_ccCommercial;
0195: }
0196:
0197: /**
0198: *
0199: * @param license
0200: */
0201: public void setLicense(String license) {
0202: m_ccLicense = license;
0203: }
0204:
0205: /**
0206: *
0207: * @return
0208: */
0209: public String getLicense() {
0210: return m_ccLicense;
0211: }
0212:
0213: /**
0214: * Record a value for instructions to be displayed to the user in the editor (for Form Items).
0215: * @param instruction The value of the instructions.
0216: */
0217: public void setInstruction(String instruction) {
0218: if (instruction == null) {
0219: instruction = "";
0220: }
0221:
0222: m_instruction = instruction.trim();
0223: }
0224:
0225: /**
0226: * Access instructions to be displayed to the user in the editor (for Form Items).
0227: * @return The instructions.
0228: */
0229: public String getInstruction() {
0230: return m_instruction;
0231: }
0232:
0233: /**
0234: * Set the character encoding type that will be used when converting content body between strings and byte arrays.
0235: * Default is UTF_8_ENCODING.
0236: * @param encoding A valid name for a character set encoding scheme (@see java.lang.Charset)
0237: */
0238: public void setEncoding(String encoding) {
0239: m_encoding = encoding;
0240: }
0241:
0242: /**
0243: * Get the character encoding type that is used when converting content body between strings and byte arrays.
0244: * Default is "UTF-8".
0245: * @return The name of the character set encoding scheme (@see java.lang.Charset)
0246: */
0247: public String getEncoding() {
0248: return m_encoding;
0249: }
0250:
0251: /**
0252: * Set marker indicating whether current item is a blank entry
0253: * @param isBlank
0254: */
0255: public void markAsBlank(boolean isBlank) {
0256: m_isBlank = isBlank;
0257: }
0258:
0259: /**
0260: * Access marker indicating whether current item is a blank entry
0261: * @return true if current entry is blank, false otherwise
0262: */
0263: public boolean isBlank() {
0264: return m_isBlank;
0265: }
0266:
0267: /**
0268: * Change the root ResourcesMetadata object that defines the form for a Structured Artifact.
0269: * @param form
0270: */
0271: public void setForm(ResourcesMetadata form) {
0272: m_form = form;
0273: }
0274:
0275: /**
0276: * Access the root ResourcesMetadata object that defines the form for a Structured Artifact.
0277: * @return the form.
0278: */
0279: public ResourcesMetadata getForm() {
0280: return m_form;
0281: }
0282:
0283: /**
0284: * @param properties
0285: */
0286: public void setProperties(List properties) {
0287: m_properties = properties;
0288:
0289: }
0290:
0291: public List getProperties() {
0292: return m_properties;
0293: }
0294:
0295: /**
0296: * Replace current values of Structured Artifact with new values.
0297: * @param map The new values.
0298: */
0299: public void setValues(Map map) {
0300: m_structuredArtifact = map;
0301:
0302: }
0303:
0304: /**
0305: * Access the entire set of values stored in the Structured Artifact
0306: * @return The set of values.
0307: */
0308: public Map getValues() {
0309: return m_structuredArtifact;
0310:
0311: }
0312:
0313: /**
0314: * @param id
0315: * @param name
0316: * @param type
0317: */
0318: public ResourcesEditItem(String type) {
0319: this (null, "", type);
0320: }
0321:
0322: /**
0323: * @param id
0324: */
0325: public void setId(String id) {
0326: m_id = id;
0327: }
0328:
0329: /**
0330: * Show the indicated metadata group for the item
0331: * @param group
0332: */
0333: public void showMetadataGroup(String group) {
0334: m_metadataGroupsShowing.add(group);
0335: }
0336:
0337: /**
0338: * Hide the indicated metadata group for the item
0339: * @param group
0340: */
0341: public void hideMetadataGroup(String group) {
0342: m_metadataGroupsShowing.remove(group);
0343: m_metadataGroupsShowing.remove(Validator.escapeUrl(group));
0344: }
0345:
0346: /**
0347: * Query whether the indicated metadata group is showing for the item
0348: * @param group
0349: * @return true if the metadata group is showing, false otherwise
0350: */
0351: public boolean isGroupShowing(String group) {
0352: return m_metadataGroupsShowing.contains(group)
0353: || m_metadataGroupsShowing.contains(Validator
0354: .escapeUrl(group));
0355: }
0356:
0357: /**
0358: * @return
0359: */
0360: public boolean isFileUpload() {
0361: return !isFolder() && !isUrl() && !isHtml() && !isPlaintext();
0362: }
0363:
0364: /**
0365: * @param type
0366: */
0367: public void setType(String type) {
0368: m_type = type;
0369: }
0370:
0371: /**
0372: * @param mimetype
0373: */
0374: public void setMimeType(String mimetype) {
0375: m_mimetype = mimetype;
0376: }
0377:
0378: public String getRightsownership() {
0379: return m_ccRightsownership;
0380: }
0381:
0382: public void setRightsownership(String owner) {
0383: m_ccRightsownership = owner;
0384: }
0385:
0386: /**
0387: * @return
0388: */
0389: public String getMimeType() {
0390: return m_mimetype;
0391: }
0392:
0393: public String getMimeCategory() {
0394: if (this .m_mimetype == null || this .m_mimetype.equals("")) {
0395: return "";
0396: }
0397: int index = this .m_mimetype.indexOf("/");
0398: if (index < 0) {
0399: return this .m_mimetype;
0400: }
0401: return this .m_mimetype.substring(0, index);
0402: }
0403:
0404: public String getMimeSubtype() {
0405: if (this .m_mimetype == null || this .m_mimetype.equals("")) {
0406: return "";
0407: }
0408: int index = this .m_mimetype.indexOf("/");
0409: if (index < 0 || index + 1 == this .m_mimetype.length()) {
0410: return "";
0411: }
0412: return this .m_mimetype.substring(index + 1);
0413: }
0414:
0415: /**
0416: * @param formtype
0417: */
0418: public void setFormtype(String formtype) {
0419: m_formtype = formtype;
0420: }
0421:
0422: /**
0423: * @return
0424: */
0425: public String getFormtype() {
0426: return m_formtype;
0427: }
0428:
0429: /**
0430: * @return Returns the copyrightInfo.
0431: */
0432: public String getCopyrightInfo() {
0433: return m_copyrightInfo;
0434: }
0435:
0436: /**
0437: * @param copyrightInfo The copyrightInfo to set.
0438: */
0439: public void setCopyrightInfo(String copyrightInfo) {
0440: m_copyrightInfo = copyrightInfo;
0441: }
0442:
0443: /**
0444: * @return Returns the copyrightStatus.
0445: */
0446: public String getCopyrightStatus() {
0447: return m_copyrightStatus;
0448: }
0449:
0450: /**
0451: * @param copyrightStatus The copyrightStatus to set.
0452: */
0453: public void setCopyrightStatus(String copyrightStatus) {
0454: m_copyrightStatus = copyrightStatus;
0455: }
0456:
0457: /**
0458: * @return Returns the description.
0459: */
0460: public String getDescription() {
0461: return m_description;
0462: }
0463:
0464: /**
0465: * @param description The description to set.
0466: */
0467: public void setDescription(String description) {
0468: m_description = description;
0469: }
0470:
0471: /**
0472: * @return Returns the filename.
0473: */
0474: public String getFilename() {
0475: return m_filename;
0476: }
0477:
0478: /**
0479: * @param filename The filename to set.
0480: */
0481: public void setFilename(String filename) {
0482: m_filename = filename;
0483: }
0484:
0485: /**
0486: * @return Returns the metadata.
0487: */
0488: public Map getMetadata() {
0489: return m_metadata;
0490: }
0491:
0492: /**
0493: * @param metadata The metadata to set.
0494: */
0495: public void setMetadata(Map metadata) {
0496: m_metadata = metadata;
0497: }
0498:
0499: /**
0500: * @param name
0501: * @param value
0502: */
0503: public void setMetadataItem(String name, Object value) {
0504: m_metadata.put(name, value);
0505: }
0506:
0507: /**
0508: * @return
0509: */
0510: public boolean isSitePossible() {
0511: return !m_pubview_inherited && !isGroupInherited()
0512: && !isSingleGroupInherited();
0513: }
0514:
0515: /**
0516: * @return
0517: */
0518: public boolean isGroupPossible() {
0519: // Collection groups = getPossibleGroups();
0520: // return ! groups.isEmpty();
0521: return this .m_allowedAddGroupRefs != null
0522: && !this .m_allowedAddGroupRefs.isEmpty();
0523:
0524: }
0525:
0526: /**
0527: * @return
0528: */
0529: public boolean isGroupInherited() {
0530: return AccessMode.INHERITED.toString().equals(this .m_access)
0531: && AccessMode.GROUPED.toString().equals(
0532: m_inheritedAccess);
0533: }
0534:
0535: /**
0536: * Does this entity inherit grouped access mode with a single group that has access?
0537: * @return true if this entity inherits grouped access mode with a single group that has access, and false otherwise.
0538: */
0539: public boolean isSingleGroupInherited() {
0540: //Collection groups = getInheritedGroups();
0541: return // AccessMode.INHERITED.toString().equals(this.m_access) &&
0542: AccessMode.GROUPED.toString().equals(this .m_inheritedAccess)
0543: && this .m_inheritedGroupRefs != null
0544: && this .m_inheritedGroupRefs.size() == 1;
0545: // && this.m_oldInheritedGroups != null
0546: // && this.m_oldInheritedGroups.size() == 1;
0547: }
0548:
0549: /**
0550: * @return
0551: */
0552: public String getSingleGroupTitle() {
0553: return (String) rb.getFormattedMessage("access.title4",
0554: new Object[] { getGroupNames() });
0555: }
0556:
0557: /**
0558: * Is this entity's access restricted to the site (not pubview) and are there no groups defined for the site?
0559: * @return
0560: */
0561: public boolean isSiteOnly() {
0562: boolean isSiteOnly = false;
0563: isSiteOnly = !isGroupPossible() && !isPubviewPossible();
0564: return isSiteOnly;
0565: }
0566:
0567: /**
0568: * @return Returns the content.
0569: */
0570: public byte[] getContent() {
0571: return m_content;
0572: }
0573:
0574: /**
0575: * @return Returns the content as a String.
0576: */
0577: public String getContentstring() {
0578: String rv = "";
0579: if (m_content != null && m_content.length > 0) {
0580: try {
0581: rv = new String(m_content, m_encoding);
0582: } catch (UnsupportedEncodingException e) {
0583: rv = new String(m_content);
0584: }
0585: }
0586: return rv;
0587: }
0588:
0589: /**
0590: * @param content The content to set.
0591: */
0592: public void setContent(byte[] content) {
0593: m_content = content;
0594: }
0595:
0596: /**
0597: * @param content The content to set.
0598: */
0599: public void setContent(String content) {
0600: try {
0601: m_content = content.getBytes(m_encoding);
0602: } catch (UnsupportedEncodingException e) {
0603: m_content = content.getBytes();
0604: }
0605: }
0606:
0607: /**
0608: * @return Returns the canSetQuota.
0609: */
0610: public boolean canSetQuota() {
0611: return m_canSetQuota;
0612: }
0613:
0614: /**
0615: * @param canSetQuota The canSetQuota to set.
0616: */
0617: public void setCanSetQuota(boolean canSetQuota) {
0618: m_canSetQuota = canSetQuota;
0619: }
0620:
0621: /**
0622: * @return Returns the hasQuota.
0623: */
0624: public boolean hasQuota() {
0625: return m_hasQuota;
0626: }
0627:
0628: /**
0629: * @param hasQuota The hasQuota to set.
0630: */
0631: public void setHasQuota(boolean hasQuota) {
0632: m_hasQuota = hasQuota;
0633: }
0634:
0635: /**
0636: * @return Returns the quota.
0637: */
0638: public String getQuota() {
0639: return m_quota;
0640: }
0641:
0642: /**
0643: * @param quota The quota to set.
0644: */
0645: public void setQuota(String quota) {
0646: m_quota = quota;
0647: }
0648:
0649: /**
0650: * @return true if content-type of item indicates it represents a URL, false otherwise
0651: */
0652: public boolean isUrl() {
0653: return ResourcesAction.TYPE_URL.equals(m_type)
0654: || ResourceProperties.TYPE_URL.equals(m_mimetype);
0655: }
0656:
0657: /**
0658: * @return true if content-type of item is "text/text" (plain text), false otherwise
0659: */
0660: public boolean isPlaintext() {
0661: return ResourcesAction.MIME_TYPE_DOCUMENT_PLAINTEXT
0662: .equals(m_mimetype)
0663: || ResourcesAction.MIME_TYPE_DOCUMENT_PLAINTEXT
0664: .equals(m_type);
0665: }
0666:
0667: /**
0668: * @return true if content-type of item is "text/html" (an html document), false otherwise
0669: */
0670: public boolean isHtml() {
0671: return ResourcesAction.MIME_TYPE_DOCUMENT_HTML
0672: .equals(m_mimetype)
0673: || ResourcesAction.MIME_TYPE_DOCUMENT_HTML
0674: .equals(m_type);
0675: }
0676:
0677: /**
0678: * @return
0679: */
0680: public boolean contentHasChanged() {
0681: return m_contentHasChanged;
0682: }
0683:
0684: /**
0685: * @param changed
0686: */
0687: public void setContentHasChanged(boolean changed) {
0688: m_contentHasChanged = changed;
0689: }
0690:
0691: /**
0692: * @return
0693: */
0694: public boolean contentTypeHasChanged() {
0695: return m_contentTypeHasChanged;
0696: }
0697:
0698: /**
0699: * @param changed
0700: */
0701: public void setContentTypeHasChanged(boolean changed) {
0702: m_contentTypeHasChanged = changed;
0703: }
0704:
0705: /**
0706: * @param notification
0707: */
0708: public void setNotification(int notification) {
0709: m_notification = notification;
0710: }
0711:
0712: /**
0713: * @return
0714: */
0715: public int getNotification() {
0716: return m_notification;
0717: }
0718:
0719: /**
0720: * @return Returns the artifact.
0721: */
0722: public Map getStructuredArtifact() {
0723: return m_structuredArtifact;
0724: }
0725:
0726: /**
0727: * @param artifact The artifact to set.
0728: */
0729: public void setStructuredArtifact(Map artifact) {
0730: this .m_structuredArtifact = artifact;
0731: }
0732:
0733: /**
0734: * @param name
0735: * @param value
0736: */
0737: public void setValue(String name, Object value) {
0738: setValue(name, 0, value);
0739: }
0740:
0741: /**
0742: * @param name
0743: * @param index
0744: * @param value
0745: */
0746: public void setValue(String name, int index, Object value) {
0747: List list = getList(name);
0748: try {
0749: list.set(index, value);
0750: } catch (ArrayIndexOutOfBoundsException e) {
0751: list.add(value);
0752: }
0753: m_structuredArtifact.put(name, list);
0754: }
0755:
0756: /**
0757: * Access a value of a structured artifact field of type String.
0758: * @param name The name of the field to access.
0759: * @return the value, or null if the named field is null or not a String.
0760: */
0761: public String getString(String name) {
0762: if (m_structuredArtifact == null) {
0763: m_structuredArtifact = new Hashtable();
0764: }
0765: Object value = m_structuredArtifact.get(name);
0766: String rv = "";
0767: if (value == null) {
0768: // do nothing
0769: } else if (value instanceof String) {
0770: rv = (String) value;
0771: } else {
0772: rv = value.toString();
0773: }
0774: return rv;
0775: }
0776:
0777: /**
0778: * @param name
0779: * @param index
0780: * @return
0781: */
0782: public Object getValue(String name, int index) {
0783: List list = getList(name);
0784: Object rv = null;
0785: try {
0786: rv = list.get(index);
0787: } catch (ArrayIndexOutOfBoundsException e) {
0788: // return null
0789: }
0790: return rv;
0791:
0792: }
0793:
0794: /**
0795: * @param name
0796: * @return
0797: */
0798: public Object getPropertyValue(String name) {
0799: return getPropertyValue(name, 0);
0800: }
0801:
0802: /**
0803: * Access a particular value in a Structured Artifact, as identified by the parameter "name". This
0804: * implementation of the method assumes that the name is a series of String identifiers delimited
0805: * by the ResourcesAction.ResourcesMetadata.DOT String.
0806: * @param name The delimited identifier for the item.
0807: * @return The value identified by the name, or null if the name does not identify a valid item.
0808: */
0809: public Object getPropertyValue(String name, int index) {
0810: String[] names = name.split(ResourcesMetadata.DOT);
0811: Object rv = null;
0812: if (m_properties == null) {
0813: m_properties = new Vector();
0814: }
0815: Iterator it = m_properties.iterator();
0816: while (rv == null && it.hasNext()) {
0817: ResourcesMetadata prop = (ResourcesMetadata) it.next();
0818: if (name.equals(prop.getDottedname())) {
0819: rv = prop.getValue(index);
0820: }
0821: }
0822: return rv;
0823:
0824: }
0825:
0826: /**
0827: * @param name
0828: * @param value
0829: */
0830: public void setPropertyValue(String name, Object value) {
0831: setPropertyValue(name, 0, value);
0832: }
0833:
0834: /**
0835: * Access a particular value in a Structured Artifact, as identified by the parameter "name". This
0836: * implementation of the method assumes that the name is a series of String identifiers delimited
0837: * by the ResourcesAction.ResourcesMetadata.DOT String.
0838: * @param name The delimited identifier for the item.
0839: * @return The value identified by the name, or null if the name does not identify a valid item.
0840: */
0841: public void setPropertyValue(String name, int index, Object value) {
0842: if (m_properties == null) {
0843: m_properties = new Vector();
0844: }
0845: boolean found = false;
0846: Iterator it = m_properties.iterator();
0847: while (!found && it.hasNext()) {
0848: ResourcesMetadata prop = (ResourcesMetadata) it.next();
0849: if (name.equals(prop.getDottedname())) {
0850: found = true;
0851: prop.setValue(index, value);
0852: }
0853: }
0854:
0855: }
0856:
0857: /**
0858: * Access a particular value in a Structured Artifact, as identified by the parameter "name". This
0859: * implementation of the method assumes that the name is a series of String identifiers delimited
0860: * by the ResourcesAction.ResourcesMetadata.DOT String.
0861: * @param name The delimited identifier for the item.
0862: * @return The value identified by the name, or null if the name does not identify a valid item.
0863: */
0864: public Object getValue(String name) {
0865: String[] names = name.split(ResourcesMetadata.DOT);
0866: Object rv = m_structuredArtifact;
0867: if (rv != null && (rv instanceof Map) && ((Map) rv).isEmpty()) {
0868: rv = null;
0869: }
0870: for (int i = 1; rv != null && i < names.length; i++) {
0871: if (rv instanceof Map) {
0872: rv = ((Map) rv).get(names[i]);
0873: } else {
0874: rv = null;
0875: }
0876: }
0877: return rv;
0878:
0879: }
0880:
0881: /**
0882: * Access a list of values associated with a named property of a structured artifact.
0883: * @param name The name of the property.
0884: * @return The list of values associated with that name, or an empty list if the property is not defined.
0885: */
0886: public List getList(String name) {
0887: if (m_structuredArtifact == null) {
0888: m_structuredArtifact = new Hashtable();
0889: }
0890: Object value = m_structuredArtifact.get(name);
0891: List rv = new Vector();
0892: if (value == null) {
0893: m_structuredArtifact.put(name, rv);
0894: } else if (value instanceof Collection) {
0895: rv.addAll((Collection) value);
0896: } else {
0897: rv.add(value);
0898: }
0899: return rv;
0900:
0901: }
0902:
0903: /**
0904: * @return
0905: */
0906: /*
0907: public Element exportStructuredArtifact(List properties)
0908: {
0909: return null;
0910: }
0911: */
0912:
0913: /**
0914: * @return Returns the name of the root of a structured artifact definition.
0915: */
0916: public String getRootname() {
0917: return m_rootname;
0918: }
0919:
0920: /**
0921: * @param rootname The name to be assigned for the root of a structured artifact.
0922: */
0923: public void setRootname(String rootname) {
0924: m_rootname = rootname;
0925: }
0926:
0927: /**
0928: * Add a property name to the list of properties missing from the input.
0929: * @param propname The name of the property.
0930: */
0931: public void setMissing(String propname) {
0932: m_missingInformation.add(propname);
0933: }
0934:
0935: /**
0936: * Query whether a particular property is missing
0937: * @param propname The name of the property
0938: * @return The value "true" if the property is missing, "false" otherwise.
0939: */
0940: public boolean isMissing(String propname) {
0941: return m_missingInformation.contains(propname)
0942: || m_missingInformation.contains(Validator
0943: .escapeUrl(propname));
0944: }
0945:
0946: /**
0947: * Empty the list of missing properties.
0948: */
0949: public void clearMissing() {
0950: m_missingInformation.clear();
0951: }
0952:
0953: public void setAdded(boolean added) {
0954: m_hasBeenAdded = added;
0955: }
0956:
0957: public boolean hasBeenAdded() {
0958: return m_hasBeenAdded;
0959: }
0960:
0961: /**
0962: * @return the releaseDate
0963: */
0964: public Time getReleaseDate() {
0965: return m_releaseDate;
0966: }
0967:
0968: /**
0969: * @param releaseDate the releaseDate to set
0970: */
0971: public void setReleaseDate(Time releaseDate) {
0972: this .m_releaseDate = releaseDate;
0973: }
0974:
0975: /**
0976: * @return the retractDate
0977: */
0978: public Time getRetractDate() {
0979: return m_retractDate;
0980: }
0981:
0982: /**
0983: * @param retractDate the retractDate to set
0984: */
0985: public void setRetractDate(Time retractDate) {
0986: this .m_retractDate = retractDate;
0987: }
0988:
0989: /**
0990: * @return the useReleaseDate
0991: */
0992: public boolean useReleaseDate() {
0993: return m_useReleaseDate;
0994: }
0995:
0996: /**
0997: * @param useReleaseDate the useReleaseDate to set
0998: */
0999: public void setUseReleaseDate(boolean useReleaseDate) {
1000: this .m_useReleaseDate = useReleaseDate;
1001: }
1002:
1003: /**
1004: * @return the useRetractDate
1005: */
1006: public boolean useRetractDate() {
1007: return m_useRetractDate;
1008: }
1009:
1010: /**
1011: * @param useRetractDate the useRetractDate to set
1012: */
1013: public void setUseRetractDate(boolean useRetractDate) {
1014: this .m_useRetractDate = useRetractDate;
1015: }
1016:
1017: } // inner class ResourcesEditItem
|