001: /*
002: * ====================================================================
003: * Copyright (c) 2004-2008 TMate Software Ltd. All rights reserved.
004: *
005: * This software is licensed as described in the file COPYING, which
006: * you should have received as part of this distribution. The terms
007: * are also available at http://svnkit.com/license.html
008: * If newer versions of this license are posted there, you may use a
009: * newer version instead, at your option.
010: * ====================================================================
011: */
012: package org.tmatesoft.svn.core.internal.wc.admin;
013:
014: import java.util.Map;
015:
016: import org.tmatesoft.svn.core.SVNException;
017: import org.tmatesoft.svn.core.SVNProperty;
018:
019: /**
020: * @version 1.1.1
021: * @author TMate Software Ltd.
022: */
023: public abstract class SVNProperties14 extends SVNVersionedProperties {
024:
025: private SVNAdminArea14 myAdminArea;
026: private String myEntryName;
027:
028: public SVNProperties14(Map props, SVNAdminArea14 adminArea,
029: String entryName) {
030: super (props);
031: myAdminArea = adminArea;
032: myEntryName = entryName;
033: }
034:
035: public boolean containsProperty(String name) throws SVNException {
036: Map propsMap = getPropertiesMap();
037: if (propsMap != null && propsMap.containsKey(name)) {
038: return true;
039: }
040:
041: SVNEntry entry = myAdminArea.getEntry(myEntryName, true);
042: if (entry == null) {
043: return false;
044: }
045: String[] cachableProps = entry.getCachableProperties();
046: if (cachableProps != null && getIndex(cachableProps, name) >= 0) {
047: String[] presentProps = entry.getPresentProperties();
048: if (presentProps == null
049: || getIndex(presentProps, name) < 0) {
050: return false;
051: }
052: return true;
053: }
054: if (!isEmpty()) {
055: Map props = loadProperties();
056: return props.containsKey(name);
057: }
058: return false;
059: }
060:
061: public String getPropertyValue(String name) throws SVNException {
062: if (getPropertiesMap() != null
063: && getPropertiesMap().containsKey(name)) {
064: return (String) getPropertiesMap().get(name);
065: }
066:
067: SVNEntry entry = myAdminArea.getEntry(myEntryName, true);
068: if (entry != null) {
069: String[] cachableProps = entry.getCachableProperties();
070: if (cachableProps != null
071: && getIndex(cachableProps, name) >= 0) {
072: String[] presentProps = entry.getPresentProperties();
073: if (presentProps == null
074: || getIndex(presentProps, name) < 0) {
075: return null;
076: }
077: if (SVNProperty.isBooleanProperty(name)) {
078: return SVNProperty.getValueOfBooleanProperty(name);
079: }
080: }
081: }
082:
083: Map props = loadProperties();
084: if (!isEmpty()) {
085: return (String) props.get(name);
086: }
087: return null;
088: }
089:
090: //TODO: this is not a good approach, however don't want to
091: //sort the original array to use it with Arrays.binarySearch(),
092: //since there's a risk to lose the order elements are stored in
093: //the array and written to the file. Maybe the storage order is
094: //important for somewhat somewhere...
095: private int getIndex(String[] array, String element) {
096: if (array == null || element == null) {
097: return -1;
098: }
099: for (int i = 0; i < array.length; i++) {
100: if (element.equals(array[i])) {
101: return i;
102: }
103: }
104: return -1;
105: }
106:
107: protected SVNVersionedProperties wrap(Map properties) {
108: return new SVNProperties13(properties);
109: }
110:
111: }
|