2 * Copyright 2000-2009 JetBrains s.r.o.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://www.apache.org/licenses/LICENSE-2.0
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
17 package com
.intellij
.util
.descriptors
.impl
;
19 import com
.intellij
.util
.descriptors
.CustomConfigFileSet
;
20 import com
.intellij
.util
.descriptors
.CustomConfigFile
;
21 import com
.intellij
.openapi
.util
.InvalidDataException
;
22 import com
.intellij
.openapi
.util
.WriteExternalException
;
23 import org
.jdom
.Element
;
24 import org
.jetbrains
.annotations
.NonNls
;
25 import org
.jetbrains
.annotations
.Nullable
;
27 import java
.util
.List
;
28 import java
.util
.ArrayList
;
29 import java
.util
.Collection
;
34 public class CustomConfigFileSetImpl
implements CustomConfigFileSet
{
35 @NonNls private static final String ELEMENT_NAME
= "deploymentDescriptor";
36 @NonNls private static final String URL_ATTRIBUTE
= "url";
37 @NonNls private static final String OPTION_ELEMENT_NAME
= "option";
38 @NonNls private static final String DEFAULT_DIR_OPTION
= "DEFAULT_DIR";
39 @NonNls private static final String NAME_ATTRIBUTE
= "name";
40 @NonNls private static final String VALUE_ATTRIBUTE
= "value";
42 private final List
<CustomConfigFile
> myDescriptors
= new ArrayList
<CustomConfigFile
>();
44 public void add(CustomConfigFile descriptor
) {
45 myDescriptors
.add(descriptor
);
48 public void remove(CustomConfigFile descriptor
) {
49 myDescriptors
.remove(descriptor
);
52 public CustomConfigFile
[] getConfigFiles() {
53 return myDescriptors
.toArray(new CustomConfigFile
[myDescriptors
.size()]);
56 public void setConfigFiles(final Collection
<CustomConfigFile
> descriptors
) {
57 myDescriptors
.clear();
58 myDescriptors
.addAll(descriptors
);
61 public void readExternal(Element element
) throws InvalidDataException
{
62 myDescriptors
.clear();
63 List
<Element
> descriptors
= element
.getChildren(ELEMENT_NAME
);
64 for (Element descriptor
: descriptors
) {
65 String url
= descriptor
.getAttributeValue(URL_ATTRIBUTE
);
66 String directory
= getDefaultDirOption(descriptor
);
67 if (directory
!= null) {
68 myDescriptors
.add(new CustomConfigFile(url
, directory
));
74 private static String
getDefaultDirOption(final Element descriptor
) {
75 List
<Element
> options
= descriptor
.getChildren(OPTION_ELEMENT_NAME
);
76 for (Element option
: options
) {
77 if (DEFAULT_DIR_OPTION
.equals(option
.getAttributeValue(NAME_ATTRIBUTE
))) {
78 return option
.getAttributeValue(VALUE_ATTRIBUTE
);
84 public void writeExternal(Element element
) throws WriteExternalException
{
85 for (CustomConfigFile descriptor
: myDescriptors
) {
86 final Element child
= new Element(ELEMENT_NAME
);
87 child
.setAttribute(URL_ATTRIBUTE
, descriptor
.getUrl());
88 final Element option
= new Element(OPTION_ELEMENT_NAME
);
89 option
.setAttribute(NAME_ATTRIBUTE
, DEFAULT_DIR_OPTION
);
90 option
.setAttribute(VALUE_ATTRIBUTE
, descriptor
.getOutputDirectoryPath());
91 child
.addContent(option
);
92 element
.addContent(child
);