| 1 | /** |
| 2 | * Licensed to jclouds, Inc. (jclouds) under one or more |
| 3 | * contributor license agreements. See the NOTICE file |
| 4 | * distributed with this work for additional information |
| 5 | * regarding copyright ownership. jclouds licenses this file |
| 6 | * to you under the Apache License, Version 2.0 (the |
| 7 | * "License"); you may not use this file except in compliance |
| 8 | * with the License. You may obtain a copy of the License at |
| 9 | * |
| 10 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 11 | * |
| 12 | * Unless required by applicable law or agreed to in writing, |
| 13 | * software distributed under the License is distributed on an |
| 14 | * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
| 15 | * KIND, either express or implied. See the License for the |
| 16 | * specific language governing permissions and limitations |
| 17 | * under the License. |
| 18 | */ |
| 19 | package org.jclouds.savvis.vpdc.xml; |
| 20 | |
| 21 | import static org.jclouds.savvis.vpdc.util.Utils.cleanseAttributes; |
| 22 | import static org.jclouds.savvis.vpdc.util.Utils.newResource; |
| 23 | import static org.jclouds.util.SaxUtils.equalsOrSuffix; |
| 24 | |
| 25 | import java.util.Map; |
| 26 | import java.util.Set; |
| 27 | |
| 28 | import org.jclouds.http.functions.ParseSax; |
| 29 | import org.jclouds.savvis.vpdc.domain.Resource; |
| 30 | import org.xml.sax.Attributes; |
| 31 | import org.xml.sax.SAXException; |
| 32 | |
| 33 | import com.google.common.collect.ImmutableSet; |
| 34 | import com.google.common.collect.ImmutableSet.Builder; |
| 35 | |
| 36 | /** |
| 37 | * @author Adrian Cole |
| 38 | */ |
| 39 | public class OrgListHandler extends ParseSax.HandlerWithResult<Set<Resource>> { |
| 40 | |
| 41 | private Builder<Resource> org = ImmutableSet.<Resource> builder(); |
| 42 | |
| 43 | public Set<Resource> getResult() { |
| 44 | try { |
| 45 | return org.build(); |
| 46 | } finally { |
| 47 | org = ImmutableSet.<Resource> builder(); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | @Override |
| 52 | public void startElement(String uri, String localName, String qName, Attributes attrs) throws SAXException { |
| 53 | Map<String, String> attributes = cleanseAttributes(attrs); |
| 54 | if (equalsOrSuffix(qName, "Org")) { |
| 55 | org.add(newResource(attributes)); |
| 56 | } |
| 57 | } |
| 58 | } |