├── .github └── workflows │ └── codeql-analysis.yml ├── .gitignore ├── Changelog ├── LICENSE.txt ├── NOTICE.txt ├── README.md ├── android-no-reg ├── .gitignore ├── README ├── app │ ├── .gitignore │ ├── build.gradle │ └── proguard-rules.pro ├── build.gradle ├── gradle.properties ├── gradle │ └── wrapper │ │ └── gradle-wrapper.properties ├── gradlew ├── gradlew.bat ├── settings.gradle └── test.sh ├── dokujclient_completion ├── man ├── build_man.sh ├── man.footer.txt └── man.header.txt ├── pom.xml ├── scripts └── descriptorRef.xml └── src ├── main ├── java │ └── dw │ │ ├── cli │ │ ├── CliOptions.java │ │ ├── Command.java │ │ ├── CommandFactory.java │ │ ├── OptionParser.java │ │ ├── Output.java │ │ ├── ParseOptionException.java │ │ ├── PasswordReader.java │ │ ├── Program.java │ │ ├── StdinReader.java │ │ └── commands │ │ │ ├── AclChanger.java │ │ │ ├── AclChecker.java │ │ │ ├── AllPageGetter.java │ │ │ ├── AttachmentDeleter.java │ │ │ ├── AttachmentGetter.java │ │ │ ├── AttachmentInfoGetter.java │ │ │ ├── AttachmentPutter.java │ │ │ ├── AttachmentReader.java │ │ │ ├── BackLinksGetter.java │ │ │ ├── CliVersion.java │ │ │ ├── HelpPrinter.java │ │ │ ├── ItemListToStringCommand.java │ │ │ ├── LinksLister.java │ │ │ ├── LocksSetter.java │ │ │ ├── PageGetter.java │ │ │ ├── PageHtmlGetter.java │ │ │ ├── PageInfoGetter.java │ │ │ ├── PageListGetter.java │ │ │ ├── PagePutter.java │ │ │ ├── PageVersionGetter.java │ │ │ ├── PageVersionsGetter.java │ │ │ ├── RPCVersionSupportedGetter.java │ │ │ ├── RecentChangesGetter.java │ │ │ ├── RecentMediaChangesGetter.java │ │ │ ├── Searcher.java │ │ │ ├── SimpleCommand.java │ │ │ ├── TimeGetter.java │ │ │ ├── TitleGetter.java │ │ │ ├── VersionGetter.java │ │ │ └── XMLRPCAPIVersionGetter.java │ │ └── xmlrpc │ │ ├── Attacher.java │ │ ├── AttachmentDetails.java │ │ ├── AttachmentInfo.java │ │ ├── CoreClient.java │ │ ├── CoreClientFactory.java │ │ ├── DokuJClient.java │ │ ├── DokuJClientConfig.java │ │ ├── ExceptionConverter.java │ │ ├── LinkInfo.java │ │ ├── LockResult.java │ │ ├── Locker.java │ │ ├── MediaChange.java │ │ ├── ObjectConverter.java │ │ ├── Page.java │ │ ├── PageChange.java │ │ ├── PageDW.java │ │ ├── PageInfo.java │ │ ├── PageVersion.java │ │ ├── SearchResult.java │ │ └── exception │ │ ├── DokuAttachmentStillReferenced.java │ │ ├── DokuAttachmentUploadException.java │ │ ├── DokuBadUrlException.java │ │ ├── DokuDeleteAttachmentException.java │ │ ├── DokuDistantFileDoesntExistException.java │ │ ├── DokuEmptyNewPageException.java │ │ ├── DokuException.java │ │ ├── DokuIncompatibleVersionException.java │ │ ├── DokuInvalidTimeStampException.java │ │ ├── DokuMethodDoesNotExistsException.java │ │ ├── DokuMisConfiguredWikiException.java │ │ ├── DokuNoChangesException.java │ │ ├── DokuPageDoesNotExistException.java │ │ ├── DokuPageLockedException.java │ │ ├── DokuTimeoutException.java │ │ ├── DokuUnauthorizedException.java │ │ ├── DokuUnknownException.java │ │ └── DokuWordblockException.java └── resources │ ├── application.properties │ └── dokujclient └── test ├── java └── dw │ ├── cli │ ├── commands │ │ └── itest │ │ │ ├── Test_AclChanger.java │ │ │ ├── Test_AclChecker.java │ │ │ ├── Test_AllPagesGetter.java │ │ │ ├── Test_AttachmentInfoGetter.java │ │ │ ├── Test_AttachmentPutterAndDeleter.java │ │ │ ├── Test_AttachmentReader.java │ │ │ ├── Test_BackLinksGetter.java │ │ │ ├── Test_Exception.java │ │ │ ├── Test_HelpPrinter.java │ │ │ ├── Test_LinksLister.java │ │ │ ├── Test_LocksSetter.java │ │ │ ├── Test_PageAppender.java │ │ │ ├── Test_PageGetterAndPutter.java │ │ │ ├── Test_PageHtmlGetter.java │ │ │ ├── Test_PageInfoGetter.java │ │ │ ├── Test_PageInfoVersionGetter.java │ │ │ ├── Test_PageListGetter.java │ │ │ ├── Test_PageVersionGetter.java │ │ │ ├── Test_PageVersionsGetter.java │ │ │ ├── Test_RPCVersionSupportedGetter.java │ │ │ ├── Test_RecentChangesGetter.java │ │ │ ├── Test_RecentMediaChangesGetter.java │ │ │ ├── Test_Searcher.java │ │ │ ├── Test_TimeGetter.java │ │ │ ├── Test_TitleGetter.java │ │ │ ├── Test_Version.java │ │ │ ├── Test_VersionGetter.java │ │ │ ├── Test_XMLRPCAPIVersionGetter.java │ │ │ └── Test_getAttachment.java │ ├── itest │ │ ├── TestHelper.java │ │ └── Test_PermissionLessUser.java │ └── utest │ │ ├── MockPasswordReader.java │ │ ├── Test_CliOptions.java │ │ ├── Test_OptionParser.java │ │ └── Test_PagePutter.java │ └── xmlrpc │ ├── itest │ ├── TestHelper.java │ ├── TestParams.java │ ├── Test_AclChanger.java │ ├── Test_Attacher.java │ ├── Test_BadQueries.java │ ├── Test_Cookies.java │ ├── Test_Exception.java │ ├── Test_Lock.java │ └── Test_XmlRpcQueries.java │ └── utest │ ├── Test_AttachmentDetails.java │ ├── Test_AttachmentInfo.java │ ├── Test_LinkInfo.java │ ├── Test_LockResult.java │ ├── Test_MediaChange.java │ ├── Test_Page.java │ ├── Test_PageChange.java │ ├── Test_PageDW.java │ ├── Test_PageInfo.java │ ├── Test_PageVersion.java │ └── Test_SearchResult.java └── resources ├── README.md ├── installTestEnvironment.sh └── testEnvironment ├── at.gif ├── conf ├── acl.auth.php ├── local.disabled_rpc.php ├── local.php ├── plugins.local.php ├── users.auth.php └── wordblock.conf ├── data ├── attic │ └── rev │ │ ├── start.1356218400.txt.gz │ │ ├── start.1356218411.txt.gz │ │ └── start.1356218419.txt.gz ├── media │ └── ro_for_tests │ │ └── img1.gif ├── meta │ ├── _dokuwiki.changes │ ├── _media.changes │ └── rev │ │ ├── start.changes │ │ ├── start.indexed │ │ └── start.meta └── pages │ ├── links │ └── start.txt │ ├── ns1 │ ├── dummy.txt │ └── start.txt │ ├── nssearch │ ├── page1.txt │ ├── page2.txt │ ├── page3.txt │ └── start.txt │ ├── nswithanotherns │ ├── dummy.txt │ ├── otherns │ │ └── page.txt │ └── start.txt │ ├── rev │ └── start.txt │ └── singlepage │ └── start.txt └── list-plus.gif /.github/workflows/codeql-analysis.yml: -------------------------------------------------------------------------------- 1 | # For most projects, this workflow file will not need changing; you simply need 2 | # to commit it to your repository. 3 | # 4 | # You may wish to alter this file to override the set of languages analyzed, 5 | # or to provide custom queries or build logic. 6 | name: "CodeQL" 7 | 8 | on: 9 | push: 10 | branches: [master] 11 | pull_request: 12 | # The branches below must be a subset of the branches above 13 | branches: [master] 14 | schedule: 15 | - cron: '0 12 * * 2' 16 | 17 | jobs: 18 | analyze: 19 | name: Analyze 20 | runs-on: ubuntu-latest 21 | 22 | strategy: 23 | fail-fast: false 24 | matrix: 25 | # Override automatic language detection by changing the below list 26 | # Supported options are ['csharp', 'cpp', 'go', 'java', 'javascript', 'python'] 27 | language: ['java'] 28 | # Learn more... 29 | # https://docs.github.com/en/github/finding-security-vulnerabilities-and-errors-in-your-code/configuring-code-scanning#overriding-automatic-language-detection 30 | 31 | steps: 32 | - name: Checkout repository 33 | uses: actions/checkout@v2 34 | with: 35 | # We must fetch at least the immediate parents so that if this is 36 | # a pull request then we can checkout the head. 37 | fetch-depth: 2 38 | 39 | # If this run was triggered by a pull request event, then checkout 40 | # the head of the pull request instead of the merge commit. 41 | - run: git checkout HEAD^2 42 | if: ${{ github.event_name == 'pull_request' }} 43 | 44 | # Initializes the CodeQL tools for scanning. 45 | - name: Initialize CodeQL 46 | uses: github/codeql-action/init@v1 47 | with: 48 | languages: ${{ matrix.language }} 49 | # If you wish to specify custom queries, you can do so here or in a config file. 50 | # By default, queries listed here will override any specified in a config file. 51 | # Prefix the list here with "+" to use these queries and those in the config file. 52 | # queries: ./path/to/local/query, your-org/your-repo/queries@main 53 | 54 | # Autobuild attempts to build any compiled languages (C/C++, C#, or Java). 55 | # If this step fails, then you should remove it and run the build manually (see below) 56 | - name: Autobuild 57 | uses: github/codeql-action/autobuild@v1 58 | 59 | # ℹ️ Command-line programs to run using the OS shell. 60 | # 📚 https://git.io/JvXDl 61 | 62 | # ✏️ If the Autobuild fails above, remove it and uncomment the following three lines 63 | # and modify them (or add more) to build your code if your project 64 | # uses a compiled language 65 | 66 | #- run: | 67 | # make bootstrap 68 | # make release 69 | 70 | - name: Perform CodeQL Analysis 71 | uses: github/codeql-action/analyze@v1 72 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | bin 2 | tmpForInstallation 3 | *.jar 4 | .*.sw* 5 | *.class 6 | target 7 | maven-build.properties 8 | maven-build.xml 9 | .classpath 10 | .project 11 | aXMLRPC/ 12 | .idea 13 | .settings/ 14 | *.iml 15 | -------------------------------------------------------------------------------- /Changelog: -------------------------------------------------------------------------------- 1 | 3.9.1 2 | * Upgrade aXMLRPC to fix #27 3 | 4 | 3.9.0 5 | * Fix getPageVersions when a non 0 offset is provided 6 | 7 | 3.8.1 8 | * Add --debug option in man page 9 | 10 | 3.8.0 11 | * Add debug mode 12 | 13 | 3.7.0 14 | * Fix compatibility with android 15 | * getAttachments also returns the filename and upload time 16 | 17 | 3.6.0 18 | * Use aXMLRPC from fr.turri instead of de.timroes to be able to publish to maven central again 19 | 20 | 3.5.2 21 | * fix Java 6 compatibility 22 | 23 | 3.5.1 24 | * fix man page 25 | 26 | 3.5.0 27 | * add man page 28 | 29 | 3.4.0 30 | * Upgrade dependency on aXMLRPC (1.8.1) to fix compatibility with DW Detritus. Hence build depends on JCenter 31 | * login command returns a boolean to indicate whether it succeeded 32 | 33 | 3.3.0 34 | * [FIX] Throws DoukMisConfiguredException instead of Unauthorized, when we fail because of the wiki's configuration 35 | * [FIX] Throw DokuPageDoesNotExistException when trying to getPageInfo on unexisting page 36 | * [FIX] Throw NotAuthorizedException when trying to upload a file without permissions 37 | * Added methods and commands addAcl and delAcl 38 | * putPage and appendPage can read from stdin 39 | * Added method logoff 40 | 41 | 3.2.0 42 | * Added option --password-interactive 43 | 44 | 3.1.0 45 | * getPagelist also compute the page hashes 46 | 47 | 3.0.0 48 | * Added a command line tool 49 | * Fixed a few bugs 50 | 51 | 2.0.0 52 | * ObjectConverter isn't public anymore 53 | * Implemented timeout 54 | * Also handles DW 2012-01-25b 55 | * Uses aXMLRPC instead of Apache xmlrpc, to enhance cookie handling 56 | 57 | 1.0.0 58 | * Let pass options when editing a page 59 | * Added DokuJClientConfig 60 | * Let build a DokuJClient with an arbitrary XmlRpcClient 61 | * Let pass arbitrary options when editing a page 62 | * Throw a relevant exception when trying to create an empty new page 63 | 64 | 0.3.0 65 | * Enhanced attachment manipularions 66 | * Added getRecentChanges(java.util.Date date) 67 | * Fixed bug when reading modification date with getPageInfo 68 | 69 | 0.2.0 70 | * Added getPageVersions(String pageId) 71 | * Fixed bug when reading page version with gePagelist 72 | 73 | 0.1.0 74 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | ========================================================================= 2 | == NOTICE file corresponding to section 4(d) of the Apache License, == 3 | == Version 2.0, in this case for DokuJClient == 4 | ========================================================================= 5 | 6 | DokuJClient 7 | Copyright 2012-2020 Guillaume Turri 8 | 9 | ######################################################################### 10 | ## DokuJClient DEPENDENCIES ## 11 | ######################################################################### 12 | 13 | A binary distribution of DokuJClient 14 | which is built from source, includes a number of dependent packages 15 | with separate copyright notices and license terms. The following notices 16 | apply to these dependencies. 17 | 18 | ========================================================================= 19 | == Apache Maven Notice == 20 | ========================================================================= 21 | Apache Maven 22 | Copyright 2001-2011 The Apache Software Foundation 23 | 24 | This product includes software developed by 25 | The Apache Software Foundation (http://www.apache.org/). 26 | 27 | This product includes software (Plexus and Classworlds) developed by 28 | The Codehaus Foundation (http://www.codehaus.org/). 29 | 30 | This product includes software (Aether, Sisu, Spice, Plexus Ciper and Sec Dispatcher) developed by 31 | Sonatype Inc. (http://www.sonatype.org/). 32 | 33 | This product includes software (NekoHTML) developed by 34 | SourceForge (http://www.sourceforge.net/). 35 | 36 | This product includes software (Guice) developed by 37 | Google Code (http://code.google.com/). 38 | 39 | ========================================================================= 40 | == Apache Ant Notice == 41 | ========================================================================= 42 | Apache Ant 43 | Copyright 1999-2012 The Apache Software Foundation 44 | 45 | The task is based on code Copyright (c) 2002, Landmark 46 | Graphics Corp that has been kindly donated to the Apache Software 47 | Foundation. 48 | -------------------------------------------------------------------------------- /android-no-reg/.gitignore: -------------------------------------------------------------------------------- 1 | *.iml 2 | .gradle 3 | /local.properties 4 | /.idea/workspace.xml 5 | /.idea/libraries 6 | .DS_Store 7 | /build 8 | /captures 9 | app/src 10 | -------------------------------------------------------------------------------- /android-no-reg/README: -------------------------------------------------------------------------------- 1 | This directory contains is a dummy library app project and is used to ensure the 2 | code is compatible with Android (eg: that we don't use an API not available on 3 | Android). 4 | 5 | To use it, on a laptop where the Android environment is setup, just `cd` into this 6 | directory, and run 7 | 8 | ./test.sh 9 | 10 | Tests are run locally so it may not be completely error proof, but it already makes 11 | catches potential issues (eg: using javax.xml.bind in the code) 12 | -------------------------------------------------------------------------------- /android-no-reg/app/.gitignore: -------------------------------------------------------------------------------- 1 | /build 2 | -------------------------------------------------------------------------------- /android-no-reg/app/build.gradle: -------------------------------------------------------------------------------- 1 | apply plugin: 'com.android.application' 2 | 3 | android { 4 | compileSdkVersion 23 5 | buildToolsVersion "23.0.2" 6 | 7 | defaultConfig { 8 | applicationId "turri.fr.jiso8601_android_no_reg" 9 | minSdkVersion 14 10 | targetSdkVersion 23 11 | versionCode 1 12 | versionName "1.0" 13 | } 14 | buildTypes { 15 | release { 16 | minifyEnabled false 17 | proguardFiles getDefaultProguardFile('proguard-android.txt'), 'proguard-rules.pro' 18 | } 19 | } 20 | } 21 | 22 | dependencies { 23 | compile fileTree(dir: 'libs', include: ['*.jar']) 24 | testCompile 'junit:junit:4.12' 25 | testCompile 'com.github.tomakehurst:wiremock:1.58' 26 | testCompile 'junit-addons:junit-addons:1.4' 27 | compile 'com.android.support:appcompat-v7:23.1.1' 28 | compile 'fr.turri:aXMLRPC:1.9.0' 29 | } 30 | -------------------------------------------------------------------------------- /android-no-reg/app/proguard-rules.pro: -------------------------------------------------------------------------------- 1 | # Add project specific ProGuard rules here. 2 | # By default, the flags in this file are appended to flags specified 3 | # in /home/guillaume/Android/Sdk/tools/proguard/proguard-android.txt 4 | # You can edit the include path and order by changing the proguardFiles 5 | # directive in build.gradle. 6 | # 7 | # For more details, see 8 | # http://developer.android.com/guide/developing/tools/proguard.html 9 | 10 | # Add any project specific keep options here: 11 | 12 | # If your project uses WebView with JS, uncomment the following 13 | # and specify the fully qualified class name to the JavaScript interface 14 | # class: 15 | #-keepclassmembers class fqcn.of.javascript.interface.for.webview { 16 | # public *; 17 | #} 18 | -------------------------------------------------------------------------------- /android-no-reg/build.gradle: -------------------------------------------------------------------------------- 1 | // Top-level build file where you can add configuration options common to all sub-projects/modules. 2 | 3 | buildscript { 4 | repositories { 5 | jcenter() 6 | mavenLocal() 7 | } 8 | dependencies { 9 | classpath 'com.android.tools.build:gradle:1.5.0' 10 | 11 | // NOTE: Do not place your application dependencies here; they belong 12 | // in the individual module build.gradle files 13 | } 14 | } 15 | 16 | allprojects { 17 | repositories { 18 | jcenter() 19 | mavenLocal() 20 | } 21 | } 22 | 23 | task clean(type: Delete) { 24 | delete rootProject.buildDir 25 | } 26 | -------------------------------------------------------------------------------- /android-no-reg/gradle.properties: -------------------------------------------------------------------------------- 1 | # Project-wide Gradle settings. 2 | 3 | # IDE (e.g. Android Studio) users: 4 | # Gradle settings configured through the IDE *will override* 5 | # any settings specified in this file. 6 | 7 | # For more details on how to configure your build environment visit 8 | # http://www.gradle.org/docs/current/userguide/build_environment.html 9 | 10 | # Specifies the JVM arguments used for the daemon process. 11 | # The setting is particularly useful for tweaking memory settings. 12 | # Default value: -Xmx10248m -XX:MaxPermSize=256m 13 | # org.gradle.jvmargs=-Xmx2048m -XX:MaxPermSize=512m -XX:+HeapDumpOnOutOfMemoryError -Dfile.encoding=UTF-8 14 | 15 | # When configured, Gradle will run in incubating parallel mode. 16 | # This option should only be used with decoupled projects. More details, visit 17 | # http://www.gradle.org/docs/current/userguide/multi_project_builds.html#sec:decoupled_projects 18 | # org.gradle.parallel=true -------------------------------------------------------------------------------- /android-no-reg/gradle/wrapper/gradle-wrapper.properties: -------------------------------------------------------------------------------- 1 | #Wed Oct 21 11:34:03 PDT 2015 2 | distributionBase=GRADLE_USER_HOME 3 | distributionPath=wrapper/dists 4 | zipStoreBase=GRADLE_USER_HOME 5 | zipStorePath=wrapper/dists 6 | distributionUrl=https\://services.gradle.org/distributions/gradle-2.8-all.zip 7 | -------------------------------------------------------------------------------- /android-no-reg/gradlew: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | ############################################################################## 4 | ## 5 | ## Gradle start up script for UN*X 6 | ## 7 | ############################################################################## 8 | 9 | # Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 10 | DEFAULT_JVM_OPTS="" 11 | 12 | APP_NAME="Gradle" 13 | APP_BASE_NAME=`basename "$0"` 14 | 15 | # Use the maximum available, or set MAX_FD != -1 to use that value. 16 | MAX_FD="maximum" 17 | 18 | warn ( ) { 19 | echo "$*" 20 | } 21 | 22 | die ( ) { 23 | echo 24 | echo "$*" 25 | echo 26 | exit 1 27 | } 28 | 29 | # OS specific support (must be 'true' or 'false'). 30 | cygwin=false 31 | msys=false 32 | darwin=false 33 | case "`uname`" in 34 | CYGWIN* ) 35 | cygwin=true 36 | ;; 37 | Darwin* ) 38 | darwin=true 39 | ;; 40 | MINGW* ) 41 | msys=true 42 | ;; 43 | esac 44 | 45 | # Attempt to set APP_HOME 46 | # Resolve links: $0 may be a link 47 | PRG="$0" 48 | # Need this for relative symlinks. 49 | while [ -h "$PRG" ] ; do 50 | ls=`ls -ld "$PRG"` 51 | link=`expr "$ls" : '.*-> \(.*\)$'` 52 | if expr "$link" : '/.*' > /dev/null; then 53 | PRG="$link" 54 | else 55 | PRG=`dirname "$PRG"`"/$link" 56 | fi 57 | done 58 | SAVED="`pwd`" 59 | cd "`dirname \"$PRG\"`/" >/dev/null 60 | APP_HOME="`pwd -P`" 61 | cd "$SAVED" >/dev/null 62 | 63 | CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar 64 | 65 | # Determine the Java command to use to start the JVM. 66 | if [ -n "$JAVA_HOME" ] ; then 67 | if [ -x "$JAVA_HOME/jre/sh/java" ] ; then 68 | # IBM's JDK on AIX uses strange locations for the executables 69 | JAVACMD="$JAVA_HOME/jre/sh/java" 70 | else 71 | JAVACMD="$JAVA_HOME/bin/java" 72 | fi 73 | if [ ! -x "$JAVACMD" ] ; then 74 | die "ERROR: JAVA_HOME is set to an invalid directory: $JAVA_HOME 75 | 76 | Please set the JAVA_HOME variable in your environment to match the 77 | location of your Java installation." 78 | fi 79 | else 80 | JAVACMD="java" 81 | which java >/dev/null 2>&1 || die "ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 82 | 83 | Please set the JAVA_HOME variable in your environment to match the 84 | location of your Java installation." 85 | fi 86 | 87 | # Increase the maximum file descriptors if we can. 88 | if [ "$cygwin" = "false" -a "$darwin" = "false" ] ; then 89 | MAX_FD_LIMIT=`ulimit -H -n` 90 | if [ $? -eq 0 ] ; then 91 | if [ "$MAX_FD" = "maximum" -o "$MAX_FD" = "max" ] ; then 92 | MAX_FD="$MAX_FD_LIMIT" 93 | fi 94 | ulimit -n $MAX_FD 95 | if [ $? -ne 0 ] ; then 96 | warn "Could not set maximum file descriptor limit: $MAX_FD" 97 | fi 98 | else 99 | warn "Could not query maximum file descriptor limit: $MAX_FD_LIMIT" 100 | fi 101 | fi 102 | 103 | # For Darwin, add options to specify how the application appears in the dock 104 | if $darwin; then 105 | GRADLE_OPTS="$GRADLE_OPTS \"-Xdock:name=$APP_NAME\" \"-Xdock:icon=$APP_HOME/media/gradle.icns\"" 106 | fi 107 | 108 | # For Cygwin, switch paths to Windows format before running java 109 | if $cygwin ; then 110 | APP_HOME=`cygpath --path --mixed "$APP_HOME"` 111 | CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` 112 | JAVACMD=`cygpath --unix "$JAVACMD"` 113 | 114 | # We build the pattern for arguments to be converted via cygpath 115 | ROOTDIRSRAW=`find -L / -maxdepth 1 -mindepth 1 -type d 2>/dev/null` 116 | SEP="" 117 | for dir in $ROOTDIRSRAW ; do 118 | ROOTDIRS="$ROOTDIRS$SEP$dir" 119 | SEP="|" 120 | done 121 | OURCYGPATTERN="(^($ROOTDIRS))" 122 | # Add a user-defined pattern to the cygpath arguments 123 | if [ "$GRADLE_CYGPATTERN" != "" ] ; then 124 | OURCYGPATTERN="$OURCYGPATTERN|($GRADLE_CYGPATTERN)" 125 | fi 126 | # Now convert the arguments - kludge to limit ourselves to /bin/sh 127 | i=0 128 | for arg in "$@" ; do 129 | CHECK=`echo "$arg"|egrep -c "$OURCYGPATTERN" -` 130 | CHECK2=`echo "$arg"|egrep -c "^-"` ### Determine if an option 131 | 132 | if [ $CHECK -ne 0 ] && [ $CHECK2 -eq 0 ] ; then ### Added a condition 133 | eval `echo args$i`=`cygpath --path --ignore --mixed "$arg"` 134 | else 135 | eval `echo args$i`="\"$arg\"" 136 | fi 137 | i=$((i+1)) 138 | done 139 | case $i in 140 | (0) set -- ;; 141 | (1) set -- "$args0" ;; 142 | (2) set -- "$args0" "$args1" ;; 143 | (3) set -- "$args0" "$args1" "$args2" ;; 144 | (4) set -- "$args0" "$args1" "$args2" "$args3" ;; 145 | (5) set -- "$args0" "$args1" "$args2" "$args3" "$args4" ;; 146 | (6) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" ;; 147 | (7) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" ;; 148 | (8) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" ;; 149 | (9) set -- "$args0" "$args1" "$args2" "$args3" "$args4" "$args5" "$args6" "$args7" "$args8" ;; 150 | esac 151 | fi 152 | 153 | # Split up the JVM_OPTS And GRADLE_OPTS values into an array, following the shell quoting and substitution rules 154 | function splitJvmOpts() { 155 | JVM_OPTS=("$@") 156 | } 157 | eval splitJvmOpts $DEFAULT_JVM_OPTS $JAVA_OPTS $GRADLE_OPTS 158 | JVM_OPTS[${#JVM_OPTS[*]}]="-Dorg.gradle.appname=$APP_BASE_NAME" 159 | 160 | exec "$JAVACMD" "${JVM_OPTS[@]}" -classpath "$CLASSPATH" org.gradle.wrapper.GradleWrapperMain "$@" 161 | -------------------------------------------------------------------------------- /android-no-reg/gradlew.bat: -------------------------------------------------------------------------------- 1 | @if "%DEBUG%" == "" @echo off 2 | @rem ########################################################################## 3 | @rem 4 | @rem Gradle startup script for Windows 5 | @rem 6 | @rem ########################################################################## 7 | 8 | @rem Set local scope for the variables with windows NT shell 9 | if "%OS%"=="Windows_NT" setlocal 10 | 11 | @rem Add default JVM options here. You can also use JAVA_OPTS and GRADLE_OPTS to pass JVM options to this script. 12 | set DEFAULT_JVM_OPTS= 13 | 14 | set DIRNAME=%~dp0 15 | if "%DIRNAME%" == "" set DIRNAME=. 16 | set APP_BASE_NAME=%~n0 17 | set APP_HOME=%DIRNAME% 18 | 19 | @rem Find java.exe 20 | if defined JAVA_HOME goto findJavaFromJavaHome 21 | 22 | set JAVA_EXE=java.exe 23 | %JAVA_EXE% -version >NUL 2>&1 24 | if "%ERRORLEVEL%" == "0" goto init 25 | 26 | echo. 27 | echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. 28 | echo. 29 | echo Please set the JAVA_HOME variable in your environment to match the 30 | echo location of your Java installation. 31 | 32 | goto fail 33 | 34 | :findJavaFromJavaHome 35 | set JAVA_HOME=%JAVA_HOME:"=% 36 | set JAVA_EXE=%JAVA_HOME%/bin/java.exe 37 | 38 | if exist "%JAVA_EXE%" goto init 39 | 40 | echo. 41 | echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% 42 | echo. 43 | echo Please set the JAVA_HOME variable in your environment to match the 44 | echo location of your Java installation. 45 | 46 | goto fail 47 | 48 | :init 49 | @rem Get command-line arguments, handling Windowz variants 50 | 51 | if not "%OS%" == "Windows_NT" goto win9xME_args 52 | if "%@eval[2+2]" == "4" goto 4NT_args 53 | 54 | :win9xME_args 55 | @rem Slurp the command line arguments. 56 | set CMD_LINE_ARGS= 57 | set _SKIP=2 58 | 59 | :win9xME_args_slurp 60 | if "x%~1" == "x" goto execute 61 | 62 | set CMD_LINE_ARGS=%* 63 | goto execute 64 | 65 | :4NT_args 66 | @rem Get arguments from the 4NT Shell from JP Software 67 | set CMD_LINE_ARGS=%$ 68 | 69 | :execute 70 | @rem Setup the command line 71 | 72 | set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar 73 | 74 | @rem Execute Gradle 75 | "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% 76 | 77 | :end 78 | @rem End local scope for the variables with windows NT shell 79 | if "%ERRORLEVEL%"=="0" goto mainEnd 80 | 81 | :fail 82 | rem Set variable GRADLE_EXIT_CONSOLE if you need the _script_ return code instead of 83 | rem the _cmd.exe /c_ return code! 84 | if not "" == "%GRADLE_EXIT_CONSOLE%" exit 1 85 | exit /b 1 86 | 87 | :mainEnd 88 | if "%OS%"=="Windows_NT" endlocal 89 | 90 | :omega 91 | -------------------------------------------------------------------------------- /android-no-reg/settings.gradle: -------------------------------------------------------------------------------- 1 | include ':app' 2 | -------------------------------------------------------------------------------- /android-no-reg/test.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -xe 2 | 3 | rm -rf app/src/test app/src/main/java 4 | 5 | mkdir -p app/src/test/java/dw 6 | cp -r ../src/test/java/dw/xmlrpc app/src/test/java/dw 7 | 8 | mkdir -p app/src/main/java/dw 9 | cp -r ../src/main/java/dw/xmlrpc app/src/main/java/dw 10 | 11 | mkdir -p app/src/test/resources 12 | cp -r ../src/test/resources/testEnvironment app/src/test/resources 13 | 14 | ./gradlew clean test 15 | -------------------------------------------------------------------------------- /dokujclient_completion: -------------------------------------------------------------------------------- 1 | #!bash 2 | 3 | #Completion support for dokujclient 4 | 5 | _dokujclient () 6 | { 7 | local cur 8 | 9 | cur=${COMP_WORDS[COMP_CWORD]} 10 | 11 | COMPREPLY=($(compgen -W "$(dokujclient --help | grep -v "\[" | grep -v "To get help" | grep -v "Available commands" | tr "\n" " " )" -- $cur)) 12 | } 13 | 14 | 15 | complete -o default -o nospace -F _dokujclient dokujclient 16 | 17 | -------------------------------------------------------------------------------- /man/build_man.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | if [ -z $DOKUJCLIENT_MAN_PATH ]; then 4 | DOKUJCLIENT_MAN_PATH=. 5 | fi 6 | 7 | if [ -z "$DOKUJCLIENT_CMD" ]; then 8 | if ! which dokujclient >/dev/null; then 9 | echo dokujclient must be in your PATH in order to run this script 10 | exit -1 11 | fi 12 | DOKUJCLIENT_CMD=dokujclient 13 | fi 14 | 15 | rm -rf man1 16 | mkdir man1 17 | 18 | cat man.header.txt > $DOKUJCLIENT_MAN_PATH/man1/dokujclient.1 19 | for COMMAND in $($DOKUJCLIENT_CMD --help | grep -v "\[" | grep -v "To get help" | grep -v "Available commands" | grep -v help | sort); do 20 | echo .br >> $DOKUJCLIENT_MAN_PATH/man1/dokujclient.1 21 | echo "\fB$COMMAND\fR" >> $DOKUJCLIENT_MAN_PATH/man1/dokujclient.1 22 | done 23 | 24 | cat man.footer.txt >> $DOKUJCLIENT_MAN_PATH/man1/dokujclient.1 25 | 26 | -------------------------------------------------------------------------------- /man/man.footer.txt: -------------------------------------------------------------------------------- 1 | 2 | .SH FILES 3 | To avoid typing your url, user, and password each time, you may create in your home a file .dokujclientrc, 4 | and put some or all of this info in it. 5 | 6 | echo "url=http://myhost/mywiki/lib/exe/xmlrpc.php" > ~/.dokujclientrc 7 | echo "user=toto" >> ~/.dokujclientrc 8 | echo "password=myPassword" >> ~/.dokujclientrc 9 | 10 | .SH EXAMPLES 11 | 12 | dokujclient \-\-user myUser \-\-password myPassword \-\-url http://mywiki/lib/exe/xmlrpc.php getTitle 13 | > myWiki title 14 | 15 | dokujclient help 16 | > [(\-u|\-\-user) ] \-\-url [(\-p|\-\-password) ] [\-h|\-\-help] [\-\-version] [\-\-password\-interactive] command 17 | > 18 | > Available commands: 19 | > [...skipped...] 20 | 21 | #put user, password, and url, in the config file 22 | vim ~/.dokujclientrc 23 | 24 | #get the list of pages of all the wiki 25 | dokujclient getPagelist . 26 | > [...skipped...] 27 | 28 | dokujclient appendPage builds:synthesis "Build launched at 12:23 took 3'24" 29 | dokujclient getPage builds:synthesis 30 | > Build launched at 11:12 took 3'19 31 | > Build launched at 12:23 took 3'24 32 | 33 | #help command can give information about a given command 34 | dokujclient help putAttachment 35 | > Syntax for putAttachment: [\-f|\-\-force] 36 | 37 | dokujclient putAttachment some:file.jpg ~/results.jpg 38 | 39 | .SH REPORTING BUGS 40 | You are welcome to report bugs to the bugtracker 41 | https://github.com/gturri/dokujclient/issues 42 | .br 43 | You may also ask questions on the mailing list dokujclient@freelists.org 44 | 45 | .SH SEE ALSO 46 | 47 | The documentation of the server API is available at 48 | https://www.dokuwiki.org/devel:xmlrpc 49 | -------------------------------------------------------------------------------- /man/man.header.txt: -------------------------------------------------------------------------------- 1 | .TH DOKUJCLIENT "1" 2 | .SH NAME 3 | dokujclient \- interact (read, write, ...) with an instance of Dokuwiki 4 | 5 | .SH SYNOPSIS 6 | .B dokujclient 7 | \fIGENERAL_OPTIONS COMMAND COMMAND_OPTIONS\fR 8 | 9 | .SH DESCRIPTION 10 | Dokuwiki is an open source wiki engine. 11 | It's hence meant to be mainly used through a web browser. 12 | However, it also has an xmlrpc API. 13 | .br 14 | Dokujclient uses this xmlrpc API, so that it's possible to interact 15 | with an instance of Dokuwiki through a console or a shell script. 16 | 17 | .SH GENERAL OPTIONS 18 | .TP 19 | \fB\-\-url\fR \fIURL\fR 20 | The url to the xmlrpc interface. Should look like http[s]://server/mywiki\fI/lib/exe/xmlrpc.php\fR. 21 | .br 22 | Obviously, the wiki should be configured to accept incoming xmlrpc queries. 23 | See Dokuwiki's \fIremote\fR config. 24 | .br 25 | This parameter is mandatory. 26 | .TP 27 | \fB\-u\fR \fIUSER\fR, \fB\-\-user\fR \fIUSER\fR 28 | Specify the username \fIUSER\fR to use to connect to the server. 29 | .br 30 | Obviously, the \fIUSER\fR should be authorized to use the xmlrpc interface. 31 | See Dokuwiki's \fIremoteuser\fR config. 32 | .TP 33 | \fB\-p\fR \fIPASSWORD\fR, \fB\-\-password\fR \fIPASSWORD\fR 34 | The password of the \fIUSER\fR 35 | .TP 36 | \fB\-\-password-interactive\fR 37 | You will be prompted to enter the user's password interactively. 38 | Useful to avoid writing the password in clear text in the command line. 39 | .TP 40 | \fB\-\-version\fR 41 | Prints the version of dokujclient 42 | .TP 43 | \fB\-h\fR \fB\-\-help\fR 44 | Prints the general help 45 | .TP 46 | \fB\-\-debug\fR 47 | Enable debug mode, which will print more information 48 | 49 | .SH COMMANDS 50 | .TP 51 | \fBhelp\fR 52 | Prints the general help 53 | .TP 54 | \fBhelp\fR \fICOMMAND\fR 55 | Prints the help and the \fICOMMAND_OPTIONS\fR for \fICOMMAND\fR 56 | .TP 57 | Other commands are: 58 | -------------------------------------------------------------------------------- /scripts/descriptorRef.xml: -------------------------------------------------------------------------------- 1 | 4 | bin 5 | 6 | tar.gz 7 | tar.bz2 8 | zip 9 | 10 | 11 | 12 | ${project.basedir} 13 | / 14 | 15 | README* 16 | LICENSE* 17 | NOTICE* 18 | 19 | 20 | 21 | ${project.build.directory} 22 | / 23 | 24 | *.jar 25 | 26 | 27 | 28 | ${project.build.directory}/site 29 | docs 30 | 31 | 32 | ${project.build.directory}/classes 33 | 34 | dokujclient 35 | 36 | / 37 | 38 | 39 | 40 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/CliOptions.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import java.net.URL; 4 | 5 | public class CliOptions { 6 | public URL url; 7 | public String user; 8 | public String password; 9 | public String command; 10 | public String[] commandArguments; 11 | public boolean debug; 12 | 13 | @Override 14 | public String toString(){ 15 | return "user: " + user 16 | + ", password: " + password 17 | + ", debug: " + debug 18 | + ", url: " + (url == null ? "null" : url.toString() 19 | + ", command: " + command); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/Command.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.JSAPResult; 6 | import com.martiansoftware.jsap.Switch; 7 | import com.martiansoftware.jsap.UnflaggedOption; 8 | 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.exception.DokuException; 11 | import dw.xmlrpc.exception.DokuUnauthorizedException; 12 | 13 | public abstract class Command { 14 | protected JSAPResult _config; 15 | 16 | public Output run(DokuJClient dokuClient, String[] commandArguments){ 17 | try { 18 | parseArguments(commandArguments); 19 | } catch (ParseOptionException e){ 20 | return new Output(e.getMessage(), -1); 21 | } 22 | 23 | try { 24 | return run(dokuClient); 25 | } catch (DokuUnauthorizedException e){ 26 | String helpMessage = getCauseMessage(e) 27 | + "\nYou can check permissions with command 'aclCheck'"; 28 | return new Output(helpMessage, -1); 29 | } catch (DokuException e){ 30 | return new Output(getCauseMessage(e), -1); 31 | } 32 | } 33 | 34 | protected void addLongFormatSwitch(JSAP jsap) throws JSAPException{ 35 | jsap.registerParameter(new Switch("longFormat").setShortFlag('l')); 36 | } 37 | 38 | protected void addPageIdOption(JSAP jsap) throws JSAPException { 39 | jsap.registerParameter(new UnflaggedOption("pageId").setRequired(true)); 40 | } 41 | 42 | private String getCauseMessage(Throwable e){ 43 | if ( e.getCause() != null ){ 44 | return e.getCause().getMessage(); 45 | } else { 46 | return e.getMessage(); 47 | } 48 | } 49 | 50 | protected void parseArguments(String[] arguments) throws ParseOptionException{ 51 | JSAP jsap = new JSAP(); 52 | 53 | try { 54 | registerParameters(jsap); 55 | } catch (JSAPException e) { 56 | throw new ParseOptionException(e.toString(), e); 57 | } 58 | 59 | _config = jsap.parse(arguments); 60 | if ( ! _config.success() ){ 61 | String helpMessage = ""; 62 | for (@SuppressWarnings("rawtypes") java.util.Iterator errs = _config.getErrorMessageIterator(); 63 | errs.hasNext();) { 64 | helpMessage += errs.next() + "\n"; 65 | } 66 | helpMessage += jsap.getUsage(); 67 | throw new ParseOptionException(helpMessage); 68 | } 69 | } 70 | 71 | protected abstract void registerParameters(JSAP jsap) throws JSAPException; 72 | 73 | protected abstract Output run(DokuJClient dokuClient) throws DokuException; 74 | 75 | public String getUsage() { 76 | JSAP jsap = new JSAP(); 77 | 78 | try { 79 | registerParameters(jsap); 80 | } catch (JSAPException e) { 81 | throw new RuntimeException("Something wrong happened", e); 82 | } 83 | 84 | return jsap.getUsage(); 85 | 86 | } 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/CommandFactory.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import java.util.HashMap; 4 | import java.util.Map; 5 | import java.util.Set; 6 | 7 | import dw.cli.commands.AclChanger; 8 | import dw.cli.commands.AclChecker; 9 | import dw.cli.commands.AllPageGetter; 10 | import dw.cli.commands.AttachmentDeleter; 11 | import dw.cli.commands.AttachmentGetter; 12 | import dw.cli.commands.AttachmentInfoGetter; 13 | import dw.cli.commands.AttachmentPutter; 14 | import dw.cli.commands.AttachmentReader; 15 | import dw.cli.commands.BackLinksGetter; 16 | import dw.cli.commands.CliVersion; 17 | import dw.cli.commands.HelpPrinter; 18 | import dw.cli.commands.LinksLister; 19 | import dw.cli.commands.LocksSetter; 20 | import dw.cli.commands.PageGetter; 21 | import dw.cli.commands.PageHtmlGetter; 22 | import dw.cli.commands.PageInfoGetter; 23 | import dw.cli.commands.PageListGetter; 24 | import dw.cli.commands.PagePutter; 25 | import dw.cli.commands.PageVersionGetter; 26 | import dw.cli.commands.PageVersionsGetter; 27 | import dw.cli.commands.RPCVersionSupportedGetter; 28 | import dw.cli.commands.RecentChangesGetter; 29 | import dw.cli.commands.RecentMediaChangesGetter; 30 | import dw.cli.commands.Searcher; 31 | import dw.cli.commands.TimeGetter; 32 | import dw.cli.commands.TitleGetter; 33 | import dw.cli.commands.VersionGetter; 34 | import dw.cli.commands.XMLRPCAPIVersionGetter; 35 | 36 | public class CommandFactory { 37 | private Map _mapping = buildMapping(); 38 | 39 | public Command build(String command){ 40 | if ( _mapping.containsKey(command) ){ 41 | return _mapping.get(command); 42 | } 43 | 44 | return new HelpPrinter(false); 45 | } 46 | 47 | public boolean commandExists(String command){ 48 | return _mapping.containsKey(command); 49 | } 50 | 51 | private static Map buildMapping(){ 52 | Map mapping = new HashMap(); 53 | 54 | mapping.put("aclCheck", new AclChecker()); 55 | mapping.put("appendPage", new PagePutter(true)); 56 | mapping.put("deleteAttachment", new AttachmentDeleter()); 57 | mapping.put("getAllPages", new AllPageGetter()); 58 | mapping.put("getAttachment", new AttachmentGetter()); 59 | mapping.put("getAttachmentInfo", new AttachmentInfoGetter()); 60 | mapping.put("getAttachments", new AttachmentReader()); 61 | mapping.put("getBackLinks", new BackLinksGetter()); 62 | mapping.put("getPage", new PageGetter()); 63 | mapping.put("getPageHTML", new PageHtmlGetter()); 64 | mapping.put("getPageHTMLVersion", new PageHtmlGetter(true)); 65 | mapping.put("getPageInfo", new PageInfoGetter()); 66 | mapping.put("getPageInfoVersion", new PageInfoGetter(true)); 67 | mapping.put("getPageVersion", new PageVersionGetter()); 68 | mapping.put("getPageVersions", new PageVersionsGetter()); 69 | mapping.put("getPagelist", new PageListGetter()); 70 | mapping.put("getRecentChanges", new RecentChangesGetter()); 71 | mapping.put("getRecentMediaChanges", new RecentMediaChangesGetter()); 72 | mapping.put("getRPCVersionSupported", new RPCVersionSupportedGetter()); 73 | mapping.put("getTime", new TimeGetter()); 74 | mapping.put("getTitle", new TitleGetter()); 75 | mapping.put("getVersion", new VersionGetter()); 76 | mapping.put("getXMLRPCAPIVersion", new XMLRPCAPIVersionGetter()); 77 | mapping.put("help", new HelpPrinter(true)); 78 | mapping.put("listLinks", new LinksLister()); 79 | mapping.put("lock", new LocksSetter(false)); 80 | mapping.put("putAttachment", new AttachmentPutter()); 81 | mapping.put("putPage", new PagePutter()); 82 | mapping.put("search", new Searcher()); 83 | mapping.put("unlock", new LocksSetter(true)); 84 | mapping.put("version", new CliVersion()); 85 | mapping.put("addAcl", new AclChanger(AclChanger.aclAction.add)); 86 | mapping.put("delAcl", new AclChanger(AclChanger.aclAction.delete)); 87 | 88 | return mapping; 89 | } 90 | 91 | public static Set commandList(){ 92 | return buildMapping().keySet(); 93 | } 94 | } 95 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/Output.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | public class Output { 4 | public String out = ""; 5 | public String err = ""; 6 | public int exitCode = 0; 7 | 8 | public Output(){ } 9 | 10 | public Output(String out){ 11 | this.out = out; 12 | } 13 | 14 | public Output(String err, int exitCode){ 15 | this.err = err; 16 | this.exitCode = exitCode; 17 | } 18 | } 19 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/ParseOptionException.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | public class ParseOptionException extends Exception { 4 | 5 | private static final long serialVersionUID = -3917728150229940890L; 6 | 7 | public ParseOptionException(String message) { 8 | super(message); 9 | } 10 | 11 | public ParseOptionException(String message, Throwable cause) { 12 | super(message, cause); 13 | } 14 | 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/PasswordReader.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import java.io.Console; 4 | 5 | public class PasswordReader { 6 | public String readPassword(){ 7 | Console console = System.console(); 8 | if ( console != null ){ 9 | char[] password = console.readPassword("Enter password: "); 10 | return new String(password); 11 | } else { 12 | throw new NullPointerException("Can't get an instance of console to read the password"); 13 | } 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/Program.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import java.net.MalformedURLException; 4 | 5 | import dw.cli.commands.HelpPrinter; 6 | import dw.xmlrpc.DokuJClient; 7 | import dw.xmlrpc.DokuJClientConfig; 8 | import dw.xmlrpc.exception.DokuException; 9 | 10 | public class Program { 11 | public static void main(String[] args) { 12 | try { 13 | Output output = run(args); 14 | printOutput(output); 15 | System.exit(output.exitCode); 16 | } catch (Exception e){ 17 | printException(e); 18 | System.exit(-1); 19 | } 20 | } 21 | 22 | public static Output run(String[] args) throws DokuException { 23 | OptionParser parser = new OptionParser(args); 24 | if ( parser.userAskForHelp() ){ 25 | return new HelpPrinter(true).run(buildNullDokuJClient(), parser.getCommandArguments()); 26 | } 27 | 28 | parser.parse(); 29 | if ( ! parser.success() ){ 30 | Output result = new Output(); 31 | result.err = parser.getHelpMessage(); 32 | result.exitCode = parser.success() ? 0 : -1; 33 | return result; 34 | } 35 | 36 | CliOptions options = parser.getCliOptions(); 37 | DokuJClient dokuClient = buildDokuClient(options); 38 | Command command = new CommandFactory().build(options.command); 39 | return command.run(dokuClient, options.commandArguments); 40 | } 41 | 42 | private static void printOutput(Output output) { 43 | if ( output.err != null && !output.err.isEmpty() ){ 44 | System.err.println(output.err); 45 | } 46 | if ( output.out != null && !output.out.isEmpty() ){ 47 | System.out.println(output.out); 48 | } 49 | } 50 | 51 | private static void printException(Exception e) { 52 | System.err.println("Error: " + e.getMessage()); 53 | } 54 | 55 | private static DokuJClient buildDokuClient(CliOptions options) throws DokuException{ 56 | if ( ! options.url.toString().endsWith("lib/exe/xmlrpc.php") ){ 57 | throw new RuntimeException("Url should look like http[s]://server/mywiki/lib/exe/xmlrpc.php"); 58 | } 59 | DokuJClientConfig clientConfig = new DokuJClientConfig(options.url); 60 | if ( options.user != null ){ 61 | clientConfig.setUser(options.user, options.password); 62 | } 63 | clientConfig.setDebug(options.debug); 64 | DokuJClient dokuClient = new DokuJClient(clientConfig); 65 | dokuClient.setLogger(null); 66 | return dokuClient; 67 | } 68 | 69 | private static DokuJClient buildNullDokuJClient() throws DokuException{ 70 | try { 71 | return new DokuJClient("http://whatever"); 72 | } catch (MalformedURLException e) { 73 | throw new RuntimeException(e); 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/StdinReader.java: -------------------------------------------------------------------------------- 1 | package dw.cli; 2 | 3 | import java.io.BufferedReader; 4 | import java.io.IOException; 5 | import java.io.InputStreamReader; 6 | 7 | public class StdinReader { 8 | public String readStdin() throws IOException{ 9 | StringBuilder result = new StringBuilder(); 10 | BufferedReader br = new BufferedReader(new InputStreamReader(System.in)); 11 | 12 | try { 13 | String input; 14 | while((input=br.readLine())!=null){ 15 | result.append(input + "\n"); 16 | } 17 | 18 | if (result.length() > 0){ 19 | result.delete(result.length()-1, result.length()); 20 | } 21 | 22 | return result.toString(); 23 | } finally { 24 | br.close(); 25 | } 26 | } 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AclChanger.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.FlaggedOption; 4 | import com.martiansoftware.jsap.JSAP; 5 | import com.martiansoftware.jsap.JSAPException; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.Output; 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | public class AclChanger extends Command { 13 | public enum aclAction { 14 | add, 15 | delete 16 | } 17 | 18 | private final aclAction _action; 19 | 20 | public AclChanger(aclAction action){ 21 | _action = action; 22 | } 23 | 24 | @Override 25 | protected void registerParameters(JSAP jsap) throws JSAPException { 26 | jsap.registerParameter(new FlaggedOption("scope") 27 | .setStringParser(JSAP.STRING_PARSER) 28 | .setRequired(true) 29 | .setLongFlag("scope")); 30 | 31 | jsap.registerParameter(new FlaggedOption("username") 32 | .setStringParser(JSAP.STRING_PARSER) 33 | .setRequired(true) 34 | .setLongFlag("username")); 35 | 36 | if ( _action == aclAction.add ){ 37 | jsap.registerParameter(new FlaggedOption("permission") 38 | .setStringParser(JSAP.INTEGER_PARSER) 39 | .setRequired(true) 40 | .setLongFlag("permission")); 41 | } 42 | } 43 | 44 | @Override 45 | protected Output run(DokuJClient dokuClient) throws DokuException { 46 | String scope = _config.getString("scope"); 47 | String username = _config.getString("username"); 48 | boolean success; 49 | 50 | if ( _action == aclAction.add ){ 51 | int permission = _config.getInt("permission"); 52 | success = dokuClient.addAcl(scope, username, permission); 53 | } else { 54 | success = dokuClient.delAcl(scope, username); 55 | } 56 | 57 | if ( success ){ 58 | return new Output(); 59 | } else { 60 | return new Output("Acl change returned false.", 1); 61 | } 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AclChecker.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | 6 | import dw.cli.Command; 7 | import dw.cli.Output; 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.exception.DokuException; 10 | 11 | public class AclChecker extends Command { 12 | @Override 13 | protected void registerParameters(JSAP jsap) throws JSAPException { 14 | addPageIdOption(jsap); 15 | } 16 | 17 | @Override 18 | protected Output run(DokuJClient dokuClient) throws DokuException { 19 | String pageId = _config.getString("pageId"); 20 | return new Output(dokuClient.aclCheck(pageId).toString()); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AllPageGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.Page; 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | public class AllPageGetter extends ItemListToStringCommand { 13 | 14 | @Override 15 | protected void registerParameters(JSAP jsap) throws JSAPException { 16 | addLongFormatSwitch(jsap); 17 | } 18 | 19 | @Override 20 | protected List query(DokuJClient dokuClient) throws DokuException { 21 | return dokuClient.getAllPages(); 22 | } 23 | 24 | @Override 25 | protected String itemToString(Page page) { 26 | if ( !_config.getBoolean("longFormat") ){ 27 | return page.id(); 28 | } else { 29 | return page.id() 30 | + " " + page.perms() 31 | + " " + page.size(); 32 | } 33 | } 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AttachmentDeleter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.Switch; 6 | import com.martiansoftware.jsap.UnflaggedOption; 7 | 8 | import dw.cli.Command; 9 | import dw.cli.Output; 10 | import dw.xmlrpc.DokuJClient; 11 | import dw.xmlrpc.exception.DokuDeleteAttachmentException; 12 | import dw.xmlrpc.exception.DokuException; 13 | 14 | public class AttachmentDeleter extends Command { 15 | 16 | @Override 17 | protected void registerParameters(JSAP jsap) throws JSAPException { 18 | jsap.registerParameter(new Switch("force").setShortFlag('f').setLongFlag("force")); 19 | jsap.registerParameter(new UnflaggedOption("attachmentId").setRequired(true)); 20 | } 21 | 22 | @Override 23 | protected Output run(DokuJClient dokuClient) throws DokuException { 24 | try { 25 | dokuClient.deleteAttachment(_config.getString("attachmentId")); 26 | } catch (DokuDeleteAttachmentException e){ 27 | if ( ! _config.getBoolean("force") ){ 28 | return new Output(e.getMessage(), -1); 29 | } 30 | } 31 | return new Output(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AttachmentGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.io.IOException; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | import com.martiansoftware.jsap.UnflaggedOption; 8 | 9 | import dw.cli.Command; 10 | import dw.cli.Output; 11 | import dw.xmlrpc.DokuJClient; 12 | import dw.xmlrpc.exception.DokuDistantFileDoesntExistException; 13 | import dw.xmlrpc.exception.DokuException; 14 | 15 | public class AttachmentGetter extends Command { 16 | 17 | @Override 18 | protected void registerParameters(JSAP jsap) throws JSAPException { 19 | jsap.registerParameter(new UnflaggedOption("fileId").setRequired(true)); 20 | jsap.registerParameter(new UnflaggedOption("localFile").setRequired(true)); 21 | } 22 | 23 | @Override 24 | protected Output run(DokuJClient dokuClient) throws DokuException { 25 | try { 26 | dokuClient.getAttachment(_config.getString("fileId"), _config.getString("localFile")); 27 | } catch (IOException e) { 28 | return new Output(e.getMessage(), -1); 29 | } catch (DokuDistantFileDoesntExistException e){ 30 | return new Output(e.getMessage(), -1); 31 | } 32 | return new Output(); 33 | } 34 | 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AttachmentInfoGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.UnflaggedOption; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.Output; 9 | import dw.xmlrpc.AttachmentInfo; 10 | import dw.xmlrpc.DokuJClient; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class AttachmentInfoGetter extends Command { 14 | 15 | @Override 16 | protected void registerParameters(JSAP jsap) throws JSAPException { 17 | jsap.registerParameter(new UnflaggedOption("mediaId").setRequired(true)); 18 | } 19 | 20 | @Override 21 | protected Output run(DokuJClient dokuClient) throws DokuException { 22 | AttachmentInfo info = dokuClient.getAttachmentInfo(_config.getString("mediaId")); 23 | return new Output(attachmentInfoToString(info)); 24 | } 25 | 26 | private String attachmentInfoToString(AttachmentInfo info) { 27 | return info.id() 28 | + " " + info.size() 29 | + " " + info.lastModified(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AttachmentPutter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.io.IOException; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | import com.martiansoftware.jsap.Switch; 8 | import com.martiansoftware.jsap.UnflaggedOption; 9 | 10 | import dw.cli.Command; 11 | import dw.cli.Output; 12 | import dw.xmlrpc.DokuJClient; 13 | import dw.xmlrpc.exception.DokuAttachmentUploadException; 14 | import dw.xmlrpc.exception.DokuException; 15 | 16 | public class AttachmentPutter extends Command { 17 | 18 | @Override 19 | protected void registerParameters(JSAP jsap) throws JSAPException { 20 | jsap.registerParameter(new Switch("overwrite").setShortFlag('f').setLongFlag("force")); 21 | jsap.registerParameter(new UnflaggedOption("attachmentId").setRequired(true)); 22 | jsap.registerParameter(new UnflaggedOption("localFile").setRequired(true)); 23 | } 24 | 25 | @Override 26 | protected Output run(DokuJClient dokuClient) throws DokuException { 27 | try { 28 | dokuClient.putAttachment(_config.getString("attachmentId"), _config.getString("localFile"), _config.getBoolean("overwrite")); 29 | } catch (IOException e) { 30 | return new Output(e.getMessage(), -1); 31 | } catch (DokuAttachmentUploadException e){ 32 | return new Output(e.getMessage(), -1); 33 | } 34 | return new Output(); 35 | } 36 | } 37 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/AttachmentReader.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | import com.martiansoftware.jsap.UnflaggedOption; 8 | 9 | import dw.xmlrpc.AttachmentDetails; 10 | import dw.xmlrpc.DokuJClient; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class AttachmentReader extends ItemListToStringCommand { 14 | 15 | @Override 16 | protected void registerParameters(JSAP jsap) throws JSAPException { 17 | addLongFormatSwitch(jsap); 18 | jsap.registerParameter(new UnflaggedOption("namespace").setRequired(true)); 19 | } 20 | 21 | @Override 22 | protected List query(DokuJClient dokuClient) throws DokuException{ 23 | return dokuClient.getAttachments(_config.getString("namespace")); 24 | } 25 | 26 | @Override 27 | protected String itemToString(AttachmentDetails attachmentsDetails){ 28 | if ( _config.getBoolean("longFormat") ){ 29 | return attachmentDetailsToLongString(attachmentsDetails); 30 | } else { 31 | return attachmentDetailsToString(attachmentsDetails); 32 | } 33 | } 34 | 35 | private String attachmentDetailsToLongString(AttachmentDetails details){ 36 | return details.perms() 37 | + " " + details.size() 38 | + " " + details.lastModified().toString() 39 | + " " + details.id(); 40 | } 41 | 42 | private String attachmentDetailsToString(AttachmentDetails details){ 43 | return details.id(); 44 | } 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/BackLinksGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.exception.DokuException; 10 | 11 | public class BackLinksGetter extends ItemListToStringCommand { 12 | 13 | @Override 14 | protected void registerParameters(JSAP jsap) throws JSAPException { 15 | addPageIdOption(jsap); 16 | } 17 | 18 | @Override 19 | protected List query(DokuJClient dokuClient) throws DokuException { 20 | return dokuClient.getBackLinks(_config.getString("pageId")); 21 | } 22 | 23 | @Override 24 | protected String itemToString(String item) { 25 | return item; 26 | } 27 | } 28 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/CliVersion.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | import java.io.IOException; 6 | import java.io.InputStream; 7 | import java.util.Properties; 8 | import java.lang.RuntimeException; 9 | 10 | public class CliVersion extends SimpleCommand { 11 | @Override 12 | protected String query(DokuJClient dokuClient) throws DokuException { 13 | Properties prop = new Properties(); 14 | InputStream input = null; 15 | 16 | try { 17 | input = CliVersion.class.getResourceAsStream("/application.properties"); 18 | 19 | // load a properties file 20 | prop.load(input); 21 | 22 | return prop.getProperty("application.version"); 23 | } catch (IOException e) { 24 | throw new RuntimeException("Can't open property file to read version", e); 25 | } finally { 26 | if (input != null) { 27 | try { 28 | input.close(); 29 | } catch (IOException e) { 30 | //Shouldn't matter that much 31 | } 32 | } 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/HelpPrinter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.UnflaggedOption; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.CommandFactory; 9 | import dw.cli.OptionParser; 10 | import dw.cli.Output; 11 | import dw.xmlrpc.DokuJClient; 12 | import dw.xmlrpc.exception.DokuException; 13 | 14 | public class HelpPrinter extends Command { 15 | 16 | private final boolean _helpExplicitlyWanted; 17 | 18 | public HelpPrinter(boolean helpExplicitlyWanted){ 19 | _helpExplicitlyWanted = helpExplicitlyWanted; 20 | } 21 | 22 | @Override 23 | protected void registerParameters(JSAP jsap) throws JSAPException { 24 | jsap.registerParameter(new UnflaggedOption("command") 25 | .setStringParser(JSAP.STRING_PARSER) 26 | .setRequired(false)); 27 | } 28 | 29 | @Override 30 | protected Output run(DokuJClient dokuClient) throws DokuException { 31 | if ( ! _helpExplicitlyWanted ){ 32 | return new Output(OptionParser.getUsage(), -1); 33 | } else { 34 | if ( _config.contains("command") ){ 35 | String commandName = _config.getString("command"); 36 | if ( new CommandFactory().commandExists(commandName) ){ 37 | Command command = new CommandFactory().build(commandName); 38 | return new Output("Syntax for " + commandName + ": " + command.getUsage()); 39 | } else { 40 | return new Output(OptionParser.getUsage()); 41 | } 42 | } else { 43 | return new Output(OptionParser.getUsage()); 44 | } 45 | } 46 | } 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/ItemListToStringCommand.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.google.common.base.Function; 6 | import com.google.common.base.Joiner; 7 | import com.google.common.collect.Lists; 8 | 9 | import dw.cli.Command; 10 | import dw.cli.Output; 11 | import dw.xmlrpc.DokuJClient; 12 | import dw.xmlrpc.exception.DokuException; 13 | 14 | abstract public class ItemListToStringCommand extends Command { 15 | 16 | @Override 17 | protected Output run(DokuJClient dokuClient) throws DokuException { 18 | List items = query(dokuClient); 19 | return new Output(itemsToString(items)); 20 | } 21 | 22 | abstract protected List query(DokuJClient dokuClient) throws DokuException; 23 | 24 | private String itemsToString(List items) { 25 | Function converter = new Function(){ 26 | @Override 27 | public String apply(T item) { return itemToString(item); } 28 | }; 29 | 30 | return Joiner.on("\n").join(Lists.transform(items, converter)); 31 | } 32 | 33 | abstract protected String itemToString(T item); 34 | } 35 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/LinksLister.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.LinkInfo; 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | public class LinksLister extends ItemListToStringCommand { 13 | 14 | @Override 15 | protected void registerParameters(JSAP jsap) throws JSAPException { 16 | addLongFormatSwitch(jsap); 17 | addPageIdOption(jsap); 18 | } 19 | 20 | @Override 21 | protected List query(DokuJClient dokuClient) throws DokuException { 22 | return dokuClient.listLinks(_config.getString("pageId")); 23 | } 24 | 25 | @Override 26 | protected String itemToString(LinkInfo link){ 27 | if ( !_config.getBoolean("longFormat") ){ 28 | return link.page(); 29 | } else { 30 | return link.type() 31 | + " " + link.page() 32 | + " " + link.href(); 33 | } 34 | } 35 | } 36 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/LocksSetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.ArrayList; 4 | import java.util.List; 5 | 6 | import com.martiansoftware.jsap.JSAP; 7 | import com.martiansoftware.jsap.JSAPException; 8 | import com.martiansoftware.jsap.UnflaggedOption; 9 | 10 | import dw.cli.Command; 11 | import dw.cli.Output; 12 | import dw.xmlrpc.DokuJClient; 13 | import dw.xmlrpc.LockResult; 14 | import dw.xmlrpc.exception.DokuException; 15 | 16 | public class LocksSetter extends Command { 17 | private final boolean _shouldUnlock; 18 | 19 | public LocksSetter(boolean shouldUnlock){ 20 | _shouldUnlock = shouldUnlock; 21 | } 22 | 23 | @Override 24 | protected void registerParameters(JSAP jsap) throws JSAPException { 25 | jsap.registerParameter(new UnflaggedOption("pageId").setRequired(true).setGreedy(true)); 26 | } 27 | 28 | @Override 29 | protected Output run(DokuJClient dokuClient) throws DokuException { 30 | List pages = getPageList(); 31 | 32 | LockResult result; 33 | if ( _shouldUnlock ){ 34 | result = dokuClient.setLocks(new ArrayList(), pages); 35 | } else { 36 | result = dokuClient.setLocks(pages, new ArrayList()); 37 | } 38 | 39 | return buildOutput(result); 40 | } 41 | 42 | private List getPageList() { 43 | List pages = new ArrayList(); 44 | 45 | for(String page : _config.getStringArray("pageId")){ 46 | pages.add(page); 47 | } 48 | 49 | return pages; 50 | } 51 | 52 | private Output buildOutput(LockResult result) { 53 | Output output = new Output(); 54 | if ( result.hasFailure() ){ 55 | output.err = "A lock or unlock operation, failed"; 56 | output.exitCode = -1; 57 | } 58 | 59 | return output; 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | 6 | import dw.cli.Command; 7 | import dw.cli.Output; 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.exception.DokuException; 10 | 11 | public class PageGetter extends Command { 12 | 13 | @Override 14 | protected void registerParameters(JSAP jsap) throws JSAPException { 15 | addPageIdOption(jsap); 16 | } 17 | 18 | @Override 19 | protected Output run(DokuJClient dokuClient) throws DokuException { 20 | return new Output(dokuClient.getPage(_config.getString("pageId"))); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageHtmlGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.UnflaggedOption; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.Output; 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | public class PageHtmlGetter extends Command { 13 | private final boolean _withVersion; 14 | 15 | public PageHtmlGetter(){ 16 | this(false); 17 | } 18 | 19 | public PageHtmlGetter(boolean withVersion){ 20 | _withVersion = withVersion; 21 | } 22 | 23 | @Override 24 | protected void registerParameters(JSAP jsap) throws JSAPException { 25 | addPageIdOption(jsap); 26 | 27 | if (_withVersion){ 28 | jsap.registerParameter(new UnflaggedOption("timestamp").setStringParser(JSAP.INTEGER_PARSER).setRequired(true)); 29 | } 30 | } 31 | 32 | @Override 33 | protected Output run(DokuJClient dokuClient) throws DokuException { 34 | String pageId = _config.getString("pageId"); 35 | 36 | if ( _withVersion ){ 37 | int timestamp = _config.getInt("timestamp"); 38 | return new Output(dokuClient.getPageHTMLVersion(pageId, timestamp)); 39 | } else { 40 | return new Output(dokuClient.getPageHTML(pageId)); 41 | } 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageInfoGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.UnflaggedOption; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.Output; 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.PageInfo; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class PageInfoGetter extends Command { 14 | private final boolean _withVersion; 15 | 16 | public PageInfoGetter(){ 17 | this(false); 18 | } 19 | 20 | public PageInfoGetter(boolean withVersion){ 21 | _withVersion = withVersion; 22 | } 23 | 24 | @Override 25 | protected void registerParameters(JSAP jsap) throws JSAPException { 26 | addPageIdOption(jsap); 27 | 28 | if (_withVersion){ 29 | jsap.registerParameter(new UnflaggedOption("timestamp").setStringParser(JSAP.INTEGER_PARSER).setRequired(true)); 30 | } 31 | } 32 | 33 | @Override 34 | protected Output run(DokuJClient dokuClient) throws DokuException { 35 | String pageId = _config.getString("pageId"); 36 | PageInfo pageInfo; 37 | 38 | if ( _withVersion ){ 39 | int timestamp = _config.getInt("timestamp"); 40 | pageInfo = dokuClient.getPageInfoVersion(pageId, timestamp); 41 | } else { 42 | pageInfo = dokuClient.getPageInfo(pageId); 43 | } 44 | 45 | return new Output(pageInfoToString(pageInfo)); 46 | } 47 | 48 | private String pageInfoToString(PageInfo pageInfo){ 49 | return pageInfo.id() 50 | + " " + pageInfo.version() 51 | + " " + pageInfo.author(); 52 | } 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageListGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | import java.util.Map; 5 | import java.util.TreeMap; 6 | 7 | import com.martiansoftware.jsap.FlaggedOption; 8 | import com.martiansoftware.jsap.JSAP; 9 | import com.martiansoftware.jsap.JSAPException; 10 | import com.martiansoftware.jsap.UnflaggedOption; 11 | 12 | import dw.xmlrpc.DokuJClient; 13 | import dw.xmlrpc.PageDW; 14 | import dw.xmlrpc.exception.DokuException; 15 | 16 | public class PageListGetter extends ItemListToStringCommand { 17 | 18 | @Override 19 | protected void registerParameters(JSAP jsap) throws JSAPException { 20 | addLongFormatSwitch(jsap); 21 | jsap.registerParameter(new UnflaggedOption("namespace").setRequired(true)); 22 | jsap.registerParameter(new FlaggedOption("depth") 23 | .setStringParser(JSAP.INTEGER_PARSER) 24 | .setRequired(false) 25 | .setLongFlag("depth")); 26 | } 27 | 28 | @Override 29 | protected List query(DokuJClient dokuClient) throws DokuException { 30 | Map clientOptions = buildClientOption(); 31 | return dokuClient.getPagelist(_config.getString("namespace"), clientOptions); 32 | } 33 | 34 | private Map buildClientOption() { 35 | Map result = new TreeMap(); 36 | 37 | if ( _config.contains("depth") ){ 38 | result.put("depth", _config.getInt("depth")); 39 | } 40 | 41 | return result; 42 | } 43 | 44 | @Override 45 | protected String itemToString(PageDW page) { 46 | if ( _config.getBoolean("longFormat") ){ 47 | return pageToLongString(page); 48 | } else { 49 | return pageToString(page); 50 | } 51 | } 52 | 53 | private String pageToLongString(PageDW page) { 54 | return page.size() 55 | + " " + page.mtime() 56 | + " " + page.version() 57 | + " " + page.id(); 58 | } 59 | 60 | private String pageToString(PageDW page) { 61 | return page.id(); 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PagePutter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.io.IOException; 4 | 5 | import com.google.common.base.Joiner; 6 | import com.martiansoftware.jsap.FlaggedOption; 7 | import com.martiansoftware.jsap.JSAP; 8 | import com.martiansoftware.jsap.JSAPException; 9 | import com.martiansoftware.jsap.Switch; 10 | import com.martiansoftware.jsap.UnflaggedOption; 11 | 12 | import dw.cli.Command; 13 | import dw.cli.Output; 14 | import dw.cli.StdinReader; 15 | import dw.xmlrpc.DokuJClient; 16 | import dw.xmlrpc.exception.DokuException; 17 | 18 | public class PagePutter extends Command { 19 | private final boolean _appendInsteadOfPut; 20 | private final StdinReader _stdinReader; 21 | 22 | public PagePutter(){ 23 | this(false); 24 | } 25 | 26 | public PagePutter(boolean appendInsteadOfPut){ 27 | this(appendInsteadOfPut, new StdinReader()); 28 | } 29 | 30 | public PagePutter(boolean appendInsteadOfPut, StdinReader stdinReader){ 31 | _appendInsteadOfPut = appendInsteadOfPut; 32 | _stdinReader = stdinReader; 33 | } 34 | 35 | @Override 36 | protected void registerParameters(JSAP jsap) throws JSAPException { 37 | jsap.registerParameter(new FlaggedOption("summary") 38 | .setLongFlag("summary") 39 | .setDefault("") 40 | .setStringParser(JSAP.STRING_PARSER)); 41 | 42 | addPageIdOption(jsap); 43 | jsap.registerParameter(new UnflaggedOption("rawWikiText").setRequired(false).setGreedy(true)); 44 | 45 | jsap.registerParameter(new Switch("minor").setLongFlag("minor")); 46 | } 47 | 48 | @Override 49 | protected Output run(DokuJClient dokuClient)throws DokuException { 50 | String pageId = _config.getString("pageId"); 51 | String rawWikiText; 52 | try { 53 | rawWikiText = buildContent(); 54 | } catch (IOException e) { 55 | return new Output("Failed to read stdin: " + e.getMessage(), 1); 56 | } 57 | String summary = _config.getString("summary"); 58 | boolean minor = _config.getBoolean("minor"); 59 | 60 | if ( _appendInsteadOfPut ){ 61 | dokuClient.appendPage(pageId, rawWikiText, summary, minor); 62 | } else { 63 | dokuClient.putPage(pageId, rawWikiText, summary, minor); 64 | } 65 | 66 | return new Output(); 67 | } 68 | 69 | private String buildContent() throws IOException { 70 | if ( _config.contains("rawWikiText")){ 71 | return Joiner.on(" ").join(_config.getStringArray("rawWikiText")); 72 | } else { 73 | return _stdinReader.readStdin(); 74 | } 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageVersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | import com.martiansoftware.jsap.UnflaggedOption; 6 | 7 | import dw.cli.Command; 8 | import dw.cli.Output; 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | public class PageVersionGetter extends Command { 13 | 14 | @Override 15 | protected void registerParameters(JSAP jsap) throws JSAPException { 16 | addPageIdOption(jsap); 17 | jsap.registerParameter(new UnflaggedOption("timestamp").setStringParser(JSAP.INTEGER_PARSER).setRequired(true)); 18 | } 19 | 20 | @Override 21 | protected Output run(DokuJClient dokuClient) throws DokuException { 22 | return new Output(dokuClient.getPageVersion(_config.getString("pageId"), _config.getInt("timestamp"))); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/PageVersionsGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.FlaggedOption; 6 | import com.martiansoftware.jsap.JSAP; 7 | import com.martiansoftware.jsap.JSAPException; 8 | 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.PageVersion; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class PageVersionsGetter extends ItemListToStringCommand { 14 | 15 | @Override 16 | protected void registerParameters(JSAP jsap) throws JSAPException { 17 | addPageIdOption(jsap); 18 | jsap.registerParameter(new FlaggedOption("offset") 19 | .setStringParser(JSAP.INTEGER_PARSER) 20 | .setRequired(false) 21 | .setLongFlag("offset")); 22 | } 23 | 24 | @Override 25 | protected List query(DokuJClient dokuClient) throws DokuException { 26 | String pageId = _config.getString("pageId"); 27 | 28 | if ( _config.contains("offset" ) ){ 29 | return dokuClient.getPageVersions(pageId, _config.getInt("offset")); 30 | } else { 31 | return dokuClient.getPageVersions(pageId); 32 | } 33 | } 34 | 35 | @Override 36 | protected String itemToString(PageVersion version) { 37 | return version.pageId() 38 | + " " + version.version() 39 | + " " + version.ip() 40 | + " " + version.type() 41 | + " " + version.author() 42 | + " - " + version.summary(); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/RPCVersionSupportedGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | 6 | public class RPCVersionSupportedGetter extends SimpleCommand { 7 | 8 | @Override 9 | protected String query(DokuJClient dokuClient) throws DokuException { 10 | return dokuClient.getRPCVersionSupported().toString(); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/RecentChangesGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | import com.martiansoftware.jsap.UnflaggedOption; 8 | 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.PageChange; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class RecentChangesGetter extends ItemListToStringCommand { 14 | 15 | @Override 16 | protected void registerParameters(JSAP jsap) throws JSAPException { 17 | jsap.registerParameter(new UnflaggedOption("timestamp").setStringParser(JSAP.INTEGER_PARSER).setRequired(true)); 18 | } 19 | 20 | @Override 21 | protected List query(DokuJClient dokuClient) throws DokuException { 22 | return dokuClient.getRecentChanges(_config.getInt("timestamp")); 23 | } 24 | 25 | @Override 26 | protected String itemToString(PageChange pageChange) { 27 | return pageChange.name() 28 | + " " + pageChange.version() 29 | + " " + pageChange.author() 30 | + " " + pageChange.perms() 31 | + " " + pageChange.size(); 32 | } 33 | } 34 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/RecentMediaChangesGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.List; 4 | 5 | import com.martiansoftware.jsap.JSAP; 6 | import com.martiansoftware.jsap.JSAPException; 7 | import com.martiansoftware.jsap.UnflaggedOption; 8 | 9 | import dw.xmlrpc.DokuJClient; 10 | import dw.xmlrpc.MediaChange; 11 | import dw.xmlrpc.exception.DokuException; 12 | 13 | public class RecentMediaChangesGetter extends ItemListToStringCommand{ 14 | @Override 15 | protected void registerParameters(JSAP jsap) throws JSAPException { 16 | jsap.registerParameter(new UnflaggedOption("timestamp").setStringParser(JSAP.INTEGER_PARSER).setRequired(true)); 17 | } 18 | 19 | @Override 20 | protected List query(DokuJClient dokuClient) throws DokuException { 21 | return dokuClient.getRecentMediaChanges(_config.getInt("timestamp")); 22 | } 23 | 24 | @Override 25 | protected String itemToString(MediaChange mediaChange) { 26 | return mediaChange.id() 27 | + " " + mediaChange.author() 28 | + " " + mediaChange.perms() 29 | + " " + mediaChange.size(); 30 | } 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/Searcher.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import java.util.Arrays; 4 | import java.util.List; 5 | 6 | import com.google.common.base.Function; 7 | import com.google.common.base.Joiner; 8 | import com.google.common.collect.Lists; 9 | import com.martiansoftware.jsap.JSAP; 10 | import com.martiansoftware.jsap.JSAPException; 11 | import com.martiansoftware.jsap.Switch; 12 | import com.martiansoftware.jsap.UnflaggedOption; 13 | 14 | import dw.xmlrpc.DokuJClient; 15 | import dw.xmlrpc.SearchResult; 16 | import dw.xmlrpc.exception.DokuException; 17 | 18 | public class Searcher extends ItemListToStringCommand { 19 | 20 | @Override 21 | protected void registerParameters(JSAP jsap) throws JSAPException { 22 | jsap.registerParameter(new UnflaggedOption("searchQuery").setRequired(true)); 23 | addLongFormatSwitch(jsap); 24 | jsap.registerParameter(new Switch("snippet").setLongFlag("snippet")); 25 | } 26 | 27 | @Override 28 | protected List query(DokuJClient dokuClient) throws DokuException { 29 | return dokuClient.search(_config.getString("searchQuery")); 30 | } 31 | 32 | @Override 33 | protected String itemToString(SearchResult searchResult) { 34 | String result; 35 | if ( _config.getBoolean("longFormat") ){ 36 | result = searchResultToLongString(searchResult); 37 | } else { 38 | result = searchResultToString(searchResult); 39 | } 40 | 41 | if ( _config.getBoolean("snippet") ){ 42 | result += "\n" + addSnippet( searchResult); 43 | } 44 | 45 | return result; 46 | } 47 | 48 | private String addSnippet(SearchResult searchResult) { 49 | Function linePrefixer = new Function(){ 50 | @Override 51 | public String apply(String line) { return "> " + line; } 52 | }; 53 | 54 | List splittedText = Arrays.asList(searchResult.snippet().split("\n")); 55 | List prefixedText = Lists.transform(splittedText, linePrefixer); 56 | return Joiner.on("\n").join(prefixedText) + "\n"; 57 | } 58 | 59 | private String searchResultToString(SearchResult searchResult) { 60 | return searchResult.id(); 61 | } 62 | 63 | private String searchResultToLongString(SearchResult searchResult) { 64 | return searchResult.score() 65 | + " " + searchResult.mtime() 66 | + " " + searchResult.rev() 67 | + " " + searchResult.title() 68 | + " " + searchResult.size() 69 | + " " + searchResult.id(); 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/SimpleCommand.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import com.martiansoftware.jsap.JSAP; 4 | import com.martiansoftware.jsap.JSAPException; 5 | 6 | import dw.cli.Command; 7 | import dw.cli.Output; 8 | import dw.xmlrpc.DokuJClient; 9 | import dw.xmlrpc.exception.DokuException; 10 | 11 | abstract public class SimpleCommand extends Command { 12 | 13 | @Override 14 | protected void registerParameters(JSAP jsap) throws JSAPException { } 15 | 16 | @Override 17 | protected Output run(DokuJClient dokuClient) throws DokuException { 18 | return new Output(query(dokuClient)); 19 | } 20 | 21 | abstract protected String query(DokuJClient dokuClient) throws DokuException; 22 | } 23 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/TimeGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | 6 | public class TimeGetter extends SimpleCommand { 7 | @Override 8 | protected String query(DokuJClient dokuClient) throws DokuException { 9 | return dokuClient.getTime().toString(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/TitleGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | 6 | public class TitleGetter extends SimpleCommand { 7 | @Override 8 | protected String query(DokuJClient dokuClient) throws DokuException { 9 | return dokuClient.getTitle(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/VersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | 6 | public class VersionGetter extends SimpleCommand { 7 | @Override 8 | protected String query(DokuJClient dokuClient) throws DokuException { 9 | return dokuClient.getVersion(); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/dw/cli/commands/XMLRPCAPIVersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands; 2 | 3 | import dw.xmlrpc.DokuJClient; 4 | import dw.xmlrpc.exception.DokuException; 5 | 6 | public class XMLRPCAPIVersionGetter extends SimpleCommand { 7 | @Override 8 | protected String query(DokuJClient dokuClient) throws DokuException { 9 | return dokuClient.getXMLRPCAPIVersion().toString(); 10 | } 11 | } -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/Attacher.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.io.File; 4 | import java.io.FileInputStream; 5 | import java.io.FileOutputStream; 6 | import java.io.IOException; 7 | import java.util.ArrayList; 8 | import java.util.Calendar; 9 | import java.util.Date; 10 | import java.util.HashMap; 11 | import java.util.List; 12 | import java.util.Map; 13 | 14 | import de.timroes.base64.Base64; 15 | import dw.xmlrpc.exception.DokuException; 16 | 17 | //! @cond 18 | class Attacher { 19 | private final CoreClient _client; 20 | 21 | public Attacher(CoreClient client){ 22 | _client = client; 23 | } 24 | 25 | byte[] serializeFile(File f) throws IOException{ 26 | byte[] b = new byte[(int)f.length()]; 27 | FileInputStream fileInputStream = new FileInputStream(f); 28 | try { 29 | fileInputStream.read(b); 30 | return b; 31 | } finally { 32 | fileInputStream.close(); 33 | } 34 | } 35 | 36 | void deserializeFile(byte[] b, File f) throws IOException{ 37 | FileOutputStream fileOutputStream = new FileOutputStream(f); 38 | try { 39 | fileOutputStream.write(b); 40 | } finally { 41 | fileOutputStream.close(); 42 | } 43 | } 44 | 45 | public void putAttachment(String fileId, byte[] file, boolean overwrite) throws DokuException{ 46 | Map additionalParam = new HashMap(); 47 | additionalParam.put("ow", overwrite); 48 | 49 | Object[] params = new Object[]{ 50 | fileId, 51 | file, 52 | additionalParam 53 | }; 54 | 55 | _client.genericQuery("wiki.putAttachment", params); 56 | } 57 | 58 | public List getRecentMediaChanges(Integer timestamp) throws DokuException{ 59 | Object result = _client.genericQuery("wiki.getRecentMediaChanges", timestamp); 60 | List res = new ArrayList(); 61 | 62 | for(Object o : (Object[]) result){ 63 | @SuppressWarnings("unchecked") 64 | Map map = (Map) o; 65 | 66 | String id = (String) map.get("name"); 67 | Date lastModified = (Date) map.get("lastModified"); 68 | String author = (String) map.get("author"); 69 | Integer version = (Integer) map.get("version"); 70 | Integer perms = (Integer) map.get("perms"); 71 | Object sizeObj = map.get("size"); 72 | Integer size = null; 73 | if ( sizeObj instanceof Integer ){ 74 | size = (Integer) sizeObj; 75 | } 76 | 77 | res.add(new MediaChange(id, lastModified, author, version, perms, size)); 78 | } 79 | 80 | return res; 81 | } 82 | 83 | public List getAttachments(String namespace, Map additionalParams) throws DokuException{ 84 | if ( additionalParams == null ){ 85 | additionalParams = new HashMap(); 86 | } 87 | Object[] params = new Object[]{namespace, additionalParams}; 88 | Object result = _client.genericQuery("wiki.getAttachments", params); 89 | List res = new ArrayList(); 90 | for(Object o : (Object[]) result){ 91 | res.add(buildAttachmentDetailsFromResult(o)); 92 | } 93 | 94 | return res; 95 | } 96 | 97 | @SuppressWarnings("unchecked") 98 | private AttachmentDetails buildAttachmentDetailsFromResult(Object o){ 99 | return buildAttachmentDetailsFromResult((Map) o); 100 | } 101 | 102 | private AttachmentDetails buildAttachmentDetailsFromResult(Map m){ 103 | String id = (String) m.get("id"); 104 | Integer size = (Integer) m.get("size"); 105 | Date lastModified = (Date) m.get("lastModified"); 106 | Boolean isImg = (Boolean) m.get("isimg"); 107 | Boolean writable = (Boolean) m.get("writable"); 108 | String file = (String) m.get("file"); 109 | Integer mtime = (Integer) m.get("mtime"); 110 | Integer perms = (Integer) m.get("perm"); 111 | if ( perms == null ){ 112 | //Because it has been renamed in API v8 113 | perms = (Integer) m.get("perms"); 114 | } 115 | return new AttachmentDetails(id, size, lastModified, isImg, writable, perms, file, mtime); 116 | } 117 | 118 | public AttachmentInfo getAttachmentInfo(String fileId) throws DokuException{ 119 | Object result = _client.genericQuery("wiki.getAttachmentInfo", fileId); 120 | return buildAttachmentInfoFromResult(result, fileId); 121 | } 122 | 123 | @SuppressWarnings("unchecked") 124 | private AttachmentInfo buildAttachmentInfoFromResult(Object o, String fileId){ 125 | return buildAttachmentInfoFromResult((Map) o, fileId); 126 | } 127 | 128 | private AttachmentInfo buildAttachmentInfoFromResult(Map m, String fileId){ 129 | Integer size = (Integer) m.get("size"); 130 | Date lastModified = null; 131 | try { 132 | lastModified = (Date) m.get("lastModified"); 133 | } catch (ClassCastException e){ 134 | //for DW up to 2012-01-25b: when the file doesn't exist, 135 | //"lastModified" is int 0 136 | lastModified = defaultDate(); 137 | } 138 | return new AttachmentInfo(fileId, size, lastModified); 139 | } 140 | 141 | private Date defaultDate(){ 142 | Calendar calendar = Calendar.getInstance(); 143 | calendar.set(1970, 0, 0); 144 | return calendar.getTime(); 145 | } 146 | 147 | public void deleteAttachment(String fileId) throws DokuException{ 148 | _client.genericQuery("wiki.deleteAttachment", fileId); 149 | } 150 | 151 | public byte[] getAttachment(String fileId) throws DokuException{ 152 | Object result = _client.genericQuery("wiki.getAttachment", fileId); 153 | try { 154 | return (byte[]) result; 155 | } catch (ClassCastException e){ 156 | //for DW up to 2012-01-25b 157 | String base64Encoded = (String) result; 158 | return Base64.decode(base64Encoded); 159 | } 160 | } 161 | //! @endcond 162 | } 163 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/AttachmentDetails.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Describes a file uploaded in the wiki as getAttachments would 7 | */ 8 | public class AttachmentDetails { 9 | private final String _id; 10 | 11 | /** 12 | * @return Media id (namespace + name) 13 | */ 14 | public String id(){ 15 | return _id; 16 | } 17 | 18 | private final Boolean _isImg; 19 | 20 | /** 21 | * @return Whether the file is an image or not 22 | */ 23 | public final Boolean isImg(){ 24 | return _isImg; 25 | } 26 | 27 | private final Boolean _writable; 28 | 29 | /** 30 | * @return Whether the file is writable or not 31 | */ 32 | public Boolean writable(){ 33 | return _writable; 34 | } 35 | 36 | private final Integer _perms; 37 | 38 | /** 39 | * @return the permissions of the file 40 | */ 41 | public Integer perms(){ 42 | return _perms; 43 | } 44 | 45 | private final Integer _size; 46 | 47 | /** 48 | * @return the size in bytes 49 | */ 50 | public Integer size(){ 51 | return _size; 52 | } 53 | 54 | private final Date _lastModified; 55 | 56 | /** 57 | * @return the date of last modification of the file 58 | */ 59 | public final Date lastModified(){ 60 | return _lastModified; 61 | } 62 | 63 | private final String _file; 64 | 65 | /** 66 | * @return the name of the file 67 | */ 68 | public final String file(){ 69 | return _file; 70 | } 71 | 72 | private final Integer _mtime; 73 | 74 | /** 75 | * @return the date where the file was uploaded 76 | */ 77 | public final Integer mtime(){ 78 | return _mtime; 79 | } 80 | 81 | 82 | public AttachmentDetails(String id, Integer size, Date lastModified, Boolean isImg, Boolean writable, Integer perms, String file, Integer mtime){ 83 | _id = id; 84 | _size = size; 85 | _lastModified = lastModified; 86 | _isImg = isImg; 87 | _writable = writable; 88 | _perms = perms; 89 | _file = file; 90 | _mtime = mtime; 91 | } 92 | 93 | @Override 94 | public String toString(){ 95 | return "id: " + _id 96 | + ", size:" + _size 97 | + ", lastModified:" + (_lastModified == null ? "null" : _lastModified.toString()) 98 | + ", isImg: " + _isImg 99 | + ", writable: " + _writable 100 | + ", perms:" + _perms 101 | + ", file: " + _file 102 | + ", mtime: " + _mtime; 103 | } 104 | } 105 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/AttachmentInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Describes a file uploaded in the wiki as getAttachmentInfo would 7 | */ 8 | public class AttachmentInfo { 9 | private final String _id; 10 | 11 | /** 12 | * @return the media id (namespace + name) 13 | */ 14 | public String id(){ 15 | return _id; 16 | } 17 | 18 | private final Integer _size; 19 | 20 | /** 21 | * @return the size in bytes 22 | */ 23 | public Integer size(){ 24 | return _size; 25 | } 26 | 27 | private final Date _lastModified; 28 | 29 | /** 30 | * @return the date of last modification of the file 31 | */ 32 | public Date lastModified(){ 33 | return _lastModified; 34 | } 35 | 36 | public AttachmentInfo(String id, Integer size, Date lastModified){ 37 | _id = id; 38 | _size = size; 39 | _lastModified = lastModified; 40 | } 41 | 42 | @Override 43 | public String toString(){ 44 | return "id: " + _id 45 | + ", size:" + _size 46 | + ", lastModified:" + (_lastModified == null ? "null" : _lastModified.toString()); 47 | } 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/CoreClient.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Map; 4 | import java.util.logging.Level; 5 | import java.util.logging.Logger; 6 | 7 | import de.timroes.axmlrpc.XMLRPCClient; 8 | import de.timroes.axmlrpc.XMLRPCException; 9 | import dw.xmlrpc.exception.DokuException; 10 | 11 | //! @cond 12 | class CoreClient { 13 | private final XMLRPCClient _client; 14 | private Logger _logger = null; 15 | 16 | public void setLogger(Logger logger){ 17 | _logger = logger; 18 | } 19 | 20 | public CoreClient(XMLRPCClient client){ 21 | _client = client; 22 | } 23 | 24 | public Map cookies(){ 25 | return _client.getCookies(); 26 | } 27 | 28 | public void clearCookies(){ 29 | _client.clearCookies(); 30 | } 31 | 32 | public Object genericQuery(String action) throws DokuException { 33 | Object[] params = new Object[]{}; 34 | return genericQuery(action, params); 35 | } 36 | 37 | public Object genericQuery(String action, Object param) throws DokuException{ 38 | return genericQuery(action, new Object[]{param}); 39 | } 40 | 41 | public Object genericQuery(String action, Object[] params) throws DokuException{ 42 | try { 43 | return _client.call(action, params); 44 | } catch (XMLRPCException e){ 45 | if ( _logger != null ){ 46 | _logger.log(Level.INFO, "Caught exception when executing action " + action + ": " + e.toString()); 47 | _logger.log(Level.FINEST, "Details of the exception: ", e); 48 | } 49 | throw ExceptionConverter.Convert(e, _client.getURL().toString(), action); 50 | } 51 | } 52 | //! @endcond 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/CoreClientFactory.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | 6 | import de.timroes.axmlrpc.XMLRPCClient; 7 | 8 | class CoreClientFactory { 9 | public static CoreClient build(String url) throws MalformedURLException{ 10 | return build(url, DokuJClientConfig.defaultUserAgent); 11 | } 12 | 13 | public static CoreClient build(String url, String userAgent) throws MalformedURLException{ 14 | return build(new URL(url), userAgent); 15 | } 16 | 17 | public static CoreClient build(DokuJClientConfig dokuConfig){ 18 | int xmlRpcClientFlags = dokuConfig.getDebug() 19 | ? dokuConfig.xmlRpcClientFlags() | XMLRPCClient.FLAGS_DEBUG 20 | : dokuConfig.xmlRpcClientFlags(); 21 | return build(dokuConfig.url(), dokuConfig.userAgent(), dokuConfig.timeoutInSeconds(), xmlRpcClientFlags); 22 | } 23 | 24 | public static CoreClient build(URL url, String userAgent) { 25 | return build(url, userAgent, DokuJClientConfig.defaultTimeoutInSeconds, DokuJClientConfig.defaultXMLRPCClientFlags); 26 | } 27 | 28 | public static CoreClient build(URL url, String userAgent, int timeoutInSeconds, int xMLRPCClientFlags) { 29 | XMLRPCClient xmlRpcClient = new XMLRPCClient(url, userAgent, xMLRPCClientFlags); 30 | xmlRpcClient.setTimeout(timeoutInSeconds); 31 | return build(xmlRpcClient); 32 | } 33 | 34 | public static CoreClient build(XMLRPCClient xmlRpcClient){ 35 | return new CoreClient(xmlRpcClient); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/DokuJClientConfig.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.net.MalformedURLException; 4 | import java.net.URL; 5 | 6 | import de.timroes.axmlrpc.XMLRPCClient; 7 | 8 | public class DokuJClientConfig { 9 | public static final String defaultUserAgent = "DokuJClient - XmlRpc client for Dokuwiki"; 10 | public static final int defaultTimeoutInSeconds = 30; 11 | public static final int defaultXMLRPCClientFlags = XMLRPCClient.FLAGS_ENABLE_COOKIES | XMLRPCClient.FLAGS_IGNORE_STATUSCODE; 12 | 13 | private final URL _url; 14 | URL url(){ 15 | return _url; 16 | } 17 | 18 | private String _user = null; 19 | String user(){ 20 | return _user; 21 | } 22 | 23 | private String _password = null; 24 | String password(){ 25 | return _password; 26 | } 27 | 28 | private String _userAgent = DokuJClientConfig.defaultUserAgent; 29 | String userAgent(){ 30 | return _userAgent; 31 | } 32 | 33 | public DokuJClientConfig(String url) throws MalformedURLException{ 34 | this(new URL(url)); 35 | } 36 | 37 | public DokuJClientConfig(URL url){ 38 | _url = url; 39 | } 40 | 41 | public void setUserAgent(String userAgent){ 42 | _userAgent = userAgent; 43 | } 44 | 45 | public void setUser(String user, String password){ 46 | _user = user; 47 | _password = password; 48 | } 49 | 50 | private int _timeoutInSeconds = defaultTimeoutInSeconds; 51 | public void setTimeOutInSeconds(int timeout){ 52 | _timeoutInSeconds = timeout; 53 | } 54 | 55 | public int timeoutInSeconds(){ 56 | return _timeoutInSeconds; 57 | } 58 | 59 | private int _xmlRpcClientFlags = defaultXMLRPCClientFlags; 60 | public void setXMLRPCClientFlags(int flags){ 61 | _xmlRpcClientFlags = flags; 62 | } 63 | 64 | public int xmlRpcClientFlags(){ 65 | return _xmlRpcClientFlags; 66 | } 67 | 68 | private boolean _debug = false; 69 | public void setDebug(boolean debug){ 70 | _debug = debug; 71 | } 72 | 73 | public boolean getDebug(){ 74 | return _debug; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/ExceptionConverter.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import org.xml.sax.SAXParseException; 4 | 5 | import de.timroes.axmlrpc.XMLRPCException; 6 | import dw.xmlrpc.exception.DokuAttachmentStillReferenced; 7 | import dw.xmlrpc.exception.DokuAttachmentUploadException; 8 | import dw.xmlrpc.exception.DokuBadUrlException; 9 | import dw.xmlrpc.exception.DokuDeleteAttachmentException; 10 | import dw.xmlrpc.exception.DokuDistantFileDoesntExistException; 11 | import dw.xmlrpc.exception.DokuEmptyNewPageException; 12 | import dw.xmlrpc.exception.DokuException; 13 | import dw.xmlrpc.exception.DokuInvalidTimeStampException; 14 | import dw.xmlrpc.exception.DokuMethodDoesNotExistsException; 15 | import dw.xmlrpc.exception.DokuMisConfiguredWikiException; 16 | import dw.xmlrpc.exception.DokuNoChangesException; 17 | import dw.xmlrpc.exception.DokuPageDoesNotExistException; 18 | import dw.xmlrpc.exception.DokuPageLockedException; 19 | import dw.xmlrpc.exception.DokuTimeoutException; 20 | import dw.xmlrpc.exception.DokuUnauthorizedException; 21 | import dw.xmlrpc.exception.DokuUnknownException; 22 | import dw.xmlrpc.exception.DokuWordblockException; 23 | 24 | //! @cond 25 | 26 | /** 27 | * Converts an XmlRpcException into a the most relevant DokuException. 28 | */ 29 | class ExceptionConverter { 30 | public static DokuException Convert(XMLRPCException e, String url, String action){ 31 | String message = e.getMessage(); 32 | if ( message.contains("The page is currently locked") ){ 33 | return new DokuPageLockedException(e); 34 | } 35 | if ( message.contains("The XMLRPC call timed out.")){ 36 | return new DokuTimeoutException(e); 37 | } 38 | if ( message.contains("not authorized to call method") 39 | || message.contains("forbidden to call the method") 40 | || message.contains("don't have permissions to") 41 | || message.contains("You are not allowed to") //for DW up to 2012-01-25b 42 | || message.contains("You don't have permissions to delete files") //for DW up to 2012-01-25b 43 | ){ 44 | return new DokuUnauthorizedException(e); 45 | } 46 | if ( message.contains("java.io.FileNotFoundException") 47 | || message.contains("The server responded with a http 301 or 302 status code")){ 48 | return buildGenericBadUrlException(e); 49 | } 50 | if ( e.getCause() != null && e.getCause().getClass() == java.net.UnknownHostException.class ){ 51 | String mess = "Host doesn't exist. Check url"; 52 | return new DokuBadUrlException(mess, e); 53 | } 54 | 55 | if ( message.contains("Positive wordblock check")){ 56 | return new DokuWordblockException(e); 57 | } 58 | if ( message.contains("HTTP server returned unexpected status: Forbidden")){ 59 | return new DokuUnauthorizedException(e); 60 | } 61 | if ( message.contains("Could not delete file")){ 62 | return new DokuDeleteAttachmentException(e); 63 | } 64 | if ( message.contains("The requested file does not exist")){ 65 | return new DokuDistantFileDoesntExistException(e); 66 | } 67 | if ( message.contains("The requested page does not exist")){ 68 | return new DokuPageDoesNotExistException(e); 69 | } 70 | if ( message.contains("File is still referenced")){ 71 | return new DokuAttachmentStillReferenced(e); 72 | } 73 | if ( message.contains("The provided value is not a valid timestamp")){ 74 | return new DokuInvalidTimeStampException(e); 75 | } 76 | if ( message.contains("There are no changes in the specified timeframe")){ 77 | return new DokuNoChangesException(e); 78 | } 79 | if ( message.contains("Refusing to write an empty new wiki page")){ 80 | return new DokuEmptyNewPageException(e); 81 | } 82 | if ((message.contains("requested method") && message.contains("not specified")) 83 | || message.contains("Method does not exist")){ 84 | return new DokuMethodDoesNotExistsException("Method does not exists: " + action, e); 85 | } 86 | 87 | //Won't match if the wiki's locale isn't 'en' 88 | if ( message.contains("Upload denied. This file extension is forbidden!") 89 | || ( message.contains("The uploaded content did not match the ") && message.contains("file extension.")) 90 | || message.contains("File already exists. Nothing done.")){ 91 | return new DokuAttachmentUploadException(message, e); 92 | } 93 | 94 | if (message.contains("XML-RPC server not enabled") || (e.getCause() != null && e.getCause().getClass() == SAXParseException.class)){ 95 | return new DokuMisConfiguredWikiException("The wiki doesn't seem to be configured to accept incoming xmlrpc requests." + 96 | " Check the 'remote' option in Dokuwiki's configuration manager.", e); 97 | } 98 | 99 | //If we reach this point, we don't know what went wrong. 100 | //We try a final educated guess before giving up 101 | if ( ! url.endsWith("/lib/exe/xmlrpc.php") ){ 102 | return buildGenericBadUrlException(e); 103 | } 104 | 105 | return new DokuUnknownException(e); 106 | } 107 | 108 | private static DokuBadUrlException buildGenericBadUrlException(Throwable e){ 109 | String mess = "Couldn't find the xmlrpc interface. Make sure url looks like http[s]://server/mywiki/lib/exe/xmlrpc.php"; 110 | return new DokuBadUrlException(mess, e); 111 | } 112 | //! @endcond 113 | } 114 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/LinkInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | /** 4 | * Describes a link in a wiki page 5 | */ 6 | public class LinkInfo { 7 | public enum Type { 8 | local, 9 | extern 10 | } 11 | 12 | private final Type _type; 13 | 14 | /** 15 | * @return Whether it is a local or extern link 16 | */ 17 | public Type type(){ 18 | return _type; 19 | } 20 | 21 | private final String _page; 22 | 23 | /** 24 | * @return The wiki page (or the complete URL if extern link) 25 | */ 26 | public String page(){ 27 | return _page; 28 | } 29 | 30 | private final String _href; 31 | 32 | /** 33 | * @return The complete URL 34 | */ 35 | public String href(){ 36 | return _href; 37 | } 38 | 39 | public LinkInfo(String type, String page, String href){ 40 | this(Type.valueOf(type), page, href); 41 | } 42 | 43 | public LinkInfo(Type type, String page, String href){ 44 | _type = type; 45 | _page = page; 46 | _href = href; 47 | } 48 | 49 | @Override 50 | public boolean equals(Object other){ 51 | if ( this == other ){ 52 | return true; 53 | } 54 | 55 | if ( other == null ){ 56 | return false; 57 | } 58 | 59 | if ( !(other instanceof LinkInfo)){ 60 | return false; 61 | } 62 | 63 | LinkInfo link = (LinkInfo) other; 64 | 65 | return _type == link._type 66 | && _page.equals(link._page) 67 | && _href.equals(link._href); 68 | } 69 | 70 | @Override 71 | public int hashCode(){ 72 | //Any arbitrary constant will do 73 | return 0; 74 | } 75 | 76 | @Override 77 | public String toString(){ 78 | return "type:" + _type.toString() 79 | + ", page:" + _page 80 | + ", href:" + _href; 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/LockResult.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Set; 4 | 5 | /** 6 | * Describes the result of an attempt to (un)lock pages 7 | */ 8 | public class LockResult { 9 | private final Set _locked; 10 | 11 | /** 12 | * @return The pages successfully locked 13 | */ 14 | public Set locked(){ 15 | return _locked; 16 | } 17 | 18 | private final Set _lockfail; 19 | 20 | /** 21 | * @return The pages we failed to lock 22 | */ 23 | public Set lockfail(){ 24 | return _lockfail; 25 | } 26 | 27 | private final Set _unlocked; 28 | 29 | /** 30 | * @return The pages successfully unlocked 31 | */ 32 | public Set unlocked(){ 33 | return _unlocked; 34 | } 35 | 36 | private final Set _unlockfail; 37 | 38 | /** 39 | * @return The pages we failed to unlock 40 | */ 41 | public Set unlockfail(){ 42 | return _unlockfail; 43 | } 44 | 45 | /** 46 | * @return Whether at least a page failed to be locked or unlocked 47 | */ 48 | public boolean hasFailure(){ 49 | return !_unlockfail.isEmpty() || !_lockfail.isEmpty(); 50 | } 51 | 52 | public LockResult(Set locked, 53 | Set lockfail, 54 | Set unlocked, 55 | Set unlockfail){ 56 | _locked = locked; 57 | _lockfail = lockfail; 58 | _unlocked = unlocked; 59 | _unlockfail = unlockfail; 60 | } 61 | 62 | @Override 63 | public String toString(){ 64 | return "[locked:" + _locked.toString() + "]" 65 | + "[lockfail:" + _lockfail.toString() + "]" 66 | + "[unlocked:" + _unlocked.toString() + "]" 67 | + "[unlockfail:" + _unlockfail.toString() + "]"; 68 | } 69 | 70 | @Override 71 | public boolean equals(Object o){ 72 | if ( this == o ){ 73 | return true; 74 | } 75 | 76 | if ( o == null ){ 77 | return false; 78 | } 79 | 80 | if ( !(o instanceof LockResult )){ 81 | return false; 82 | } 83 | LockResult other = (LockResult) o; 84 | 85 | return _locked.equals(other._locked) 86 | && _lockfail.equals(other._lockfail) 87 | && _unlocked.equals(other._unlocked) 88 | && _unlockfail.equals(other._unlockfail); 89 | } 90 | 91 | @Override 92 | public int hashCode(){ 93 | //Any arbitrary constant will do 94 | return 0; 95 | } 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/Locker.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.HashMap; 5 | import java.util.HashSet; 6 | import java.util.List; 7 | import java.util.Map; 8 | import java.util.Set; 9 | 10 | import dw.xmlrpc.exception.DokuException; 11 | 12 | //! @cond 13 | class Locker { 14 | private final CoreClient _client; 15 | 16 | public Locker(CoreClient client){ 17 | _client = client; 18 | } 19 | 20 | public LockResult lock(String pageId) throws DokuException{ 21 | List pageIds = new ArrayList(); 22 | pageIds.add(pageId); 23 | return setLocks(pageIds, null); 24 | } 25 | 26 | public LockResult unlock(String pageId) throws DokuException{ 27 | List pageIds = new ArrayList(); 28 | pageIds.add(pageId); 29 | return setLocks(null, pageIds); 30 | } 31 | 32 | @SuppressWarnings("unchecked") 33 | public LockResult setLocks(List pagesToLock, List pagesToUnlock) throws DokuException{ 34 | Map params = BuildParams(pagesToLock, pagesToUnlock); 35 | Object result = _client.genericQuery("dokuwiki.setLocks", params); 36 | return BuildLockResult((Map) result); 37 | } 38 | 39 | private Map BuildParams(List pagesToLock, List pagesToUnlock){ 40 | Map params = new HashMap(); 41 | params.put("lock", pagesToLock == null ? new Object[]{} : pagesToLock.toArray()); 42 | params.put("unlock", pagesToUnlock == null ? new Object[]{} : pagesToUnlock.toArray()); 43 | return params; 44 | } 45 | 46 | private LockResult BuildLockResult(Map data){ 47 | Object lockedObj = data.get("locked"); 48 | Object lockfailObj = data.get("lockfail"); 49 | Object unlockedObj = data.get("unlocked"); 50 | Object unlockfailObj = data.get("unlockfail"); 51 | 52 | return new LockResult(objToStr(lockedObj), 53 | objToStr(lockfailObj), 54 | objToStr(unlockedObj), 55 | objToStr(unlockfailObj)); 56 | } 57 | 58 | private Set objToStr(Object objects){ 59 | return objToStr((Object[]) objects); 60 | } 61 | 62 | private Set objToStr(Object[] objects){ 63 | Set result = new HashSet(); 64 | if ( objects == null ){ 65 | return result; 66 | } 67 | 68 | for(Object o : objects){ 69 | result.add((String) o); 70 | } 71 | 72 | return result; 73 | } 74 | //! @endcond 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/MediaChange.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Describes a revision of a media 7 | */ 8 | public class MediaChange { 9 | private final String _id; 10 | 11 | /** 12 | * @return The id of the media (namespace + name) 13 | */ 14 | public String id(){ 15 | return _id; 16 | } 17 | 18 | private final Date _lastModified; 19 | 20 | /** 21 | * @return The date of this modification of the media 22 | */ 23 | public Date lastModified(){ 24 | return _lastModified; 25 | } 26 | 27 | private final String _author; 28 | 29 | /** 30 | * @return The author of this modification of the media 31 | */ 32 | public String author(){ 33 | return _author; 34 | } 35 | 36 | private final Integer _version; 37 | 38 | /** 39 | * Version of the revision as a timestamp. 40 | * 41 | * Should correspond to {@link #lastModified()} 42 | * 43 | * @return The version of the revision as a timestamp 44 | */ 45 | public Integer version(){ 46 | return _version; 47 | } 48 | 49 | private final Integer _perms; 50 | 51 | /** 52 | * @return The permissions of the file 53 | */ 54 | public Integer perms(){ 55 | return _perms; 56 | } 57 | 58 | private final Integer _size; 59 | 60 | /** 61 | * @return The size of the file in bytes 62 | */ 63 | public Integer size(){ 64 | return _size; 65 | } 66 | 67 | public MediaChange(String id, Date lastModified, String author, Integer version, Integer perms, Integer size){ 68 | _id = id; 69 | _lastModified = lastModified; 70 | _author = author; 71 | _version = version; 72 | _perms = perms; 73 | _size = size; 74 | } 75 | 76 | @Override 77 | public String toString(){ 78 | return "id=" + _id 79 | + ", lastModified=" + (_lastModified == null ? "null" : _lastModified.toString()) 80 | + ", author=" + _author 81 | + ", version=" + _version 82 | + ", perms=" + _perms 83 | + ", size=" + _size; 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/ObjectConverter.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Date; 5 | import java.util.List; 6 | import java.util.Map; 7 | 8 | //! @cond 9 | class ObjectConverter { 10 | 11 | static List toPageDW(Object[] objs){ 12 | List result = new ArrayList(); 13 | for(Object o : objs){ 14 | result.add(toPageDW(o)); 15 | } 16 | return result; 17 | } 18 | 19 | static PageDW toPageDW(Object o){ 20 | @SuppressWarnings("unchecked") 21 | Map map = (Map) o; 22 | String id = (String) map.get("id"); 23 | Integer size = (Integer) map.get("size"); 24 | Integer version = (Integer) map.get("rev"); 25 | Integer mtime = (Integer) map.get("mtime"); 26 | String hash = (String) map.get("hash"); 27 | return new PageDW(id, size, version, mtime, hash); 28 | } 29 | 30 | static List toSearchResult(Object[] objs){ 31 | List result = new ArrayList(); 32 | for ( Object o : objs ){ 33 | result.add(toSearchResult(o)); 34 | } 35 | return result; 36 | } 37 | 38 | static SearchResult toSearchResult(Object o){ 39 | @SuppressWarnings("unchecked") 40 | Map mapResult = (Map) o; 41 | 42 | String id = (String) mapResult.get("id"); 43 | String title = (String) mapResult.get("title"); 44 | if ( title == null){ 45 | //for DW up to 2012-01-25 46 | title = id; 47 | } 48 | Integer rev = (Integer) mapResult.get("rev"); 49 | Integer mtime = (Integer) mapResult.get("mtime"); 50 | Integer size = (Integer) mapResult.get("size"); 51 | Integer score = (Integer) mapResult.get("score"); 52 | String snippet = (String) mapResult.get("snippet"); 53 | 54 | return new SearchResult(id, title, rev, mtime, score, snippet, size); 55 | } 56 | 57 | static PageInfo toPageInfo(Object o){ 58 | @SuppressWarnings("unchecked") 59 | Map resMap = (Map) o; 60 | String name = (String) resMap.get("name"); 61 | Date modified = (Date) resMap.get("lastModified"); 62 | String author = (String) resMap.get("author"); 63 | Integer version = (Integer) resMap.get("version"); 64 | return new PageInfo(name, modified, author, version); 65 | } 66 | 67 | static List toPage(Object[] objs){ 68 | List result = new ArrayList(); 69 | for(Object o : objs){ 70 | result.add(toPage(o)); 71 | } 72 | return result; 73 | } 74 | 75 | static Page toPage(Object o){ 76 | @SuppressWarnings("unchecked") 77 | Map resMap = (Map) o; 78 | String id = (String) resMap.get("id"); 79 | Integer perms = toPerms(resMap.get("perms")); 80 | Date lastModified = (Date) resMap.get("lastModified"); 81 | Integer size = (Integer) resMap.get("size"); 82 | return new Page(id, perms, lastModified, size); 83 | } 84 | 85 | static List toString(Object[] objs){ 86 | List result = new ArrayList(); 87 | for(Object o : objs){ 88 | result.add((String) o); 89 | } 90 | return result; 91 | } 92 | 93 | static List toLinkInfo(Object[] objs){ 94 | List result = new ArrayList(); 95 | for ( Object o : objs ){ 96 | result.add(toLinkInfo(o)); 97 | } 98 | return result; 99 | } 100 | 101 | static LinkInfo toLinkInfo(Object o){ 102 | @SuppressWarnings("unchecked") 103 | Map resMap = (Map) o; 104 | String type = (String) resMap.get("type"); 105 | String page = (String) resMap.get("page"); 106 | String href = (String) resMap.get("href"); 107 | return new LinkInfo(type, page, href); 108 | } 109 | 110 | static List toPageChange(Object[] objs){ 111 | List result = new ArrayList(); 112 | for(Object o : objs){ 113 | result.add(toPageChange(o)); 114 | } 115 | return result; 116 | } 117 | 118 | static PageChange toPageChange(Object o){ 119 | @SuppressWarnings("unchecked") 120 | Map resMap = (Map) o; 121 | String id = (String) resMap.get("name"); 122 | Integer perms = toPerms(resMap.get("perms")); 123 | Date lastModified = (Date) resMap.get("lastModified"); 124 | Integer size = null; 125 | try { 126 | size = (Integer) resMap.get("size"); 127 | } catch (ClassCastException e) 128 | { 129 | //Sometimes Dokuwiki fails to get a size (it seems to be the case if the 130 | //corresponding page doesn't exist anymore) 131 | size = null; 132 | } 133 | String author = (String) resMap.get("author"); 134 | Integer version = (Integer) resMap.get("version"); 135 | return new PageChange(id, perms, lastModified, size, author, version); 136 | 137 | } 138 | 139 | static List toPageVersion(Object[] objs, String pageId){ 140 | List result = new ArrayList(); 141 | for ( Object o : objs ){ 142 | result.add(toPageVersion(o, pageId)); 143 | } 144 | return result; 145 | } 146 | 147 | static PageVersion toPageVersion(Object o, String pageId){ 148 | @SuppressWarnings("unchecked") 149 | Map resMap = (Map) o; 150 | String author = (String) resMap.get("author"); 151 | if ( author == null ){ 152 | author = (String) resMap.get("user"); 153 | } 154 | String ip = (String) resMap.get("ip"); 155 | String type = (String) resMap.get("type"); 156 | String summary = (String) resMap.get("sum"); 157 | Date modified = (Date) resMap.get("modified"); 158 | Integer version = (Integer) resMap.get("version"); 159 | return new PageVersion(pageId, author, ip, type, summary, modified, version); 160 | } 161 | 162 | static Integer toPerms(Object o){ 163 | //Because DW may sometime return a string instead 164 | //(fixed after Adora Belle (2012-10-03)) 165 | if (o instanceof Integer){ 166 | return (Integer) o; 167 | } 168 | return Integer.valueOf((String) o); 169 | } 170 | } 171 | //! @endcond 172 | 173 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/Page.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Page as describe by the method getAllPage 7 | */ 8 | public class Page { 9 | private final String _id; 10 | 11 | /** 12 | * @return The id of the page, that is namespace + name 13 | */ 14 | public String id(){ 15 | return _id; 16 | } 17 | 18 | private final Integer _perms; 19 | 20 | /** 21 | * @return An integer denoting the permissions on the page 22 | */ 23 | public Integer perms(){ 24 | return _perms; 25 | } 26 | 27 | private final Date _lastModified; 28 | 29 | /** 30 | * @return The last modification date 31 | */ 32 | public Date lastModified(){ 33 | return _lastModified; 34 | } 35 | 36 | private final Integer _size; 37 | 38 | /** 39 | * @return The size of the page 40 | */ 41 | public Integer size(){ 42 | return _size; 43 | } 44 | 45 | public Page(String id, Integer perms, Date lastModified, Integer size){ 46 | if ( id == null ){ 47 | throw new IllegalArgumentException("Can't build a Page with a null id"); 48 | } 49 | 50 | _id = id; 51 | _perms = perms; 52 | _lastModified = lastModified; 53 | _size = size; 54 | } 55 | 56 | @Override 57 | public String toString(){ 58 | return "id:" + _id 59 | + ", perms:" + _perms 60 | + ", lastModified:" + (_lastModified == null ? "null" : _lastModified.toString()) 61 | + ", size:" + _size; 62 | } 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/PageChange.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Describe a page change, as returned by the getRecentChanges xmlrpc method 7 | * 8 | */ 9 | public class PageChange { 10 | private final String _pageId; 11 | 12 | /** 13 | * @return The id of the page changed 14 | */ 15 | public String pageId(){ 16 | return _pageId; 17 | } 18 | 19 | /** 20 | * Alias for {@link #pageId()} 21 | * 22 | * This alias is provided because it is the way it is called by the xmlrpc method 23 | * 24 | * @return The id of the page changed 25 | */ 26 | public String name(){ 27 | return _pageId; 28 | } 29 | 30 | private final Integer _perms; 31 | 32 | /** 33 | * @return An integer representing the permissions on the file 34 | */ 35 | public Integer perms(){ 36 | return _perms; 37 | } 38 | 39 | private final Date _lastModified; 40 | 41 | /** 42 | * @return The date of the modification 43 | */ 44 | public Date lastModified(){ 45 | return _lastModified; 46 | } 47 | 48 | private final Integer _size; 49 | public Integer size(){ 50 | return _size; 51 | } 52 | 53 | private final String _author; 54 | 55 | /** 56 | * @return The author of the page 57 | */ 58 | public String author(){ 59 | return _author; 60 | } 61 | 62 | private final Integer _version; 63 | 64 | /** 65 | * @return The version of the page 66 | */ 67 | public Integer version(){ 68 | return _version; 69 | } 70 | 71 | public PageChange(String pageId, Integer perms, Date lastModified, Integer size, String author, Integer version){ 72 | if ( pageId == null ){ 73 | throw new IllegalArgumentException("Can't build a PageChange with a null pageId"); 74 | } 75 | 76 | _pageId = pageId; 77 | _perms = perms; 78 | _lastModified = lastModified; 79 | _size = size; 80 | _author = author; 81 | _version = version; 82 | } 83 | 84 | @Override 85 | public String toString(){ 86 | return "pageId:" + _pageId 87 | + ", perms:" + _perms 88 | + ", lastModified:" + (_lastModified == null ? "null" : _lastModified.toString()) 89 | + ", size: " + _size 90 | + ", author: " + _author 91 | + ", version: " + _version; 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/PageDW.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | /** 4 | * Page as describe by DokuWiki's xmlrpc method getPageList 5 | */ 6 | public class PageDW { 7 | private final String _id; 8 | public String id(){ 9 | return _id; 10 | } 11 | 12 | private final Integer _size; 13 | public Integer size(){ 14 | return _size; 15 | } 16 | 17 | private final Integer _version; 18 | public Integer version(){ 19 | return _version; 20 | } 21 | 22 | private final Integer _mtime; 23 | public Integer mtime(){ 24 | return _mtime; 25 | } 26 | 27 | private final String _hash; 28 | public String hash(){ 29 | return _hash; 30 | } 31 | 32 | public PageDW(String id, Integer size, Integer version, Integer mtime, String hash){ 33 | if ( id == null ){ 34 | throw new IllegalArgumentException("Can't build a PageDW with a null id"); 35 | } 36 | 37 | _id = id; 38 | _size = size; 39 | _version = version; 40 | _mtime = mtime; 41 | _hash = hash; 42 | } 43 | 44 | @Override 45 | public String toString(){ 46 | return "id=" + _id 47 | + ", size=" + _size 48 | + ", version=" + _version 49 | + ", mtime=" + _mtime 50 | + ", hash=" + _hash; 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/PageInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Information about a wiki page 7 | */ 8 | public class PageInfo { 9 | private final String _id; 10 | 11 | /** 12 | * @return The dd of the page (namespace + name) 13 | */ 14 | public String id(){ 15 | return _id; 16 | } 17 | 18 | private final Date _modified; 19 | 20 | /** 21 | * @return The date of the modification of this version 22 | */ 23 | public Date modified(){ 24 | return _modified; 25 | } 26 | 27 | private final String _author; 28 | 29 | /** 30 | * @return The author of this version 31 | */ 32 | public String author(){ 33 | return _author; 34 | } 35 | 36 | private final Integer _version; 37 | 38 | /** 39 | * Version as a timestamp 40 | * 41 | * Should correspond to {@link #modified()} 42 | * 43 | * @return the version 44 | */ 45 | public Integer version(){ 46 | return _version; 47 | } 48 | 49 | public PageInfo(String id, Date modified, String author, Integer version){ 50 | if ( id == null ){ 51 | throw new IllegalArgumentException("Can't build a PageInfo with a null id"); 52 | } 53 | 54 | _id = id; 55 | _modified = modified; 56 | _author = author; 57 | _version = version; 58 | } 59 | 60 | @Override 61 | public String toString(){ 62 | return "id:" + _id 63 | + ", modified:" + (_modified == null ? "null" : _modified.toString()) 64 | + ", author:" + _author 65 | + ", version:" + _version; 66 | } 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/PageVersion.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | import java.util.Date; 4 | 5 | /** 6 | * Describe a version of a page. 7 | * 8 | * Dokuwiki may not always return every field (because the information is already 9 | * missing on Dokuwiki's side or because it isn't meant to give such field for a 10 | * given query). 11 | * Hence it's better to always check if a given field isn't null before using it. 12 | */ 13 | public class PageVersion { 14 | private final String _pageId; 15 | 16 | /** 17 | * @return The page id (namespace + name) 18 | */ 19 | public String pageId(){ 20 | return _pageId; 21 | } 22 | 23 | private final String _author; 24 | 25 | /** 26 | * @return The author of the revision 27 | */ 28 | public String author(){ 29 | return _author; 30 | } 31 | 32 | /** 33 | * Alias of {@link #author()} 34 | * 35 | * Provided because this is how this fields is named by the xmlrpc query 36 | * @return The page id 37 | */ 38 | public String user(){ 39 | return _author; 40 | } 41 | 42 | private final String _ip; 43 | 44 | /** 45 | * @return The ip who made this revision 46 | */ 47 | public String ip(){ 48 | return _ip; 49 | } 50 | 51 | private final String _type; 52 | 53 | /** 54 | * @return The type of revision (creation, edition, ...) 55 | */ 56 | public String type(){ 57 | return _type; 58 | } 59 | 60 | private final String _summary; 61 | 62 | /** 63 | * @return The summary of the revision 64 | */ 65 | public String summary(){ 66 | return _summary; 67 | } 68 | 69 | private final Date _modified; 70 | 71 | /** 72 | * @return The date of the revision 73 | */ 74 | public Date lastModified(){ 75 | return _modified; 76 | } 77 | 78 | /** 79 | * Alias of lastModifie 80 | * 81 | * Provided because it's called this way by the xmlrpc query 82 | * 83 | * @return The date of the revision 84 | */ 85 | public Date modified(){ 86 | return _modified; 87 | } 88 | 89 | private final Integer _version; 90 | 91 | /** 92 | * Version of the revision, as a timestamp 93 | * 94 | * Should correspond to {@link #modified()} 95 | * 96 | * @return The version of the revision 97 | */ 98 | public Integer version(){ 99 | return _version; 100 | } 101 | 102 | public PageVersion(String pageId, String author, String ip, String type, String summary, Date modified, Integer version){ 103 | if ( pageId == null ){ 104 | throw new IllegalArgumentException("Can't build a PageVersion with a null id"); 105 | } 106 | 107 | _pageId = pageId; 108 | _author = author; 109 | _ip = ip; 110 | _type = type; 111 | _summary = summary; 112 | _modified = modified; 113 | _version = version; 114 | } 115 | 116 | @Override 117 | public String toString(){ 118 | return "pageId=" + _pageId 119 | + ", author=" + _author 120 | + ", ip=" + _ip 121 | + ", type=" + _type 122 | + ", summary=" + _summary 123 | + ", modified=" + (_modified == null ? "null" : _modified.toString()) 124 | + ", version=" + _version; 125 | } 126 | } 127 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/SearchResult.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc; 2 | 3 | /** 4 | * Result of a text search on the wiki 5 | */ 6 | public class SearchResult { 7 | private final String _id; 8 | public String id(){ 9 | return _id; 10 | } 11 | 12 | private final String _title; 13 | public String title(){ 14 | return _title; 15 | } 16 | 17 | private final Integer _size; 18 | public Integer size(){ 19 | return _size; 20 | } 21 | 22 | private final Integer _rev; 23 | public Integer rev(){ 24 | return _rev; 25 | } 26 | 27 | private final Integer _mtime; 28 | public Integer mtime(){ 29 | return _mtime; 30 | } 31 | 32 | private final Integer _score; 33 | 34 | /** 35 | * @return Score of the result. 36 | * The higher, the more relevant this result is. 37 | * 38 | */ 39 | public Integer score(){ 40 | return _score; 41 | } 42 | 43 | private final String _snippet; 44 | 45 | /** 46 | * @return The snippet of the page matching the search. 47 | */ 48 | public String snippet(){ 49 | return _snippet; 50 | } 51 | 52 | public SearchResult(String id, String title, Integer rev, Integer mtime, Integer score, String snippet, Integer size){ 53 | if ( id == null ){ 54 | throw new IllegalArgumentException("Can't build a SearchResult with a null id"); 55 | } 56 | 57 | _id = id; 58 | _title = title; 59 | _rev = rev; 60 | _mtime = mtime; 61 | _score = score; 62 | _snippet = snippet; 63 | _size = size; 64 | } 65 | 66 | @Override 67 | public String toString(){ 68 | return "id: " + _id 69 | + ", title:" + _title 70 | + ", rev:" + _rev 71 | + ", mtime:" + _mtime 72 | + ", score: " + _score 73 | + ", snippet: " + _snippet 74 | + ", size: " + _size; 75 | } 76 | } 77 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuAttachmentStillReferenced.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when one tries to delete a distant media still referenced. 5 | * 6 | * Dokuwiki won't let delete a media if a page still uses it. 7 | * If one tries to delete such a media, Dokuwiki won't allow it, and this exception 8 | * will be thrown 9 | */ 10 | public class DokuAttachmentStillReferenced extends DokuException { 11 | 12 | private static final long serialVersionUID = -1349452363587746526L; 13 | 14 | public DokuAttachmentStillReferenced(Throwable cause) { 15 | super(cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuAttachmentUploadException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | public class DokuAttachmentUploadException extends DokuException { 4 | 5 | private static final long serialVersionUID = 3307739440250260529L; 6 | 7 | public DokuAttachmentUploadException(String message, Throwable cause) { 8 | super(message, cause); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuBadUrlException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when a bad url has been provided 5 | */ 6 | public class DokuBadUrlException extends DokuException { 7 | 8 | private static final long serialVersionUID = 7969663858357866492L; 9 | 10 | public DokuBadUrlException(String message, Throwable cause) { 11 | super(message, cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuDeleteAttachmentException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when an attempt to delete a file on the wiki failed 5 | */ 6 | public class DokuDeleteAttachmentException extends DokuException { 7 | 8 | private static final long serialVersionUID = -5093967783205014204L; 9 | 10 | public DokuDeleteAttachmentException(Throwable cause) { 11 | super(cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuDistantFileDoesntExistException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when one attemps to work on a file which doesn't exist on the wiki 5 | */ 6 | public class DokuDistantFileDoesntExistException extends DokuException { 7 | 8 | private static final long serialVersionUID = -5014826815320361555L; 9 | 10 | public DokuDistantFileDoesntExistException(Throwable cause) { 11 | super(cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuEmptyNewPageException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown by Dokuwiki when one try to use putPage with an empty page content 5 | * if the page doesn't exist yet (or has alreay been deleted) 6 | */ 7 | public class DokuEmptyNewPageException extends DokuException { 8 | 9 | private static final long serialVersionUID = 3088375008770606694L; 10 | 11 | public DokuEmptyNewPageException(Throwable cause) { 12 | super(cause); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Generic exception 5 | */ 6 | public class DokuException extends Exception { 7 | 8 | private static final long serialVersionUID = 7882114034813429168L; 9 | 10 | public DokuException(Throwable cause) { 11 | super(cause); 12 | } 13 | 14 | public DokuException(String message, Throwable cause) { 15 | super(message, cause); 16 | } 17 | 18 | public DokuException(String message){ 19 | super(message); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuIncompatibleVersionException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | public class DokuIncompatibleVersionException extends DokuException { 4 | private static final long serialVersionUID = 7903625706488374779L; 5 | 6 | public DokuIncompatibleVersionException(String oldestCompatibleVersion){ 7 | super(getMessage(oldestCompatibleVersion)); 8 | } 9 | 10 | private static String getMessage(String oldestCompatibleVersion){ 11 | return "The version of Dokuwiki we're querying doesn't support the action we're trying to perform. " 12 | + "The older compatible version is " + oldestCompatibleVersion + ". " 13 | + "Try to update your Dokuwiki server."; 14 | } 15 | 16 | } 17 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuInvalidTimeStampException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | import dw.xmlrpc.exception.DokuException; 4 | 5 | /** 6 | * Thrown when an invalid timestamp is provided 7 | */ 8 | public class DokuInvalidTimeStampException extends DokuException { 9 | 10 | private static final long serialVersionUID = -2041584428271122864L; 11 | 12 | public DokuInvalidTimeStampException(Throwable cause) { 13 | super(cause); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuMethodDoesNotExistsException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | public class DokuMethodDoesNotExistsException extends DokuException { 4 | 5 | private static final long serialVersionUID = 2005563951980285304L; 6 | 7 | public DokuMethodDoesNotExistsException(String message, Throwable cause){ 8 | super(message, cause); 9 | } 10 | 11 | } 12 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuMisConfiguredWikiException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | public class DokuMisConfiguredWikiException extends DokuException { 4 | 5 | private static final long serialVersionUID = 7988621871633643736L; 6 | 7 | public DokuMisConfiguredWikiException(String message, Throwable cause) { 8 | super(message, cause); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuNoChangesException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when one looked out for changes when there are none 5 | */ 6 | public class DokuNoChangesException extends DokuException { 7 | private static final long serialVersionUID = 6200266566237242596L; 8 | 9 | public DokuNoChangesException(Throwable cause) { 10 | super(cause); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuPageDoesNotExistException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | public class DokuPageDoesNotExistException extends DokuException { 4 | private static final long serialVersionUID = 8579585910287045131L; 5 | 6 | public DokuPageDoesNotExistException(Throwable cause) { 7 | super(cause); 8 | } 9 | 10 | } -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuPageLockedException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when one tries to edit a page locked by someone else 5 | */ 6 | public class DokuPageLockedException extends DokuException { 7 | 8 | private static final long serialVersionUID = -6402957075601882399L; 9 | 10 | public DokuPageLockedException(Throwable cause) { 11 | super(cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuTimeoutException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when a call timeout 5 | */ 6 | public class DokuTimeoutException extends DokuException { 7 | 8 | private static final long serialVersionUID = -1156444596841763628L; 9 | 10 | public DokuTimeoutException(Throwable cause) { 11 | super(cause); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuUnauthorizedException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when a user attempts to make a query he isn't allowed to. 5 | * 6 | * If this exception is unexpected you may want to check: 7 | * * The credentials given to the #dw.xmlrpc.DokuJClient 8 | * * The wiki configuration (xmlrpc interface must be enabled, and this user must be allowed to use it) 9 | */ 10 | public class DokuUnauthorizedException extends DokuException { 11 | 12 | private static final long serialVersionUID = -1970601945755526735L; 13 | 14 | public DokuUnauthorizedException(Throwable cause) { 15 | super(cause); 16 | } 17 | 18 | public DokuUnauthorizedException(String message, Throwable cause) { 19 | super(message, cause); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuUnknownException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown when an xmlrpc query failed for an unknown reason. 5 | * 6 | * To have more information on the failure you may access the original exception 7 | * using getCause() 8 | */ 9 | public class DokuUnknownException extends DokuException { 10 | 11 | private static final long serialVersionUID = -4230515595018490484L; 12 | 13 | public DokuUnknownException(Throwable cause) { 14 | super(cause); 15 | } 16 | 17 | public DokuUnknownException(String message, Throwable cause) { 18 | super(message, cause); 19 | } 20 | 21 | } 22 | -------------------------------------------------------------------------------- /src/main/java/dw/xmlrpc/exception/DokuWordblockException.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.exception; 2 | 3 | /** 4 | * Thrown if a page can't be edited because of a wordblock. 5 | * 6 | * The list of forbidden words for a given wiki are defined in its wordblock.conf file. 7 | * If one try to edit a page addind one of this words, DokuWiki won't allow the edition, 8 | * and this exception will be thrown. 9 | */ 10 | public class DokuWordblockException extends DokuException { 11 | 12 | private static final long serialVersionUID = -3281103378061961240L; 13 | 14 | public DokuWordblockException(Throwable cause) { 15 | super(cause); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/main/resources/application.properties: -------------------------------------------------------------------------------- 1 | application.version=${project.version} 2 | -------------------------------------------------------------------------------- /src/main/resources/dokujclient: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | if [ -L "$0" ] && [ -x $(which greadlink) ]; then 3 | thisFile="$(greadlink -mn "$0")" 4 | elif [ -L "$0" ] && [ -x $(which readlink) ]; then 5 | thisFile="$(readlink -mn "$0")" 6 | else 7 | thisFile="$0" 8 | fi 9 | cpBase="$(dirname "$thisFile")" 10 | java -cp "$cpBase/*" dw.cli.Program $@ 11 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AclChanger.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_AclChanger extends TestHelper { 6 | @org.junit.Before 7 | public void clean() throws Exception { 8 | //It stings a bit since the setup rely on the tested code. However: 9 | // * without it, we can't launch two mutation runs in a row 10 | // * if there's a bug in the tested code, it will be caught anyway 11 | runWithArguments("addAcl", "--scope", "*", "--username", "@user", "--permission", "8"); 12 | } 13 | 14 | @org.junit.Test 15 | public void canAddAndRemoveAcl() throws Exception { 16 | assertSuccess("8", runWithArgumentAsWriterUser("aclCheck", "ns1:start")); 17 | 18 | assertSuccess("", runWithArguments("delAcl", "--scope", "*", "--username", "@user")); 19 | assertSuccess("0", runWithArgumentAsWriterUser("aclCheck", "ns1:start")); 20 | 21 | assertSuccess("", runWithArguments("addAcl", "--scope", "*", "--username", "@user", "--permission", "8")); 22 | assertSuccess("8", runWithArgumentAsWriterUser("aclCheck", "ns1:start")); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AclChecker.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_AclChecker extends TestHelper { 6 | @org.junit.Test 7 | public void aclCheck() throws Exception { 8 | assertSuccess("255", runWithArguments("aclCheck", "ns1:start")); 9 | assertSuccess("8", runWithArgumentAsWriterUser("aclCheck", "ns1:start")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AllPagesGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | import static org.junit.Assert.fail; 5 | 6 | import dw.cli.Output; 7 | import dw.cli.itest.TestHelper; 8 | 9 | public class Test_AllPagesGetter extends TestHelper { 10 | @org.junit.Test 11 | public void getAllPages() throws Exception { 12 | Output output = runWithArguments("getAllPages"); 13 | assertGenericSuccess(output); 14 | 15 | String[] pages = output.out.split("\n"); 16 | assertTrue(pages.length >= 11); //Don't assertEquals because other tests may create new pages 17 | assertHasExactlyOnceThisLine("nssearch:page3", pages); 18 | } 19 | 20 | @org.junit.Test 21 | public void getAllPagesWithLongFlag() throws Exception { 22 | Output output = runWithArguments("getAllPages", "-l"); 23 | assertGenericSuccess(output); 24 | 25 | String[] pages = output.out.split("\n"); 26 | assertTrue(pages.length >= 11); //Don't assertEquals because other tests may create new pages 27 | assertHasExactlyOnceThisLine("nssearch:page3 255 197", pages); 28 | } 29 | 30 | private void assertHasExactlyOnceThisLine(String expected, String[] actual){ 31 | boolean found = false; 32 | for(String line : actual){ 33 | if ( line.equals(expected) ){ 34 | if ( found ){ 35 | fail("line found twice: " + expected); 36 | } 37 | found = true; 38 | } 39 | } 40 | if ( ! found ){ 41 | fail("line not found: " + expected); 42 | } 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AttachmentInfoGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.Output; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_AttachmentInfoGetter extends TestHelper { 8 | @org.junit.Test 9 | public void getAttachmentInfo() throws Exception { 10 | Output output = runWithArguments("getAttachmentInfo", "ro_for_tests:img1.gif"); 11 | 12 | assertGenericSuccess(output); 13 | assertTrue(output.out.contains("ro_for_tests:img1.gif 67")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AttachmentPutterAndDeleter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.assertFalse; 4 | import static org.junit.Assert.assertTrue; 5 | import static junitx.framework.FileAssert.assertBinaryEquals; 6 | 7 | import java.io.File; 8 | 9 | import dw.cli.Output; 10 | import dw.cli.itest.TestHelper; 11 | import dw.xmlrpc.itest.TestParams; 12 | 13 | public class Test_AttachmentPutterAndDeleter extends TestHelper { 14 | 15 | private static String ns = "putAndDelete_ns"; 16 | private static String localFileName = "localToto.gif"; 17 | private final File localFile = new File(localFileName); 18 | 19 | @org.junit.Before 20 | @org.junit.After 21 | public void clean() throws Exception { 22 | localFile.delete(); 23 | runWithArguments("deleteAttachment", ns + ":toto.gif"); 24 | } 25 | 26 | @org.junit.Test 27 | public void putAndDeleteAttachment() throws Exception { 28 | assertFalse(runWithArguments("getAttachments", ns).out.contains("toto.gif")); 29 | 30 | Output outputPut = runWithArguments("putAttachment", ns + ":toto.gif", TestParams.localFileToUpload); 31 | assertSuccess("", outputPut); 32 | assertTrue(runWithArguments("getAttachments", ns).out.contains("toto.gif")); 33 | 34 | Output outputDelete = runWithArguments("deleteAttachment", ns + ":toto.gif"); 35 | assertSuccess("", outputDelete); 36 | assertFalse(runWithArguments("getAttachments", ns).out.contains("toto.gif")); 37 | } 38 | 39 | @org.junit.Test 40 | public void putAttachmentWontOverwriteWithoutTheForceOption() throws Exception{ 41 | //Ensure we start in a clean state 42 | runWithArguments("putAttachment", ns + ":toto.gif", TestParams.localFileToUpload); 43 | runWithArguments("getAttachment", ns + ":toto.gif", localFileName); 44 | assertBinaryEquals(new File(TestParams.localFileToUpload), localFile); 45 | 46 | //Try to override the distant file without providing the flag 47 | Output output = runWithArguments("putAttachment", ns + ":toto.gif", TestParams.localFile2ToUpload); 48 | assertGenericError(output); 49 | 50 | //Assert the attachment hasn't been overrided 51 | runWithArguments("getAttachment", ns + ":toto.gif", localFileName); 52 | assertBinaryEquals(new File(TestParams.localFileToUpload), localFile); 53 | } 54 | 55 | @org.junit.Test 56 | public void putAttachmentWillOverwriteWithTheForceOption() throws Exception{ 57 | //Ensure we start in a clean state 58 | runWithArguments("putAttachment", ns + ":toto.gif", TestParams.localFileToUpload); 59 | runWithArguments("getAttachment", ns + ":toto.gif", localFileName); 60 | assertBinaryEquals(new File(TestParams.localFileToUpload), localFile); 61 | 62 | //Try to override the distant file without providing the flag 63 | Output output = runWithArguments("putAttachment", ns + ":toto.gif", "-f", TestParams.localFile2ToUpload); 64 | assertSuccess("", output); 65 | 66 | //Assert the attachment hasn't been overrided 67 | runWithArguments("getAttachment", ns + ":toto.gif", localFileName); 68 | assertBinaryEquals(new File(TestParams.localFile2ToUpload), localFile); 69 | } 70 | 71 | @org.junit.Test 72 | public void deletingAnUnexistingFileYieldsAnErrorOnlyIfNoForceFlagHasBeenProvided() throws Exception { 73 | Output outputForceLess = runWithArguments("deleteAttachment", ns + ":unknown_file.gif"); 74 | assertGenericError(outputForceLess); 75 | 76 | Output outputForced = runWithArguments("deleteAttachment", "-f", ns + ":unknown_file.gif"); 77 | assertSuccess("", outputForced); 78 | } 79 | 80 | @org.junit.Test 81 | public void getAFileToANonWritablePlaceDoesntCrash() throws Exception{ 82 | //Ensure we start in a clean state 83 | runWithArguments("putAttachment", ns + ":toto.gif", TestParams.localFileToUpload); 84 | runWithArguments("getAttachment", ns + ":toto.gif", localFileName); 85 | assertTrue(runWithArguments("getAttachments", ns).out.contains("toto.gif")); 86 | 87 | //Actually test 88 | Output output = runWithArguments("getAttachment", ns + ":toto.gif", "/home/whatever/icantwrite/here.jpg"); 89 | assertGenericError(output); 90 | } 91 | 92 | @org.junit.Test 93 | public void putAFileWhichDoesntExistDoesntCrash() throws Exception { 94 | Output output = runWithArguments("putAttachment", ns + ":toto.gif", "unexistingFile.jpg"); 95 | assertGenericError(output); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_AttachmentReader.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.Output; 4 | import dw.cli.itest.TestHelper; 5 | 6 | public class Test_AttachmentReader extends TestHelper { 7 | @org.junit.Test 8 | public void getAttachments() throws Exception { 9 | Output output = runWithArguments("getAttachments", "ro_for_tests"); 10 | assertSuccess("ro_for_tests:img1.gif", output); 11 | } 12 | 13 | @org.junit.Test 14 | public void getAttachmentsLongListingFormat() throws Exception { 15 | Output output = runWithArguments("getAttachments", "-l", "ro_for_tests"); 16 | assertSuccessRegex("255 67 " + dateRegex + " ro_for_tests:img1.gif", output); 17 | } 18 | 19 | @org.junit.Test 20 | public void getAttachmentsMissingNamespaceShouldPrintError() throws Exception { 21 | Output output = runWithArguments("getAttachments"); 22 | assertGenericError(output); 23 | } 24 | } 25 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_BackLinksGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_BackLinksGetter extends TestHelper { 6 | 7 | @org.junit.Test 8 | public void getBackLinks() throws Exception { 9 | assertSuccess("links:start", runWithArguments("getBackLinks", "ns1:dummy")); 10 | } 11 | } 12 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_Exception.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | import static org.junit.Assert.fail; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_Exception extends TestHelper { 8 | @org.junit.Test 9 | public void knownBadUrlYieldErrorWithUsefulHint() throws Exception { 10 | try { 11 | runWithUrl("http://localhost/badUrl", "getVersion"); 12 | } catch(Exception e){ 13 | assertTrue(e.getMessage().contains("lib/exe/xmlrpc.php")); 14 | return; 15 | } 16 | fail("Should have thrown"); 17 | } 18 | 19 | @org.junit.Test 20 | public void badUrlYieldErrorWithUsefulHint() throws Exception { 21 | try { 22 | runWithUrl("http://localhost/badUrl/lib/exe/xmlrpc.php", "getVersion"); 23 | } catch(Exception e){ 24 | assertTrue(e.getMessage().contains("lib/exe/xmlrpc.php")); 25 | return; 26 | } 27 | fail("Should have thrown"); 28 | } 29 | } 30 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_HelpPrinter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | 5 | import java.util.ArrayList; 6 | import java.util.List; 7 | 8 | import dw.cli.Output; 9 | import dw.cli.Program; 10 | import dw.cli.itest.TestHelper; 11 | 12 | public class Test_HelpPrinter extends TestHelper { 13 | 14 | @org.junit.Test 15 | public void commandHelpPrintsGenericHelp() throws Exception { 16 | Output output = runWithoutGenericArguments("help"); 17 | assertGenericSuccess(output); 18 | assertIsGenericHelpMessage(output.out); 19 | } 20 | 21 | @org.junit.Test 22 | public void commandHelpCanPrintHelpForAGivenCommand() throws Exception { 23 | Output output = runWithoutGenericArguments("help", "getPagelist"); 24 | assertGenericSuccess(output); 25 | assertTrue(output.out.contains("[-l] [--depth ]")); 26 | } 27 | 28 | @org.junit.Test 29 | public void commandHelpPrintsGenericHelpIfQueriedWithInvalidCommand() throws Exception { 30 | Output output = runWithoutGenericArguments("help", "doesntExist"); 31 | assertGenericSuccess(output); 32 | assertIsGenericHelpMessage(output.out); 33 | } 34 | 35 | @org.junit.Test 36 | public void optionHelpPrintsHelp() throws Exception { 37 | Output output = runWithoutGenericArguments("--help"); 38 | assertGenericSuccess(output); 39 | assertIsGenericHelpMessage(output.out); 40 | } 41 | 42 | @org.junit.Test 43 | public void unexistingCommandPrintsHelp() throws Exception { 44 | Output output = runWithArguments("doesntExist"); 45 | assertGenericError(output); 46 | assertIsGenericHelpMessage(output.err); 47 | } 48 | 49 | @org.junit.Test 50 | public void incorrectOptionsPrintsHelp() throws Exception { 51 | List args = new ArrayList(); 52 | args.add("--urll"); args.add("http://localhost/myWiki/lib/exe/xmlrpc.php"); 53 | Output output = Program.run(args.toArray(new String[]{})); 54 | 55 | assertGenericError(output); 56 | assertIsGenericHelpMessage(output.err); 57 | } 58 | 59 | 60 | private void assertIsGenericHelpMessage(String message) { 61 | assertMessageContainsGenericOptions(message); 62 | assertMessageContainsListOfCommands(message); 63 | assertMessageTellHowToGetHelpForAGivenCommand(message); 64 | } 65 | 66 | private void assertMessageContainsGenericOptions(String message){ 67 | assertTrue(message.contains("--user")); 68 | assertTrue(message.contains("--url")); 69 | assertTrue(message.contains("--help")); 70 | assertTrue(message.contains("--password")); 71 | } 72 | 73 | private void assertMessageContainsListOfCommands(String message){ 74 | assertTrue(message.contains("getTitle")); 75 | assertTrue(message.contains("getAttachments")); 76 | assertTrue(message.contains("deleteAttachment")); 77 | assertTrue(message.contains("getPagelist")); 78 | } 79 | 80 | private void assertMessageTellHowToGetHelpForAGivenCommand(String message) { 81 | assertTrue(message.contains("help ")); 82 | } 83 | } 84 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_LinksLister.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_LinksLister extends TestHelper{ 6 | @org.junit.Test 7 | public void listLinks() throws Exception { 8 | String expected = "http://dokuwiki.org" 9 | + "\nhttp://github.com/gturri" 10 | + "\nns1:dummy"; 11 | assertSuccess(expected, runWithArguments("listLinks", "links:start")); 12 | } 13 | 14 | @org.junit.Test 15 | public void listLinksWithLongFormat() throws Exception { 16 | String expected = "extern http://dokuwiki.org http://dokuwiki.org" 17 | + "\nextern http://github.com/gturri http://github.com/gturri" 18 | + "\nlocal ns1:dummy /dokuwikiITestsForXmlRpcClient_dokuwiki-2020-07-29/doku.php?id=ns1:dummy"; 19 | 20 | assertSuccess(expected, runWithArguments("listLinks", "-l", "links:start")); 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_LocksSetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_LocksSetter extends TestHelper { 6 | 7 | @org.junit.Before 8 | @org.junit.After 9 | public void unlockAll() throws Exception { 10 | runWithArguments("unlock", "ns2:p1", "ns2:p2", "ns2:p3"); 11 | runWithArgumentAsWriterUser("unlock", "ns2:p1", "ns2:p2", "ns2:p3"); 12 | } 13 | 14 | @org.junit.Test 15 | public void canLockAPage() throws Exception { 16 | //Check initial state 17 | assertIsntLocked("ns2:p1"); 18 | assertIsntLocked("ns2:p3"); 19 | 20 | //Act 21 | assertSuccess("", runWithArguments("lock", "ns2:p1")); 22 | 23 | //Check final state 24 | assertIsLocked("ns2:p1"); 25 | assertIsntLocked("ns2:p3"); 26 | } 27 | 28 | private void assertIsntLocked(String pageId) throws Exception { 29 | assertGenericSuccess(runWithArgumentAsWriterUser("putPage", pageId, "some text")); 30 | } 31 | 32 | private void assertIsLocked(String pageId) throws Exception { 33 | assertGenericError(runWithArgumentAsWriterUser("putPage", pageId, "some text")); 34 | } 35 | 36 | @org.junit.Test 37 | public void canLockSeveralPages() throws Exception { 38 | //Check initial state 39 | assertIsntLocked("ns2:p1"); 40 | assertIsntLocked("ns2:p2"); 41 | assertIsntLocked("ns2:p3"); 42 | 43 | //Act 44 | assertSuccess("", runWithArguments("lock", "ns2:p1", "ns2:p2")); 45 | 46 | //Check final state 47 | assertIsLocked("ns2:p1"); 48 | assertIsLocked("ns2:p2"); 49 | assertIsntLocked("ns2:p3"); 50 | } 51 | 52 | @org.junit.Test 53 | public void canUnlockAPage() throws Exception { 54 | //Prepare and check initial state 55 | runWithArguments("lock", "ns2:p1"); 56 | assertIsLocked("ns2:p1"); 57 | 58 | //Act 59 | assertSuccess("", runWithArguments("unlock", "ns2:p1")); 60 | 61 | //Check final state 62 | assertIsntLocked("ns2:p1"); 63 | } 64 | 65 | @org.junit.Test 66 | public void canUnlockSeveralPage() throws Exception { 67 | //Prepare and check initial state 68 | runWithArguments("lock", "ns2:p1", "ns2:p2"); 69 | assertIsLocked("ns2:p1"); 70 | assertIsLocked("ns2:p2"); 71 | 72 | //Act 73 | assertSuccess("", runWithArguments("unlock", "ns2:p1", "ns2:p2")); 74 | 75 | //Check final state 76 | assertIsntLocked("ns2:p1"); 77 | assertIsntLocked("ns2:p2"); 78 | } 79 | 80 | @org.junit.Test 81 | public void reportsAnErrorIfAtLeastOneLockFailed() throws Exception { 82 | //Prepare initial state 83 | runWithArgumentAsWriterUser("lock", "ns2:p1"); 84 | 85 | //Act 86 | assertGenericError(runWithArguments("lock", "ns2:p1", "ns2:p2")); 87 | } 88 | 89 | @org.junit.Test 90 | public void reportsAnErrorIfAtLeastOneUnlockFailed() throws Exception { 91 | //Prepare initial state 92 | runWithArgumentAsWriterUser("lock", "ns2:p1"); 93 | 94 | //Act 95 | assertGenericError(runWithArguments("unlock", "ns2:p1", "ns2:p2")); 96 | } 97 | } 98 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageAppender.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageAppender extends TestHelper { 6 | private final String pageId = "ns1:dummy"; 7 | private final String initialContent = "put page in a clean state."; 8 | 9 | @org.junit.Before 10 | public void setUp() throws Exception{ 11 | runWithArguments("putPage", pageId, initialContent); 12 | } 13 | 14 | @org.junit.Test 15 | public void appendPage() throws Exception { 16 | String append1 = "text appened"; 17 | assertSuccess("", runWithArguments("appendPage", pageId, append1)); 18 | assertSuccess(initialContent + append1, runWithArguments("getPage", pageId)); 19 | 20 | String append2 = "final text"; 21 | assertSuccess("", runWithArguments("appendPage", pageId, append2)); 22 | assertSuccess(initialContent + append1 + append2, runWithArguments("getPage", pageId)); 23 | } 24 | 25 | @org.junit.Test 26 | public void appendPageWithSeveralParts() throws Exception { 27 | String part1 = "toto"; 28 | String part2 = "tata"; 29 | assertSuccess("", runWithArguments("appendPage", pageId, part1, part2)); 30 | assertSuccess(initialContent + part1 + " " + part2, runWithArguments("getPage", pageId)); 31 | 32 | String part3 = "tutu"; 33 | assertSuccess("", runWithArguments("appendPage", pageId, part3)); 34 | assertSuccess(initialContent + part1 + " " + part2 + part3, runWithArguments("getPage", pageId)); 35 | } 36 | 37 | @org.junit.Test 38 | public void appendPageWithSummary() throws Exception{ 39 | //Sleep because DW behaves badly wrt revisions,when there are more than 1 version per second 40 | Thread.sleep(1000, 0); 41 | String summary1 = "I needed this change"; 42 | assertSuccess("", runWithArguments("appendPage", "--summary", summary1, pageId, "some text")); 43 | assertLastModificationSummary(summary1, runWithArguments("getPageVersions", pageId)); 44 | 45 | Thread.sleep(1000, 0); 46 | String summary2 = "fixed a typo"; 47 | assertSuccess("", runWithArguments("appendPage", "--summary", summary2, pageId, "some other text")); 48 | assertLastModificationSummary(summary2, runWithArguments("getPageVersions", pageId)); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageGetterAndPutter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import java.io.ByteArrayInputStream; 4 | import java.io.InputStream; 5 | 6 | import dw.cli.itest.TestHelper; 7 | 8 | public class Test_PageGetterAndPutter extends TestHelper { 9 | private final String pageId = "ns1:dummy"; 10 | 11 | @org.junit.Before 12 | public void setUp() throws Exception{ 13 | runWithArguments("putPage", pageId, ""); 14 | } 15 | 16 | 17 | @org.junit.Test 18 | public void putPageAndgetPage() throws Exception{ 19 | final String content1 = "content1"; 20 | final String content2 = "content2"; 21 | 22 | assertSuccess("", runWithArguments("putPage", pageId, content1)); 23 | assertSuccess(content1, runWithArguments("getPage", pageId)); 24 | 25 | assertSuccess("", runWithArguments("putPage", pageId, content2)); 26 | assertSuccess(content2, runWithArguments("getPage", pageId)); 27 | } 28 | 29 | @org.junit.Test 30 | public void putPageWithSeveralParts() throws Exception { 31 | runWithArguments("putPage", pageId, "toto", "tata"); 32 | assertSuccess("toto tata", runWithArguments("getPage", pageId)); 33 | } 34 | 35 | @org.junit.Test 36 | public void canPutAPageWithASummary() throws Exception { 37 | //Sleep because DW behaves badly wrt revisions,when there are more than 1 version per second 38 | Thread.sleep(1000, 0); 39 | assertSuccess("", runWithArguments("putPage", pageId, "--summary", "my summary 1", "some content 2")); 40 | assertLastModificationSummary("my summary 1", runWithArguments("getPageVersions", pageId)); 41 | 42 | //Sleep because DW behaves badly wrt revisions,when there are more than 1 version per second 43 | Thread.sleep(1000, 0); 44 | assertSuccess("", runWithArguments("putPage", pageId, "--summary", "my other summary", "some other content")); 45 | assertLastModificationSummary("my other summary", runWithArguments("getPageVersions", pageId)); 46 | } 47 | 48 | @org.junit.Test 49 | public void shouldReadFromStdinIfThereIsNoTextOnTheCommandLine() throws Exception { 50 | String data = "Some text on stdin"; 51 | InputStream stdin = System.in; 52 | try { 53 | System.setIn(new ByteArrayInputStream(data.getBytes())); 54 | 55 | runWithArguments("putPage", pageId); 56 | assertSuccess("Some text on stdin", runWithArguments("getPage", pageId)); 57 | } finally { 58 | System.setIn(stdin); 59 | } 60 | } 61 | } 62 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageHtmlGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageHtmlGetter extends TestHelper { 6 | private final String pageId = "rev:start"; 7 | 8 | @org.junit.Test 9 | public void getPageHTML() throws Exception { 10 | assertSuccess("\n

