├── android-no-reg
├── app
│ ├── .gitignore
│ ├── proguard-rules.pro
│ └── build.gradle
├── settings.gradle
├── .gitignore
├── gradle
│ └── wrapper
│ │ └── gradle-wrapper.properties
├── test.sh
├── README
├── build.gradle
├── gradle.properties
├── gradlew.bat
└── gradlew
├── src
├── test
│ ├── resources
│ │ ├── testEnvironment
│ │ │ ├── data
│ │ │ │ ├── meta
│ │ │ │ │ ├── rev
│ │ │ │ │ │ ├── start.indexed
│ │ │ │ │ │ ├── start.changes
│ │ │ │ │ │ └── start.meta
│ │ │ │ │ ├── _media.changes
│ │ │ │ │ └── _dokuwiki.changes
│ │ │ │ ├── pages
│ │ │ │ │ ├── ns1
│ │ │ │ │ │ ├── start.txt
│ │ │ │ │ │ └── dummy.txt
│ │ │ │ │ ├── rev
│ │ │ │ │ │ └── start.txt
│ │ │ │ │ ├── nswithanotherns
│ │ │ │ │ │ ├── dummy.txt
│ │ │ │ │ │ ├── start.txt
│ │ │ │ │ │ └── otherns
│ │ │ │ │ │ │ └── page.txt
│ │ │ │ │ ├── singlepage
│ │ │ │ │ │ └── start.txt
│ │ │ │ │ ├── nssearch
│ │ │ │ │ │ ├── start.txt
│ │ │ │ │ │ ├── page1.txt
│ │ │ │ │ │ ├── page2.txt
│ │ │ │ │ │ └── page3.txt
│ │ │ │ │ └── links
│ │ │ │ │ │ └── start.txt
│ │ │ │ ├── media
│ │ │ │ │ └── ro_for_tests
│ │ │ │ │ │ └── img1.gif
│ │ │ │ └── attic
│ │ │ │ │ └── rev
│ │ │ │ │ ├── start.1356218400.txt.gz
│ │ │ │ │ ├── start.1356218411.txt.gz
│ │ │ │ │ └── start.1356218419.txt.gz
│ │ │ ├── conf
│ │ │ │ ├── wordblock.conf
│ │ │ │ ├── acl.auth.php
│ │ │ │ ├── plugins.local.php
│ │ │ │ ├── users.auth.php
│ │ │ │ ├── local.php
│ │ │ │ └── local.disabled_rpc.php
│ │ │ ├── at.gif
│ │ │ └── list-plus.gif
│ │ ├── README.md
│ │ └── installTestEnvironment.sh
│ └── java
│ │ └── dw
│ │ ├── cli
│ │ ├── itest
│ │ │ ├── Test_PermissionLessUser.java
│ │ │ └── TestHelper.java
│ │ ├── commands
│ │ │ └── itest
│ │ │ │ ├── Test_BackLinksGetter.java
│ │ │ │ ├── Test_PageInfoGetter.java
│ │ │ │ ├── Test_TitleGetter.java
│ │ │ │ ├── Test_VersionGetter.java
│ │ │ │ ├── Test_RPCVersionSupportedGetter.java
│ │ │ │ ├── Test_AclChecker.java
│ │ │ │ ├── Test_Version.java
│ │ │ │ ├── Test_PageInfoVersionGetter.java
│ │ │ │ ├── Test_XMLRPCAPIVersionGetter.java
│ │ │ │ ├── Test_RecentChangesGetter.java
│ │ │ │ ├── Test_AttachmentInfoGetter.java
│ │ │ │ ├── Test_RecentMediaChangesGetter.java
│ │ │ │ ├── Test_TimeGetter.java
│ │ │ │ ├── Test_PageVersionGetter.java
│ │ │ │ ├── Test_PageHtmlGetter.java
│ │ │ │ ├── Test_LinksLister.java
│ │ │ │ ├── Test_AttachmentReader.java
│ │ │ │ ├── Test_PageVersionsGetter.java
│ │ │ │ ├── Test_Exception.java
│ │ │ │ ├── Test_Searcher.java
│ │ │ │ ├── Test_AclChanger.java
│ │ │ │ ├── Test_PageListGetter.java
│ │ │ │ ├── Test_getAttachment.java
│ │ │ │ ├── Test_AllPagesGetter.java
│ │ │ │ ├── Test_PageAppender.java
│ │ │ │ ├── Test_PageGetterAndPutter.java
│ │ │ │ ├── Test_LocksSetter.java
│ │ │ │ ├── Test_HelpPrinter.java
│ │ │ │ └── Test_AttachmentPutterAndDeleter.java
│ │ └── utest
│ │ │ ├── Test_CliOptions.java
│ │ │ ├── MockPasswordReader.java
│ │ │ ├── Test_PagePutter.java
│ │ │ └── Test_OptionParser.java
│ │ └── xmlrpc
│ │ ├── utest
│ │ ├── Test_AttachmentInfo.java
│ │ ├── Test_MediaChange.java
│ │ ├── Test_AttachmentDetails.java
│ │ ├── Test_PageDW.java
│ │ ├── Test_Page.java
│ │ ├── Test_PageInfo.java
│ │ ├── Test_SearchResult.java
│ │ ├── Test_PageChange.java
│ │ ├── Test_PageVersion.java
│ │ ├── Test_LinkInfo.java
│ │ └── Test_LockResult.java
│ │ └── itest
│ │ ├── Test_Cookies.java
│ │ ├── TestHelper.java
│ │ ├── Test_AclChanger.java
│ │ ├── TestParams.java
│ │ ├── Test_BadQueries.java
│ │ └── Test_Lock.java
└── main
│ ├── resources
│ ├── application.properties
│ └── dokujclient
│ └── java
│ └── dw
│ ├── xmlrpc
│ ├── exception
│ │ ├── DokuPageDoesNotExistException.java
│ │ ├── DokuAttachmentUploadException.java
│ │ ├── DokuMisConfiguredWikiException.java
│ │ ├── DokuTimeoutException.java
│ │ ├── DokuMethodDoesNotExistsException.java
│ │ ├── DokuNoChangesException.java
│ │ ├── DokuBadUrlException.java
│ │ ├── DokuPageLockedException.java
│ │ ├── DokuDeleteAttachmentException.java
│ │ ├── DokuDistantFileDoesntExistException.java
│ │ ├── DokuInvalidTimeStampException.java
│ │ ├── DokuEmptyNewPageException.java
│ │ ├── DokuException.java
│ │ ├── DokuAttachmentStillReferenced.java
│ │ ├── DokuUnknownException.java
│ │ ├── DokuWordblockException.java
│ │ ├── DokuIncompatibleVersionException.java
│ │ └── DokuUnauthorizedException.java
│ ├── AttachmentInfo.java
│ ├── PageDW.java
│ ├── Page.java
│ ├── CoreClientFactory.java
│ ├── PageInfo.java
│ ├── CoreClient.java
│ ├── LinkInfo.java
│ ├── SearchResult.java
│ ├── MediaChange.java
│ ├── DokuJClientConfig.java
│ ├── PageChange.java
│ ├── LockResult.java
│ ├── Locker.java
│ ├── AttachmentDetails.java
│ ├── PageVersion.java
│ ├── ExceptionConverter.java
│ ├── Attacher.java
│ └── ObjectConverter.java
│ └── cli
│ ├── commands
│ ├── TitleGetter.java
│ ├── TimeGetter.java
│ ├── VersionGetter.java
│ ├── XMLRPCAPIVersionGetter.java
│ ├── RPCVersionSupportedGetter.java
│ ├── PageGetter.java
│ ├── AclChecker.java
│ ├── SimpleCommand.java
│ ├── BackLinksGetter.java
│ ├── PageVersionGetter.java
│ ├── AllPageGetter.java
│ ├── LinksLister.java
│ ├── CliVersion.java
│ ├── AttachmentInfoGetter.java
│ ├── ItemListToStringCommand.java
│ ├── RecentMediaChangesGetter.java
│ ├── RecentChangesGetter.java
│ ├── AttachmentDeleter.java
│ ├── AttachmentGetter.java
│ ├── PageHtmlGetter.java
│ ├── AttachmentPutter.java
│ ├── PageVersionsGetter.java
│ ├── AttachmentReader.java
│ ├── PageInfoGetter.java
│ ├── HelpPrinter.java
│ ├── LocksSetter.java
│ ├── AclChanger.java
│ ├── PageListGetter.java
│ ├── PagePutter.java
│ └── Searcher.java
│ ├── Output.java
│ ├── ParseOptionException.java
│ ├── PasswordReader.java
│ ├── CliOptions.java
│ ├── StdinReader.java
│ ├── Program.java
│ ├── Command.java
│ └── CommandFactory.java
├── .gitignore
├── dokujclient_completion
├── man
├── build_man.sh
├── man.footer.txt
└── man.header.txt
├── scripts
└── descriptorRef.xml
├── Changelog
├── NOTICE.txt
└── .github
└── workflows
└── codeql-analysis.yml
/android-no-reg/app/.gitignore:
--------------------------------------------------------------------------------
1 | /build
2 |
--------------------------------------------------------------------------------
/android-no-reg/settings.gradle:
--------------------------------------------------------------------------------
1 | include ':app'
2 |
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/meta/rev/start.indexed:
--------------------------------------------------------------------------------
1 | 5
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/conf/wordblock.conf:
--------------------------------------------------------------------------------
1 | forbiddenword
2 |
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/ns1/start.txt:
--------------------------------------------------------------------------------
1 | Index of ns1
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/rev/start.txt:
--------------------------------------------------------------------------------
1 | 3rd version
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/nswithanotherns/dummy.txt:
--------------------------------------------------------------------------------
1 | dummy
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/nswithanotherns/start.txt:
--------------------------------------------------------------------------------
1 | start
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/ns1/dummy.txt:
--------------------------------------------------------------------------------
1 | dummy page inside ns1
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/nswithanotherns/otherns/page.txt:
--------------------------------------------------------------------------------
1 | page
--------------------------------------------------------------------------------
/src/main/resources/application.properties:
--------------------------------------------------------------------------------
1 | application.version=${project.version}
2 |
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/singlepage/start.txt:
--------------------------------------------------------------------------------
1 | text after (time test)
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/data/pages/nssearch/start.txt:
--------------------------------------------------------------------------------
1 | Lorem ipsum dolor sit amet, consectetur adipiscing elit.
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/at.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturri/dokuJClient/HEAD/src/test/resources/testEnvironment/at.gif
--------------------------------------------------------------------------------
/src/test/resources/testEnvironment/list-plus.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturri/dokuJClient/HEAD/src/test/resources/testEnvironment/list-plus.gif
--------------------------------------------------------------------------------
/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]]
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/media/ro_for_tests/img1.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturri/dokuJClient/HEAD/src/test/resources/testEnvironment/data/media/ro_for_tests/img1.gif
--------------------------------------------------------------------------------
/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/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/attic/rev/start.1356218400.txt.gz:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/gturri/dokuJClient/HEAD/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/HEAD/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/HEAD/src/test/resources/testEnvironment/data/attic/rev/start.1356218419.txt.gz
--------------------------------------------------------------------------------
/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/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 |
--------------------------------------------------------------------------------
/.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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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/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/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/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/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/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/resources/testEnvironment/conf/plugins.local.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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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_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_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/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/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/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/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/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/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/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/test/resources/testEnvironment/conf/local.php:
--------------------------------------------------------------------------------
1 | 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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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/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:"";}}
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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/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_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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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/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 |
--------------------------------------------------------------------------------
/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/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/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/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/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/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/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/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/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/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