Example usage for com.amazonaws.services.route53.model CreateHostedZoneRequest setName

List of usage examples for com.amazonaws.services.route53.model CreateHostedZoneRequest setName

Introduction

In this page you can find the example usage for com.amazonaws.services.route53.model CreateHostedZoneRequest setName.

Prototype


public void setName(String name) 

Source Link

Document

The name of the domain.

Usage

From source file:com.msi.dns53.server.query.CreateHostedZone.java

License:Apache License

public CreateHostedZoneRequest unmarshall(HttpServletRequest req)
        throws IOException, ParserConfigurationException, SAXException {
    final CreateHostedZoneRequest request = new CreateHostedZoneRequest();

    StringBuilder stringBuilder = new StringBuilder(1000);
    Scanner scanner = new Scanner(req.getInputStream());
    while (scanner.hasNextLine()) {
        stringBuilder.append(scanner.nextLine());
    }/*w  w w  .j ava  2s  .  c o  m*/
    String body = stringBuilder.toString();
    logger.debug("XML Body Content: " + body);

    DefaultHandler handler = new DefaultHandler() {
        private boolean createHostedZoneRequest = false;
        private boolean hostedZoneConfig = false;
        private CharArrayWriter contents = new CharArrayWriter();

        public void startElement(String uri, String localName, String nodeName, Attributes attributes)
                throws SAXException {
            contents.reset();
            if (!uri.equals(DNS53Constants.XMLNS_VALUE)) {
                throw DNS53Faults.InvalidInput("The XML you provided did not have the correct namespace.");
            }
            if (nodeName.equals(DNS53Constants.CREATEHOSTEDZONEREQUEST)) {
                createHostedZoneRequest = true;
            }
            if (nodeName.equals(DNS53Constants.HOSTEDZONECONFIG)) {
                hostedZoneConfig = true;
            }
        }

        public void endElement(String uri, String localName, String nodeName) throws SAXException {
            if (createHostedZoneRequest && localName.equals(DNS53Constants.CREATEHOSTEDZONEREQUEST)) {
                createHostedZoneRequest = false;
            }
            if (createHostedZoneRequest && hostedZoneConfig
                    && localName.equals(DNS53Constants.HOSTEDZONECONFIG)) {
                hostedZoneConfig = false;
            }
            if (createHostedZoneRequest && localName.equals(DNS53Constants.NAME)) {
                request.setName(contents.toString());
            }
            if (createHostedZoneRequest && localName.equals(DNS53Constants.CALLERREFERENCE)) {
                request.setCallerReference(contents.toString());
            }
            if (createHostedZoneRequest && hostedZoneConfig && localName.equals(DNS53Constants.COMMENT)) {
                HostedZoneConfig config = new HostedZoneConfig();
                config.setComment(contents.toString());
                request.setHostedZoneConfig(config);
            }
        }

        public void characters(char ch[], int start, int length) throws SAXException {
            this.contents.write(ch, start, length);
        }
    };

    XMLReader xr = XMLReaderFactory.createXMLReader();
    xr.setContentHandler(handler);
    xr.parse(new InputSource(new StringReader(body)));

    logger.debug("Unmarshalling complete: " + request.toString());
    return request;
}