1 /*
2  * Copyright (c) 2017, Oracle and/or its affiliates. All rights reserved.
3  */
4 /*
5  * Licensed to the Apache Software Foundation (ASF) under one
6  * or more contributor license agreements. See the NOTICE file
7  * distributed with this work for additional information
8  * regarding copyright ownership. The ASF licenses this file
9  * to you under the Apache License, Version 2.0 (the  "License");
10  * you may not use this file except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *     http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  */
21 
22 package com.sun.org.apache.xml.internal.serializer.dom3;
23 
24 //import org.apache.xerces.dom3.DOMStringList;
25 import java.util.ArrayList;
26 import java.util.List;
27 import org.w3c.dom.DOMStringList;
28 
29 /**
30  * This class implemets the DOM Level 3 Core interface DOMStringList.
31  *
32  * @xsl.usage internal
33  * @LastModified: Oct 2017
34  */
35 final class DOMStringListImpl implements DOMStringList {
36 
37     //A collection of DOMString values
38     private List<String> fStrings;
39 
40     /**
41      * Construct an empty list of DOMStringListImpl
42      */
DOMStringListImpl()43     DOMStringListImpl() {
44         fStrings = new ArrayList<>();
45     }
46 
47     /**
48      * Construct an empty list of DOMStringListImpl
49      */
DOMStringListImpl(List<String> params)50     DOMStringListImpl(List<String> params) {
51         fStrings = params;
52     }
53 
54     /**
55      * Construct an empty list of DOMStringListImpl
56      */
DOMStringListImpl(String[] params )57     DOMStringListImpl(String[] params ) {
58         fStrings = new ArrayList<>();
59         if (params != null) {
60             for (int i=0; i < params.length; i++) {
61                 fStrings.add(params[i]);
62             }
63         }
64     }
65 
66     /**
67      * @see org.apache.xerces.dom3.DOMStringList#item(int)
68      */
item(int index)69     public String item(int index) {
70         try {
71             return fStrings.get(index);
72         } catch (IndexOutOfBoundsException e) {
73             return null;
74         }
75     }
76 
77     /**
78      * @see org.apache.xerces.dom3.DOMStringList#getLength()
79      */
getLength()80     public int getLength() {
81         return fStrings.size();
82     }
83 
84     /**
85      * @see org.apache.xerces.dom3.DOMStringList#contains(String)
86      */
contains(String param)87     public boolean contains(String param) {
88         return fStrings.contains(param) ;
89     }
90 
91     /**
92      * DOM Internal:
93      * Add a <code>DOMString</code> to the list.
94      *
95      * @param domString A string to add to the list
96      */
add(String param)97     public void add(String param) {
98         fStrings.add(param);
99     }
100 
101 }
102