/** * @see <a href="http://docs.aws.amazon.com/IAM/latest/APIReference/API_GetGroupPolicy.html" /> * @author Adrian Cole */ public class PolicyHandler extends ParseSax.HandlerForGeneratedRequestWithResult<Policy> { private StringBuilder currentText = new StringBuilder(); private Policy.Builder builder = Policy.builder(); @Override public Policy getResult() { try { return builder.build(); } finally { builder = Policy.builder(); } } @Override public void startElement(String url, String name, String qName, Attributes attributes) {} @Override public void endElement(String uri, String name, String qName) { if (qName.equals("PolicyName")) { builder.name(currentOrNull(currentText)); } else if (qName.endsWith("Name")) { builder.owner(currentOrNull(currentText)); } else if (qName.equals("PolicyDocument")) { builder.document(urlDecode(currentOrNull(currentText))); } currentText = new StringBuilder(); } @Override public void characters(char ch[], int start, int length) { currentText.append(ch, start, length); } }
@Override public Policy getResult() { try { return builder.build(); } finally { builder = Policy.builder(); } }