1 31 32 package org.opencms.workplace.editors.directedit; 33 34 import org.opencms.util.CmsStringUtil; 35 36 62 public final class CmsDirectEditMode { 63 64 65 public static final CmsDirectEditMode AUTO = new CmsDirectEditMode(2); 66 67 68 public static final CmsDirectEditMode FALSE = new CmsDirectEditMode(0); 69 70 71 public static final CmsDirectEditMode MANUAL = new CmsDirectEditMode(3); 72 73 74 public static final CmsDirectEditMode TRUE = new CmsDirectEditMode(1); 75 76 77 private static final CmsDirectEditMode[] MODES = {FALSE, TRUE, AUTO, MANUAL}; 78 79 80 private static final String VALUE_AUTO = "auto"; 81 82 83 private static final String VALUE_FALSE = CmsStringUtil.FALSE; 84 85 86 private static final String VALUE_MANUAL = "manual"; 87 88 89 private static final String VALUE_TRUE = CmsStringUtil.TRUE; 90 91 92 private int m_mode; 93 94 99 private CmsDirectEditMode(int mode) { 100 101 m_mode = mode; 102 } 103 104 111 public static CmsDirectEditMode valueOf(boolean value) { 112 113 return value ? TRUE : FALSE; 114 } 115 116 131 public static CmsDirectEditMode valueOf(int mode) { 132 133 if ((mode > 0) && (mode < MODES.length)) { 134 return MODES[mode]; 135 } 136 return FALSE; 137 } 138 139 148 public static CmsDirectEditMode valueOf(String value) { 149 150 CmsDirectEditMode result = FALSE; 151 if (CmsStringUtil.isNotEmpty(value)) { 152 value = value.trim().toLowerCase(); 153 if (Boolean.valueOf(value).booleanValue()) { 154 result = TRUE; 155 } else if (VALUE_AUTO.equals(value)) { 156 result = AUTO; 157 } else if (VALUE_MANUAL.equals(value)) { 158 result = MANUAL; 159 } 160 } 161 return result; 162 } 163 164 171 public int getMode() { 172 173 return m_mode; 174 } 175 176 184 public boolean isEnabled() { 185 186 return m_mode > 0; 187 } 188 189 193 public String toString() { 194 195 switch (m_mode) { 196 case 1: 197 return VALUE_TRUE; 198 case 2: 199 return VALUE_AUTO; 200 case 3: 201 return VALUE_MANUAL; 202 default: 203 return VALUE_FALSE; 204 } 205 } 206 } | Popular Tags |