1.1 --- a/src/net/fortuna/ical4j/model/ParameterFactoryImpl.java Thu Feb 12 18:02:00 2015 +0100 1.2 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 1.3 @@ -1,524 +0,0 @@ 1.4 -/** 1.5 - * Copyright (c) 2012, Ben Fortuna 1.6 - * All rights reserved. 1.7 - * 1.8 - * Redistribution and use in source and binary forms, with or without 1.9 - * modification, are permitted provided that the following conditions 1.10 - * are met: 1.11 - * 1.12 - * o Redistributions of source code must retain the above copyright 1.13 - * notice, this list of conditions and the following disclaimer. 1.14 - * 1.15 - * o Redistributions in binary form must reproduce the above copyright 1.16 - * notice, this list of conditions and the following disclaimer in the 1.17 - * documentation and/or other materials provided with the distribution. 1.18 - * 1.19 - * o Neither the name of Ben Fortuna nor the names of any other contributors 1.20 - * may be used to endorse or promote products derived from this software 1.21 - * without specific prior written permission. 1.22 - * 1.23 - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1.24 - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1.25 - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1.26 - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR 1.27 - * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 1.28 - * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, 1.29 - * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR 1.30 - * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF 1.31 - * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING 1.32 - * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS 1.33 - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 1.34 - */ 1.35 -package net.fortuna.ical4j.model; 1.36 - 1.37 -import java.net.URISyntaxException; 1.38 - 1.39 -import net.fortuna.ical4j.model.parameter.Abbrev; 1.40 -import net.fortuna.ical4j.model.parameter.AltRep; 1.41 -import net.fortuna.ical4j.model.parameter.Cn; 1.42 -import net.fortuna.ical4j.model.parameter.CuType; 1.43 -import net.fortuna.ical4j.model.parameter.DelegatedFrom; 1.44 -import net.fortuna.ical4j.model.parameter.DelegatedTo; 1.45 -import net.fortuna.ical4j.model.parameter.Dir; 1.46 -import net.fortuna.ical4j.model.parameter.Encoding; 1.47 -import net.fortuna.ical4j.model.parameter.FbType; 1.48 -import net.fortuna.ical4j.model.parameter.FmtType; 1.49 -import net.fortuna.ical4j.model.parameter.Language; 1.50 -import net.fortuna.ical4j.model.parameter.Member; 1.51 -import net.fortuna.ical4j.model.parameter.PartStat; 1.52 -import net.fortuna.ical4j.model.parameter.Range; 1.53 -import net.fortuna.ical4j.model.parameter.RelType; 1.54 -import net.fortuna.ical4j.model.parameter.Related; 1.55 -import net.fortuna.ical4j.model.parameter.Role; 1.56 -import net.fortuna.ical4j.model.parameter.Rsvp; 1.57 -import net.fortuna.ical4j.model.parameter.ScheduleAgent; 1.58 -import net.fortuna.ical4j.model.parameter.ScheduleStatus; 1.59 -import net.fortuna.ical4j.model.parameter.SentBy; 1.60 -import net.fortuna.ical4j.model.parameter.Type; 1.61 -import net.fortuna.ical4j.model.parameter.TzId; 1.62 -import net.fortuna.ical4j.model.parameter.Value; 1.63 -import net.fortuna.ical4j.model.parameter.Vvenue; 1.64 -import net.fortuna.ical4j.model.parameter.XParameter; 1.65 -import net.fortuna.ical4j.util.Strings; 1.66 - 1.67 -/** 1.68 - * A factory for creating iCalendar parameters. 1.69 - * 1.70 - * $Id $ 1.71 - * 1.72 - * [05-Apr-2004] 1.73 - * 1.74 - * @author Ben Fortuna 1.75 - */ 1.76 -public class ParameterFactoryImpl extends AbstractContentFactory implements ParameterFactory { 1.77 - 1.78 - private static final long serialVersionUID = -4034423507432249165L; 1.79 - 1.80 - private static ParameterFactoryImpl instance = new ParameterFactoryImpl(); 1.81 - 1.82 - protected ParameterFactoryImpl() { 1.83 - registerDefaultFactory(Parameter.ABBREV, new AbbrevFactory()); 1.84 - registerDefaultFactory(Parameter.ALTREP, new AltRepFactory()); 1.85 - registerDefaultFactory(Parameter.CN, new CnFactory()); 1.86 - registerDefaultFactory(Parameter.CUTYPE, new CuTypeFactory()); 1.87 - registerDefaultFactory(Parameter.DELEGATED_FROM, new DelegatedFromFactory()); 1.88 - registerDefaultFactory(Parameter.DELEGATED_TO, new DelegatedToFactory()); 1.89 - registerDefaultFactory(Parameter.DIR, new DirFactory()); 1.90 - registerDefaultFactory(Parameter.ENCODING, new EncodingFactory()); 1.91 - registerDefaultFactory(Parameter.FMTTYPE, new FmtTypeFactory()); 1.92 - registerDefaultFactory(Parameter.FBTYPE, new FbTypeFactory()); 1.93 - registerDefaultFactory(Parameter.LANGUAGE, new LanguageFactory()); 1.94 - registerDefaultFactory(Parameter.MEMBER, new MemberFactory()); 1.95 - registerDefaultFactory(Parameter.PARTSTAT, new PartStatFactory()); 1.96 - registerDefaultFactory(Parameter.RANGE, new RangeFactory()); 1.97 - registerDefaultFactory(Parameter.RELATED, new RelatedFactory()); 1.98 - registerDefaultFactory(Parameter.RELTYPE, new RelTypeFactory()); 1.99 - registerDefaultFactory(Parameter.ROLE, new RoleFactory()); 1.100 - registerDefaultFactory(Parameter.RSVP, new RsvpFactory()); 1.101 - registerDefaultFactory(Parameter.SCHEDULE_AGENT, new ScheduleAgentFactory()); 1.102 - registerDefaultFactory(Parameter.SCHEDULE_STATUS, new ScheduleStatusFactory()); 1.103 - registerDefaultFactory(Parameter.SENT_BY, new SentByFactory()); 1.104 - registerDefaultFactory(Parameter.TYPE, new TypeFactory()); 1.105 - registerDefaultFactory(Parameter.TZID, new TzIdFactory()); 1.106 - registerDefaultFactory(Parameter.VALUE, new ValueFactory()); 1.107 - registerDefaultFactory(Parameter.VVENUE, new VvenueFactory()); 1.108 - } 1.109 - 1.110 - /** 1.111 - * @return Returns the instance. 1.112 - */ 1.113 - public static ParameterFactoryImpl getInstance() { 1.114 - return instance; 1.115 - } 1.116 - 1.117 - /** 1.118 - * Creates a parameter. 1.119 - * @param name name of the parameter 1.120 - * @param value a parameter value 1.121 - * @return a component 1.122 - * @throws URISyntaxException thrown when the specified string is not a valid representation of a URI for selected 1.123 - * parameters 1.124 - */ 1.125 - public Parameter createParameter(final String name, final String value) 1.126 - throws URISyntaxException { 1.127 - final ParameterFactory factory = (ParameterFactory) getFactory(name); 1.128 - Parameter parameter = null; 1.129 - if (factory != null) { 1.130 - parameter = factory.createParameter(name, value); 1.131 - } 1.132 - else if (isExperimentalName(name)) { 1.133 - parameter = new XParameter(name, value); 1.134 - } 1.135 - else if (allowIllegalNames()) { 1.136 - parameter = new XParameter(name, value); 1.137 - } 1.138 - else { 1.139 - throw new IllegalArgumentException("Invalid parameter name: " 1.140 - + name); 1.141 - } 1.142 - return parameter; 1.143 - } 1.144 - 1.145 - /** 1.146 - * @param name 1.147 - * @return 1.148 - */ 1.149 - private boolean isExperimentalName(final String name) { 1.150 - return name.startsWith(Parameter.EXPERIMENTAL_PREFIX) 1.151 - && name.length() > Parameter.EXPERIMENTAL_PREFIX.length(); 1.152 - } 1.153 - 1.154 - private static class AbbrevFactory implements ParameterFactory { 1.155 - private static final long serialVersionUID = 1L; 1.156 - 1.157 - public Parameter createParameter(final String name, final String value) throws URISyntaxException { 1.158 - return new Abbrev(value); 1.159 - } 1.160 - } 1.161 - 1.162 - private static class AltRepFactory implements ParameterFactory { 1.163 - private static final long serialVersionUID = 1L; 1.164 - 1.165 - public Parameter createParameter(final String name, final String value) throws URISyntaxException { 1.166 - return new AltRep(value); 1.167 - } 1.168 - } 1.169 - 1.170 - private static class CnFactory implements ParameterFactory { 1.171 - private static final long serialVersionUID = 1L; 1.172 - 1.173 - public Parameter createParameter(final String name, 1.174 - final String value) throws URISyntaxException { 1.175 - return new Cn(value); 1.176 - } 1.177 - } 1.178 - 1.179 - private static class CuTypeFactory implements ParameterFactory { 1.180 - private static final long serialVersionUID = 1L; 1.181 - 1.182 - public Parameter createParameter(final String name, final String value) throws URISyntaxException { 1.183 - CuType parameter = new CuType(value); 1.184 - if (CuType.INDIVIDUAL.equals(parameter)) { 1.185 - parameter = CuType.INDIVIDUAL; 1.186 - } 1.187 - else if (CuType.GROUP.equals(parameter)) { 1.188 - parameter = CuType.GROUP; 1.189 - } 1.190 - else if (CuType.RESOURCE.equals(parameter)) { 1.191 - parameter = CuType.RESOURCE; 1.192 - } 1.193 - else if (CuType.ROOM.equals(parameter)) { 1.194 - parameter = CuType.ROOM; 1.195 - } 1.196 - else if (CuType.UNKNOWN.equals(parameter)) { 1.197 - parameter = CuType.UNKNOWN; 1.198 - } 1.199 - return parameter; 1.200 - } 1.201 - } 1.202 - 1.203 - private static class DelegatedFromFactory implements ParameterFactory { 1.204 - private static final long serialVersionUID = 1L; 1.205 - 1.206 - public Parameter createParameter(final String name, 1.207 - final String value) throws URISyntaxException { 1.208 - return new DelegatedFrom(value); 1.209 - } 1.210 - } 1.211 - 1.212 - private static class DelegatedToFactory implements ParameterFactory { 1.213 - private static final long serialVersionUID = 1L; 1.214 - 1.215 - public Parameter createParameter(final String name, 1.216 - final String value) throws URISyntaxException { 1.217 - return new DelegatedTo(value); 1.218 - } 1.219 - } 1.220 - 1.221 - private static class DirFactory implements ParameterFactory { 1.222 - private static final long serialVersionUID = 1L; 1.223 - 1.224 - public Parameter createParameter(final String name, 1.225 - final String value) throws URISyntaxException { 1.226 - return new Dir(value); 1.227 - } 1.228 - } 1.229 - 1.230 - private static class EncodingFactory implements ParameterFactory { 1.231 - private static final long serialVersionUID = 1L; 1.232 - 1.233 - public Parameter createParameter(final String name, 1.234 - final String value) throws URISyntaxException { 1.235 - Encoding parameter = new Encoding(value); 1.236 - if (Encoding.EIGHT_BIT.equals(parameter)) { 1.237 - parameter = Encoding.EIGHT_BIT; 1.238 - } 1.239 - else if (Encoding.BASE64.equals(parameter)) { 1.240 - parameter = Encoding.BASE64; 1.241 - } 1.242 - return parameter; 1.243 - } 1.244 - } 1.245 - 1.246 - private static class FmtTypeFactory implements ParameterFactory { 1.247 - private static final long serialVersionUID = 1L; 1.248 - 1.249 - public Parameter createParameter(final String name, 1.250 - final String value) throws URISyntaxException { 1.251 - return new FmtType(value); 1.252 - } 1.253 - } 1.254 - 1.255 - private static class FbTypeFactory implements ParameterFactory { 1.256 - private static final long serialVersionUID = 1L; 1.257 - 1.258 - public Parameter createParameter(final String name, 1.259 - final String value) throws URISyntaxException { 1.260 - FbType parameter = new FbType(value); 1.261 - if (FbType.FREE.equals(parameter)) { 1.262 - parameter = FbType.FREE; 1.263 - } 1.264 - else if (FbType.BUSY.equals(parameter)) { 1.265 - parameter = FbType.BUSY; 1.266 - } 1.267 - else if (FbType.BUSY_TENTATIVE.equals(parameter)) { 1.268 - parameter = FbType.BUSY_TENTATIVE; 1.269 - } 1.270 - else if (FbType.BUSY_UNAVAILABLE.equals(parameter)) { 1.271 - parameter = FbType.BUSY_UNAVAILABLE; 1.272 - } 1.273 - return parameter; 1.274 - } 1.275 - } 1.276 - 1.277 - private static class LanguageFactory implements ParameterFactory { 1.278 - private static final long serialVersionUID = 1L; 1.279 - 1.280 - public Parameter createParameter(final String name, 1.281 - final String value) throws URISyntaxException { 1.282 - return new Language(value); 1.283 - } 1.284 - } 1.285 - 1.286 - private static class MemberFactory implements ParameterFactory { 1.287 - private static final long serialVersionUID = 1L; 1.288 - 1.289 - public Parameter createParameter(final String name, 1.290 - final String value) throws URISyntaxException { 1.291 - return new Member(value); 1.292 - } 1.293 - } 1.294 - 1.295 - private static class PartStatFactory implements ParameterFactory { 1.296 - private static final long serialVersionUID = 1L; 1.297 - 1.298 - public Parameter createParameter(final String name, 1.299 - final String value) throws URISyntaxException { 1.300 - PartStat parameter = new PartStat(value); 1.301 - if (PartStat.NEEDS_ACTION.equals(parameter)) { 1.302 - parameter = PartStat.NEEDS_ACTION; 1.303 - } 1.304 - else if (PartStat.ACCEPTED.equals(parameter)) { 1.305 - parameter = PartStat.ACCEPTED; 1.306 - } 1.307 - else if (PartStat.DECLINED.equals(parameter)) { 1.308 - parameter = PartStat.DECLINED; 1.309 - } 1.310 - else if (PartStat.TENTATIVE.equals(parameter)) { 1.311 - parameter = PartStat.TENTATIVE; 1.312 - } 1.313 - else if (PartStat.DELEGATED.equals(parameter)) { 1.314 - parameter = PartStat.DELEGATED; 1.315 - } 1.316 - else if (PartStat.COMPLETED.equals(parameter)) { 1.317 - parameter = PartStat.COMPLETED; 1.318 - } 1.319 - else if (PartStat.IN_PROCESS.equals(parameter)) { 1.320 - parameter = PartStat.IN_PROCESS; 1.321 - } 1.322 - return parameter; 1.323 - } 1.324 - } 1.325 - 1.326 - private static class RangeFactory implements ParameterFactory { 1.327 - private static final long serialVersionUID = 1L; 1.328 - 1.329 - public Parameter createParameter(final String name, 1.330 - final String value) throws URISyntaxException { 1.331 - Range parameter = new Range(value); 1.332 - if (Range.THISANDFUTURE.equals(parameter)) { 1.333 - parameter = Range.THISANDFUTURE; 1.334 - } 1.335 - else if (Range.THISANDPRIOR.equals(parameter)) { 1.336 - parameter = Range.THISANDPRIOR; 1.337 - } 1.338 - return parameter; 1.339 - } 1.340 - } 1.341 - 1.342 - private static class RelatedFactory implements ParameterFactory { 1.343 - private static final long serialVersionUID = 1L; 1.344 - 1.345 - public Parameter createParameter(final String name, 1.346 - final String value) throws URISyntaxException { 1.347 - Related parameter = new Related(value); 1.348 - if (Related.START.equals(parameter)) { 1.349 - parameter = Related.START; 1.350 - } 1.351 - else if (Related.END.equals(parameter)) { 1.352 - parameter = Related.END; 1.353 - } 1.354 - return parameter; 1.355 - } 1.356 - } 1.357 - 1.358 - private static class RelTypeFactory implements ParameterFactory { 1.359 - private static final long serialVersionUID = 1L; 1.360 - 1.361 - public Parameter createParameter(final String name, 1.362 - final String value) throws URISyntaxException { 1.363 - RelType parameter = new RelType(value); 1.364 - if (RelType.PARENT.equals(parameter)) { 1.365 - parameter = RelType.PARENT; 1.366 - } 1.367 - else if (RelType.CHILD.equals(parameter)) { 1.368 - parameter = RelType.CHILD; 1.369 - } 1.370 - if (RelType.SIBLING.equals(parameter)) { 1.371 - parameter = RelType.SIBLING; 1.372 - } 1.373 - return parameter; 1.374 - } 1.375 - } 1.376 - 1.377 - private static class RoleFactory implements ParameterFactory { 1.378 - private static final long serialVersionUID = 1L; 1.379 - 1.380 - public Parameter createParameter(final String name, 1.381 - final String value) throws URISyntaxException { 1.382 - Role parameter = new Role(value); 1.383 - if (Role.CHAIR.equals(parameter)) { 1.384 - parameter = Role.CHAIR; 1.385 - } 1.386 - else if (Role.REQ_PARTICIPANT.equals(parameter)) { 1.387 - parameter = Role.REQ_PARTICIPANT; 1.388 - } 1.389 - else if (Role.OPT_PARTICIPANT.equals(parameter)) { 1.390 - parameter = Role.OPT_PARTICIPANT; 1.391 - } 1.392 - else if (Role.NON_PARTICIPANT.equals(parameter)) { 1.393 - parameter = Role.NON_PARTICIPANT; 1.394 - } 1.395 - return parameter; 1.396 - } 1.397 - } 1.398 - 1.399 - private static class RsvpFactory implements ParameterFactory { 1.400 - private static final long serialVersionUID = 1L; 1.401 - 1.402 - public Parameter createParameter(final String name, 1.403 - final String value) throws URISyntaxException { 1.404 - Rsvp parameter = new Rsvp(value); 1.405 - if (Rsvp.TRUE.equals(parameter)) { 1.406 - parameter = Rsvp.TRUE; 1.407 - } 1.408 - else if (Rsvp.FALSE.equals(parameter)) { 1.409 - parameter = Rsvp.FALSE; 1.410 - } 1.411 - return parameter; 1.412 - } 1.413 - } 1.414 - 1.415 - private static class ScheduleAgentFactory implements ParameterFactory { 1.416 - public Parameter createParameter(final String name, 1.417 - final String value) throws URISyntaxException { 1.418 - final ScheduleAgent parameter = new ScheduleAgent(value); 1.419 - if (ScheduleAgent.SERVER.equals(parameter)) { 1.420 - return ScheduleAgent.SERVER; 1.421 - } 1.422 - else if (ScheduleAgent.CLIENT.equals(parameter)) { 1.423 - return ScheduleAgent.CLIENT; 1.424 - } 1.425 - else if (ScheduleAgent.NONE.equals(parameter)) { 1.426 - return ScheduleAgent.NONE; 1.427 - } 1.428 - return parameter; 1.429 - } 1.430 - } 1.431 - 1.432 - private static class ScheduleStatusFactory implements ParameterFactory { 1.433 - public Parameter createParameter(final String name, 1.434 - final String value) throws URISyntaxException { 1.435 - return new ScheduleStatus(value); 1.436 - } 1.437 - } 1.438 - 1.439 - private static class SentByFactory implements ParameterFactory { 1.440 - private static final long serialVersionUID = 1L; 1.441 - 1.442 - public Parameter createParameter(final String name, 1.443 - final String value) throws URISyntaxException { 1.444 - return new SentBy(value); 1.445 - } 1.446 - } 1.447 - 1.448 - private static class VvenueFactory implements ParameterFactory { 1.449 - private static final long serialVersionUID = 1L; 1.450 - 1.451 - public Parameter createParameter(final String name, final String value) 1.452 - throws URISyntaxException { 1.453 - return new Vvenue(value); 1.454 - } 1.455 - } 1.456 - 1.457 - private static class TypeFactory implements ParameterFactory { 1.458 - private static final long serialVersionUID = 1L; 1.459 - 1.460 - public Parameter createParameter(final String name, 1.461 - final String value) throws URISyntaxException { 1.462 - return new Type(value); 1.463 - } 1.464 - } 1.465 - 1.466 - private static class TzIdFactory implements ParameterFactory { 1.467 - private static final long serialVersionUID = 1L; 1.468 - 1.469 - public Parameter createParameter(final String name, 1.470 - final String value) throws URISyntaxException { 1.471 - return new TzId(Strings.unescape(value)); 1.472 - } 1.473 - } 1.474 - 1.475 - private static class ValueFactory implements ParameterFactory { 1.476 - private static final long serialVersionUID = 1L; 1.477 - 1.478 - public Parameter createParameter(final String name, 1.479 - final String value) throws URISyntaxException { 1.480 - Value parameter = new Value(value); 1.481 - if (Value.BINARY.equals(parameter)) { 1.482 - parameter = Value.BINARY; 1.483 - } 1.484 - else if (Value.BOOLEAN.equals(parameter)) { 1.485 - parameter = Value.BOOLEAN; 1.486 - } 1.487 - else if (Value.CAL_ADDRESS.equals(parameter)) { 1.488 - parameter = Value.CAL_ADDRESS; 1.489 - } 1.490 - else if (Value.DATE.equals(parameter)) { 1.491 - parameter = Value.DATE; 1.492 - } 1.493 - else if (Value.DATE_TIME.equals(parameter)) { 1.494 - parameter = Value.DATE_TIME; 1.495 - } 1.496 - else if (Value.DURATION.equals(parameter)) { 1.497 - parameter = Value.DURATION; 1.498 - } 1.499 - else if (Value.FLOAT.equals(parameter)) { 1.500 - parameter = Value.FLOAT; 1.501 - } 1.502 - else if (Value.INTEGER.equals(parameter)) { 1.503 - parameter = Value.INTEGER; 1.504 - } 1.505 - else if (Value.PERIOD.equals(parameter)) { 1.506 - parameter = Value.PERIOD; 1.507 - } 1.508 - else if (Value.RECUR.equals(parameter)) { 1.509 - parameter = Value.RECUR; 1.510 - } 1.511 - else if (Value.TEXT.equals(parameter)) { 1.512 - parameter = Value.TEXT; 1.513 - } 1.514 - else if (Value.TIME.equals(parameter)) { 1.515 - parameter = Value.TIME; 1.516 - } 1.517 - else if (Value.URI.equals(parameter)) { 1.518 - parameter = Value.URI; 1.519 - } 1.520 - else if (Value.UTC_OFFSET.equals(parameter)) { 1.521 - parameter = Value.UTC_OFFSET; 1.522 - } 1.523 - return parameter; 1.524 - } 1.525 - } 1.526 - 1.527 -}