Compare commits
4 Commits
feature/po
...
master
Author | SHA1 | Date | |
---|---|---|---|
|
c0f33eb1a5 | ||
|
ab3de22275 | ||
|
1779a964ca | ||
|
bd462e0450 |
10
pom.xml
10
pom.xml
@ -25,12 +25,12 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
<parent>
|
||||
<groupId>org.nanoboot.essential</groupId>
|
||||
<artifactId>nanoboot-parent</artifactId>
|
||||
<version>0.1.0-SNAPSHOT</version>
|
||||
<version>0.1.0</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
<packaging>pom</packaging>
|
||||
|
||||
<name>Power Framework</name>
|
||||
@ -54,19 +54,15 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
<module>power-log</module>
|
||||
<module>power-io</module>
|
||||
<module>power-web</module>
|
||||
|
||||
<module>power-wiki</module>
|
||||
|
||||
<module>power-sql</module>
|
||||
<module>power-db</module>
|
||||
<module>power-persistence</module>
|
||||
<module>power-svg</module>
|
||||
|
||||
<module>power-view</module>
|
||||
<module>power-xml</module>
|
||||
<module>power-reflection</module>
|
||||
<module>power-mail</module>
|
||||
<module>power-blockchain</module>
|
||||
|
||||
<module>power-security</module>
|
||||
<!-- TODO:
|
||||
@ -76,7 +72,7 @@ Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
</modules>
|
||||
|
||||
<properties>
|
||||
<power.version>2.0.0-SNAPSHOT</power.version>
|
||||
<power.version>2.0.0</power.version>
|
||||
<checkstyle.skip>true</checkstyle.skip><!-- TODO: make false-->
|
||||
</properties>
|
||||
|
||||
|
@ -1,122 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
power-framework: Java library with many purposes of usage.
|
||||
Copyright (C) 2016-2022 the original author or authors.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation;
|
||||
version 2.1 of the License only.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-blockchain</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Power Blockchain</name>
|
||||
<description>Blockchain library</description>
|
||||
|
||||
<build>
|
||||
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-assembly-plugin</artifactId>
|
||||
<version>3.3.0</version>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.nanoboot.powerframework.blockchain.orig.core.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
<descriptorRefs>
|
||||
<descriptorRef>jar-with-dependencies</descriptorRef>
|
||||
</descriptorRefs>
|
||||
</configuration>
|
||||
<executions>
|
||||
<execution>
|
||||
<id>make-assembly</id> <!-- this is used for inheritance merges -->
|
||||
<phase>package</phase> <!-- bind to the packaging phase -->
|
||||
<goals>
|
||||
<goal>single</goal>
|
||||
</goals>
|
||||
</execution>
|
||||
</executions>
|
||||
</plugin>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-jar-plugin</artifactId>
|
||||
<configuration>
|
||||
<archive>
|
||||
<manifest>
|
||||
<mainClass>org.nanoboot.powerframework.blockchain.orig.core.Main</mainClass>
|
||||
</manifest>
|
||||
</archive>
|
||||
</configuration>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
|
||||
<dependencies>
|
||||
<!-- Power dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-core</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-time</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-json</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-random</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-security</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Other dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.projectlombok</groupId>
|
||||
<artifactId>lombok</artifactId>
|
||||
<version>1.18.10</version>
|
||||
<scope>compile</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
@ -1,34 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
module powerframework.blockchain {
|
||||
requires lombok;
|
||||
requires powerframework.core;
|
||||
requires powerframework.time;
|
||||
requires powerframework.json;
|
||||
requires powerframework.random;
|
||||
requires powerframework.security;
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.core.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockDeserializer {
|
||||
Block deserialize(String serializedBlock);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.core.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockSerializer {
|
||||
String serialize(Block block);
|
||||
}
|
@ -1,132 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.core;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.api.BlockSerializer;
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
import org.nanoboot.powerframework.json.JsonObjectSerializable;
|
||||
import org.nanoboot.powerframework.security.hash.api.HashCalculator;
|
||||
import org.nanoboot.powerframework.time.moment.UniversalDateTime;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class Block implements JsonObjectSerializable {
|
||||
private static final String BLOCKCHAIN_PROTOCOL = "blockchainProtocol";
|
||||
|
||||
private static final String HEIGHT = "height";
|
||||
|
||||
private static final String PREVIOUS_HASH = "previousHash";
|
||||
private static final String TIMESTAMP = "timestamp";
|
||||
private static final String DIFFICULTY = "difficulty";
|
||||
private static final String DATA = "data";
|
||||
private static final String NONCE = "nonce";
|
||||
|
||||
@Getter
|
||||
private final BlockchainProtocol blockchainProtocol;
|
||||
|
||||
@Getter
|
||||
private final long height;
|
||||
@Getter
|
||||
private final String previousHash;
|
||||
@Getter
|
||||
private final String timeStamp;
|
||||
@Getter
|
||||
private final String difficultyTarget;
|
||||
@Getter
|
||||
private final byte[] data;
|
||||
|
||||
@Getter
|
||||
private long nonce;
|
||||
|
||||
//
|
||||
@Getter
|
||||
private String hash = null;
|
||||
|
||||
//Block Constructor.
|
||||
public Block(BlockchainProtocol blockchainProtocol,
|
||||
long height,
|
||||
String previousHash,
|
||||
String difficultyTarget,
|
||||
byte[] data) {
|
||||
this.blockchainProtocol=blockchainProtocol;
|
||||
this.height = height;
|
||||
this.previousHash = previousHash;
|
||||
this.timeStamp = UniversalDateTime.now().toString();
|
||||
this.difficultyTarget = difficultyTarget;
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
//Calculate new hash based on blocks contents
|
||||
public String calculateHash(HashCalculator hashCalculator, BlockSerializer blockSerializer) {
|
||||
String serializedBlock = blockSerializer.serialize(this);
|
||||
String calculatedhash = hashCalculator.hash(serializedBlock);
|
||||
return calculatedhash;
|
||||
}
|
||||
|
||||
//Increases nonce value until hash target is reached.
|
||||
public void mineBlock(HashCalculator hashCalculator, BlockSerializer blockSerializer) {
|
||||
String target = this.difficultyTarget;
|
||||
|
||||
for (long i = 0; i <= Long.MAX_VALUE; i++) {
|
||||
this.nonce = i;
|
||||
if (nonce == Integer.MAX_VALUE) {
|
||||
throw new BlockChainException("Nonce was not found.");
|
||||
}
|
||||
if (nonce % 1000000 == 0) {
|
||||
System.out.println("Nonce # " + nonce);
|
||||
}
|
||||
|
||||
|
||||
|
||||
String hash = calculateHash(hashCalculator, blockSerializer);
|
||||
|
||||
if (hashCalculator.compareHexNumbers(hash, this.getDifficultyTarget()) <= 0) {
|
||||
System.out.println("Found nonce: " + nonce + " A new block was just mined: " + getHash() + "\n" /*+ block.toJsonObject().toPrettyString()*/);
|
||||
System.out.println("Block Mined!!! : " + hash);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJsonObject() {
|
||||
|
||||
JsonObject jo = new JsonObject();
|
||||
|
||||
jo.add(BLOCKCHAIN_PROTOCOL, blockchainProtocol.toJsonObject());
|
||||
|
||||
jo.add(HEIGHT, height);
|
||||
|
||||
jo.add(PREVIOUS_HASH, previousHash);
|
||||
jo.add(TIMESTAMP, timeStamp);
|
||||
jo.add(DIFFICULTY, difficultyTarget);
|
||||
jo.add(DATA, new String(data));
|
||||
jo.add(NONCE, nonce);
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.core;
|
||||
|
||||
import org.nanoboot.powerframework.core.PowerException;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class BlockChainException extends PowerException {
|
||||
public BlockChainException(String msg) {
|
||||
super(msg);
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.core;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BlockchainEngine {
|
||||
@Getter
|
||||
private final String protocolName;
|
||||
private List<BlockchainEngineVersion> blockchainEngineVersionList = new ArrayList<>();
|
||||
}
|
@ -1,54 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.core;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.api.BlockSerializer;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BlockchainEngineVersion {
|
||||
@Getter
|
||||
private final String version;
|
||||
@Getter
|
||||
private final String hashCalculatorName;
|
||||
@Getter
|
||||
private final String targetDifficulty;
|
||||
@Getter
|
||||
private final BlockSerializer blockSerializer;
|
||||
@Getter
|
||||
private final long validFromBlock;
|
||||
@Getter
|
||||
private final long validUntilBlock;
|
||||
|
||||
public String getMayorVersion() {
|
||||
return version.split(("\\."))[0];
|
||||
}
|
||||
public String getMinorVersion() {
|
||||
return version.split(("\\."))[1];
|
||||
}
|
||||
}
|
@ -1,56 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.core;
|
||||
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
import org.nanoboot.powerframework.json.JsonObjectSerializable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BlockchainProtocol implements JsonObjectSerializable {
|
||||
private static final String PROTOCOL_NAME = "protocolName";
|
||||
private static final String PROTOCOL_MAYOR_VERSION = "protocolMayorVersion";
|
||||
private static final String PROTOCOL_MINOR_VERSION = "protocolMinorVersion";
|
||||
@Getter
|
||||
private final String protocolName;
|
||||
@Getter
|
||||
private final int protocolMayorVersion;
|
||||
@Getter
|
||||
private final int protocolMinorVersion;
|
||||
@Override
|
||||
public JsonObject toJsonObject() {
|
||||
|
||||
JsonObject jo = new JsonObject();
|
||||
|
||||
jo.add(PROTOCOL_NAME, protocolName);
|
||||
jo.add(PROTOCOL_MAYOR_VERSION, protocolMayorVersion);
|
||||
jo.add(PROTOCOL_MINOR_VERSION, protocolMinorVersion);
|
||||
|
||||
return jo;
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.api.BlockSerializer;
|
||||
import org.nanoboot.powerframework.blockchain.core.Block;
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class JsonBlockSerializer implements BlockSerializer {
|
||||
|
||||
@Override
|
||||
public String serialize(Block block) {
|
||||
JsonObject jsonObject = block.toJsonObject();
|
||||
return jsonObject.toMinimalString();
|
||||
}
|
||||
}
|
@ -1,45 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.api.BlockSerializer;
|
||||
import org.nanoboot.powerframework.blockchain.core.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class StringSerializer implements BlockSerializer {
|
||||
|
||||
public static final String SEPARATOR = "::";
|
||||
|
||||
@Override
|
||||
public String serialize(Block block) {
|
||||
return block.getBlockchainProtocol().toString() + SEPARATOR +
|
||||
block.getHeight() + SEPARATOR +
|
||||
block.getPreviousHash() + SEPARATOR +
|
||||
block.getTimeStamp() + SEPARATOR +
|
||||
block.getDifficultyTarget() + SEPARATOR +
|
||||
new String(block.getData()) + SEPARATOR +
|
||||
block.getNonce();
|
||||
}
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.api;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockData {
|
||||
String convertToString();
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockDeserializer {
|
||||
Block deserialize(String serializedBlock);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockFragment;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockType;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockMiner {
|
||||
Block mine(BlockFragment blockFragment, BlockType blockType);
|
||||
}
|
@ -1,33 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockSerializer {
|
||||
String serialize(Block block);
|
||||
}
|
@ -1,35 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.api;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockType;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public interface BlockValidator {
|
||||
BlockType getBlockType();
|
||||
void validate(Block block);
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockData;
|
||||
import org.nanoboot.powerframework.blockchain.core.BlockChainException;
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
import org.nanoboot.powerframework.json.JsonObjectSerializable;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class Block implements JsonObjectSerializable {
|
||||
public static final String BLOCK_TYPE_ID = "blockTypeId";
|
||||
public static final String BLOCK_HEADER = "blockHeader";
|
||||
public static final String BLOCK_DATA = "blockData";
|
||||
public static final String NONCE = "nonce";
|
||||
|
||||
@Getter
|
||||
private BlockHeader blockHeader;
|
||||
|
||||
@Getter
|
||||
private BlockData blockData;
|
||||
|
||||
private long nonce;
|
||||
|
||||
@Getter
|
||||
private String hash;
|
||||
@Getter
|
||||
private boolean locked = false;
|
||||
|
||||
@Getter
|
||||
private BlockType internalBlockType;
|
||||
|
||||
public Block(BlockHeader blockHeader, JsonObject additionBlockHeader, BlockData blockData) {
|
||||
this.blockHeader = blockHeader;
|
||||
|
||||
this.blockData = blockData;
|
||||
}
|
||||
|
||||
public void injectBlockType(BlockType blockType) {
|
||||
this.internalBlockType = blockType;
|
||||
}
|
||||
|
||||
public String calculateHashTest(long nonce) {
|
||||
this.nonce = nonce;
|
||||
String hashedSerializedBlock = internalCalculateHash();
|
||||
this.nonce = 0;//todo
|
||||
return hashedSerializedBlock;
|
||||
}
|
||||
|
||||
private String internalCalculateHash() {
|
||||
if (nonce == 0) {
|
||||
throw new BlockChainException("Nonce cannot be zero.");
|
||||
}
|
||||
if (locked) {
|
||||
throw new BlockChainException("This block is already locked. Cannot set nonce and calculate nonce.");
|
||||
}
|
||||
|
||||
if (internalBlockType == null) {
|
||||
throw new BlockChainException("internalBlockType was not injected.");
|
||||
}
|
||||
String serializedBlock = this.internalBlockType.getBlockSerializer().serialize(this);
|
||||
|
||||
String hashedSerializedBlock = this.internalBlockType.getHashCalculator().hash(serializedBlock);
|
||||
|
||||
//System.out.println("internalCalculateHash - hash for nonce " + nonce + " = " + hashedSerializedBlock);
|
||||
return hashedSerializedBlock;
|
||||
}
|
||||
|
||||
public void lock(long nonce) {
|
||||
this.nonce = nonce;
|
||||
String hashedSerializedBlock = internalCalculateHash();
|
||||
this.hash = hashedSerializedBlock;
|
||||
|
||||
this.locked = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JsonObject toJsonObject() {
|
||||
if (nonce == 0) {
|
||||
throw new BlockChainException("Nonce cannot be zero, if json object is created from this block instance.");
|
||||
}
|
||||
if (internalBlockType == null) {
|
||||
throw new BlockChainException("internalBlockType was not injected.");
|
||||
}
|
||||
JsonObject jo = new JsonObject();
|
||||
jo.add(BLOCK_TYPE_ID, internalBlockType.getBlockTypeId());
|
||||
jo.add(BLOCK_HEADER, blockHeader.toJsonObject());
|
||||
|
||||
jo.add(BLOCK_DATA, blockData.convertToString());
|
||||
jo.add(NONCE, nonce);
|
||||
return jo;
|
||||
}
|
||||
}
|
@ -1,100 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.core.BlockChainException;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class BlockChain {
|
||||
private String blockChainEngineName;
|
||||
private List<Block> blocks = new ArrayList<>();
|
||||
|
||||
public int getTotalHeight() {
|
||||
return blocks.size() - 1;
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return blocks.isEmpty();
|
||||
}
|
||||
|
||||
public Block getGenesisBlock() {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return getBlock(0);
|
||||
}
|
||||
|
||||
public Block getLastBlock() {
|
||||
if (isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
return getBlock(blocks.size() - 1);
|
||||
}
|
||||
|
||||
public List<Block> getLastXBlocks(int xCount) {
|
||||
List<Block> result = new ArrayList<>();
|
||||
|
||||
if (isEmpty()) {
|
||||
return result;
|
||||
}
|
||||
if (xCount <= blocks.size()) {
|
||||
for (Block b : blocks) {
|
||||
result.add(b);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
for (int i = blocks.size() - xCount; i <= (blocks.size() - 1); i++) {
|
||||
result.add(blocks.get(i));
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
public void addBlock(Block block) {
|
||||
if (!block.isLocked()) {
|
||||
throw new BlockChainException("Block is not locked. It cannot be added");
|
||||
}
|
||||
if (blocks.isEmpty() && block.getBlockHeader().getHeight() != 0) {
|
||||
throw new BlockChainException("New block is a genesis block, but its height is not zero.");
|
||||
}
|
||||
Block lastBlock = getLastBlock();
|
||||
String previousBlockHash = lastBlock == null ? "0" : lastBlock.getHash();
|
||||
|
||||
if (!block.getBlockHeader().getPreviousHash().equals(previousBlockHash)) {
|
||||
throw new BlockChainException("Block previous hash is not equal to the hash of the previous block. It cannot be added to the blockchain.");
|
||||
}
|
||||
blocks.add(block);
|
||||
}
|
||||
|
||||
public Block getBlock(int blockHeight) {
|
||||
if (blockHeight >= blocks.size()) {
|
||||
throw new BlockChainException("There is no block with height " + blockHeight);
|
||||
}
|
||||
return blocks.get(blockHeight);
|
||||
}
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.core.BlockChainException;
|
||||
import lombok.AllArgsConstructor;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public abstract class BlockChainEngine {
|
||||
private String blockChainEngineName;
|
||||
protected BlockChain blockChain;
|
||||
protected BlockTypeVersionList blockTypeVersionList;
|
||||
|
||||
public void addData(String data) {
|
||||
BlockFragment blockFragment = createNewBlockFragment(data);
|
||||
BlockType blockType = blockTypeVersionList.findBlockType(blockFragment.getBlockHeader().getBlockTypeId());
|
||||
if (blockType == null) {
|
||||
throw new BlockChainException("blockType " + blockFragment.getBlockHeader().getBlockTypeId() + " was not found.");
|
||||
}
|
||||
|
||||
Block block = blockType.getBlockMiner().mine(blockFragment, blockType);
|
||||
addBlock(block);
|
||||
}
|
||||
|
||||
public abstract BlockFragment createNewBlockFragment(String data);
|
||||
|
||||
public void addBlock(Block newBlock) {
|
||||
blockChain.addBlock(newBlock);
|
||||
}
|
||||
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockData;
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BlockFragment {
|
||||
@Getter
|
||||
private BlockHeader blockHeader;
|
||||
|
||||
@Getter
|
||||
private BlockData blockData;
|
||||
|
||||
}
|
@ -1,60 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
import org.nanoboot.powerframework.json.JsonObjectSerializable;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
@AllArgsConstructor
|
||||
public class BlockHeader implements JsonObjectSerializable {
|
||||
public static final String BLOCK_TYPE_ID = "blockTypeId";
|
||||
public static final String HEIGHT = "height";
|
||||
public static final String TIME_STAMP = "timeStamp";
|
||||
public static final String PREVIOUS_HASH = "previousHash";
|
||||
@Getter
|
||||
private String blockTypeId;
|
||||
@Getter
|
||||
private int height;
|
||||
@Getter
|
||||
private long timeStamp;
|
||||
@Getter
|
||||
private String previousHash;
|
||||
@Getter
|
||||
private String difficulty;
|
||||
|
||||
public JsonObject toJsonObject() {
|
||||
JsonObject jo = new JsonObject();
|
||||
jo.add(BLOCK_TYPE_ID, blockTypeId);
|
||||
jo.add(HEIGHT, height);
|
||||
jo.add(TIME_STAMP, timeStamp);
|
||||
jo.add(PREVIOUS_HASH, previousHash);
|
||||
return jo;
|
||||
}
|
||||
|
||||
}
|
@ -1,55 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockDeserializer;
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockMiner;
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockSerializer;
|
||||
import org.nanoboot.powerframework.security.hash.api.HashCalculator;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
@AllArgsConstructor
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class BlockType {
|
||||
@Getter
|
||||
private String type;
|
||||
@Getter
|
||||
private int mayorVersion;
|
||||
@Getter
|
||||
private int minorVersion;
|
||||
@Getter
|
||||
private HashCalculator hashCalculator;
|
||||
@Getter
|
||||
private BlockSerializer blockSerializer;
|
||||
@Getter
|
||||
private BlockDeserializer blockDeserializer;
|
||||
@Getter
|
||||
BlockMiner blockMiner;
|
||||
public String getBlockTypeId() {
|
||||
return type + ":" + mayorVersion + ":" + minorVersion;
|
||||
}
|
||||
}
|
@ -1,47 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.base;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class BlockTypeVersionList {
|
||||
private Map<String, BlockType> blockTypes;
|
||||
|
||||
public BlockTypeVersionList(List<BlockType> blockTypesList) {
|
||||
blockTypes = new HashMap<>();
|
||||
for (BlockType bt : blockTypesList) {
|
||||
blockTypes.put(bt.getBlockTypeId(), bt);
|
||||
}
|
||||
}
|
||||
|
||||
public BlockType findBlockType(String blockTypeId) {
|
||||
return blockTypes.get(blockTypeId);
|
||||
}
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.cash;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class Transaction {
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.cash;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class TransactionValidator {
|
||||
}
|
@ -1,29 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.cash;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class Wallet {
|
||||
}
|
@ -1,48 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.core;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockChain;
|
||||
import org.nanoboot.powerframework.blockchain.orig.impl.TestCash_BlockChainEngine;
|
||||
import org.nanoboot.powerframework.random.generators.linearcongruent.combined.w5.W5RandomGenerator;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
// HashCalculator.main(null);
|
||||
//
|
||||
// if(true) return;
|
||||
BlockChain blockChain = new BlockChain();
|
||||
TestCash_BlockChainEngine bce = new TestCash_BlockChainEngine(blockChain);
|
||||
bce.addData("ahoj");
|
||||
bce.addData("pavle");
|
||||
bce.addData("leo");
|
||||
for(int i =0;i<100000000;i++){
|
||||
bce.addData(W5RandomGenerator.getStaticInstance().nextText(8));
|
||||
}
|
||||
|
||||
}
|
||||
}
|
@ -1,41 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockSerializer;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
import org.nanoboot.powerframework.json.JsonObject;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class JsonBlockSerializer implements BlockSerializer {
|
||||
|
||||
@Override
|
||||
public String serialize(Block block) {
|
||||
JsonObject jsonObject = block.toJsonObject();
|
||||
//System.out.println(jsonObject.toMinimalString());
|
||||
return jsonObject.toMinimalString();
|
||||
}
|
||||
}
|
@ -1,40 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockData;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Getter;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
@AllArgsConstructor
|
||||
public class SimpleBlockData implements BlockData {
|
||||
@Getter
|
||||
private final String string;
|
||||
@Override
|
||||
public String convertToString() {
|
||||
return string;
|
||||
}
|
||||
}
|
@ -1,36 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockData;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockHeader;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class TestCash_1_0_Block extends Block {
|
||||
public TestCash_1_0_Block(BlockHeader blockHeader, BlockData blockData) {
|
||||
super(blockHeader, null, blockData);
|
||||
}
|
||||
}
|
@ -1,95 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.api.BlockMiner;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.Block;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockFragment;
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockType;
|
||||
import org.nanoboot.powerframework.blockchain.core.BlockChainException;
|
||||
import org.nanoboot.powerframework.security.hash.api.HashCalculator;
|
||||
import org.nanoboot.powerframework.time.duration.Duration;
|
||||
import org.nanoboot.powerframework.time.duration.StopWatch;
|
||||
import org.nanoboot.powerframework.time.utils.TimeUnit;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class TestCash_1_0_BlockMiner implements BlockMiner {
|
||||
public static List<Integer> lastFiveBlockMiningTimesInMilliseconds = new ArrayList<>();
|
||||
|
||||
@Override
|
||||
public Block mine(BlockFragment blockFragment, BlockType blockType) {
|
||||
|
||||
TestCash_1_0_Block block = new TestCash_1_0_Block(blockFragment.getBlockHeader(), blockFragment.getBlockData());
|
||||
block.injectBlockType(blockType);
|
||||
|
||||
////System.out.println("Starting mining block # " + block.getBlockHeader().getHeight());
|
||||
//System.out.println("Note: One block should be mined in 1 minute, but the last time was " + countOfSecondsToMineLastBlock + " second(s).");
|
||||
//System.out.println("Starting mining block # " + block.getBlockHeader().getHeight());
|
||||
StopWatch sw = new StopWatch();
|
||||
|
||||
//System.out.println("start: " + UniversalDateTime.now().toString());
|
||||
sw.start();
|
||||
|
||||
////System.out.println("Searching hash equal or less than " + block.getBlockHeader().getDifficulty());
|
||||
for (long nonce = 1; nonce <= Long.MAX_VALUE; nonce++) {
|
||||
if (nonce == Integer.MAX_VALUE) {
|
||||
throw new BlockChainException("Nonce was not found.");
|
||||
}
|
||||
if (nonce % 1000000 == 0) {
|
||||
System.out.println("Nonce # " + nonce);
|
||||
}
|
||||
|
||||
|
||||
HashCalculator hashCalculator = block.getInternalBlockType().getHashCalculator();
|
||||
String hash = block.calculateHashTest(nonce);
|
||||
//System.err.println("hashCalculator.compareHexNumbers("+hash+"+, block.getBlockHeader().getDifficulty()="+block.getBlockHeader().getDifficulty()+")="+hashCalculator.compareHexNumbers(hash, block.getBlockHeader().getDifficulty()));
|
||||
if (hashCalculator.compareHexNumbers(hash, block.getBlockHeader().getDifficulty()) <= 0) {
|
||||
|
||||
//System.err.println("hashCalculator.compareHexNumbers("+hash+"+, block.getBlockHeader().getDifficulty()="+block.getBlockHeader().getDifficulty()+")="+hashCalculator.compareHexNumbers(hash, block.getBlockHeader().getDifficulty()));
|
||||
block.lock(nonce);
|
||||
////System.out.println("Found nonce: " + nonce + " A new block was just mined: " + block.getHash() + "\n" /*+ block.toJsonObject().toPrettyString()*/);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
//System.out.println("end: " + UniversalDateTime.now().toString());
|
||||
sw.stop();
|
||||
Duration lastDuration = sw.getCurrentDuration();
|
||||
if (lastFiveBlockMiningTimesInMilliseconds.size() == 1000) {
|
||||
lastFiveBlockMiningTimesInMilliseconds.remove(0);
|
||||
}
|
||||
lastFiveBlockMiningTimesInMilliseconds.add((int) lastDuration.toTotal(TimeUnit.MILLISECOND));
|
||||
//countOfSecondsToMineLastBlock = (int) lastDuration.toTotal(TimeUnit.SECOND);
|
||||
if (block.getBlockHeader().getHeight() % 100 == 0)
|
||||
System.out.println("Mining block " + block.getBlockHeader().getHeight() + " + took " + lastDuration.toString() + " .");
|
||||
return block;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -1,39 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.BlockType;
|
||||
import org.nanoboot.powerframework.security.hash.locator.HashCalculatorLocator;
|
||||
import org.nanoboot.powerframework.security.hash.locator.HashImpl;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class TestCash_1_0_BlockType extends BlockType {
|
||||
private static final String TYPE = "test_cash";
|
||||
private static final int MAYOR_VERSION = 1;
|
||||
private static final int MINOR_VERSION = 0;
|
||||
public TestCash_1_0_BlockType() {
|
||||
super(TYPE, MAYOR_VERSION, MINOR_VERSION, HashCalculatorLocator.locate(HashImpl.SHA_256), new JsonBlockSerializer(), null, new TestCash_1_0_BlockMiner());
|
||||
}
|
||||
}
|
@ -1,136 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.blockchain.orig.impl;
|
||||
|
||||
import org.nanoboot.powerframework.blockchain.orig.base.*;
|
||||
import org.nanoboot.powerframework.security.hash.api.HashCalculator;
|
||||
import org.nanoboot.powerframework.time.duration.Duration;
|
||||
import org.nanoboot.powerframework.time.moment.UniversalDateTime;
|
||||
import org.nanoboot.powerframework.time.utils.TimeUnit;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.BigInteger;
|
||||
import java.util.List;
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class TestCash_BlockChainEngine extends BlockChainEngine {
|
||||
|
||||
public static final String TEST_CASH = "TestCash";
|
||||
public static final int COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK = 10;
|
||||
//public static final String DEFAULT_DIFFICULTY = "0fffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff";
|
||||
public static final String DEFAULT_DIFFICULTY = "00184f329993e8d38cd0a31969b54367b4fc5af6ed86d827c1343dbf8b66a4a5";
|
||||
|
||||
public static float DIFFICULTY_PERCENT_CHANGE = (float) 1;
|
||||
|
||||
public TestCash_BlockChainEngine(BlockChain blockChain) {
|
||||
super(TEST_CASH, blockChain, new BlockTypeVersionList(List.of(new TestCash_1_0_BlockType())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockFragment createNewBlockFragment(String data) {
|
||||
Block lastBlock = blockChain.getLastBlock();
|
||||
int newBlockHeight = lastBlock == null ? 0 : lastBlock.getBlockHeader().getHeight() + 1;
|
||||
long newTimeStamp = UniversalDateTime.now().toLong();
|
||||
String previousBlockHash = lastBlock == null ? "0" : lastBlock.getHash();
|
||||
String oldDifficulty = lastBlock == null ? DEFAULT_DIFFICULTY : lastBlock.getBlockHeader().getDifficulty();
|
||||
String newDifficulty = oldDifficulty;
|
||||
|
||||
int newDifficultyPeriod = 1000;
|
||||
if (lastBlock != null && newBlockHeight % newDifficultyPeriod == 0) {
|
||||
|
||||
List<Block> lastBlocks = blockChain.getLastXBlocks(newDifficultyPeriod);
|
||||
int lastBlocksCount = lastBlocks.size();
|
||||
Block blockStart = lastBlocks.get(0);
|
||||
Block blockEnd = lastBlocks.get(lastBlocks.size() - 1);
|
||||
long moment1 = blockStart.getBlockHeader().getTimeStamp();
|
||||
long moment2 = blockEnd.getBlockHeader().getTimeStamp();
|
||||
UniversalDateTime udt1 = new UniversalDateTime(moment1);
|
||||
UniversalDateTime udt2 = new UniversalDateTime(moment2);
|
||||
Duration duration = new org.nanoboot.powerframework.time.duration.Period(udt1, udt2).getDuration();
|
||||
duration.toTotal(TimeUnit.SECOND);
|
||||
double averageCountOfMillisecondsToMineABlockForTenLastBlocks = (duration.toTotal(TimeUnit.SECOND) / (lastBlocksCount - 1));
|
||||
|
||||
int countX = 0;
|
||||
int sum = 0;
|
||||
for (Integer i : TestCash_1_0_BlockMiner.lastFiveBlockMiningTimesInMilliseconds) {
|
||||
sum = sum + i;
|
||||
countX = countX + 1;
|
||||
}
|
||||
System.out.println("sumInSeconds="+((double)sum));
|
||||
|
||||
averageCountOfMillisecondsToMineABlockForTenLastBlocks = ((((double) sum) / ((double) countX)) /*/ 1*/);
|
||||
System.out.println("averageCountOfMillisecondsToMineABlockForTenLastBlocks=" + averageCountOfMillisecondsToMineABlockForTenLastBlocks);
|
||||
boolean plus = false;
|
||||
if(((int)Math.round(averageCountOfMillisecondsToMineABlockForTenLastBlocks))==COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK) {
|
||||
DIFFICULTY_PERCENT_CHANGE=1f/16;
|
||||
} else {
|
||||
if(DIFFICULTY_PERCENT_CHANGE != (float) 1f/1f) {
|
||||
DIFFICULTY_PERCENT_CHANGE = (float) 1f/1f;
|
||||
}
|
||||
}
|
||||
if (averageCountOfMillisecondsToMineABlockForTenLastBlocks < COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK) {
|
||||
plus = false;
|
||||
System.out.println("Difficulty +++ increasing");
|
||||
|
||||
}
|
||||
if (averageCountOfMillisecondsToMineABlockForTenLastBlocks > COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK) {
|
||||
plus = true;
|
||||
System.out.println("Difficulty --- decreasing");
|
||||
}
|
||||
// if (DIFFICULTY_PERCENT_CHANGE >= 16) {
|
||||
// DIFFICULTY_PERCENT_CHANGE = 4;
|
||||
// }
|
||||
|
||||
System.out.println("averageCountOfSecondsToMineABlockForTenLastBlocks=" + averageCountOfMillisecondsToMineABlockForTenLastBlocks);
|
||||
if (averageCountOfMillisecondsToMineABlockForTenLastBlocks != COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK) {
|
||||
//DIFFICULTY_PERCENT_CHANGE = DIFFICULTY_PERCENT_CHANGE * 2;
|
||||
double realDifficultyPercentChange = DIFFICULTY_PERCENT_CHANGE;
|
||||
double more = averageCountOfMillisecondsToMineABlockForTenLastBlocks > COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK ? averageCountOfMillisecondsToMineABlockForTenLastBlocks : COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK;
|
||||
double less = averageCountOfMillisecondsToMineABlockForTenLastBlocks < COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK ? averageCountOfMillisecondsToMineABlockForTenLastBlocks : COUNT_OF_MILLISECONDS_TO_MINE_A_BLOCK;
|
||||
|
||||
if ((less / more) < 0.5) {
|
||||
realDifficultyPercentChange = 50;
|
||||
}
|
||||
double change = 1 + ((plus ? 1 : (-1)) * (realDifficultyPercentChange / 100));
|
||||
// if((double)(averageCountOfSecondsToMineABlockForTenLastBlocks) / (double)(COUNT_OF_SECONDS_TO_MINE_A_BLOCK)<0.9 || (double)(averageCountOfSecondsToMineABlockForTenLastBlocks) / (double)(COUNT_OF_SECONDS_TO_MINE_A_BLOCK)> 1.1){
|
||||
// change = 1 + ((plus ? 1 : (-1)) * (25f / 100));
|
||||
// }
|
||||
System.out.println(" Changing to " + change);
|
||||
BlockType blockType = blockTypeVersionList.findBlockType("test_cash:1:0");
|
||||
HashCalculator hashCalculator = blockType.getHashCalculator();
|
||||
String oldDifficultyAsDec = hashCalculator.convertHexStringToDecString(oldDifficulty);
|
||||
System.out.println("oldDifficultyAsDec=" + oldDifficultyAsDec);
|
||||
BigInteger bi = new BigDecimal(oldDifficultyAsDec).multiply(new BigDecimal(change)).toBigInteger();
|
||||
System.out.println("newDifficultyAsDec=" + bi.toString());
|
||||
newDifficulty = hashCalculator.convertDecStringToHexString(bi.toString());
|
||||
System.err.println("NEW_DIFFICULTY = " + newDifficulty);
|
||||
} else {
|
||||
//DIFFICULTY_PERCENT_CHANGE = DIFFICULTY_PERCENT_CHANGE / 2;
|
||||
}
|
||||
}
|
||||
BlockHeader blockHeader = new BlockHeader("test_cash:1:0", newBlockHeight, newTimeStamp, previousBlockHash, newDifficulty);
|
||||
return new BlockFragment(blockHeader, new SimpleBlockData(data));
|
||||
}
|
||||
}
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-collections</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-core</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-db</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-io</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-json</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-log</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-mail</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-persistence</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-random</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-reflection</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-security</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-sql</artifactId>
|
||||
|
@ -1,58 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
power-framework: Java library with many purposes of usage.
|
||||
Copyright (C) 2016-2022 the original author or authors.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation;
|
||||
version 2.1 of the License only.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-svg</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Power SVG</name>
|
||||
<description>SVG for the Power library</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Power dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-core</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-log</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Other dependencies -->
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<version>4.12</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
</project>
|
@ -1,32 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
module powerframework.template {
|
||||
requires powerframework.core;
|
||||
requires powerframework.log;
|
||||
requires powerframework.utils;
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
/*
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
|
||||
* Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
|
||||
*/
|
||||
package org.nanoboot.powerframework.svg;
|
||||
|
||||
/**
|
||||
*
|
||||
* @author robertvokac
|
||||
*/
|
||||
public class Svg {
|
||||
|
||||
}
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-template</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-text</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-time</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-utils</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-view</artifactId>
|
||||
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-web</artifactId>
|
||||
|
@ -1,52 +0,0 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<!--
|
||||
power-framework: Java library with many purposes of usage.
|
||||
Copyright (C) 2016-2022 the original author or authors.
|
||||
|
||||
This library is free software; you can redistribute it and/or
|
||||
modify it under the terms of the GNU Lesser General Public
|
||||
License as published by the Free Software Foundation;
|
||||
version 2.1 of the License only.
|
||||
|
||||
This library is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
Lesser General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Lesser General Public
|
||||
License along with this library; if not, write to the Free Software
|
||||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
-->
|
||||
<project xmlns="http://maven.apache.org/POM/4.0.0"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-wiki</artifactId>
|
||||
<packaging>jar</packaging>
|
||||
|
||||
<name>Power Wiki</name>
|
||||
<description>Wiki functionality for the Power library</description>
|
||||
|
||||
<dependencies>
|
||||
<!-- Power dependencies -->
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-core</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-log</artifactId>
|
||||
<version>${power.version}</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Other dependencies -->
|
||||
</dependencies>
|
||||
</project>
|
@ -1,31 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
module powerframework.wiki {
|
||||
requires powerframework.core;
|
||||
requires powerframework.log;
|
||||
requires powerframework.utils;
|
||||
}
|
@ -1,170 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class Block {
|
||||
|
||||
private final ArrayList<String> lines = new ArrayList<>();
|
||||
private final ArrayList<String> origLines = new ArrayList<>();
|
||||
private final BlockType blockType;
|
||||
|
||||
public Block(BlockType lineType) {
|
||||
this.blockType = lineType;
|
||||
}
|
||||
|
||||
void addLine(String line) {
|
||||
if(blockType.isOneLined() && lines.size() == 1) {
|
||||
throw new WikiException(blockType.getDescription() + " is one lined. Cannot add line " + line);
|
||||
}
|
||||
origLines.add(line);
|
||||
if(this.blockType != BlockType.PARSER) {
|
||||
line = preProcessLine(line);
|
||||
}
|
||||
lines.add(line);
|
||||
}
|
||||
|
||||
private String preProcessLine(String lineIn) {
|
||||
BlockType lineType = BlockType.getBlockType(lineIn);
|
||||
if(blockType != lineType) {
|
||||
throw new WikiException("Cannot add line to block. Line type is " + lineType + ", but the block type is " + blockType);
|
||||
}
|
||||
|
||||
String line = lineIn;
|
||||
switch (blockType) {
|
||||
|
||||
// case OL: {
|
||||
// line = line.replace(WikiMarks.ORDERED_LIST, HtmlTags.LI_START);
|
||||
// line = line + HtmlTags.LI_END;
|
||||
// }
|
||||
// break;
|
||||
// case UL: {
|
||||
// line = line.replace(WikiMarks.UNORDERED_LIST, HtmlTags.LI_START);
|
||||
// line = line + HtmlTags.LI_END;
|
||||
// }
|
||||
// break;
|
||||
case BLANK: {
|
||||
|
||||
}
|
||||
break;
|
||||
case P: {
|
||||
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
return line;
|
||||
}
|
||||
|
||||
BlockType getBlockType() {
|
||||
return blockType;
|
||||
}
|
||||
|
||||
public String getLine(int lineNumber) {
|
||||
return lines.get(lineNumber);
|
||||
}
|
||||
|
||||
public String toHtml() {
|
||||
StringBuilder stringBuilder = new StringBuilder("<span style=\"background-color:orange\">" + this.blockType + "</span><br />");
|
||||
int linesMaxIndex = lines.size() - 1;
|
||||
int i = 0;
|
||||
for (String line : lines) {
|
||||
stringBuilder.append(line);
|
||||
if(i++ < linesMaxIndex) {
|
||||
stringBuilder.append('\n');
|
||||
}
|
||||
}
|
||||
|
||||
String string = stringBuilder.toString();
|
||||
switch (blockType) {
|
||||
|
||||
case H1: {
|
||||
string = string.replace(WikiMarks.HEADING1_START, HtmlTags.H1_START);
|
||||
string = string.replace(WikiMarks.HEADING1_END, HtmlTags.H1_END);
|
||||
}
|
||||
break;
|
||||
case H2: {
|
||||
string = string.replace(WikiMarks.HEADING2_START, HtmlTags.H2_START);
|
||||
string = string.replace(WikiMarks.HEADING2_END, HtmlTags.H2_END);
|
||||
}
|
||||
break;
|
||||
case H3: {
|
||||
string = string.replace(WikiMarks.HEADING3_START, HtmlTags.H3_START);
|
||||
string = string.replace(WikiMarks.HEADING3_END, HtmlTags.H3_END);
|
||||
}
|
||||
break;
|
||||
case H4: {
|
||||
string = string.replace(WikiMarks.HEADING4_START, HtmlTags.H4_START);
|
||||
string = string.replace(WikiMarks.HEADING4_END, HtmlTags.H4_END);
|
||||
}
|
||||
break;
|
||||
case H5: {
|
||||
string = string.replace(WikiMarks.HEADING5_START, HtmlTags.H5_START);
|
||||
string = string.replace(WikiMarks.HEADING5_END, HtmlTags.H5_END);
|
||||
}
|
||||
break;
|
||||
case H6: {
|
||||
string = string.replace(WikiMarks.HEADING6_START, HtmlTags.H6_START);
|
||||
string = string.replace(WikiMarks.HEADING6_END, HtmlTags.H6_END);
|
||||
}
|
||||
break;
|
||||
case LIST: {
|
||||
string = HtmlTags.OL_START + '\n' + string + '\n' + HtmlTags.OL_END;
|
||||
}
|
||||
break;
|
||||
// case UL: {
|
||||
// string = HtmlTags.UL_START + '\n' + string + '\n' + HtmlTags.UL_END;
|
||||
// }
|
||||
// break;
|
||||
case BLANK: {
|
||||
|
||||
}
|
||||
break;
|
||||
case P: {
|
||||
string = HtmlTags.P_START + '\n' + string + '\n' + HtmlTags.P_END;
|
||||
}
|
||||
break;
|
||||
default: {
|
||||
}
|
||||
}
|
||||
//s = "\n\n\n\n### ZZZZZZZZZZZZZZZZZZZ ###\n" + s + "\n---------------------\n" + string + "\n-----------------";
|
||||
//System.out.println(s);
|
||||
string = "<!-- Block begins- lineType=" + this.blockType.getDescription() + " -->\n" + string + "\n<!-- Block ends- lineType=" + this.blockType.getDescription() + " -->";
|
||||
return string;
|
||||
}
|
||||
public String getOrig(){
|
||||
StringBuilder stringBuilder=new StringBuilder();
|
||||
for(String e:origLines){
|
||||
stringBuilder.append(e).append("\n");
|
||||
}
|
||||
return stringBuilder.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,70 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
import java.util.ArrayList;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
class BlockList {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(BlockList.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private final ArrayList<Block> blocks = new ArrayList<>();
|
||||
private Block currentBlock = null;
|
||||
|
||||
void addLine(String lineIn) {
|
||||
BlockType lineType = BlockType.getBlockType(lineIn);
|
||||
if(currentBlock == null) {
|
||||
currentBlock = new Block(lineType);
|
||||
currentBlock.addLine(lineIn);
|
||||
return;
|
||||
}
|
||||
try {
|
||||
currentBlock.addLine(lineIn);
|
||||
} catch (WikiException e) {
|
||||
blocks.add(currentBlock);
|
||||
currentBlock = new Block(lineType);
|
||||
currentBlock.addLine(lineIn);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public ArrayList<Block> getList() {
|
||||
if(currentBlock != null) {
|
||||
blocks.add(currentBlock);
|
||||
}
|
||||
currentBlock = null;
|
||||
return blocks;
|
||||
}
|
||||
|
||||
}
|
@ -1,158 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
enum BlockType {
|
||||
|
||||
H1("Heading 1", true),
|
||||
H2("Heading 2", true),
|
||||
H3("Heading 3", true),
|
||||
H4("Heading 4", true),
|
||||
H5("Heading 5", true),
|
||||
H6("Heading 6", true),
|
||||
LIST("List", false),
|
||||
BLANK("Blank line", true),
|
||||
P("Paragraph", false),
|
||||
TABLE("Table", false),
|
||||
PARSER("Parser", false),
|
||||
HR("Horizontal rule", false),
|
||||
CONTENT("Content", false),
|
||||
COMMENT("Comment", false);
|
||||
|
||||
private String description;
|
||||
private boolean oneLined;
|
||||
|
||||
BlockType(String string, boolean oneLined) {
|
||||
this.description = string;
|
||||
this.oneLined = oneLined;
|
||||
}
|
||||
|
||||
static BlockType getBlockType(String line) {
|
||||
if(line.isEmpty()) {
|
||||
return BlockType.BLANK;
|
||||
}
|
||||
if(lineIsH1(line)) {
|
||||
return BlockType.H1;
|
||||
}
|
||||
if(lineIsH2(line)) {
|
||||
return BlockType.H2;
|
||||
}
|
||||
if(lineIsH3(line)) {
|
||||
return BlockType.H3;
|
||||
}
|
||||
if(lineIsH4(line)) {
|
||||
return BlockType.H4;
|
||||
}
|
||||
if(lineIsH5(line)) {
|
||||
return BlockType.H5;
|
||||
}
|
||||
if(lineIsH6(line)) {
|
||||
return BlockType.H6;
|
||||
}
|
||||
if(lineIsList(line)) {
|
||||
return BlockType.LIST;
|
||||
}
|
||||
|
||||
if(lineIsTable(line)) {
|
||||
return BlockType.TABLE;
|
||||
}
|
||||
if(lineIsParser(line)) {
|
||||
return BlockType.PARSER;
|
||||
}
|
||||
if(lineIsHR(line)) {
|
||||
return BlockType.HR;
|
||||
}
|
||||
if(lineIsComment(line)) {
|
||||
return BlockType.COMMENT;
|
||||
}
|
||||
|
||||
return BlockType.P;
|
||||
}
|
||||
|
||||
private static boolean lineIsH1(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING1_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsH2(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING2_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsH3(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING3_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsH4(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING4_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsH5(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING5_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsH6(String line) {
|
||||
return line.startsWith(WikiMarks.HEADING6_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsList(String line) {
|
||||
line = " " + line.trim();
|
||||
return line.startsWith(WikiMarks.UNORDERED_LIST) || line.startsWith(WikiMarks.ORDERED_LIST);
|
||||
}
|
||||
|
||||
private static boolean lineIsTable(String line) {
|
||||
return line.startsWith(WikiMarks.TABLE_BORDER);
|
||||
}
|
||||
|
||||
private static boolean lineIsParser(String line) {
|
||||
return line.startsWith(WikiMarks.PARSER_START);
|
||||
}
|
||||
|
||||
private static boolean lineIsHR(String line) {
|
||||
return line.startsWith(WikiMarks.HORIZONTAL_RULE_4);
|
||||
}
|
||||
|
||||
private static boolean lineIsComment(String line) {
|
||||
return line.startsWith(WikiMarks.COMMENT_LINE_BEGINNING);
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public boolean isOneLined() {
|
||||
return this.oneLined;
|
||||
}
|
||||
|
||||
public static boolean isIn(BlockType blockType, BlockType... blockTypes) {
|
||||
for (BlockType e : blockTypes) {
|
||||
if(e == blockType) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
@ -1,117 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public class HtmlTags {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(HtmlTags.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
static final String B_START = "<b>";
|
||||
public static final String B_END = "</b>";
|
||||
public static final String I_START = "<i>";
|
||||
public static final String I_END = "</i>";
|
||||
public static final String U_START = "<u>";
|
||||
public static final String U_END = "</u>";
|
||||
public static final String COLOURED_START = "<span style=\"colour:%s\">";
|
||||
public static final String COLOURED_END = "</span>";
|
||||
public static final String BACKGROUND_HIGHLIGHTED_START = "<span style=\"background-colour:%s\">";
|
||||
public static final String BACKGROUND_HIGHLIGHTED_END = "</span>";
|
||||
public static final String SUPER_SCRIPT_START = "<sup>";
|
||||
public static final String SUPER_SCRIPT_END = "</sup>";
|
||||
public static final String SUB_SCRIPT_START = "<sub>";
|
||||
public static final String SUB_SCRIPT_END = "</sub>";
|
||||
public static final String MONOSPACE_START = "<span style=\"font-family: monospace, monospace;\">";
|
||||
public static final String MONOSPACE_SCRIPT_END = "</span>";
|
||||
public static final String STROKE_START = "<span style=\"text-decoration: line-through;\">";
|
||||
public static final String STROKE_END = "</span>";
|
||||
public static final String SMALLER_START = "<span style=\"font-size: 60%;\">";
|
||||
public static final String SMALLER_END = "</span>";
|
||||
public static final String LARGER_START = "<span style=\"font-size:140%;\">";
|
||||
public static final String LARGER_END = "</span>";
|
||||
public static final String LINK = "<a href=\"%s\">%s</a>";
|
||||
public static final String EMBED_IMG = "<img src=\"%s\" alt=\"%s\">";
|
||||
public static final String SIZE_START = "<span style=\"font-size:%s;\">";
|
||||
public static final String SIZE_END = "</span>";
|
||||
|
||||
public static final String H1_START = "<h1>";
|
||||
public static final String H1_END = "</h1>";
|
||||
public static final String H2_START = "<h2>";
|
||||
public static final String H2_END = "</h2>";
|
||||
public static final String H3_START = "<h3>";
|
||||
public static final String H3_END = "</h3>";
|
||||
public static final String H4_START = "<h4>";
|
||||
public static final String H4_END = "</h4>";
|
||||
public static final String H5_START = "<h5>";
|
||||
public static final String H5_END = "</h5>";
|
||||
public static final String H6_START = "<h6>";
|
||||
public static final String H6_END = "</h6>";
|
||||
|
||||
public static final String OL_START = "<ol>";
|
||||
public static final String OL_END = "</ol>";
|
||||
public static final String UL_START = "<ul>";
|
||||
public static final String UL_END = "</ul>";
|
||||
public static final String LI_START = "<li>";
|
||||
public static final String LI_END = "</li>";
|
||||
public static final String P_START = "<p>";
|
||||
public static final String P_END = "</p>";
|
||||
|
||||
public static final String TABLE_START = "<table>";
|
||||
public static final String TABLE_END = "</table>";
|
||||
public static final String TR_START = "<tr>";
|
||||
public static final String TR_END = "</tr>";
|
||||
public static final String TH_START = "<th>";
|
||||
public static final String TH_END = "</th>";
|
||||
public static final String TD_START = "<td>";
|
||||
public static final String TD_END = "</td>";
|
||||
|
||||
public static final String HR4 = "<hr style=\"height: 1px;\">";
|
||||
public static final String HR5 = "<hr style=\"height: 2px;\">";
|
||||
public static final String HR6 = "<hr style=\"height: 3px;\">";
|
||||
public static final String HR7 = "<hr style=\"height: 4px;\">";
|
||||
public static final String HR8 = "<hr style=\"height: 5px;\">";
|
||||
public static final String HR9 = "<hr style=\"height: 6px;\">";
|
||||
public static final String HR10 = "<hr style=\"height: 7px;\">";
|
||||
|
||||
public static final String COMMENT_TEMPLATE = "<!-- %s -->";
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Not meant to be instantiated.
|
||||
*/
|
||||
private HtmlTags() {
|
||||
}
|
||||
|
||||
}
|
@ -1,63 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
|
||||
public class Macro {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(Macro.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String content;
|
||||
private final String value;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Constructor description
|
||||
*/
|
||||
public Macro(String content, TextProcessorI processor) {
|
||||
this.content = content;
|
||||
this.value = processor.process(content);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
}
|
@ -1,75 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class StringSource {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(StringSource.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String string;
|
||||
private int position = 0;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
*/
|
||||
public StringSource(String string) {
|
||||
this.string = string;
|
||||
}
|
||||
|
||||
public char getNext() {
|
||||
return string.charAt(position++);
|
||||
}
|
||||
|
||||
public char getLast() {
|
||||
if(position - 1 == 0) {
|
||||
return ' ';
|
||||
}
|
||||
return string.charAt(position - 1);
|
||||
}
|
||||
|
||||
public boolean hasNext() {
|
||||
return position <= string.length() - 1;
|
||||
}
|
||||
|
||||
public char get(int number) {
|
||||
return string.charAt(position + number);
|
||||
}
|
||||
|
||||
}
|
@ -1,81 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class TextFormatter {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(TextFormatter.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Not meant to be instantiated.
|
||||
*/
|
||||
private TextFormatter() {
|
||||
}
|
||||
|
||||
public static String format(String text) {
|
||||
StringSource stringSource = new StringSource(text);
|
||||
StringBuilder out = new StringBuilder();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
while (stringSource.hasNext()) {
|
||||
char ch = stringSource.getNext();
|
||||
|
||||
if(ch == '[' && stringSource.getLast() == '[') {
|
||||
ch = stringSource.getNext();
|
||||
while (!(ch == ']' && stringSource.get(1) == ']')) {
|
||||
buffer.append(ch);
|
||||
if(!stringSource.hasNext()) {
|
||||
break;
|
||||
}
|
||||
ch = stringSource.getNext();
|
||||
}
|
||||
out.append(buffer.toString());
|
||||
buffer.delete(0, buffer.length());
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*/
|
||||
public interface TextProcessorI {
|
||||
|
||||
public String process(String text);
|
||||
|
||||
public String getName();
|
||||
}
|
@ -1,53 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
import org.nanoboot.powerframework.core.PowerException;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class WikiException extends PowerException {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(WikiException.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String name;
|
||||
|
||||
public WikiException(String messageIn) {
|
||||
super(messageIn);
|
||||
}
|
||||
|
||||
}
|
@ -1,108 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class WikiMarks {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(WikiMarks.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
public static final String BOLD = "\\*\\*";
|
||||
public static final String ITALIC = "//";
|
||||
public static final String UNDERLINED = "__";
|
||||
public static final String COLOURED = "$$";
|
||||
public static final String BACKGROUND_HIGHLIGHTED = "##";
|
||||
public static final String SUPERSCRIPT = "^";
|
||||
public static final String SUBSCRIPT = ",,";
|
||||
public static final String MONOSPACE = "`";
|
||||
public static final String STROKE = "--";
|
||||
public static final String SMALLER_START = "~-";
|
||||
public static final String SMALLER_END = "-~";
|
||||
public static final String LARGER_START = "~+";
|
||||
public static final String LARGER_END = "+~";
|
||||
|
||||
public static final String LINK_START = "[[";
|
||||
public static final String LINK_END = "]]";
|
||||
public static final String EMBED_START = "{{";
|
||||
public static final String EMBED_END = "}}";
|
||||
public static final String SIZE = "&&";
|
||||
|
||||
public static final String MACRO_START = "<<";
|
||||
public static final String MACRO_END = ">>";
|
||||
|
||||
public static final String PARSER_START = "{{{";
|
||||
public static final String PARSER_END = "}}}";
|
||||
|
||||
public static final String HEADING1_START = "= ";
|
||||
public static final String HEADING2_START = "== ";
|
||||
public static final String HEADING3_START = "=== ";
|
||||
public static final String HEADING4_START = "==== ";
|
||||
public static final String HEADING5_START = "===== ";
|
||||
public static final String HEADING6_START = "====== ";
|
||||
public static final String HEADING1_END = " =";
|
||||
public static final String HEADING2_END = " ==";
|
||||
public static final String HEADING3_END = " ===";
|
||||
public static final String HEADING4_END = " ====";
|
||||
public static final String HEADING5_END = " =====";
|
||||
public static final String HEADING6_END = " ======";
|
||||
public static final String UNORDERED_LIST = " *";
|
||||
public static final String ORDERED_LIST = " 1.";
|
||||
public static final String TABLE_BORDER = " || ";
|
||||
public static final String TABLE_COLOURED = "$$$";
|
||||
public static final String TABLE_BACKGROUND_HIGHLIGHTED = "###";
|
||||
|
||||
public static final String HORIZONTAL_RULE_4 = "----";
|
||||
public static final String HORIZONTAL_RULE_5 = "-----";
|
||||
public static final String HORIZONTAL_RULE_6 = "------";
|
||||
public static final String HORIZONTAL_RULE_7 = "-------";
|
||||
public static final String HORIZONTAL_RULE_8 = "--------";
|
||||
public static final String HORIZONTAL_RULE_9 = "---------";
|
||||
public static final String HORIZONTAL_RULE_10 = "----------";
|
||||
public static final String COMMENT_LINE_BEGINNING = "####";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Not meant to be instantiated.
|
||||
*/
|
||||
private WikiMarks() {
|
||||
}
|
||||
|
||||
}
|
@ -1,192 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.regex.Pattern;
|
||||
import org.nanoboot.powerframework.utils.StringUtils;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class WikiParser {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
//private static final org.nanoboot.powerframework.logging.Logger LOG = org.nanoboot.powerframework.logging.Logger.getLogger(WikiParser.class);
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private static TextProcessorI linkProcessor;
|
||||
private static final Map<String, TextProcessorI> macroProcessorsList = new HashMap<>();
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Not meant to be instantiated.
|
||||
*/
|
||||
public static void setLinkProcessor(TextProcessorI linkProcessorIn) {
|
||||
linkProcessor = linkProcessorIn;
|
||||
}
|
||||
|
||||
public String convertWiki(String wikiText) {
|
||||
System.out.println("Converting wiki text:\n\n"+wikiText);
|
||||
ArrayList<Block> blocks = splitWikiTextToBlocks(wikiText);
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
for (Block block : blocks) {
|
||||
System.out.println("\n====================\n"+block.getBlockType()+"\n\n");
|
||||
String html = block.toHtml();
|
||||
System.out.println(block.getOrig());
|
||||
System.out.println("VVVVVVVVVVVVVVVVVVVV");
|
||||
System.out.println(html);
|
||||
stringBuilder.append(html).append('\n').append('\n');
|
||||
}
|
||||
String string = stringBuilder.toString();
|
||||
return string;
|
||||
}
|
||||
|
||||
public void setStyle(String string) {
|
||||
|
||||
}
|
||||
|
||||
public void addMacroProcessor(TextProcessorI macroProcessor) {
|
||||
macroProcessorsList.put(macroProcessor.getName(), macroProcessor);
|
||||
}
|
||||
|
||||
public TextProcessorI getMacroProcessor(String macroName) {
|
||||
return macroProcessorsList.get(macroName);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static String convert(String wikiText) {
|
||||
|
||||
//System.err.println("\n\n\nWIKI" + "\n{\n" + wikiText + "\n}######$$$");
|
||||
while (true) {
|
||||
if(wikiText.contains(WikiMarks.BOLD)) {
|
||||
wikiText = wikiText.replaceFirst(WikiMarks.BOLD, HtmlTags.B_START);
|
||||
//System.err.println(String.format("Replacing %s by %s", BOLD, B_START));
|
||||
}
|
||||
if(wikiText.contains(WikiMarks.BOLD)) {
|
||||
wikiText = wikiText.replaceFirst(WikiMarks.BOLD, HtmlTags.B_END);
|
||||
//System.err.println(String.format("Replacing %s by %s", BOLD, B_END));
|
||||
}
|
||||
|
||||
if(!wikiText.contains(WikiMarks.BOLD)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
while (true) {
|
||||
|
||||
if(wikiText.contains(WikiMarks.ITALIC)) {
|
||||
wikiText = wikiText.replaceFirst(WikiMarks.ITALIC, HtmlTags.I_START);
|
||||
//System.err.println(String.format("Replacing %s by %s", ITALIC, I_START));
|
||||
}
|
||||
if(wikiText.contains(WikiMarks.ITALIC)) {
|
||||
wikiText = wikiText.replaceFirst(WikiMarks.ITALIC, HtmlTags.I_END);
|
||||
//System.err.println(String.format("Replacing %s by %s", ITALIC, I_END));
|
||||
}
|
||||
if(!wikiText.contains(WikiMarks.ITALIC)) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
StringBuilder stringBuilder = new StringBuilder();
|
||||
|
||||
ArrayList<Block> blocks = splitWikiTextToBlocks(wikiText);
|
||||
|
||||
// StringBuilder stringBuilder2 = new StringBuilder("Adding block\n\n");
|
||||
// for (Block block : blocks) {
|
||||
// stringBuilder2.append("\n###{\n").append(block.toHtml()).append("\n}\n");
|
||||
// }
|
||||
//System.err.println(stringBuilder2);
|
||||
// try {
|
||||
// Thread.sleep(10000);
|
||||
// } catch (InterruptedException ex) {
|
||||
// Logger.getLogger(WikiParser.class.getName()).log(Level.SEVERE, null, ex);
|
||||
// }
|
||||
for (Block block : blocks) {
|
||||
String html = block.toHtml();
|
||||
|
||||
stringBuilder.append(html).append('\n').append('\n');
|
||||
}
|
||||
String string = stringBuilder.toString();
|
||||
//System.out.println("Wiki convertor returned\n\n\n{\n" + string + "\n}\n\n\n");
|
||||
return string;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
private String processText(String text) {
|
||||
StringSource stringSource = new StringSource(text);
|
||||
StringBuilder out = new StringBuilder();
|
||||
StringBuilder buffer = new StringBuilder();
|
||||
while (stringSource.hasNext()) {
|
||||
char ch = stringSource.getNext();
|
||||
|
||||
if(ch == '[' && stringSource.getLast() == '[') {
|
||||
ch = stringSource.getNext();
|
||||
while (!(ch == ']' && stringSource.get(1) == ']')) {
|
||||
buffer.append(ch);
|
||||
if(!stringSource.hasNext()) {
|
||||
break;
|
||||
}
|
||||
ch = stringSource.getNext();
|
||||
}
|
||||
out.append(buffer.toString());
|
||||
buffer.delete(0, buffer.length());
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
return out.toString();
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static void replaceOccurences(StringBuilder stringBuilder, String what, String replacement) {
|
||||
Pattern.compile(what).matcher(stringBuilder).replaceAll(replacement);
|
||||
}
|
||||
|
||||
public static ArrayList<Block> splitWikiTextToBlocks(String wikiText) {
|
||||
BlockList blockList = new BlockList();
|
||||
|
||||
ArrayList<Block> blocks;
|
||||
String[] lines = StringUtils.toLines(wikiText);
|
||||
|
||||
for (String line : lines) {
|
||||
blockList.addLine(line);
|
||||
}
|
||||
blocks = blockList.getList();
|
||||
|
||||
return blocks;
|
||||
}
|
||||
|
||||
}
|
@ -1,89 +0,0 @@
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
// power-framework: Java library with many purposes of usage.
|
||||
// Copyright (C) 2016-2022 the original author or authors.
|
||||
//
|
||||
// This library is free software; you can redistribute it and/or
|
||||
// modify it under the terms of the GNU Lesser General Public
|
||||
// License as published by the Free Software Foundation;
|
||||
// version 2.1 of the License only.
|
||||
//
|
||||
// This library is distributed in the hope that it will be useful,
|
||||
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
||||
// Lesser General Public License for more details.
|
||||
//
|
||||
// You should have received a copy of the GNU Lesser General Public
|
||||
// License along with this library; if not, write to the Free Software
|
||||
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
///////////////////////////////////////////////////////////////////////////////////////////////
|
||||
|
||||
package org.nanoboot.powerframework.wiki.convertors;
|
||||
|
||||
import org.nanoboot.powerframework.core.PowerObject;
|
||||
|
||||
/**
|
||||
* Here goes the description of this class.
|
||||
*
|
||||
* @author <a href="mailto:robertvokac@nanoboot.org">Robert Vokac</a>
|
||||
* @since 0.0.0
|
||||
*
|
||||
*/
|
||||
public class ListConvertor extends PowerObject {
|
||||
|
||||
/**
|
||||
* Logger for this class.
|
||||
*/
|
||||
private static final org.nanoboot.powerframework.log.Logger LOG = org.nanoboot.powerframework.log.Logger.getLogger(ListConvertor.class);
|
||||
|
||||
/**
|
||||
* Constant description
|
||||
*/
|
||||
private static final String CONSTANT = "constant";
|
||||
|
||||
/**
|
||||
* Field description
|
||||
*/
|
||||
private String name;
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Not meant to be instantiated.
|
||||
*/
|
||||
private ListConvertor() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Constructor
|
||||
*
|
||||
* Constructor description
|
||||
*
|
||||
* @param nameIn
|
||||
*/
|
||||
public ListConvertor(String nameIn) {
|
||||
this.name = nameIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Setter for name.
|
||||
*
|
||||
* @param nameIn
|
||||
*/
|
||||
public void setName(String nameIn) {
|
||||
LOG.traceStartOfMethod(this, "setName", "name", name);
|
||||
this.name = nameIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Getter for name.
|
||||
*
|
||||
* @return name
|
||||
*/
|
||||
public String getName() {
|
||||
LOG.traceStartOfMethod(this, "getName");
|
||||
return this.name;
|
||||
}
|
||||
|
||||
|
||||
}
|
@ -25,7 +25,7 @@
|
||||
<parent>
|
||||
<groupId>org.nanoboot.powerframework</groupId>
|
||||
<artifactId>power-framework</artifactId>
|
||||
<version>2.0.0-SNAPSHOT</version>
|
||||
<version>2.0.0</version>
|
||||
</parent>
|
||||
|
||||
<artifactId>power-xml</artifactId>
|
||||
|
Reference in New Issue
Block a user