001/** 002 * 003 * Copyright 2018-2020 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.full; 018 019import java.io.File; 020import java.io.FileNotFoundException; 021import java.io.PrintWriter; 022import java.nio.file.Path; 023import java.nio.file.Paths; 024 025import org.jivesoftware.smack.c2s.ModularXmppClientToServerConnectionConfiguration; 026 027import org.jxmpp.stringprep.XmppStringprepException; 028 029public class ModularXmppClientToServerConnectionTool { 030 031 @SuppressWarnings("DefaultCharset") 032 public static void main(String[] args) throws XmppStringprepException, FileNotFoundException { 033 034 final PrintWriter pw; 035 final boolean breakStateName; 036 037 switch (args.length) { 038 case 0: 039 pw = new PrintWriter(System.out); 040 breakStateName = false; 041 break; 042 case 1: 043 Path outputFilePath = Paths.get(args[0]); 044 File outputFile = outputFilePath.toFile(); 045 if (outputFile.exists()) { 046 outputFile.delete(); 047 } 048 pw = new PrintWriter(outputFile); 049 breakStateName = true; 050 break; 051 default: 052 throw new IllegalArgumentException("At most one argument allowed"); 053 } 054 055 printStateGraph(pw, breakStateName); 056 pw.flush(); 057 } 058 059 public static void printStateGraph(PrintWriter pw, boolean breakStateName) throws XmppStringprepException { 060 ModularXmppClientToServerConnectionConfiguration.Builder configurationBuilder = ModularXmppClientToServerConnectionConfiguration.builder() 061 .setUsernameAndPassword("user", "password") 062 .setXmppDomain("example.org"); 063 064 ModularXmppClientToServerConnectionConfiguration configuration = configurationBuilder.build(); 065 066 configuration.printStateGraphInDotFormat(pw, breakStateName); 067 068 pw.flush(); 069 } 070 071}