\n3rd version\n

\n", runWithArguments("getPageHTML", pageId)); 11 | } 12 | 13 | @org.junit.Test 14 | public void getPageHTMLVersion() throws Exception { 15 | assertSuccess("\n

\nv2\n

\n", runWithArguments("getPageHTMLVersion", pageId, "1356218411")); 16 | } 17 | } 18 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageInfoGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageInfoGetter extends TestHelper { 6 | @org.junit.Test 7 | public void getPageInfo() throws Exception { 8 | assertSuccess("rev:start 1356218419 lulu", runWithArguments("getPageInfo", "rev:start")); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageInfoVersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageInfoVersionGetter extends TestHelper { 6 | @org.junit.Test 7 | public void getPageInfoVersion() throws Exception { 8 | String expected = "rev:start 1356218411 fifi"; 9 | assertSuccess(expected, runWithArguments("getPageInfoVersion", "rev:start", "1356218411")); 10 | 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageListGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import dw.cli.Output; 6 | import dw.cli.itest.TestHelper; 7 | 8 | public class Test_PageListGetter extends TestHelper { 9 | @org.junit.Test 10 | public void getPagelist() throws Exception { 11 | Output output = runWithArguments("getPagelist", "ns1"); 12 | assertSuccess("ns1:dummy\nns1:start", output); 13 | } 14 | 15 | @org.junit.Test 16 | public void getPageListLongFormat() throws Exception { 17 | Output output = runWithArguments("getPagelist", "-l", "nswithanotherns:otherns"); 18 | assertSuccess("4 1375372800 1375372800 nswithanotherns:otherns:page", output); 19 | } 20 | 21 | @org.junit.Test 22 | public void getPageListWithDepth() throws Exception { 23 | Output output = runWithArguments("getPagelist", "--depth", "3", "nswithanotherns"); 24 | 25 | assertGenericSuccess(output); 26 | assertTrue(output.out.contains("nswithanotherns:start")); 27 | assertTrue(output.out.contains("nswithanotherns:dummy")); 28 | assertTrue(output.out.contains("nswithanotherns:otherns:page")); 29 | } 30 | } 31 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageVersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageVersionGetter extends TestHelper { 6 | private final String pageId = "rev:start"; 7 | 8 | @org.junit.Test 9 | public void getPageVersion() throws Exception{ 10 | assertSuccess("version 1", runWithArguments("getPageVersion", pageId, "1356218400")); 11 | assertSuccess("", runWithArguments("getPageVersion", pageId, "1356218401")); 12 | assertSuccess("v2", runWithArguments("getPageVersion", pageId, "1356218411")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_PageVersionsGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_PageVersionsGetter extends TestHelper { 6 | @org.junit.Test 7 | public void getPageVersionsWithExplicitOffset() throws Exception{ 8 | String expected = "rev:start 1356218411 127.0.0.1 E fifi - edit 1" 9 | + "\nrev:start 1356218400 127.0.0.1 C riri - created"; 10 | 11 | assertSuccess(expected, runWithArguments("getPageVersions", "rev:start", "--offset", "1")); 12 | } 13 | 14 | @org.junit.Test 15 | public void getPageVersionsWithoutExplicitOffset() throws Exception{ 16 | String expected = "rev:start 1356218419 127.0.0.1 E lulu - edit 2" 17 | + "\nrev:start 1356218411 127.0.0.1 E fifi - edit 1" 18 | + "\nrev:start 1356218400 127.0.0.1 C riri - created"; 19 | assertSuccess(expected, runWithArguments("getPageVersions", "rev:start")); 20 | } 21 | } 22 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_RPCVersionSupportedGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.itest.TestHelper; 4 | 5 | public class Test_RPCVersionSupportedGetter extends TestHelper { 6 | @org.junit.Test 7 | public void getRPCVersionSupported() throws Exception { 8 | assertSuccess(params.rpcVersionSupported.toString(), runWithArguments("getRPCVersionSupported")); 9 | } 10 | } 11 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_RecentChangesGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.Output; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_RecentChangesGetter extends TestHelper { 8 | @org.junit.Test 9 | public void getRecentChanges() throws Exception { 10 | Output output = runWithArguments("getRecentChanges", "1356218401"); 11 | assertGenericSuccess(output); 12 | assertTrue(output.out.contains("rev:start 1356218419 someuser 255 11")); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_RecentMediaChangesGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.Output; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_RecentMediaChangesGetter extends TestHelper { 8 | @org.junit.Test 9 | public void getRecentMediaChanges() throws Exception { 10 | Output output = runWithArguments("getRecentMediaChanges", "1356383400"); 11 | 12 | assertGenericSuccess(output); 13 | assertTrue(output.out.contains("ro_for_tests:img1.gif fifi 255 67")); 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_Searcher.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.Output; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_Searcher extends TestHelper { 8 | @org.junit.Test 9 | public void search() throws Exception{ 10 | Output output = runWithArguments("search", "amet"); 11 | assertSuccess("nssearch:page3\nnssearch:start", output); 12 | } 13 | 14 | @org.junit.Test 15 | public void searchWithLongSwitch() throws Exception { 16 | Output output = runWithArguments("search", "-l", "amet"); 17 | assertSuccess("2 1375376400 1375376400 Page 3 title 197 nssearch:page3\n1 1383544045 1383544045 56 nssearch:start", output); 18 | } 19 | 20 | @org.junit.Test 21 | public void searchWithSnippetSwitch() throws Exception { 22 | Output output = runWithArguments("search", "--snippet", "amet"); 23 | assertGenericSuccess(output); 24 | assertTrue(output.out.contains("nssearch:page3\n> ======Page 3 title======")); 25 | } 26 | } 27 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_TimeGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.Output; 5 | import dw.cli.itest.TestHelper; 6 | 7 | public class Test_TimeGetter extends TestHelper { 8 | 9 | @org.junit.Test 10 | public void getTime() throws Exception{ 11 | Output output = runWithArguments("getTime"); 12 | assertGenericSuccess(output); 13 | assertIsTimestamp(output.out); 14 | } 15 | 16 | private void assertIsTimestamp(String string) { 17 | assertEquals(10, string.length()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_TitleGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.Output; 4 | import dw.cli.itest.TestHelper; 5 | 6 | public class Test_TitleGetter extends TestHelper { 7 | 8 | @org.junit.Test 9 | public void getTitle() throws Exception{ 10 | Output output = runWithArguments("getTitle"); 11 | assertSuccess("test xmlrpc", output); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_Version.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.Output; 4 | import dw.cli.itest.TestHelper; 5 | 6 | public class Test_Version extends TestHelper { 7 | 8 | @org.junit.Test 9 | public void optionVersion() throws Exception{ 10 | Output output = runWithArguments("--version"); 11 | assertGenericSuccess(output); 12 | assertNotNullOrEmpty(output.out); 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_VersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.Output; 4 | import dw.cli.itest.TestHelper; 5 | 6 | public class Test_VersionGetter extends TestHelper { 7 | @org.junit.Test 8 | public void getVersion() throws Exception { 9 | Output output = runWithArguments("getVersion"); 10 | assertSuccess(params.wikiVersion, output); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_XMLRPCAPIVersionGetter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import dw.cli.Output; 4 | import dw.cli.itest.TestHelper; 5 | 6 | 7 | public class Test_XMLRPCAPIVersionGetter extends TestHelper { 8 | @org.junit.Test 9 | public void getXMLRPCAPIVersion() throws Exception{ 10 | Output output = runWithArguments("getXMLRPCAPIVersion"); 11 | assertSuccess(params.apiVersion.toString(), output); 12 | } 13 | } 14 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/commands/itest/Test_getAttachment.java: -------------------------------------------------------------------------------- 1 | package dw.cli.commands.itest; 2 | 3 | import static org.junit.Assert.*; 4 | import static junitx.framework.FileAssert.assertBinaryEquals; 5 | 6 | import java.io.File; 7 | 8 | import dw.cli.Output; 9 | import dw.cli.itest.TestHelper; 10 | import dw.xmlrpc.itest.TestParams; 11 | 12 | public class Test_getAttachment extends TestHelper { 13 | private final File localFile = new File("myFile.gif"); 14 | 15 | @org.junit.Before 16 | @org.junit.After 17 | public void clean(){ 18 | localFile.delete(); 19 | } 20 | 21 | @org.junit.Test 22 | public void canGetAttachment() throws Exception { 23 | //Make sure we're in a clean state 24 | assertFalse(localFile.exists()); 25 | 26 | Output output = runWithArguments("getAttachment", "ro_for_tests:img1.gif", "myFile.gif"); 27 | assertSuccess("", output); 28 | assertTrue(localFile.exists()); 29 | assertBinaryEquals(new File(TestParams.localFileToUpload), new File("myFile.gif")); 30 | } 31 | 32 | @org.junit.Test 33 | public void attachmentDoesntExist() throws Exception { 34 | Output output = runWithArguments("getAttachment", "ro_for_tests:unexisting_file.gif", "myFile.gif"); 35 | assertGenericError(output); 36 | } 37 | } 38 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/itest/TestHelper.java: -------------------------------------------------------------------------------- 1 | package dw.cli.itest; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertNotNull; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | import java.util.ArrayList; 9 | import java.util.List; 10 | 11 | import dw.cli.Output; 12 | import dw.cli.Program; 13 | import dw.xmlrpc.itest.TestParams; 14 | 15 | public class TestHelper { 16 | protected final TestParams params = new TestParams("dokuwiki-2020-07-29", "Release 2020-07-29 \"Hogfather\"", 10, 2); 17 | 18 | protected final String dateRegex = "[A-Za-z]{3} [A-Za-z]{3} [0-9]{2} [0-9]{2}:[0-9]{2}:[0-9]{2} [A-Z]{3}? [0-9]{4}"; 19 | 20 | protected void assertNotNullOrEmpty(String str){ 21 | assertNotNull(str); 22 | assertFalse(str.equals("")); 23 | } 24 | 25 | protected void assertNotZero(int number){ 26 | assertFalse(number == 0); 27 | } 28 | 29 | protected Output runWithArguments(String command, String... extraArguments) throws Exception{ 30 | String[] arguments = buildArguments(TestParams.user, TestParams.password, command, extraArguments); 31 | return Program.run(arguments); 32 | } 33 | 34 | protected Output runWithUrl(String url, String command, String... extraArguments) throws Exception { 35 | String[] arguments = buildArguments(TestParams.user, TestParams.password, command, url, extraArguments); 36 | return Program.run(arguments); 37 | } 38 | 39 | protected Output runWithoutGenericArguments(String command, String... extraArguments) throws Exception { 40 | List args = new ArrayList(); 41 | args.add(command); 42 | for(String extraArg : extraArguments){ 43 | args.add(extraArg); 44 | } 45 | return Program.run(args.toArray(new String[]{})); 46 | } 47 | 48 | protected Output runWithArgumentAsWriterUser(String command, String... extraArguments) throws Exception { 49 | String[] arguments = buildArguments(TestParams.writerLogin, TestParams.writerPwd, command, extraArguments); 50 | return Program.run(arguments); 51 | } 52 | 53 | protected Output runWithArgumentAsPermissionLessUser(String command, String...extraArguments) throws Exception { 54 | String[] arguments = buildArguments("badUser", "badPassword", command, extraArguments); 55 | return Program.run(arguments); 56 | } 57 | 58 | private String[] buildArguments(String user, String password, String command, String... extraArguments){ 59 | return buildArguments(user, password, command, params.url, extraArguments); 60 | } 61 | 62 | private String[] buildArguments(String user, String password, String command, String url, String... extraArguments){ 63 | List args = new ArrayList(); 64 | args.add("-u"); args.add(user); 65 | args.add("-p"); args.add(password); 66 | args.add("--url"); args.add(url); 67 | args.add(command); 68 | for(String extraArg : extraArguments){ 69 | args.add(extraArg); 70 | } 71 | return args.toArray(new String[]{}); 72 | } 73 | 74 | protected void assertSuccess(String expectedOutput, Output actualOutput){ 75 | assertEquals(expectedOutput, actualOutput.out); 76 | assertGenericSuccess(actualOutput); 77 | } 78 | 79 | protected void assertSuccessRegex(String expectedOutput, Output actualOutput){ 80 | assertTrue(actualOutput.out.matches(expectedOutput)); 81 | assertGenericSuccess(actualOutput); 82 | } 83 | 84 | protected void assertGenericSuccess(Output actualOutput){ 85 | assertEquals("", actualOutput.err); 86 | assertEquals(0, actualOutput.exitCode); 87 | } 88 | 89 | protected void assertGenericError(Output actualOutput){ 90 | assertNotNullOrEmpty(actualOutput.err); 91 | assertEquals("", actualOutput.out); 92 | assertNotZero(actualOutput.exitCode); 93 | } 94 | 95 | protected void assertLastModificationSummary(String expectedSummary, Output actualOutput) { 96 | String lastModification = actualOutput.out.split("\n")[0]; 97 | String actualSummary = lastModification.split(" - ")[1]; 98 | assertEquals(expectedSummary, actualSummary); 99 | } 100 | } 101 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/itest/Test_PermissionLessUser.java: -------------------------------------------------------------------------------- 1 | package dw.cli.itest; 2 | 3 | public class Test_PermissionLessUser extends TestHelper { 4 | @org.junit.Test 5 | public void shouldntCrashIfUserDoesntHaveEnoughPermissions() throws Exception { 6 | assertGenericError(runWithArgumentAsPermissionLessUser("putPage", "start", "some text")); 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/utest/MockPasswordReader.java: -------------------------------------------------------------------------------- 1 | package dw.cli.utest; 2 | 3 | import dw.cli.PasswordReader; 4 | 5 | public class MockPasswordReader extends PasswordReader { 6 | private final String _string; 7 | 8 | public MockPasswordReader(String string){ 9 | _string = string; 10 | } 11 | 12 | @Override 13 | public String readPassword(){ 14 | return _string; 15 | } 16 | } 17 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/utest/Test_CliOptions.java: -------------------------------------------------------------------------------- 1 | package dw.cli.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.cli.CliOptions; 5 | 6 | public class Test_CliOptions { 7 | @org.junit.Test 8 | public void toStringDoesntThrowNullPointerException(){ 9 | CliOptions cliWithNullMembers = new CliOptions(); 10 | assertNotNull(cliWithNullMembers.toString()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/utest/Test_OptionParser.java: -------------------------------------------------------------------------------- 1 | package dw.cli.utest; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertFalse; 5 | import static org.junit.Assert.assertNotNull; 6 | import static org.junit.Assert.assertTrue; 7 | 8 | import java.net.URL; 9 | 10 | import dw.cli.CliOptions; 11 | import dw.cli.OptionParser; 12 | 13 | public class Test_OptionParser { 14 | 15 | @org.junit.Test 16 | public void canParseGenericOptions() throws Exception{ 17 | String[] args = new String[]{"-u", "toto", "-p", "123456", "--url", "http://myUrl", "getTitle", "arg0"}; 18 | OptionParser parser = new OptionParser(args); 19 | parser.parse(); 20 | 21 | System.out.println(parser.getHelpMessage()); 22 | assertTrue(parser.success()); 23 | assertNotNull(parser.getHelpMessage()); 24 | 25 | CliOptions options = parser.getCliOptions(); 26 | assertEquals("toto", options.user); 27 | assertEquals("123456", options.password); 28 | assertEquals(new URL("http://myUrl"), options.url); 29 | assertFalse(options.debug); 30 | assertEquals("getTitle", options.command); 31 | assertEquals(1, options.commandArguments.length); 32 | assertEquals("arg0", options.commandArguments[0]); 33 | } 34 | 35 | @org.junit.Test 36 | public void canParseCommandFlags() throws Exception { 37 | String[] args = new String[]{"--url", "http://myUrl", "someCommand", "arg0", "-l", "3"}; 38 | 39 | OptionParser parser = new OptionParser(args); 40 | parser.parse(); 41 | 42 | assertTrue(parser.success()); 43 | CliOptions options = parser.getCliOptions(); 44 | assertEquals("someCommand", options.command); 45 | assertEquals(3, options.commandArguments.length); 46 | assertEquals("arg0", options.commandArguments[0]); 47 | assertEquals("-l", options.commandArguments[1]); 48 | assertEquals("3", options.commandArguments[2]); 49 | } 50 | 51 | @org.junit.Test 52 | public void canParseDebugSwitch() throws Exception { 53 | String[] args = new String[]{"--url", "http://myUrl", "--debug", "someCommand", "arg0", "-l", "3"}; 54 | 55 | OptionParser parser = new OptionParser(args); 56 | parser.parse(); 57 | 58 | assertTrue(parser.success()); 59 | assertTrue(parser.getCliOptions().debug); 60 | } 61 | 62 | @org.junit.Test 63 | public void failsIfAnArgumentIsMissingItsValue() throws Exception{ 64 | String[] args = new String[]{"-u", "toto", "-p", "123456", "--url"}; 65 | OptionParser parser = new OptionParser(args); 66 | parser.parse(); 67 | assertFalse(parser.success()); 68 | } 69 | 70 | @org.junit.Test 71 | public void canReadPasswordInteractively() throws Exception { 72 | String[] args = new String[]{"-u", "toto", "--password-interactive", "--url", "http://myUrl", "getTitle", "arg0"}; 73 | OptionParser parser = new OptionParser(args, new MockPasswordReader("abcdef")); 74 | parser.parse(); 75 | 76 | assertEquals(true, parser.success()); 77 | CliOptions options = parser.getCliOptions(); 78 | assertEquals("abcdef", options.password); 79 | assertEquals("toto", options.user); 80 | assertEquals(new URL("http://myUrl"), options.url); 81 | assertEquals("getTitle", options.command); 82 | } 83 | 84 | @org.junit.Test 85 | public void failsIfBothFlagsPasswordAndInteractivePassword() throws Exception { 86 | String[] args = new String[]{"-u", "toto", "-p", "123456", "--password-interactive", "--url", "http://myUrl", "getTitle", "arg0"}; 87 | OptionParser parser = new OptionParser(args); 88 | parser.parse(); 89 | assertFalse(parser.success()); 90 | } 91 | } 92 | -------------------------------------------------------------------------------- /src/test/java/dw/cli/utest/Test_PagePutter.java: -------------------------------------------------------------------------------- 1 | package dw.cli.utest; 2 | 3 | import static org.mockito.Matchers.anyBoolean; 4 | import static org.mockito.Matchers.anyString; 5 | import static org.mockito.Matchers.eq; 6 | import static org.mockito.Mockito.mock; 7 | import static org.mockito.Mockito.verify; 8 | import static org.mockito.Mockito.when; 9 | 10 | import java.io.IOException; 11 | 12 | import dw.cli.StdinReader; 13 | import dw.cli.commands.PagePutter; 14 | import dw.xmlrpc.DokuJClient; 15 | 16 | public class Test_PagePutter { 17 | private DokuJClient _mockDokuJClient; 18 | private PagePutter _sut; 19 | 20 | private static final String PAGE_ID = "somePageId"; 21 | private static final String TEXT_ON_CMD_LINE = "some text on cmd line"; 22 | private static final String TEXT_ON_STDIN = "some text on stdin"; 23 | 24 | @org.junit.Before 25 | public void before() throws IOException{ 26 | StdinReader mockStdinReader = mock(StdinReader.class); 27 | _mockDokuJClient = mock(DokuJClient.class); 28 | when(mockStdinReader.readStdin()).thenReturn(TEXT_ON_STDIN); 29 | 30 | _sut = new PagePutter(false, mockStdinReader); 31 | } 32 | 33 | @org.junit.Test 34 | public void shouldReadFromStdinIfThereIsTextOnTheCommandLine() throws Exception{ 35 | String[] args = new String[]{ 36 | PAGE_ID, 37 | TEXT_ON_CMD_LINE 38 | }; 39 | 40 | _sut.run(_mockDokuJClient, args); 41 | 42 | verify(_mockDokuJClient).putPage(eq(PAGE_ID), eq(TEXT_ON_CMD_LINE), anyString(), anyBoolean()); 43 | } 44 | 45 | @org.junit.Test 46 | public void shouldReadFromStdinIfThereIsNoTextOnTheCommandLine() throws Exception { 47 | String[] args = new String[]{ 48 | PAGE_ID 49 | }; 50 | 51 | _sut.run(_mockDokuJClient, args); 52 | verify(_mockDokuJClient).putPage(eq(PAGE_ID), eq(TEXT_ON_STDIN), anyString(), anyBoolean()); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/TestHelper.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import static org.junit.Assert.assertTrue; 4 | import static org.junit.Assert.fail; 5 | 6 | import java.util.Calendar; 7 | import java.util.Date; 8 | import java.util.TimeZone; 9 | 10 | import dw.xmlrpc.DokuJClient; 11 | import dw.xmlrpc.exception.DokuException; 12 | import dw.xmlrpc.exception.DokuPageLockedException; 13 | 14 | public class TestHelper { 15 | /** 16 | * Assert that the actual Date is equal to the expected one. 17 | * Since we don't want to bother with timezones, we add a margin 18 | */ 19 | static void assertDatesNear(int year, int month, int day, int hour, int minute, int second, Date actual){ 20 | Date date = buildDate(year, month, day, hour, minute, second); 21 | int marginInMs = 24 * 3600 * 1000 + 1; 22 | assertTrue(Math.abs(date.getTime() - actual.getTime()) < marginInMs); 23 | } 24 | 25 | static Date buildDate(int year, int month, int day, int hour, int minute, int second){ 26 | TimeZone.setDefault(TimeZone.getTimeZone("GMT")); 27 | Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT")); 28 | cal.set(year, month, day, hour, minute, second); 29 | return cal.getTime(); 30 | } 31 | 32 | public static void assertPagesAreLockForMe(Iterable pageIds, DokuJClient client) throws DokuException { 33 | for(String pageId : pageIds){ 34 | assertPageIsLockForMe(pageId, client); 35 | } 36 | } 37 | 38 | public static void assertPageIsLockForMe(String pageId, DokuJClient client) throws DokuException{ 39 | boolean lockExceptionCaught = false; 40 | try { 41 | client.appendPage(pageId, "something"); 42 | } catch ( DokuPageLockedException e){ 43 | lockExceptionCaught = true; 44 | } 45 | 46 | assertTrue(lockExceptionCaught); 47 | } 48 | 49 | public static void assertPagesAreUnlockForMe(Iterable pageIds, DokuJClient client) throws DokuException { 50 | for(String pageId : pageIds){ 51 | assertPageIsUnlockForMe(pageId, client); 52 | } 53 | } 54 | 55 | public static void assertPageIsUnlockForMe(String pageId, DokuJClient client) throws DokuException{ 56 | String initialContent = client.getPage(pageId); 57 | try { 58 | client.appendPage(pageId, "something"); 59 | } catch (DokuPageLockedException e){ 60 | fail(); 61 | } 62 | 63 | //Clean page content 64 | client.putPage(pageId, initialContent); 65 | } 66 | } 67 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/TestParams.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import java.util.ArrayList; 4 | import java.util.Collection; 5 | import java.util.List; 6 | 7 | public class TestParams { 8 | public final String localPath; 9 | public final String url; 10 | public final String urlToWikiNotConfiguredToAcceptRpcQueries; 11 | public final String wikiVersion; 12 | public final Integer apiVersion; 13 | public final Integer rpcVersionSupported; 14 | public final String name; 15 | 16 | public static final String urlPrefix = "http://localhost/"; 17 | public static final String urlSuffix = "/lib/exe/xmlrpc.php"; 18 | 19 | public TestParams(String name, String wikiVersion, Integer apiVersion, Integer rpcVersionSupported){ 20 | this.name = name; 21 | this.localPath = "dokuwikiITestsForXmlRpcClient_" + name; 22 | this.url = urlPrefix + localPath + urlSuffix; 23 | this.urlToWikiNotConfiguredToAcceptRpcQueries = urlPrefix + localPath + "_noRpc" + urlSuffix; 24 | this.wikiVersion = wikiVersion; 25 | this.apiVersion = apiVersion; 26 | this.rpcVersionSupported = rpcVersionSupported; 27 | } 28 | 29 | 30 | public static final String user = "xmlrpcuser"; 31 | public static final String password = "xmlrpc"; 32 | 33 | public static final String writerLogin = "writeruser"; 34 | public static final String writerPwd = "writer"; 35 | 36 | public static final String unauthorizedLogin = "norightsuser"; 37 | public static final String unauthorizedPwd = "norights"; 38 | public static final String wikiTitle = "test xmlrpc"; 39 | 40 | private static final String localRoot = "src/test/resources/testEnvironment"; 41 | public static final String localFileToUpload = localRoot + "/list-plus.gif"; 42 | public static final String localFile2ToUpload = localRoot + "/at.gif"; 43 | 44 | public static Collection data() { 45 | List result = new ArrayList(); 46 | //result.add(new Object[]{new TestParams("dokuwiki-2013-12-08", "Release 2013-12-08 \"Binky\"", 8, 2)}); 47 | //result.add(new Object[]{new TestParams("dokuwiki-2014-05-05", "Release 2014-05-05 \"Ponder Stibbons\"", 9, 2)}); 48 | //result.add(new Object[]{new TestParams("dokuwiki-2014-09-29a", "Release 2014-09-29a \"Hrun\"", 9, 2)}); 49 | //result.add(new Object[]{new TestParams("dokuwiki-2015-08-10a", "Release 2015-08-10a \"Detritus\"", 9, 2)}); 50 | //result.add(new Object[]{new TestParams("dokuwiki-2016-06-26", "Release 2016-06-26 \"Elenor of Tsort\"", 10, 2)}); 51 | //result.add(new Object[]{new TestParams("dokuwiki-2017-02-19", "Release 2017-02-19 \"Frusterick Manners\"", 10, 2)}); 52 | result.add(new Object[]{new TestParams("dokuwiki-2018-04-22a", "Release 2018-04-22a \"Greebo\"", 10, 2)}); 53 | result.add(new Object[]{new TestParams("dokuwiki-2020-07-29", "Release 2020-07-29 \"Hogfather\"", 10, 2)}); 54 | return result; 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/Test_AclChanger.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import static org.junit.Assert.assertEquals; 4 | import static org.junit.Assert.assertNotNull; 5 | import static org.junit.Assert.assertTrue; 6 | import static org.junit.Assert.fail; 7 | 8 | import java.net.MalformedURLException; 9 | import java.util.Collection; 10 | 11 | import org.junit.runner.RunWith; 12 | import org.junit.runners.Parameterized; 13 | import org.junit.runners.Parameterized.Parameters; 14 | 15 | import dw.xmlrpc.DokuJClient; 16 | import dw.xmlrpc.exception.DokuException; 17 | import dw.xmlrpc.exception.DokuIncompatibleVersionException; 18 | import dw.xmlrpc.exception.DokuUnauthorizedException; 19 | 20 | @RunWith(value = Parameterized.class) 21 | public class Test_AclChanger extends TestHelper { 22 | private final DokuJClient _client; 23 | private final String _pageId = "ns1:start"; 24 | 25 | TestParams _params; 26 | 27 | public Test_AclChanger(TestParams params) throws MalformedURLException, DokuException { 28 | _client = new DokuJClient(params.url, TestParams.user, TestParams.password); 29 | _params = params; 30 | } 31 | 32 | @Parameters 33 | public static Collection data() { 34 | return TestParams.data(); 35 | } 36 | 37 | @org.junit.Test 38 | public void canAddAndRemoveAcl() throws MalformedURLException, DokuException{ 39 | if ( dwIsTooOldAndDoesntSupportAclChanges()){ 40 | assertExpectedExceptionIsThrown(); 41 | } else { 42 | assertCanAddAndRemoveAcl(); 43 | } 44 | } 45 | 46 | private void assertExpectedExceptionIsThrown() throws DokuException{ 47 | try { 48 | _client.addAcl(_pageId, TestParams.unauthorizedLogin, 1); 49 | } 50 | catch(DokuIncompatibleVersionException e){ 51 | assertNotNull(e.getMessage()); 52 | return; 53 | } 54 | fail("Didn't receive the expected exception"); 55 | } 56 | 57 | private void assertCanAddAndRemoveAcl() throws MalformedURLException, DokuException{ 58 | assertCanRead(false); 59 | assertTrue(_client.addAcl(_pageId, TestParams.unauthorizedLogin, 1)); 60 | assertCanRead(true); 61 | assertTrue(_client.delAcl(_pageId, TestParams.unauthorizedLogin)); 62 | assertCanRead(false); 63 | 64 | } 65 | 66 | private boolean dwIsTooOldAndDoesntSupportAclChanges() { 67 | return _params.apiVersion < 8 || _params.name.equals("dokuwiki-2013-05-10"); 68 | } 69 | 70 | private void assertCanRead(boolean shouldBeAbleToRead) throws MalformedURLException, DokuException{ 71 | DokuJClient unauthorizedClient = new DokuJClient(_params.url, TestParams.unauthorizedLogin, TestParams.unauthorizedPwd); 72 | boolean couldRead = true; 73 | 74 | try { 75 | unauthorizedClient.getPage(_pageId); 76 | } catch(DokuUnauthorizedException e){ 77 | couldRead = false; 78 | } 79 | 80 | assertEquals(shouldBeAbleToRead, couldRead); 81 | } 82 | } 83 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/Test_BadQueries.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import java.io.IOException; 4 | import java.net.MalformedURLException; 5 | import java.net.ServerSocket; 6 | 7 | import static com.github.tomakehurst.wiremock.client.WireMock.*; 8 | 9 | import org.junit.Rule; 10 | 11 | import com.github.tomakehurst.wiremock.http.Fault; 12 | import com.github.tomakehurst.wiremock.junit.WireMockRule; 13 | 14 | import dw.xmlrpc.DokuJClient; 15 | import dw.xmlrpc.DokuJClientConfig; 16 | import dw.xmlrpc.exception.DokuException; 17 | import dw.xmlrpc.exception.DokuTimeoutException; 18 | import dw.xmlrpc.exception.DokuUnknownException; 19 | 20 | public class Test_BadQueries { 21 | 22 | private static int port; 23 | static { 24 | ServerSocket ss = null; 25 | try { 26 | ss = new ServerSocket(0); 27 | port = ss.getLocalPort(); 28 | System.out.println("Wiremock will use port " + port); 29 | } catch (IOException e) { 30 | System.err.println("Socket Exception while opening socket: " + e); 31 | } finally { 32 | try { 33 | ss.close(); 34 | } catch (IOException e) { 35 | System.err.println("Socket Exception while closing socket: " + e); 36 | } 37 | } 38 | } 39 | 40 | @Rule 41 | public WireMockRule wireMockRule = new WireMockRule(port); 42 | 43 | @org.junit.Test(expected=DokuTimeoutException.class) 44 | public void iCanStopIfItTakesTooLongToRespond() throws MalformedURLException, DokuException{ 45 | setTimeout(); 46 | DokuJClient client = buildClientWithTimeOut(1); 47 | makeADummyCall(client); 48 | } 49 | 50 | @org.junit.Test 51 | public void iCanWaitEvenIfResponseTakesLong() throws MalformedURLException, DokuException{ 52 | setTimeout(); 53 | DokuJClient client = buildClientWithTimeOut(60); 54 | makeADummyCall(client); 55 | } 56 | 57 | @org.junit.Test 58 | public void timeoutOfZeroMeansWaitAsLongAsYouNeed() throws MalformedURLException, DokuException{ 59 | setTimeout(); 60 | DokuJClient client = buildClientWithTimeOut(0); 61 | makeADummyCall(client); 62 | } 63 | 64 | private void setTimeout(){ 65 | stubFor(post(urlEqualTo("/lib/exe/xmlrpc.php")) 66 | .willReturn(aResponse() 67 | .withStatus(200) 68 | .withFixedDelay(5*1000) 69 | .withBody("") 70 | )); 71 | } 72 | 73 | @org.junit.Test(expected=DokuUnknownException.class) 74 | public void corruptedReply() throws Exception { 75 | stubFor(post(urlEqualTo("/lib/exe/xmlrpc.php")) 76 | .willReturn(aResponse() 77 | .withStatus(200) 78 | .withFault(Fault.MALFORMED_RESPONSE_CHUNK))); 79 | makeADummyCall(buildClient()); 80 | } 81 | 82 | private DokuJClient buildClient() throws MalformedURLException, DokuException { 83 | return buildClientWithTimeOut(0); 84 | } 85 | 86 | private DokuJClient buildClientWithTimeOut(int timeoutInSeconds) throws MalformedURLException, DokuException{ 87 | DokuJClientConfig config = new DokuJClientConfig("http://localhost:" + port + "/lib/exe/xmlrpc.php"); 88 | config.setTimeOutInSeconds(timeoutInSeconds); 89 | return new DokuJClient(config); 90 | } 91 | 92 | private void makeADummyCall(DokuJClient client) throws DokuException{ 93 | client.genericQuery("wiki.getAllPages"); 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/Test_Cookies.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.net.MalformedURLException; 6 | import java.util.Collection; 7 | 8 | import org.junit.runner.RunWith; 9 | import org.junit.runners.Parameterized; 10 | import org.junit.runners.Parameterized.Parameters; 11 | 12 | import dw.xmlrpc.DokuJClient; 13 | import dw.xmlrpc.exception.DokuException; 14 | 15 | @RunWith(value = Parameterized.class) 16 | public class Test_Cookies { 17 | private TestParams _params; 18 | 19 | public Test_Cookies(TestParams params) throws MalformedURLException, DokuException{ 20 | _params = params; 21 | } 22 | 23 | @Parameters 24 | public static Collection data() { 25 | return TestParams.data(); 26 | } 27 | 28 | @org.junit.Test 29 | public void cookies() throws Exception { 30 | DokuJClient client = new DokuJClient(_params.url); 31 | assertEquals(0, client.cookies().size()); 32 | assertFalse(client.hasDokuwikiCookies()); 33 | 34 | client.login(TestParams.writerLogin, TestParams.writerPwd); 35 | assertTrue(client.cookies().size() > 0); 36 | assertTrue(client.hasDokuwikiCookies()); 37 | } 38 | 39 | @org.junit.Test 40 | public void loginSuccess() throws Exception { 41 | DokuJClient client = new DokuJClient(_params.url); 42 | assertTrue(client.login(TestParams.writerLogin, TestParams.writerPwd)); 43 | } 44 | 45 | @org.junit.Test 46 | public void loginFail() throws Exception { 47 | DokuJClient client = new DokuJClient(_params.url); 48 | assertFalse(client.login(TestParams.writerLogin, "badPassword")); 49 | } 50 | } 51 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/itest/Test_Lock.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.itest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.ArrayList; 6 | import java.util.Collection; 7 | import java.util.HashSet; 8 | import java.util.List; 9 | import java.util.Set; 10 | 11 | import org.junit.runner.RunWith; 12 | import org.junit.runners.Parameterized; 13 | import org.junit.runners.Parameterized.Parameters; 14 | 15 | import dw.xmlrpc.DokuJClient; 16 | import dw.xmlrpc.LockResult; 17 | import dw.xmlrpc.exception.DokuException; 18 | import dw.xmlrpc.exception.DokuPageLockedException; 19 | 20 | @RunWith(value = Parameterized.class) 21 | public class Test_Lock extends TestHelper { 22 | private DokuJClient _client; 23 | private DokuJClient _otherClient; 24 | 25 | public Test_Lock(TestParams params) throws Exception{ 26 | _client = new DokuJClient(params.url, TestParams.user, TestParams.password); 27 | _otherClient = new DokuJClient(params.url, TestParams.writerLogin, TestParams.writerPwd); 28 | clean(); 29 | } 30 | 31 | @Parameters 32 | public static Collection data() { 33 | return TestParams.data(); 34 | } 35 | 36 | @org.junit.After 37 | public void clean() throws Exception { 38 | tryUnlock(_client, "ns2:p1"); 39 | tryUnlock(_client, "ns2:p2"); 40 | tryUnlock(_client, "ns2:p3"); 41 | tryUnlock(_client, "ns2:p4"); 42 | 43 | tryUnlock(_otherClient, "ns2:p1"); 44 | tryUnlock(_otherClient, "ns2:p2"); 45 | } 46 | 47 | private void tryUnlock(DokuJClient client, String pageId) throws DokuException{ 48 | try { 49 | client.unlock(pageId); 50 | } catch (DokuPageLockedException e){ } 51 | } 52 | 53 | @org.junit.Test 54 | public void iCanPlayWihLockToAllowYouToWriteOrNot() throws Exception{ 55 | String pageId = "ns1:start"; 56 | _client.lock(pageId); 57 | 58 | assertPageIsLockForMe(pageId, _otherClient); 59 | assertTrue(_client.unlock("ns1:start")); 60 | assertPageIsUnlockForMe(pageId, _otherClient); 61 | } 62 | 63 | @org.junit.Test 64 | public void iCanLockOrUnlockSeveralPagesAtOnce() throws Exception{ 65 | //1st round: lock some pages and unlock some already unlock pages 66 | List pagesToLock = new ArrayList(); 67 | pagesToLock.add("ns2:p1"); 68 | pagesToLock.add("ns2:p2"); 69 | List pagesToUnlock = new ArrayList(); 70 | pagesToUnlock.add("ns2:p3"); 71 | pagesToUnlock.add("ns2:p4"); 72 | 73 | 74 | _client.setLocks(pagesToLock, pagesToUnlock); 75 | assertPagesAreLockForMe(pagesToLock, _otherClient); 76 | assertPagesAreUnlockForMe(pagesToUnlock, _otherClient); 77 | 78 | //2nd round: lock some pages, some of which are already locked. Play with unlock too 79 | pagesToLock = new ArrayList(); 80 | pagesToLock.add("ns2:p1"); 81 | pagesToLock.add("ns2:p3"); 82 | pagesToUnlock = new ArrayList(); 83 | pagesToUnlock.add("ns2:p2"); 84 | pagesToUnlock.add("ns2:p4"); 85 | 86 | 87 | _client.setLocks(pagesToLock, pagesToUnlock); 88 | assertPagesAreLockForMe(pagesToLock, _otherClient); 89 | assertPagesAreUnlockForMe(pagesToUnlock, _otherClient); 90 | } 91 | 92 | //This doesn't really test the client, but it documents Dokuwiki's behavior, 93 | //hence it documents a non-intuitive behavior of the client 94 | @org.junit.Test 95 | public void iUnlockAutomaticallyWhenIWrite() throws Exception { 96 | String pageId = "ns1:start"; 97 | String initialContent = "init"; 98 | String addedContent1 = "added1"; 99 | String addedContent2 = "added2"; 100 | 101 | //Get a known state 102 | _client.putPage(pageId, initialContent); 103 | 104 | assertTrue(_client.lock(pageId)); 105 | 106 | //Now I write to let Dokuwiki unlock the page 107 | _client.appendPage(pageId, addedContent1); 108 | 109 | //And I make sure everyone may now write 110 | _otherClient.appendPage(pageId, addedContent2); 111 | String currentContent = _client.getPage(pageId); 112 | assertEquals(initialContent + addedContent1 + addedContent2, currentContent); 113 | } 114 | 115 | @org.junit.Test 116 | public void lockResult() throws Exception { 117 | Set emptySet = new HashSet(); 118 | 119 | //1st round: lock some pages and unlock some already unlocked pages 120 | List pagesToLock = new ArrayList(); 121 | pagesToLock.add("ns2:p1"); 122 | pagesToLock.add("ns2:p2"); 123 | List pagesToUnlock = new ArrayList(); 124 | pagesToUnlock.add("ns2:p3"); 125 | pagesToUnlock.add("ns2:p4"); 126 | 127 | LockResult expected = new LockResult(new HashSet(pagesToLock), emptySet, emptySet, new HashSet(pagesToUnlock)); 128 | LockResult actual = _client.setLocks(pagesToLock, pagesToUnlock); 129 | assertEquals(expected, actual); 130 | 131 | //2nd round: lock some pages, some of which are already locked. Play with unlock too 132 | pagesToLock = new ArrayList(); 133 | pagesToLock.add("ns2:p1"); 134 | pagesToLock.add("ns2:p3"); 135 | pagesToUnlock = new ArrayList(); 136 | pagesToUnlock.add("ns2:p2"); 137 | pagesToUnlock.add("ns2:p4"); 138 | 139 | Set locked = new HashSet(); 140 | locked.add("ns2:p1"); 141 | locked.add("ns2:p3"); 142 | Set unlocked = new HashSet(); 143 | unlocked.add("ns2:p2"); 144 | Set failedUnlock = new HashSet(); 145 | failedUnlock.add("ns2:p4"); 146 | 147 | expected = new LockResult(locked, emptySet, unlocked, failedUnlock); 148 | actual = _client.setLocks(pagesToLock, pagesToUnlock); 149 | assertEquals(expected, actual); 150 | } 151 | 152 | @org.junit.Test 153 | public void getFailedLockedAndUnlockedPages() throws Exception { 154 | Set emptySet = new HashSet(); 155 | 156 | _otherClient.lock("ns2:p1"); 157 | _otherClient.lock("ns2:p2"); 158 | 159 | List pagesToLock = new ArrayList(); 160 | pagesToLock.add("ns2:p1"); 161 | List pagesToUnlock = new ArrayList(); 162 | pagesToUnlock.add("ns2:p2"); 163 | 164 | 165 | LockResult expected = new LockResult(emptySet, new HashSet(pagesToLock), emptySet, new HashSet(pagesToUnlock)); 166 | LockResult actual = _client.setLocks(pagesToLock, pagesToUnlock); 167 | 168 | assertEquals(expected, actual); 169 | } 170 | } 171 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_AttachmentDetails.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.AttachmentDetails; 5 | 6 | public class Test_AttachmentDetails { 7 | @org.junit.Test 8 | public void toStringShouldntThrowNullRef(){ 9 | AttachmentDetails details = new AttachmentDetails(null, null, null, null, null, null, null, null); 10 | assertNotNull(details.toString()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_AttachmentInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.AttachmentInfo; 5 | 6 | public class Test_AttachmentInfo { 7 | @org.junit.Test 8 | public void toStringShouldntThrowNullRef(){ 9 | AttachmentInfo info = new AttachmentInfo(null, null, null); 10 | assertNotNull(info.toString()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_LinkInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.AttachmentDetails; 5 | import dw.xmlrpc.LinkInfo; 6 | 7 | public class Test_LinkInfo { 8 | @org.junit.Test 9 | public void equals(){ 10 | String link = "http://dokuwiki.org"; 11 | LinkInfo link1 = new LinkInfo("extern", link, link); 12 | LinkInfo link1bis = new LinkInfo(LinkInfo.Type.extern, link, link); 13 | LinkInfo link2 = new LinkInfo("local", "start", "http://mywiki?id=start"); 14 | 15 | assertTrue(link1.equals(link1bis)); 16 | assertFalse(link1.equals(link2)); 17 | assertFalse(link1bis.equals(link2)); 18 | 19 | assertTrue(link1bis.equals(link1)); 20 | assertFalse(link2.equals(link1)); 21 | assertFalse(link2.equals(link1bis)); 22 | 23 | assertFalse(link1.equals(null)); //case null 24 | assertFalse(link1.equals(new AttachmentDetails(null, null, null, null, null, null, null, null))); //Other kind of object 25 | } 26 | 27 | @org.junit.Test 28 | public void toStringShouldntThrowNullRef(){ 29 | LinkInfo link = new LinkInfo(LinkInfo.Type.local, null, null); 30 | link.toString(); 31 | } 32 | 33 | @org.junit.Test 34 | public void equalsLinkInfoHaveSameHashCode(){ 35 | LinkInfo link1 = new LinkInfo("local", "start", "http://something"); 36 | LinkInfo link2 = new LinkInfo("local", "start", "http://something"); 37 | assertEquals(link1.hashCode(), link2.hashCode()); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_LockResult.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.HashSet; 6 | import java.util.Set; 7 | import java.util.TreeSet; 8 | 9 | import dw.xmlrpc.LockResult; 10 | 11 | public class Test_LockResult { 12 | 13 | @org.junit.Test 14 | public void LockResultEquality(){ 15 | Set locked1 = new HashSet(); 16 | locked1.add("myPage"); 17 | Set locked2 = new TreeSet(); 18 | locked2.add("myPage"); 19 | Set locked3 = new HashSet(); 20 | locked3.add("yourPage"); 21 | 22 | LockResult res1 = BuildLockResult(locked1); 23 | LockResult res2 = BuildLockResult(locked2); 24 | LockResult res3 = BuildLockResult(locked3); 25 | 26 | assertTrue(res1.equals(res2)); 27 | assertFalse(res1.equals(res3)); 28 | assertFalse(res2.equals(res3)); 29 | 30 | assertFalse(res3.equals(res2)); 31 | assertFalse(res3.equals(res1)); 32 | assertTrue(res2.equals(res1)); 33 | 34 | assertTrue(res1.equals(res1)); 35 | assertFalse(res1.equals(null)); 36 | assertFalse(res1.equals(new Integer(1))); 37 | } 38 | 39 | @org.junit.Test 40 | public void equalsLockResultHaveSameHashCode(){ 41 | Set locked1 = new HashSet(); 42 | locked1.add("myPage"); 43 | Set locked2 = new TreeSet(); 44 | locked2.add("myPage"); 45 | 46 | LockResult result1 = BuildLockResult(locked1); 47 | LockResult result2 = BuildLockResult(locked2); 48 | 49 | assertEquals(result1.hashCode(), result2.hashCode()); 50 | } 51 | 52 | private LockResult BuildLockResult(Set locked){ 53 | Set emptySet = new HashSet(); 54 | return new LockResult(locked, emptySet, emptySet, emptySet); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_MediaChange.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.assertNotNull; 4 | import dw.xmlrpc.MediaChange; 5 | 6 | public class Test_MediaChange { 7 | @org.junit.Test 8 | public void toStringShouldntThrowNullRef(){ 9 | MediaChange change = new MediaChange(null, null, null, null, null, null); 10 | assertNotNull(change.toString()); 11 | } 12 | } 13 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_Page.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.Page; 5 | 6 | import java.util.Date; 7 | 8 | public class Test_Page { 9 | @org.junit.Test(expected=IllegalArgumentException.class) 10 | public void ShouldntAcceptToBuildWithNullId(){ 11 | new Page(null, 255, new Date(), 0); 12 | } 13 | 14 | @org.junit.Test 15 | public void toStringShouldntThrowNullRef(){ 16 | Page page = new Page("id", null, null, null); 17 | assertNotNull(page.toString()); 18 | } 19 | } 20 | -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_PageChange.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.PageChange; 5 | 6 | import java.util.Date; 7 | 8 | public class Test_PageChange { 9 | @org.junit.Test(expected=IllegalArgumentException.class) 10 | public void ShouldntAcceptToBuildWithNullId(){ 11 | new PageChange(null, 255, new Date(), 0,"author", 123456789); 12 | } 13 | 14 | @org.junit.Test 15 | public void toStringShouldntThrowNullRef(){ 16 | PageChange page = new PageChange("id", null, null, null, null, null); 17 | assertNotNull(page.toString()); 18 | } 19 | } -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_PageDW.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.PageDW; 5 | 6 | public class Test_PageDW { 7 | @org.junit.Test(expected=IllegalArgumentException.class) 8 | public void ShouldntAcceptToBuildWithNullId(){ 9 | new PageDW(null, 255, 123456789, 123456789, "123"); 10 | } 11 | 12 | @org.junit.Test 13 | public void toStringShouldntThrowNullRef(){ 14 | PageDW page = new PageDW("id", null, null, null, null); 15 | assertNotNull(page.toString()); 16 | } 17 | } -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_PageInfo.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Date; 6 | 7 | import dw.xmlrpc.PageInfo; 8 | 9 | public class Test_PageInfo { 10 | @org.junit.Test(expected=IllegalArgumentException.class) 11 | public void ShouldntAcceptToBuildWithNullId(){ 12 | new PageInfo(null, new Date(), "author", 123456789); 13 | } 14 | 15 | @org.junit.Test 16 | public void toStringShouldntThrowNullRef(){ 17 | PageInfo page = new PageInfo("id", null, null, null); 18 | assertNotNull(page.toString()); 19 | } 20 | } -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_PageVersion.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | 5 | import java.util.Date; 6 | 7 | import dw.xmlrpc.PageVersion; 8 | 9 | public class Test_PageVersion { 10 | @org.junit.Test(expected=IllegalArgumentException.class) 11 | public void ShouldntAcceptToBuildWithNullId(){ 12 | new PageVersion(null, "author", "127.0.0.1", "E", "summary", new Date(), 123456789); 13 | } 14 | 15 | @org.junit.Test 16 | public void toStringShouldntThrowNullRef(){ 17 | PageVersion page = new PageVersion("id", null, null, null, null, null, null); 18 | assertNotNull(page.toString()); 19 | } 20 | 21 | @org.junit.Test 22 | public void userAndAuthorReturnTheSameValue(){ 23 | PageVersion page = new PageVersion("id", "toto", null, null, null, null, null); 24 | assertEquals(page.user(), page.author()); 25 | } 26 | 27 | @org.junit.Test 28 | public void returnTheExpectedDate(){ 29 | Date date = new Date(); 30 | PageVersion page = new PageVersion("id", "author", "127.0.0.1", "E", "summary", new Date(), 123456789); 31 | assertEquals(date, page.lastModified()); 32 | } 33 | } -------------------------------------------------------------------------------- /src/test/java/dw/xmlrpc/utest/Test_SearchResult.java: -------------------------------------------------------------------------------- 1 | package dw.xmlrpc.utest; 2 | 3 | import static org.junit.Assert.*; 4 | import dw.xmlrpc.SearchResult; 5 | 6 | public class Test_SearchResult { 7 | @org.junit.Test(expected=IllegalArgumentException.class) 8 | public void ShouldntAcceptToBuildWithNullId(){ 9 | new SearchResult(null, "title", 123456789, 123456789, 3, "snippet", 1); 10 | } 11 | 12 | @org.junit.Test 13 | public void toStringShouldntThrowNullRef(){ 14 | SearchResult page = new SearchResult("id", null, null, null, null, null, null); 15 | assertNotNull(page.toString()); 16 | } 17 | } -------------------------------------------------------------------------------- /src/test/resources/README.md: -------------------------------------------------------------------------------- 1 | Running integration tests 2 | ========================= 3 | 4 | Tests will try to connect to an instance of Dokuwiki. 5 | To set up such an instance you should run the installTestEnvironment.sh script. 6 | You may need to run it as root since it will try to write files in your server filesystem and 7 | give ownership to its user. 8 | -------------------------------------------------------------------------------- /src/test/resources/installTestEnvironment.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash -e 2 | 3 | # Make sure we're in the directory where the script is 4 | if [ -L "$0" ] && [ -x $(which readlink) ]; then 5 | thisFile="$(readlink -mn "$0")" 6 | else 7 | thisFile="$0" 8 | fi 9 | cd "$(dirname "$thisFile")" 10 | 11 | #directory where Dokuwiki should be installed in order to be reachable at http://localhost 12 | serverFileSystemRoot=/var/www/html 13 | #Owner of the files (to make sure the instance of dokuwiki can ediable its pages) 14 | serverFileSystemOwner=www-data 15 | #Shouldn't be changed since itests try to connect to this url 16 | baseUrl=http://localhost 17 | dirNamePrefix=dokuwikiITestsForXmlRpcClient_ 18 | 19 | dwVersions="dokuwiki-2018-04-22a dokuwiki-2020-07-29" 20 | installDir=tmpForInstallation 21 | relativeTestFileDir=testEnvironment 22 | 23 | mkdir -p $installDir 24 | cd $installDir 25 | 26 | function runIndexer { 27 | # Must be called from a directory where are all the pages (to find out all the names) 28 | # The required environment variables must be set beforehand 29 | for f in $(find . -name "*txt"); do 30 | f=$(echo $f | cut -d '.' -f 2 | tr / :) 31 | wget -O /dev/null -q $baseUrl/$dirName/lib/exe/indexer.php?id=$f || wget -O /dev/null -q $baseUrl/$dirName/lib/exe/taskrunner.php?id=$f 32 | done 33 | } 34 | 35 | function runIndexerSeveralTimes { 36 | # run it several times (and sleep in between) because on some setups, one time only seems to not be enough 37 | runIndexer 38 | for i in {1..10}; do 39 | echo Indexer: $i/10 40 | sleep 1 41 | runIndexer 42 | done 43 | } 44 | 45 | function installFakeWiki { 46 | #Argument 1 is the name of the version of Dokuwiki to install 47 | #Argument 2 is optional. It can be "norpc". It asks for the setup of a particular wiki 48 | #Argument 3 is required if arg2 is provided. It overrides the destination name 49 | dwVersion=$1 50 | if [ $# -eq 3 ]; then 51 | typeOfWiki=$2 52 | customDestDir=$3 53 | else 54 | unset typeOfWiki 55 | unset customDestDir 56 | fi 57 | echo "Going to install $dwVersion" 58 | pushd . >/dev/null 59 | 60 | #Avoid downloading the tarball again if we already have it 61 | if [ ! -e $dwVersion.tgz ]; then 62 | echo " Starting to download $dwVersion.tgz" 63 | wget http://download.dokuwiki.org/src/dokuwiki/$dwVersion.tgz 64 | else 65 | echo " $dwVersion.tgz found. No need to download it again." 66 | fi 67 | 68 | rm -rf $dwVersion 69 | tar -xzf $dwVersion.tgz 70 | 71 | 72 | echo " Copying files to the server" 73 | dirName=${dirNamePrefix}${dwVersion} 74 | 75 | if [ $# -eq 3 ]; then 76 | destDir=$serverFileSystemRoot/$customDestDir 77 | echo " Installing in $destDir" 78 | else 79 | destDir=$serverFileSystemRoot/$dirName 80 | fi 81 | 82 | rm -rf $destDir 83 | cp -r $dwVersion $destDir 84 | 85 | echo " Configuring the wiki" 86 | cp ../$relativeTestFileDir/conf/* $destDir/conf 87 | rm -rf $destDir/data/pages 88 | cp -r ../$relativeTestFileDir/data/* $destDir/data 89 | chown -R $serverFileSystemOwner $destDir 90 | 91 | if [ x$typeOfWiki = xnorpc ]; then 92 | echo " Using conf to not accept rpc queries" 93 | cp ../$relativeTestFileDir/conf/local.disabled_rpc.php $destDir/conf/local.php 94 | fi 95 | 96 | echo " Reseting some mtimes" 97 | touch -t201212230020.00 $destDir/data/attic/rev/start.1356218400.txt.gz 98 | touch -t201212230020.11 $destDir/data/attic/rev/start.1356218411.txt.gz 99 | touch -t201212230020.19 $destDir/data/attic/rev/start.1356218419.txt.gz 100 | touch -t201212230020.19 $destDir/data/pages/rev/start.txt 101 | touch -t201308011800.00 $destDir/data/pages/nswithanotherns/otherns/page.txt 102 | touch -t201311040647.25 $destDir/data/pages/nssearch/start.txt 103 | touch -t201308011900.00 $destDir/data/pages/nssearch/page3.txt 104 | touch -t201212242111.00 $destDir/data/media/ro_for_tests/img1.gif 105 | 106 | echo " Running the indexer" 107 | cd ../$relativeTestFileDir/data/pages 108 | 109 | runIndexerSeveralTimes 110 | 111 | echo " Installed $dwVersion" 112 | popd >/dev/null 113 | } 114 | 115 | for dwVersion in $dwVersions; do 116 | installFakeWiki $dwVersion 117 | installFakeWiki $dwVersion norpc ${dirNamePrefix}${dwVersion}_noRpc 118 | done 119 | 120 | echo Done. 121 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/at.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/at.gif -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/conf/acl.auth.php: -------------------------------------------------------------------------------- 1 | # acl.auth.php 2 | # 3 | # Don't modify the lines above 4 | # 5 | # Access Control Lists 6 | # 7 | # Auto-generated by install script 8 | # Date: Sun, 16 Dec 2012 10:55:52 +0000 9 | * @ALL 0 10 | * norightsuser 0 11 | * @user 8 12 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/conf/local.disabled_rpc.php: -------------------------------------------------------------------------------- 1 | 3 | # Don't modify the lines above 4 | # 5 | # Userfile 6 | # 7 | # Format: 8 | # 9 | # login:passwordhash:Real Name:email:groups,comma,seperated 10 | 11 | 12 | xmlrpcuser:$1$0TQWcl7p$fsl5QHQMcJ1hN4pKpQkrB0:xmlrpcuser:xml@rpc:admin,user 13 | writeruser:$1$U7Eovyk4$JO.B.1x9SWUFhklKh7516.:writeruser:wri@ter:user 14 | norightsuser:$1$2fTAmWKY$zuoiU7ibDsUpbXFEP7l130:norightsuser:no@rights:untouchables 15 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/conf/wordblock.conf: -------------------------------------------------------------------------------- 1 | forbiddenword 2 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/attic/rev/start.1356218400.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/data/attic/rev/start.1356218400.txt.gz -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/attic/rev/start.1356218411.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/data/attic/rev/start.1356218411.txt.gz -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/attic/rev/start.1356218419.txt.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/data/attic/rev/start.1356218419.txt.gz -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/media/ro_for_tests/img1.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/data/media/ro_for_tests/img1.gif -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/meta/_dokuwiki.changes: -------------------------------------------------------------------------------- 1 | 1356218400 127.0.0.1 C rev:start someuser created 2 | 1356218411 127.0.0.1 E rev:start someuser 3 | 1356218419 127.0.0.1 E rev:start someuser 4 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/meta/_media.changes: -------------------------------------------------------------------------------- 1 | 1356383460 127.0.0.1 C ro_for_tests:img1.gif fifi updated my file 2 | 1356383462 127.0.0.1 D ro_for_tests:img2.gif riri some comment 3 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/meta/rev/start.changes: -------------------------------------------------------------------------------- 1 | 1356218400 127.0.0.1 C rev:start riri created 2 | 1356218411 127.0.0.1 E rev:start fifi edit 1 3 | 1356218419 127.0.0.1 E rev:start lulu edit 2 4 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/meta/rev/start.indexed: -------------------------------------------------------------------------------- 1 | 5 -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/meta/rev/start.meta: -------------------------------------------------------------------------------- 1 | a:2:{s:7:"current";a:7:{s:4:"date";a:2:{s:7:"created";i:1356218400;s:8:"modified";i:1356218419;}s:11:"last_change";a:7:{s:4:"date";i:1356218419;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"E";s:2:"id";s:9:"rev:start";s:4:"user";N;s:3:"sum";s:0:"";s:5:"extra";s:0:"";}s:4:"user";s:0:"";s:7:"creator";s:0:"";s:8:"internal";a:2:{s:5:"cache";b:1;s:3:"toc";b:1;}s:11:"description";a:1:{s:8:"abstract";s:11:"3rd version";}s:8:"relation";a:1:{s:10:"firstimage";s:0:"";}}s:10:"persistent";a:4:{s:4:"date";a:2:{s:7:"created";i:1356218400;s:8:"modified";i:1356218419;}s:11:"last_change";a:7:{s:4:"date";i:1356218419;s:2:"ip";s:9:"127.0.0.1";s:4:"type";s:1:"E";s:2:"id";s:9:"rev:start";s:4:"user";N;s:3:"sum";s:0:"";s:5:"extra";s:0:"";}s:4:"user";s:0:"";s:7:"creator";s:0:"";}} -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/links/start.txt: -------------------------------------------------------------------------------- 1 | * first link: [[http://dokuwiki.org]] 2 | * other one: http://github.com/gturri 3 | * [[ns1:dummy]] -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/ns1/dummy.txt: -------------------------------------------------------------------------------- 1 | dummy page inside ns1 -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/ns1/start.txt: -------------------------------------------------------------------------------- 1 | Index of ns1 -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nssearch/page1.txt: -------------------------------------------------------------------------------- 1 | Pellentesque fringilla, lectus in faucibus venenatis, ante purus imperdiet elit, at ornare augue lectus nec dui. -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nssearch/page2.txt: -------------------------------------------------------------------------------- 1 | Sed dui urna, posuere non tempor ac, condimentum nec ante. Vivamus risus justo, euismod eu ultricies dictum, accumsan ac libero -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nssearch/page3.txt: -------------------------------------------------------------------------------- 1 | ======Page 3 title====== 2 | 3 | Amet in hac habitasse platea dictumst. Phasellus eros purus, consectetur a pretium id, venenatis a est. Aenean magna ipsum, condimentum at pretium ut, porta sit amet sem. 4 | -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nssearch/start.txt: -------------------------------------------------------------------------------- 1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit. -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nswithanotherns/dummy.txt: -------------------------------------------------------------------------------- 1 | dummy -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nswithanotherns/otherns/page.txt: -------------------------------------------------------------------------------- 1 | page -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/nswithanotherns/start.txt: -------------------------------------------------------------------------------- 1 | start -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/rev/start.txt: -------------------------------------------------------------------------------- 1 | 3rd version -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/data/pages/singlepage/start.txt: -------------------------------------------------------------------------------- 1 | text after (time test) -------------------------------------------------------------------------------- /src/test/resources/testEnvironment/list-plus.gif: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gturri/dokuJClient/87dc4894c3bab468a1ca959555c79b46da950826/src/test/resources/testEnvironment/list-plus.gif --------------------------------------------------------------------------------