001/**
002 *
003 * Copyright 2014-2015 Florian Schmaus
004 *
005 * Licensed under the Apache License, Version 2.0 (the "License");
006 * you may not use this file except in compliance with the License.
007 * You may obtain a copy of the License at
008 *
009 *     http://www.apache.org/licenses/LICENSE-2.0
010 *
011 * Unless required by applicable law or agreed to in writing, software
012 * distributed under the License is distributed on an "AS IS" BASIS,
013 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014 * See the License for the specific language governing permissions and
015 * limitations under the License.
016 */
017package org.jivesoftware.smack.java7;
018
019import java.util.List;
020
021import org.jivesoftware.smack.SmackConfiguration;
022import org.jivesoftware.smack.initializer.SmackInitializer;
023import org.jivesoftware.smack.util.DNSUtil;
024import org.jivesoftware.smack.util.StringTransformer;
025import org.jivesoftware.smack.util.SystemUtil;
026import org.jivesoftware.smack.util.stringencoder.Base64;
027import org.jivesoftware.smack.util.stringencoder.Base64UrlSafeEncoder;
028import org.jivesoftware.smack.util.stringencoder.java7.Java7Base64Encoder;
029import org.jivesoftware.smack.util.stringencoder.java7.Java7Base64UrlSafeEncoder;
030
031public class Java7SmackInitializer implements SmackInitializer {
032
033    @Override
034    public List<Exception> initialize() {
035        if (SystemUtil.onAndroid()) {
036            // @formatter:off
037            throw new RuntimeException(
038                            "You need to remove the smack-java7 dependency/jar from your build, " +
039                            "as it does not run on Android. " +
040                            "Use smack-android instead.");
041            // @formatter:on
042        }
043        SmackConfiguration.setDefaultHostnameVerifier(new XmppHostnameVerifier());
044        Base64.setEncoder(Java7Base64Encoder.getInstance());
045        Base64UrlSafeEncoder.setEncoder(Java7Base64UrlSafeEncoder.getInstance());
046        DNSUtil.setIdnaTransformer(new StringTransformer() {
047            @Override
048            public String transform(String string) {
049                return java.net.IDN.toASCII(string);
050            }
051        });
052        return null;
053    }
054
055}