repo_name
stringlengths
7
104
file_path
stringlengths
13
198
context
stringlengths
67
7.15k
import_statement
stringlengths
16
4.43k
code
stringlengths
40
6.98k
prompt
stringlengths
227
8.27k
next_line
stringlengths
8
795
GerritCodeReview/plugins_replication
src/main/java/com/googlesource/gerrit/plugins/replication/events/RefReplicatedEvent.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // static String resolveNodeName(URIish uri) { // StringBuilder sb = new StringBuilder(); // if (uri.isRemote()) { // sb.append(uri.getHost()); // if (uri.getPort() != -1) { // sb.append(":"); // sb.append(uri.getPort()); // } // } else { // sb.append(uri.getPath()); // } // return sb.toString(); // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationState.java // public enum RefPushResult { // /** The ref was not successfully replicated. */ // FAILED, // // /** The ref is not configured to be replicated. */ // NOT_ATTEMPTED, // // /** The ref was successfully replicated. */ // SUCCEEDED; // // @Override // public String toString() { // return name().toLowerCase().replace("_", "-"); // } // }
import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.resolveNodeName; import com.googlesource.gerrit.plugins.replication.ReplicationState.RefPushResult; import java.util.Objects; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; import org.eclipse.jgit.transport.URIish;
// Copyright (C) 2013 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication.events; public class RefReplicatedEvent extends RemoteRefReplicationEvent { public static final String TYPE = "ref-replicated"; @Deprecated public final String targetNode; public final Status refStatus; public RefReplicatedEvent( String project, String ref, URIish targetUri, RefPushResult status, RemoteRefUpdate.Status refStatus) { super(TYPE, project, ref, targetUri, status.toString());
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // static String resolveNodeName(URIish uri) { // StringBuilder sb = new StringBuilder(); // if (uri.isRemote()) { // sb.append(uri.getHost()); // if (uri.getPort() != -1) { // sb.append(":"); // sb.append(uri.getPort()); // } // } else { // sb.append(uri.getPath()); // } // return sb.toString(); // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationState.java // public enum RefPushResult { // /** The ref was not successfully replicated. */ // FAILED, // // /** The ref is not configured to be replicated. */ // NOT_ATTEMPTED, // // /** The ref was successfully replicated. */ // SUCCEEDED; // // @Override // public String toString() { // return name().toLowerCase().replace("_", "-"); // } // } // Path: src/main/java/com/googlesource/gerrit/plugins/replication/events/RefReplicatedEvent.java import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.resolveNodeName; import com.googlesource.gerrit.plugins.replication.ReplicationState.RefPushResult; import java.util.Objects; import org.eclipse.jgit.transport.RemoteRefUpdate; import org.eclipse.jgit.transport.RemoteRefUpdate.Status; import org.eclipse.jgit.transport.URIish; // Copyright (C) 2013 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication.events; public class RefReplicatedEvent extends RemoteRefReplicationEvent { public static final String TYPE = "ref-replicated"; @Deprecated public final String targetNode; public final Status refStatus; public RefReplicatedEvent( String project, String ref, URIish targetUri, RefPushResult status, RemoteRefUpdate.Status refStatus) { super(TYPE, project, ref, targetUri, status.toString());
this.targetNode = resolveNodeName(targetUri);
GerritCodeReview/plugins_replication
src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java // public static class QueueInfo { // public final Map<URIish, PushOne> pending; // public final Map<URIish, PushOne> inFlight; // // public QueueInfo(Map<URIish, PushOne> pending, Map<URIish, PushOne> inFlight) { // this.pending = ImmutableMap.copyOf(pending); // this.inFlight = ImmutableMap.copyOf(inFlight); // } // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // }
import static com.google.common.truth.Truth.assertThat; import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.Destination.QueueInfo; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Stream; import org.eclipse.jgit.transport.URIish; import org.junit.Test;
@Test public void shouldCleanupBothTasksAndLocksAfterNewProjectReplication() throws Exception { setReplicationDestination("task_cleanup_locks_project", "replica", ALL_PROJECTS); config.setInt("remote", "task_cleanup_locks_project", "replicationRetry", 0); config.save(); reloadConfig(); assertThat(listRunning()).hasSize(0); Project.NameKey sourceProject = createTestProject("task_cleanup_locks_project"); WaitUtil.waitUntil( () -> nonEmptyProjectExists(Project.nameKey(sourceProject + "replica.git")), TEST_NEW_PROJECT_TIMEOUT); WaitUtil.waitUntil(() -> isTaskCleanedUp(), TEST_TASK_FINISH_TIMEOUT); } @Test public void shouldCleanupBothTasksAndLocksAfterReplicationCancelledAfterMaxRetries() throws Exception { String projectName = "task_cleanup_locks_project_cancelled"; String remoteDestination = "http://invalidurl:9090/"; URIish urish = new URIish(remoteDestination + projectName + ".git"); setReplicationDestination(projectName, "replica", Optional.of(projectName)); // replace correct urls with invalid one to trigger retry config.setString("remote", projectName, "url", remoteDestination + "${name}.git"); config.setInt("remote", projectName, "replicationMaxRetries", TEST_REPLICATION_MAX_RETRIES); config.save(); reloadConfig(); Destination destination =
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java // public static class QueueInfo { // public final Map<URIish, PushOne> pending; // public final Map<URIish, PushOne> inFlight; // // public QueueInfo(Map<URIish, PushOne> pending, Map<URIish, PushOne> inFlight) { // this.pending = ImmutableMap.copyOf(pending); // this.inFlight = ImmutableMap.copyOf(inFlight); // } // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // } // Path: src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java import static com.google.common.truth.Truth.assertThat; import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.Destination.QueueInfo; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Stream; import org.eclipse.jgit.transport.URIish; import org.junit.Test; @Test public void shouldCleanupBothTasksAndLocksAfterNewProjectReplication() throws Exception { setReplicationDestination("task_cleanup_locks_project", "replica", ALL_PROJECTS); config.setInt("remote", "task_cleanup_locks_project", "replicationRetry", 0); config.save(); reloadConfig(); assertThat(listRunning()).hasSize(0); Project.NameKey sourceProject = createTestProject("task_cleanup_locks_project"); WaitUtil.waitUntil( () -> nonEmptyProjectExists(Project.nameKey(sourceProject + "replica.git")), TEST_NEW_PROJECT_TIMEOUT); WaitUtil.waitUntil(() -> isTaskCleanedUp(), TEST_TASK_FINISH_TIMEOUT); } @Test public void shouldCleanupBothTasksAndLocksAfterReplicationCancelledAfterMaxRetries() throws Exception { String projectName = "task_cleanup_locks_project_cancelled"; String remoteDestination = "http://invalidurl:9090/"; URIish urish = new URIish(remoteDestination + projectName + ".git"); setReplicationDestination(projectName, "replica", Optional.of(projectName)); // replace correct urls with invalid one to trigger retry config.setString("remote", projectName, "url", remoteDestination + "${name}.git"); config.setInt("remote", projectName, "replicationMaxRetries", TEST_REPLICATION_MAX_RETRIES); config.save(); reloadConfig(); Destination destination =
destinationCollection.getAll(FilterType.ALL).stream()
GerritCodeReview/plugins_replication
src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java // public static class QueueInfo { // public final Map<URIish, PushOne> pending; // public final Map<URIish, PushOne> inFlight; // // public QueueInfo(Map<URIish, PushOne> pending, Map<URIish, PushOne> inFlight) { // this.pending = ImmutableMap.copyOf(pending); // this.inFlight = ImmutableMap.copyOf(inFlight); // } // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // }
import static com.google.common.truth.Truth.assertThat; import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.Destination.QueueInfo; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Stream; import org.eclipse.jgit.transport.URIish; import org.junit.Test;
() -> isTaskRescheduled(destination.getQueueInfo(), urish), TEST_NEW_PROJECT_TIMEOUT); // replicationRetry is set to 1 minute which is the minimum value. That's why // should be safe to get the pushOne object from pending because it should be // here for one minute PushOne pushOp = destination.getQueueInfo().pending.get(urish); WaitUtil.waitUntil(() -> pushOp.wasCanceled(), MAX_RETRY_WITH_TOLERANCE_TIMEOUT); WaitUtil.waitUntil(() -> isTaskCleanedUp(), TEST_TASK_FINISH_TIMEOUT); } private void replicateBranchDeletion(boolean mirror) throws Exception { setReplicationDestination("foo", "replica", ALL_PROJECTS); reloadConfig(); Project.NameKey targetProject = createTestProject(project + "replica"); String branchToDelete = "refs/heads/todelete"; String master = "refs/heads/master"; BranchInput input = new BranchInput(); input.revision = master; gApi.projects().name(project.get()).branch(branchToDelete).create(input); isPushCompleted(targetProject, branchToDelete, TEST_PUSH_TIMEOUT); setReplicationDestination("foo", "replica", ALL_PROJECTS, Integer.MAX_VALUE, mirror); reloadConfig(); gApi.projects().name(project.get()).branch(branchToDelete).delete(); assertThat(listWaitingReplicationTasks(branchToDelete)).hasSize(1); }
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/Destination.java // public static class QueueInfo { // public final Map<URIish, PushOne> pending; // public final Map<URIish, PushOne> inFlight; // // public QueueInfo(Map<URIish, PushOne> pending, Map<URIish, PushOne> inFlight) { // this.pending = ImmutableMap.copyOf(pending); // this.inFlight = ImmutableMap.copyOf(inFlight); // } // } // // Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // } // Path: src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationStorageIT.java import static com.google.common.truth.Truth.assertThat; import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.NO_OP; import com.google.gerrit.acceptance.TestPlugin; import com.google.gerrit.acceptance.UseLocalDisk; import com.google.gerrit.acceptance.WaitUtil; import com.google.gerrit.entities.Project; import com.google.gerrit.extensions.api.projects.BranchInput; import com.googlesource.gerrit.plugins.replication.Destination.QueueInfo; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import com.googlesource.gerrit.plugins.replication.ReplicationTasksStorage.ReplicateRefUpdate; import java.io.IOException; import java.net.URISyntaxException; import java.nio.file.Files; import java.nio.file.Path; import java.util.Arrays; import java.util.HashMap; import java.util.List; import java.util.Map; import java.util.Optional; import java.util.regex.Pattern; import java.util.stream.Stream; import org.eclipse.jgit.transport.URIish; import org.junit.Test; () -> isTaskRescheduled(destination.getQueueInfo(), urish), TEST_NEW_PROJECT_TIMEOUT); // replicationRetry is set to 1 minute which is the minimum value. That's why // should be safe to get the pushOne object from pending because it should be // here for one minute PushOne pushOp = destination.getQueueInfo().pending.get(urish); WaitUtil.waitUntil(() -> pushOp.wasCanceled(), MAX_RETRY_WITH_TOLERANCE_TIMEOUT); WaitUtil.waitUntil(() -> isTaskCleanedUp(), TEST_TASK_FINISH_TIMEOUT); } private void replicateBranchDeletion(boolean mirror) throws Exception { setReplicationDestination("foo", "replica", ALL_PROJECTS); reloadConfig(); Project.NameKey targetProject = createTestProject(project + "replica"); String branchToDelete = "refs/heads/todelete"; String master = "refs/heads/master"; BranchInput input = new BranchInput(); input.revision = master; gApi.projects().name(project.get()).branch(branchToDelete).create(input); isPushCompleted(targetProject, branchToDelete, TEST_PUSH_TIMEOUT); setReplicationDestination("foo", "replica", ALL_PROJECTS, Integer.MAX_VALUE, mirror); reloadConfig(); gApi.projects().name(project.get()).branch(branchToDelete).delete(); assertThat(listWaitingReplicationTasks(branchToDelete)).hasSize(1); }
private boolean isTaskRescheduled(QueueInfo queue, URIish uri) {
GerritCodeReview/plugins_replication
src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfigTest.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // }
import static com.google.common.truth.Truth.assertThat; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import java.io.IOException; import java.util.List; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.junit.Test;
// Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication; public class ReplicationFileBasedConfigTest extends AbstractConfigTest { public ReplicationFileBasedConfigTest() throws IOException { super(); } @Test public void shouldLoadOneDestination() throws Exception { String remoteName = "foo"; String remoteUrl = "ssh://[email protected]/${name}"; FileBasedConfig config = newReplicationConfig(); config.setString("remote", remoteName, "url", remoteUrl); config.save(); DestinationsCollection destinationsCollections = newDestinationsCollections(newReplicationFileBasedConfig()); destinationsCollections.startup(workQueueMock);
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationConfig.java // enum FilterType { // PROJECT_CREATION, // PROJECT_DELETION, // ALL // } // Path: src/test/java/com/googlesource/gerrit/plugins/replication/ReplicationFileBasedConfigTest.java import static com.google.common.truth.Truth.assertThat; import com.googlesource.gerrit.plugins.replication.ReplicationConfig.FilterType; import java.io.IOException; import java.util.List; import org.eclipse.jgit.storage.file.FileBasedConfig; import org.junit.Test; // Copyright (C) 2019 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication; public class ReplicationFileBasedConfigTest extends AbstractConfigTest { public ReplicationFileBasedConfigTest() throws IOException { super(); } @Test public void shouldLoadOneDestination() throws Exception { String remoteName = "foo"; String remoteUrl = "ssh://[email protected]/${name}"; FileBasedConfig config = newReplicationConfig(); config.setString("remote", remoteName, "url", remoteUrl); config.save(); DestinationsCollection destinationsCollections = newDestinationsCollections(newReplicationFileBasedConfig()); destinationsCollections.startup(workQueueMock);
List<Destination> destinations = destinationsCollections.getAll(FilterType.ALL);
GerritCodeReview/plugins_replication
src/main/java/com/googlesource/gerrit/plugins/replication/OnStartStop.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // public static class GitUpdateProcessing implements PushResultProcessing { // private static final FluentLogger logger = FluentLogger.forEnclosingClass(); // // private final EventDispatcher dispatcher; // // public GitUpdateProcessing(EventDispatcher dispatcher) { // this.dispatcher = dispatcher; // } // // @Override // public void onRefReplicatedToOneNode( // String project, // String ref, // URIish uri, // RefPushResult status, // RemoteRefUpdate.Status refStatus) { // postEvent(new RefReplicatedEvent(project, ref, uri, status, refStatus)); // } // // @Override // public void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) { // postEvent(new RefReplicationDoneEvent(project, ref, nodesCount)); // } // // private void postEvent(RefEvent event) { // try { // dispatcher.postEvent(event); // } catch (StorageException | PermissionBackendException e) { // logger.atSevere().withCause(e).log("Cannot post event"); // } // } // }
import com.google.common.util.concurrent.Atomics; import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.systemstatus.ServerInformation; import com.google.gerrit.server.events.EventDispatcher; import com.google.inject.Inject; import com.googlesource.gerrit.plugins.replication.PushResultProcessing.GitUpdateProcessing; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference;
// Copyright (C) 2012 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication; public class OnStartStop implements LifecycleListener { private final AtomicReference<Future<?>> pushAllFuture; private final ServerInformation srvInfo; private final PushAll.Factory pushAll; private final ReplicationConfig config; private final DynamicItem<EventDispatcher> eventDispatcher; @Inject protected OnStartStop( ServerInformation srvInfo, PushAll.Factory pushAll, ReplicationConfig config, DynamicItem<EventDispatcher> eventDispatcher) { this.srvInfo = srvInfo; this.pushAll = pushAll; this.config = config; this.eventDispatcher = eventDispatcher; this.pushAllFuture = Atomics.newReference(); } @Override public void start() { if (srvInfo.getState() == ServerInformation.State.STARTUP && config.isReplicateAllOnPluginStart()) {
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // public static class GitUpdateProcessing implements PushResultProcessing { // private static final FluentLogger logger = FluentLogger.forEnclosingClass(); // // private final EventDispatcher dispatcher; // // public GitUpdateProcessing(EventDispatcher dispatcher) { // this.dispatcher = dispatcher; // } // // @Override // public void onRefReplicatedToOneNode( // String project, // String ref, // URIish uri, // RefPushResult status, // RemoteRefUpdate.Status refStatus) { // postEvent(new RefReplicatedEvent(project, ref, uri, status, refStatus)); // } // // @Override // public void onRefReplicatedToAllNodes(String project, String ref, int nodesCount) { // postEvent(new RefReplicationDoneEvent(project, ref, nodesCount)); // } // // private void postEvent(RefEvent event) { // try { // dispatcher.postEvent(event); // } catch (StorageException | PermissionBackendException e) { // logger.atSevere().withCause(e).log("Cannot post event"); // } // } // } // Path: src/main/java/com/googlesource/gerrit/plugins/replication/OnStartStop.java import com.google.common.util.concurrent.Atomics; import com.google.gerrit.extensions.events.LifecycleListener; import com.google.gerrit.extensions.registration.DynamicItem; import com.google.gerrit.extensions.systemstatus.ServerInformation; import com.google.gerrit.server.events.EventDispatcher; import com.google.inject.Inject; import com.googlesource.gerrit.plugins.replication.PushResultProcessing.GitUpdateProcessing; import java.util.concurrent.Future; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicReference; // Copyright (C) 2012 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication; public class OnStartStop implements LifecycleListener { private final AtomicReference<Future<?>> pushAllFuture; private final ServerInformation srvInfo; private final PushAll.Factory pushAll; private final ReplicationConfig config; private final DynamicItem<EventDispatcher> eventDispatcher; @Inject protected OnStartStop( ServerInformation srvInfo, PushAll.Factory pushAll, ReplicationConfig config, DynamicItem<EventDispatcher> eventDispatcher) { this.srvInfo = srvInfo; this.pushAll = pushAll; this.config = config; this.eventDispatcher = eventDispatcher; this.pushAllFuture = Atomics.newReference(); } @Override public void start() { if (srvInfo.getState() == ServerInformation.State.STARTUP && config.isReplicateAllOnPluginStart()) {
ReplicationState state = new ReplicationState(new GitUpdateProcessing(eventDispatcher.get()));
GerritCodeReview/plugins_replication
src/main/java/com/googlesource/gerrit/plugins/replication/events/ReplicationScheduledEvent.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // static String resolveNodeName(URIish uri) { // StringBuilder sb = new StringBuilder(); // if (uri.isRemote()) { // sb.append(uri.getHost()); // if (uri.getPort() != -1) { // sb.append(":"); // sb.append(uri.getPort()); // } // } else { // sb.append(uri.getPath()); // } // return sb.toString(); // }
import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.resolveNodeName; import com.google.gerrit.entities.Project; import org.eclipse.jgit.transport.URIish;
// Copyright (C) 2016 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication.events; public class ReplicationScheduledEvent extends RemoteRefReplicationEvent { public static final String TYPE = "ref-replication-scheduled"; @Deprecated public final String targetNode; public ReplicationScheduledEvent(String project, String ref, URIish targetUri) { super(TYPE, project, ref, targetUri, null);
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/PushResultProcessing.java // static String resolveNodeName(URIish uri) { // StringBuilder sb = new StringBuilder(); // if (uri.isRemote()) { // sb.append(uri.getHost()); // if (uri.getPort() != -1) { // sb.append(":"); // sb.append(uri.getPort()); // } // } else { // sb.append(uri.getPath()); // } // return sb.toString(); // } // Path: src/main/java/com/googlesource/gerrit/plugins/replication/events/ReplicationScheduledEvent.java import static com.googlesource.gerrit.plugins.replication.PushResultProcessing.resolveNodeName; import com.google.gerrit.entities.Project; import org.eclipse.jgit.transport.URIish; // Copyright (C) 2016 The Android Open Source Project // // Licensed under the Apache License, Version 2.0 (the "License"); // you may not use this file except in compliance with the License. // You may obtain a copy of the License at // // http://www.apache.org/licenses/LICENSE-2.0 // // Unless required by applicable law or agreed to in writing, software // distributed under the License is distributed on an "AS IS" BASIS, // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. // See the License for the specific language governing permissions and // limitations under the License. package com.googlesource.gerrit.plugins.replication.events; public class ReplicationScheduledEvent extends RemoteRefReplicationEvent { public static final String TYPE = "ref-replication-scheduled"; @Deprecated public final String targetNode; public ReplicationScheduledEvent(String project, String ref, URIish targetUri) { super(TYPE, project, ref, targetUri, null);
this.targetNode = resolveNodeName(targetUri);
GerritCodeReview/plugins_replication
src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java // static final NamedFluentLogger repLog = NamedFluentLogger.forName(REPLICATION_LOG_NAME);
import static com.google.common.base.Suppliers.memoize; import static com.googlesource.gerrit.plugins.replication.ReplicationQueue.repLog; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.gerrit.server.config.ConfigUtil; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.transport.RemoteConfig;
remoteNameStyle = MoreObjects.firstNonNull(cfg.getString("remote", name, "remoteNameStyle"), "slash"); maxRetries = getInt( remoteConfig, cfg, "replicationMaxRetries", cfg.getInt("replication", "maxRetries", 0)); slowLatencyThreshold = (int) ConfigUtil.getTimeUnit( cfg, "remote", remoteConfig.getName(), "slowLatencyThreshold", DEFAULT_SLOW_LATENCY_THRESHOLD_SECS, TimeUnit.SECONDS); pushBatchSize = memoize( () -> { int configuredBatchSize = Math.max( 0, getInt( remoteConfig, cfg, "pushBatchSize", cfg.getInt("gerrit", "pushBatchSize", 0))); if (configuredBatchSize > 0) { int distributionInterval = cfg.getInt("replication", "distributionInterval", 0); if (distributionInterval > 0) {
// Path: src/main/java/com/googlesource/gerrit/plugins/replication/ReplicationQueue.java // static final NamedFluentLogger repLog = NamedFluentLogger.forName(REPLICATION_LOG_NAME); // Path: src/main/java/com/googlesource/gerrit/plugins/replication/DestinationConfiguration.java import static com.google.common.base.Suppliers.memoize; import static com.googlesource.gerrit.plugins.replication.ReplicationQueue.repLog; import com.google.common.base.MoreObjects; import com.google.common.collect.ImmutableList; import com.google.gerrit.server.config.ConfigUtil; import java.util.concurrent.TimeUnit; import java.util.function.Supplier; import org.eclipse.jgit.lib.Config; import org.eclipse.jgit.transport.RemoteConfig; remoteNameStyle = MoreObjects.firstNonNull(cfg.getString("remote", name, "remoteNameStyle"), "slash"); maxRetries = getInt( remoteConfig, cfg, "replicationMaxRetries", cfg.getInt("replication", "maxRetries", 0)); slowLatencyThreshold = (int) ConfigUtil.getTimeUnit( cfg, "remote", remoteConfig.getName(), "slowLatencyThreshold", DEFAULT_SLOW_LATENCY_THRESHOLD_SECS, TimeUnit.SECONDS); pushBatchSize = memoize( () -> { int configuredBatchSize = Math.max( 0, getInt( remoteConfig, cfg, "pushBatchSize", cfg.getInt("gerrit", "pushBatchSize", 0))); if (configuredBatchSize > 0) { int distributionInterval = cfg.getInt("replication", "distributionInterval", 0); if (distributionInterval > 0) {
repLog.atWarning().log(
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/GetAccountController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import com.webpagebytes.wpbsample.data.Session; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetAccountController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/GetAccountController.java import com.webpagebytes.wpbsample.data.Session; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetAccountController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/GetAccountController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import com.webpagebytes.wpbsample.data.Session; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetAccountController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/GetAccountController.java import com.webpagebytes.wpbsample.data.Session; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetAccountController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try {
Account account = database.getAccount(user_id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ConfirmEmailController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // }
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.User;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class ConfirmEmailController extends BaseController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { String code = request.getParameter("code"); try { if (code != null && code.length()>0) { model.getCmsApplicationModel().put("code", code);
// Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ConfirmEmailController.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.User; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class ConfirmEmailController extends BaseController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { String code = request.getParameter("code"); try { if (code != null && code.length()>0) { model.getCmsApplicationModel().put("code", code);
User user = null;
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
{ String username = request.getParameter("username"); String password = request.getParameter("password"); if (username.length() == 0 || username.length() > 255) { errors.put("username", "Error.username.length"); } else if (!username.matches("[[email protected]]*")) { errors.put("username", "Error.username.format"); } if (errors.containsKey("username")) { values.put("username", ""); } else { values.put("username", username); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; { String username = request.getParameter("username"); String password = request.getParameter("password"); if (username.length() == 0 || username.length() > 255) { errors.put("username", "Error.username.length"); } else if (!username.matches("[[email protected]]*")) { errors.put("username", "Error.username.format"); } if (errors.containsKey("username")) { values.put("username", ""); } else { values.put("username", username); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); session.getSessionMap().clear(); session.setUser_id(null); try { database.setSession(session); } catch (SQLException e) { throw new WPBException("Cannot set user session", e); } String username = request.getParameter("username"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); Map<String, String> values = new HashMap<String, String>(); performValidation(request, errors, values); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { model.getCmsApplicationModel().put("values", values); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; }
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); session.getSessionMap().clear(); session.setUser_id(null); try { database.setSession(session); } catch (SQLException e) { throw new WPBException("Cannot set user session", e); } String username = request.getParameter("username"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); Map<String, String> values = new HashMap<String, String>(); performValidation(request, errors, values); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { model.getCmsApplicationModel().put("values", values); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; }
User user = null;
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
if (errors.size() >0) { model.getCmsApplicationModel().put("values", values); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; } User user = null; try { user = database.getUser(username); } catch (SQLException e) { throw new WPBException("Cannot get user", e); } if (user == null) { values.clear(); errors.put("username", "Error.username.notfound"); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; } String hashDB = user.getPassword(); String hashUser = ""; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/LoginController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; if (errors.size() >0) { model.getCmsApplicationModel().put("values", values); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; } User user = null; try { user = database.getUser(username); } catch (SQLException e) { throw new WPBException("Cannot get user", e); } if (user == null) { values.clear(); errors.put("username", "Error.username.notfound"); String regPageKey = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("LOGIN_PAGE_KEY"); forward.setForwardTo(regPageKey); return; } String hashDB = user.getPassword(); String hashUser = ""; try {
hashUser = HashService.getHashSha1(password.getBytes());
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/GetProfileController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // }
import java.sql.SQLException; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetProfileController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/GetProfileController.java import java.sql.SQLException; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetProfileController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/GetProfileController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // }
import java.sql.SQLException; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetProfileController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/GetProfileController.java import java.sql.SQLException; import java.util.HashMap; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GetProfileController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try {
User user = database.getUser(user_id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/NotificationImageController.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class NotificationImageController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { OutputStream os = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(10000); ByteArrayInputStream bis = null; try { String type=request.getParameter("type"); if (null != type) { model.getCmsApplicationModel().put("type", type); } response.setContentType("image/png");
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/NotificationImageController.java import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class NotificationImageController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { OutputStream os = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(10000); ByteArrayInputStream bis = null; try { String type=request.getParameter("type"); if (null != type) { model.getCmsApplicationModel().put("type", type); } response.setContentType("image/png");
SampleFopService fopService = SampleFopService.getInstance();
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/GenericController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import com.webpagebytes.wpbsample.data.Session; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GenericController extends BaseController { protected static final int PAGE_SIZE = 11; protected boolean handleAuthentication(HttpServletRequest request,
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/GenericController.java import com.webpagebytes.wpbsample.data.Session; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class GenericController extends BaseController { protected static final int PAGE_SIZE = 11; protected boolean handleAuthentication(HttpServletRequest request,
HttpServletResponse response, WPBModel model, WPBForward forward, Session session) {
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class SuccessDWController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class SuccessDWController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class SuccessDWController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { String idStr = request.getParameter("id"); Long id = 0L; try { id = Long.valueOf(idStr); } catch (NumberFormatException e) { id = null; } if (id == null) { model.getCmsApplicationModel().put("invalidId", 1); } else {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class SuccessDWController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { String idStr = request.getParameter("id"); Long id = 0L; try { id = Long.valueOf(idStr); } catch (NumberFormatException e) { id = null; } if (id == null) { model.getCmsApplicationModel().put("invalidId", 1); } else {
DepositWithdrawal operation = database.getDepositOrWithdrawal(id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session;
return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { String idStr = request.getParameter("id"); Long id = 0L; try { id = Long.valueOf(idStr); } catch (NumberFormatException e) { id = null; } if (id == null) { model.getCmsApplicationModel().put("invalidId", 1); } else { DepositWithdrawal operation = database.getDepositOrWithdrawal(id); if (operation == null) { model.getCmsApplicationModel().put("invalidId", 1); } else if (operation.getUser_id() != user_id.intValue()) { model.getCmsApplicationModel().put("notAllowed", 1); } else {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/SuccessDWController.java import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { String idStr = request.getParameter("id"); Long id = 0L; try { id = Long.valueOf(idStr); } catch (NumberFormatException e) { id = null; } if (id == null) { model.getCmsApplicationModel().put("invalidId", 1); } else { DepositWithdrawal operation = database.getDepositOrWithdrawal(id); if (operation == null) { model.getCmsApplicationModel().put("invalidId", 1); } else if (operation.getUser_id() != user_id.intValue()) { model.getCmsApplicationModel().put("notAllowed", 1); } else {
Account account = database.getAccount(user_id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/AccountStatementPDFController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class AccountStatementPDFController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/AccountStatementPDFController.java import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class AccountStatementPDFController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/AccountStatementPDFController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class AccountStatementPDFController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); OutputStream os = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(10000); ByteArrayInputStream bis = null; try { model.getCmsApplicationModel().put("user_id", user_id); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=wpb-demo-statements.pdf");
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/AccountStatementPDFController.java import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.OutputStream; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.apache.commons.io.IOUtils; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class AccountStatementPDFController extends GenericController { public void initialize(WPBContentProvider contentProvider) { // TODO Auto-generated method stub super.initialize(contentProvider); } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); OutputStream os = null; ByteArrayOutputStream baos = new ByteArrayOutputStream(10000); ByteArrayInputStream bis = null; try { model.getCmsApplicationModel().put("user_id", user_id); response.setContentType("application/pdf"); response.setHeader("Content-Disposition", "attachment; filename=wpb-demo-statements.pdf");
SampleFopService fopService = SampleFopService.getInstance();
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/LogoutController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.io.IOException; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class LogoutController extends BaseController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/LogoutController.java import java.io.IOException; import java.sql.SQLException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class LogoutController extends BaseController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportTransactionsController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Transaction.java // public class Transaction { // private Long id; // private Date date; // int source_user_id; // int destination_user_id; // Long amount; // String sourceUserName; // String destinationUserName; // // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // public Long getId() { // return id; // } // public void setId(Long id) { // this.id = id; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public Long getAmount() { // return amount; // } // public void setAmount(Long amount) { // this.amount = amount; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.Transaction; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model);
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Transaction.java // public class Transaction { // private Long id; // private Date date; // int source_user_id; // int destination_user_id; // Long amount; // String sourceUserName; // String destinationUserName; // // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // public Long getId() { // return id; // } // public void setId(Long id) { // this.id = id; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public Long getAmount() { // return amount; // } // public void setAmount(Long amount) { // this.amount = amount; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportTransactionsController.java import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.Transaction; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model);
Date past = DateUtility.addDays(new Date(), -interval);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportTransactionsController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Transaction.java // public class Transaction { // private Long id; // private Date date; // int source_user_id; // int destination_user_id; // Long amount; // String sourceUserName; // String destinationUserName; // // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // public Long getId() { // return id; // } // public void setId(Long id) { // this.id = id; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public Long getAmount() { // return amount; // } // public void setAmount(Long amount) { // this.amount = amount; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.Transaction; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
} Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> receiveAmountPerDays = new HashMap<String, Long>(); Map<String, Integer> receiveTransactionsPerDays = new HashMap<String, Integer>(); Map<String, Long> paidAmountPerDays = new HashMap<String, Long>(); Map<String, Integer> paidTransactionsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); receiveAmountPerDays.put(String.valueOf(i), 0L); receiveTransactionsPerDays.put(String.valueOf(i), 0); paidAmountPerDays.put(String.valueOf(i), 0L); paidTransactionsPerDays.put(String.valueOf(i), 0); keys.add(String.valueOf(i)); } int maxNumTransactions = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Transaction.java // public class Transaction { // private Long id; // private Date date; // int source_user_id; // int destination_user_id; // Long amount; // String sourceUserName; // String destinationUserName; // // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // public Long getId() { // return id; // } // public void setId(Long id) { // this.id = id; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public Long getAmount() { // return amount; // } // public void setAmount(Long amount) { // this.amount = amount; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportTransactionsController.java import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.Transaction; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> receiveAmountPerDays = new HashMap<String, Long>(); Map<String, Integer> receiveTransactionsPerDays = new HashMap<String, Integer>(); Map<String, Long> paidAmountPerDays = new HashMap<String, Long>(); Map<String, Integer> paidTransactionsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); receiveAmountPerDays.put(String.valueOf(i), 0L); receiveTransactionsPerDays.put(String.valueOf(i), 0); paidAmountPerDays.put(String.valueOf(i), 0L); paidTransactionsPerDays.put(String.valueOf(i), 0); keys.add(String.valueOf(i)); } int maxNumTransactions = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
List<Transaction> transactions = database.getTransactionsForUser(user_id, past, 1, MAX_RECORDS);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath");
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath");
sampleConfigPath = PathUtility.safePath(sampleConfigPath);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath"); sampleConfigPath = PathUtility.safePath(sampleConfigPath); if (null == sampleConfigPath) { throw new RuntimeException("cannot get wpbSampleConfigPath value from context patameters"); } try { log.log(Level.INFO, "config path for sample app: " + sampleConfigPath);
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath"); sampleConfigPath = PathUtility.safePath(sampleConfigPath); if (null == sampleConfigPath) { throw new RuntimeException("cannot get wpbSampleConfigPath value from context patameters"); } try { log.log(Level.INFO, "config path for sample app: " + sampleConfigPath);
SampleConfigurator.initialize(sampleConfigPath);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // }
import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath"); sampleConfigPath = PathUtility.safePath(sampleConfigPath); if (null == sampleConfigPath) { throw new RuntimeException("cannot get wpbSampleConfigPath value from context patameters"); } try { log.log(Level.INFO, "config path for sample app: " + sampleConfigPath); SampleConfigurator.initialize(sampleConfigPath); }catch (IOException e) { throw new RuntimeException("cannot initialize WPBSampleConfigurator with file " + sampleConfigPath); } //speed up the creation of SampleFopService instance;
// Path: src/main/java/com/webpagebytes/wpbsample/utility/PathUtility.java // public class PathUtility { // // public static String safePath(String path) // { // if (path != null) // { // return path.replace('/', File.separatorChar).replace('\\', File.separatorChar); // } // return null; // } // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleContextListener.java import static org.quartz.CronScheduleBuilder.*; import static org.quartz.JobBuilder.*; import com.webpagebytes.cms.WPBContentServiceFactory; import com.webpagebytes.wpbsample.utility.PathUtility; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import com.webpagebytes.wpbsample.utility.SampleFopService; import java.io.IOException; import java.util.logging.Level; import java.util.logging.Logger; import javax.servlet.ServletContextEvent; import javax.servlet.ServletContextListener; import org.quartz.JobDetail; import org.quartz.Scheduler; import org.quartz.SchedulerFactory; import org.quartz.Trigger; import org.quartz.impl.StdSchedulerFactory; import static org.quartz.TriggerBuilder.*; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleContextListener implements ServletContextListener { private static final Logger log = Logger.getLogger(WPBSampleContextListener.class.getName()); @Override public void contextDestroyed(ServletContextEvent servletContext) { } @Override public void contextInitialized(ServletContextEvent servletContext) { log.log(Level.INFO, "WBPBSampleContextListener context initialized"); String sampleConfigPath = servletContext.getServletContext().getInitParameter("sampleConfigurationPath"); sampleConfigPath = PathUtility.safePath(sampleConfigPath); if (null == sampleConfigPath) { throw new RuntimeException("cannot get wpbSampleConfigPath value from context patameters"); } try { log.log(Level.INFO, "config path for sample app: " + sampleConfigPath); SampleConfigurator.initialize(sampleConfigPath); }catch (IOException e) { throw new RuntimeException("cannot initialize WPBSampleConfigurator with file " + sampleConfigPath); } //speed up the creation of SampleFopService instance;
SampleFopService.getInstance();
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/database/WPBDatabaseService.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // }
import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import com.webpagebytes.wpbsample.utility.SampleConfigurator;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.database; public class WPBDatabaseService { private static final Logger log = Logger.getLogger(WPBDatabaseService.class.getName()); public static final String DB_PROPS_CONNECTION_URL = "db_connectionUrl"; public static final String DB_PROPS_DRIVER_CLASS = "db_driverClass"; public static final String DB_PROPS_USER_NAME = "db_userName"; public static final String DB_PROPS_PASSWORD = "db_password"; public static final String DB_PROPS_TEST_ON_BORROW = "db_testOnBorrow"; public static final String DB_PROPS_VALIDATION_QUERY = "db_validationQuery"; private static WPBDatabase database; private static final Object lock = new Object(); public static WPBDatabase getInstance() { if (database == null) { synchronized (lock) { if (database == null) {
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/database/WPBDatabaseService.java import java.util.HashMap; import java.util.Map; import java.util.logging.Level; import java.util.logging.Logger; import com.webpagebytes.wpbsample.utility.SampleConfigurator; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.database; public class WPBDatabaseService { private static final Logger log = Logger.getLogger(WPBDatabaseService.class.getName()); public static final String DB_PROPS_CONNECTION_URL = "db_connectionUrl"; public static final String DB_PROPS_DRIVER_CLASS = "db_driverClass"; public static final String DB_PROPS_USER_NAME = "db_userName"; public static final String DB_PROPS_PASSWORD = "db_password"; public static final String DB_PROPS_TEST_ON_BORROW = "db_testOnBorrow"; public static final String DB_PROPS_VALIDATION_QUERY = "db_validationQuery"; private static WPBDatabase database; private static final Object lock = new Object(); public static WPBDatabase getInstance() { if (database == null) { synchronized (lock) { if (database == null) {
SampleConfigurator configurator = SampleConfigurator.getInstance();
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class ReportDWController extends GenericController { private int getInterval(WPBModel model) { String intervalStr = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("interval"); int interval = 1; try { interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class ReportDWController extends GenericController { private int getInterval(WPBModel model) { String intervalStr = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("interval"); int interval = 1; try { interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model);
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; interval = Integer.valueOf(intervalStr); } catch (NumberFormatException e) { // do nothing, go with the default } switch (interval) { case 1: case 7: case 30: break; default: interval = 1; } return interval; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model);
Date past = DateUtility.addDays(new Date(), -interval);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> amountDepositsPerDays = new HashMap<String, Long>(); Map<String, Integer> numDepositsPerDays = new HashMap<String, Integer>(); Map<String, Long> amountWithdrawalsPerDays = new HashMap<String, Long>(); Map<String, Integer> numWithdrawalsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); String iStr = String.valueOf(i); amountDepositsPerDays.put(iStr, 0L); numDepositsPerDays.put(iStr, 0); amountWithdrawalsPerDays.put(iStr, 0L); numWithdrawalsPerDays.put(iStr, 0); keys.add(iStr); } int maxNumOperations = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> amountDepositsPerDays = new HashMap<String, Long>(); Map<String, Integer> numDepositsPerDays = new HashMap<String, Integer>(); Map<String, Long> amountWithdrawalsPerDays = new HashMap<String, Long>(); Map<String, Integer> numWithdrawalsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); String iStr = String.valueOf(i); amountDepositsPerDays.put(iStr, 0L); numDepositsPerDays.put(iStr, 0); amountWithdrawalsPerDays.put(iStr, 0L); numWithdrawalsPerDays.put(iStr, 0); keys.add(iStr); } int maxNumOperations = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
List<DepositWithdrawal> operations = database.getDepositsWithdrawalsForUser(user_id, DepositWithdrawal.OperationType.DEPOSIT, past, 1, MAX_RECORDS);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // }
import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException;
Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> amountDepositsPerDays = new HashMap<String, Long>(); Map<String, Integer> numDepositsPerDays = new HashMap<String, Integer>(); Map<String, Long> amountWithdrawalsPerDays = new HashMap<String, Long>(); Map<String, Integer> numWithdrawalsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); String iStr = String.valueOf(i); amountDepositsPerDays.put(iStr, 0L); numDepositsPerDays.put(iStr, 0); amountWithdrawalsPerDays.put(iStr, 0L); numWithdrawalsPerDays.put(iStr, 0); keys.add(iStr); } int maxNumOperations = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public class DepositWithdrawal { // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // private long id; // private OperationType type; // private int user_id; // private long amount; // private Date date; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public OperationType getType() { // return type; // } // public void setType(OperationType type) { // this.type = type; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/DepositWithdrawal.java // public enum OperationType // { // DEPOSIT, // WITHDRAWAL // }; // // Path: src/main/java/com/webpagebytes/wpbsample/utility/DateUtility.java // public class DateUtility { // public static Date addDays(Date aDate, int days) // { // Calendar cal = Calendar.getInstance(); // cal.setTime(aDate); // cal.add(Calendar.DATE, days); // return cal.getTime(); // } // public static Date getToday() // { // Calendar cal = Calendar.getInstance(); // cal.set(Calendar.HOUR_OF_DAY, 0); // cal.set(Calendar.MINUTE, 0); // cal.set(Calendar.SECOND, 0); // cal.set(Calendar.MILLISECOND, 0); // return cal.getTime(); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ReportDWController.java import com.webpagebytes.wpbsample.data.DepositWithdrawal; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.DepositWithdrawal.OperationType; import com.webpagebytes.wpbsample.utility.DateUtility; import java.io.IOException; import java.io.OutputStream; import java.util.ArrayList; import java.util.Date; import java.util.HashMap; import java.util.List; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); int interval = getInterval(model); Date past = DateUtility.addDays(new Date(), -interval); List<Date> dates = new ArrayList<Date>(); List<String> keys = new ArrayList<String>(); Map<String, Long> amountDepositsPerDays = new HashMap<String, Long>(); Map<String, Integer> numDepositsPerDays = new HashMap<String, Integer>(); Map<String, Long> amountWithdrawalsPerDays = new HashMap<String, Long>(); Map<String, Integer> numWithdrawalsPerDays = new HashMap<String, Integer>(); for(int i = 0; i<= interval-1 ; i++) { Date aDate = DateUtility.addDays(past, i); dates.add(aDate); String iStr = String.valueOf(i); amountDepositsPerDays.put(iStr, 0L); numDepositsPerDays.put(iStr, 0); amountWithdrawalsPerDays.put(iStr, 0L); numWithdrawalsPerDays.put(iStr, 0); keys.add(iStr); } int maxNumOperations = 0; long maxAmountPerDay = 0; OutputStream os = null; try {
List<DepositWithdrawal> operations = database.getDepositsWithdrawalsForUser(user_id, DepositWithdrawal.OperationType.DEPOSIT, past, 1, MAX_RECORDS);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/WPBSampleThread.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // }
import com.webpagebytes.wpbsample.utility.SampleFopService; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBContentService; import com.webpagebytes.cms.WPBModel;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleThread implements Runnable { private static final Logger log = Logger.getLogger(WPBSampleThread.class.getName()); private WPBContentService contentService; public WPBSampleThread(WPBContentService contentService) { this.contentService = contentService; } @Override public void run() { try { log.log(Level.INFO, "Execution of backgroud thread started"); WPBContentProvider contentProvider = contentService.getContentProvider(); WPBModel configModel = contentService.createModel(); String maxRunsStr = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_RUNS_PDF_GENERATION");; String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION"); if (null == maxRunsStr || user_name == null) { return; } long t0 = System.currentTimeMillis();
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleThread.java import com.webpagebytes.wpbsample.utility.SampleFopService; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBContentService; import com.webpagebytes.cms.WPBModel; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample; public class WPBSampleThread implements Runnable { private static final Logger log = Logger.getLogger(WPBSampleThread.class.getName()); private WPBContentService contentService; public WPBSampleThread(WPBContentService contentService) { this.contentService = contentService; } @Override public void run() { try { log.log(Level.INFO, "Execution of backgroud thread started"); WPBContentProvider contentProvider = contentService.getContentProvider(); WPBModel configModel = contentService.createModel(); String maxRunsStr = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_RUNS_PDF_GENERATION");; String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION"); if (null == maxRunsStr || user_name == null) { return; } long t0 = System.currentTimeMillis();
String basePath = SampleConfigurator.getInstance().getConfig("storageDir");
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/WPBSampleThread.java
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // }
import com.webpagebytes.wpbsample.utility.SampleFopService; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBContentService; import com.webpagebytes.cms.WPBModel;
String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION"); if (null == maxRunsStr || user_name == null) { return; } long t0 = System.currentTimeMillis(); String basePath = SampleConfigurator.getInstance().getConfig("storageDir"); int i = 0; int max_runs = 0; try { max_runs = Integer.valueOf(maxRunsStr); } catch (NumberFormatException e) {}; log.log(Level.INFO, "Execution of backgroud thread to generate PDF's for user " + user_name); while (i< max_runs) { WPBModel model = contentService.createModel(); String pageGuid = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("STATEMENT_FOP_PAGE_GUID"); if (pageGuid != null) { model.getCmsApplicationModel().put("user_name", user_name); ByteArrayOutputStream bos = new ByteArrayOutputStream(4096); contentProvider.writePageContent(pageGuid, model, bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); String filePath = basePath + File.separator + java.util.UUID.randomUUID().toString() + ".pdf"; FileOutputStream fos = new FileOutputStream(filePath);
// Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleFopService.java // public class SampleFopService { // // private static SampleFopService instance; // private FopFactory fopFactory; // private TransformerFactory transformerFactory; // private static volatile Object lock = new Object(); // // private SampleFopService() // { // transformerFactory = TransformerFactory.newInstance(); // fopFactory = FopFactory.newInstance(); // } // // public static SampleFopService getInstance() // { // if (instance == null) // { // synchronized (lock) // { // if (null == instance) // { // instance = new SampleFopService(); // } // } // } // return instance; // } // // public void getContent(InputStream is, String mimeType, OutputStream os) throws Exception // { // Source source = null; // try // { // Transformer transformer = transformerFactory.newTransformer(); // identity transformer // source = new StreamSource(is); // Fop fop = fopFactory.newFop(mimeType, os); // Result res = new SAXResult(fop.getDefaultHandler()); // transformer.transform(source, res); // } catch (Exception e) // { // throw e; // } // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/SampleConfigurator.java // public class SampleConfigurator { // // private Properties properties; // private static SampleConfigurator instance; // // private SampleConfigurator() {}; // // public static void initialize(String configPath) throws IOException // { // Properties properties = new Properties(); // properties.load(new FileInputStream(configPath)); // SampleConfigurator instance = new SampleConfigurator(); // instance.properties = properties; // SampleConfigurator.instance = instance; // } // public static SampleConfigurator getInstance() // { // return instance; // } // public String getConfig(String key) // { // if (properties.containsKey(key)) // return properties.get(key).toString(); // else // return ""; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/WPBSampleThread.java import com.webpagebytes.wpbsample.utility.SampleFopService; import com.webpagebytes.wpbsample.utility.SampleConfigurator; import java.io.ByteArrayInputStream; import java.io.ByteArrayOutputStream; import java.io.File; import java.io.FileOutputStream; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.fop.apps.MimeConstants; import com.webpagebytes.cms.WPBContentProvider; import com.webpagebytes.cms.WPBContentService; import com.webpagebytes.cms.WPBModel; String user_name = configModel.getCmsModel().get(WPBModel.GLOBALS_KEY).get("TEST_USERNAME_PDF_GENERATION"); if (null == maxRunsStr || user_name == null) { return; } long t0 = System.currentTimeMillis(); String basePath = SampleConfigurator.getInstance().getConfig("storageDir"); int i = 0; int max_runs = 0; try { max_runs = Integer.valueOf(maxRunsStr); } catch (NumberFormatException e) {}; log.log(Level.INFO, "Execution of backgroud thread to generate PDF's for user " + user_name); while (i< max_runs) { WPBModel model = contentService.createModel(); String pageGuid = model.getCmsModel().get(WPBModel.GLOBALS_KEY).get("STATEMENT_FOP_PAGE_GUID"); if (pageGuid != null) { model.getCmsApplicationModel().put("user_name", user_name); ByteArrayOutputStream bos = new ByteArrayOutputStream(4096); contentProvider.writePageContent(pageGuid, model, bos); ByteArrayInputStream bis = new ByteArrayInputStream(bos.toByteArray()); String filePath = basePath + File.separator + java.util.UUID.randomUUID().toString() + ".pdf"; FileOutputStream fos = new FileOutputStream(filePath);
SampleFopService fopService = SampleFopService.getInstance();
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/HomeController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/AccountOperation.java // public class AccountOperation { // private long id; // private int type; // private int user_id; // private long amount; // private Date date; // int source_user_id; // int destination_user_id; // String sourceUserName; // String destinationUserName; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public int getType() { // return type; // } // public void setType(int type) { // this.type = type; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.sql.SQLException; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.AccountOperation; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class HomeController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/AccountOperation.java // public class AccountOperation { // private long id; // private int type; // private int user_id; // private long amount; // private Date date; // int source_user_id; // int destination_user_id; // String sourceUserName; // String destinationUserName; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public int getType() { // return type; // } // public void setType(int type) { // this.type = type; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/HomeController.java import java.sql.SQLException; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.AccountOperation; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class HomeController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/HomeController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/AccountOperation.java // public class AccountOperation { // private long id; // private int type; // private int user_id; // private long amount; // private Date date; // int source_user_id; // int destination_user_id; // String sourceUserName; // String destinationUserName; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public int getType() { // return type; // } // public void setType(int type) { // this.type = type; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import java.sql.SQLException; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.AccountOperation; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class HomeController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { model.getCmsApplicationModel().put("user_id", user_id);
// Path: src/main/java/com/webpagebytes/wpbsample/data/Account.java // public class Account { // private int user_id; // private long balance; // // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getBalance() { // return balance; // } // public void setBalance(long balance) { // this.balance = balance; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/AccountOperation.java // public class AccountOperation { // private long id; // private int type; // private int user_id; // private long amount; // private Date date; // int source_user_id; // int destination_user_id; // String sourceUserName; // String destinationUserName; // public long getId() { // return id; // } // public void setId(long id) { // this.id = id; // } // public int getType() { // return type; // } // public void setType(int type) { // this.type = type; // } // public int getUser_id() { // return user_id; // } // public void setUser_id(int user_id) { // this.user_id = user_id; // } // public long getAmount() { // return amount; // } // public void setAmount(long amount) { // this.amount = amount; // } // public Date getDate() { // return date; // } // public void setDate(Date date) { // this.date = date; // } // public int getSource_user_id() { // return source_user_id; // } // public void setSource_user_id(int source_user_id) { // this.source_user_id = source_user_id; // } // public int getDestination_user_id() { // return destination_user_id; // } // public void setDestination_user_id(int destination_user_id) { // this.destination_user_id = destination_user_id; // } // public String getSourceUserName() { // return sourceUserName; // } // public void setSourceUserName(String sourceUserName) { // this.sourceUserName = sourceUserName; // } // public String getDestinationUserName() { // return destinationUserName; // } // public void setDestinationUserName(String destinationUserName) { // this.destinationUserName = destinationUserName; // } // // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/HomeController.java import java.sql.SQLException; import java.util.Date; import java.util.List; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Account; import com.webpagebytes.wpbsample.data.AccountOperation; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class HomeController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { model.getCmsApplicationModel().put("user_id", user_id);
Account account = database.getAccount(user_id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ChangeProfileController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session;
{ values.put("email", ""); } else { values.put("email", email); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } if (!(receiveNewsletter == null || receiveNewsletter.equals("1") || receiveNewsletter.equals("0"))) { errors.put("receiveNewsletter", "Error.newsLetter.value"); } if (errors.containsKey("receiveNewsletter")) { values.put("receiveNewsletter", "0"); } else { values.put("receiveNewsletter", receiveNewsletter); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ChangeProfileController.java import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; { values.put("email", ""); } else { values.put("email", email); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } if (!(receiveNewsletter == null || receiveNewsletter.equals("1") || receiveNewsletter.equals("0"))) { errors.put("receiveNewsletter", "Error.newsLetter.value"); } if (errors.containsKey("receiveNewsletter")) { values.put("receiveNewsletter", "0"); } else { values.put("receiveNewsletter", receiveNewsletter); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ChangeProfileController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session;
return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { User user = database.getUser(user_id); String password = request.getParameter("password"); String newEmail = request.getParameter("email"); String receiveNewsletterStr = request.getParameter("receiveNewsletter"); Map<String, String> errors = new HashMap<String, String>(); Map<String, String> values = new HashMap<String, String>(); performValidation(user, request, errors, values); model.getCmsApplicationModel().put("errors", errors); model.getCmsApplicationModel().put("values", values); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } String pswHash = ""; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ChangeProfileController.java import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import java.util.UUID; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); try { User user = database.getUser(user_id); String password = request.getParameter("password"); String newEmail = request.getParameter("email"); String receiveNewsletterStr = request.getParameter("receiveNewsletter"); Map<String, String> errors = new HashMap<String, String>(); Map<String, String> values = new HashMap<String, String>(); performValidation(user, request, errors, values); model.getCmsApplicationModel().put("errors", errors); model.getCmsApplicationModel().put("values", values); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } String pswHash = ""; try {
pswHash = HashService.getHashSha1(password.getBytes());
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
if (oldPassword.length() == 0) { errors.put("oldPassword", "Error.password.empty"); } else if (oldPassword.length() > 255) { errors.put("oldPassword", "Error.password.length"); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } else if (! password.equals(password2)) { errors.put("password", "Error.password.different"); } if (password2.length() == 0) { errors.put("password2", "Error.password.empty"); }else if (password2.length() > 255) { errors.put("password2", "Error.password.length"); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; if (oldPassword.length() == 0) { errors.put("oldPassword", "Error.password.empty"); } else if (oldPassword.length() > 255) { errors.put("oldPassword", "Error.password.length"); } if (password.length() == 0) { errors.put("password", "Error.password.empty"); } else if (password.length() > 255) { errors.put("password", "Error.password.length"); } else if (! password.equals(password2)) { errors.put("password", "Error.password.different"); } if (password2.length() == 0) { errors.put("password2", "Error.password.empty"); }else if (password2.length() > 255) { errors.put("password2", "Error.password.length"); } } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
} public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); String oldPassword = request.getParameter("oldPassword"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); performValidation(request, errors); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; } public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException { Session session = getSession(request, response); if (false == handleAuthentication(request, response, model, forward, session)) { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); String oldPassword = request.getParameter("oldPassword"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); performValidation(request, errors); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } try {
User user = database.getUser(user_id);
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // }
import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel;
{ return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); String oldPassword = request.getParameter("oldPassword"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); performValidation(request, errors); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } try { User user = database.getUser(user_id); String oldPswHash = ""; String newPasswordHash = ""; try {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/data/User.java // public class User { // private String userName; // private Integer receiveNewsletter; // private String email; // private Integer id; // private String password; // private Date open_date; // private Integer confirmEmailFlag; // private String confirmEmailRandom; // private Date confirmEmailDate; // // public String getUserName() { // return userName; // } // public void setUserName(String userName) { // this.userName = userName; // } // public String getEmail() { // return email; // } // public void setEmail(String email) { // this.email = email; // } // public Integer getId() { // return id; // } // public void setId(int id) { // this.id = id; // } // public String getPassword() { // return password; // } // public void setPassword(String password) { // this.password = password; // } // public Date getOpen_date() { // return open_date; // } // public void setOpen_date(Date open_date) { // this.open_date = open_date; // } // public Integer getReceiveNewsletter() { // return receiveNewsletter; // } // public void setReceiveNewsletter(Integer receiveNewsletter) { // this.receiveNewsletter = receiveNewsletter; // } // public Integer getConfirmEmailFlag() { // return confirmEmailFlag; // } // public void setConfirmEmailFlag(Integer confirmEmailFlag) { // this.confirmEmailFlag = confirmEmailFlag; // } // public String getConfirmEmailRandom() { // return confirmEmailRandom; // } // public void setConfirmEmailRandom(String confirmEmailRandom) { // this.confirmEmailRandom = confirmEmailRandom; // } // public Date getConfirmEmailDate() { // return confirmEmailDate; // } // public void setConfirmEmailDate(Date confirmEmailDate) { // this.confirmEmailDate = confirmEmailDate; // } // // } // // Path: src/main/java/com/webpagebytes/wpbsample/utility/HashService.java // public class HashService { // // public static String getHashSha1(byte[] data) throws NoSuchAlgorithmException // { // MessageDigest crypt = MessageDigest.getInstance("SHA-1"); // crypt.reset(); // crypt.update(data); // return new BigInteger(1, crypt.digest()).toString(16); // } // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/ChangePasswordController.java import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; import com.webpagebytes.wpbsample.data.User; import com.webpagebytes.wpbsample.utility.HashService; import java.io.IOException; import java.security.NoSuchAlgorithmException; import java.sql.SQLException; import java.util.HashMap; import java.util.Map; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; { return; } Integer user_id = (Integer) session.getSessionMap().get(SESSION_LOGIN_USERID); String oldPassword = request.getParameter("oldPassword"); String password = request.getParameter("password"); Map<String, String> errors = new HashMap<String, String>(); performValidation(request, errors); model.getCmsApplicationModel().put("errors", errors); if (errors.size() >0) { String regPageKey = model.getCmsModel().get(WPBModel.URI_PARAMETERS_KEY).get("pageGuid"); forward.setForwardTo(regPageKey); return; } try { User user = database.getUser(user_id); String oldPswHash = ""; String newPasswordHash = ""; try {
oldPswHash = HashService.getHashSha1(oldPassword.getBytes());
webpagebytes/demo-cms-app
src/main/java/com/webpagebytes/wpbsample/controllers/LoginGetController.java
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // }
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session;
/* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class LoginGetController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
// Path: src/main/java/com/webpagebytes/wpbsample/data/Session.java // public class Session { // private String id; // private Integer user_id; // private Date create_timestamp; // private HashMap<String, Object> sessionMap; // // public String getId() { // return id; // } // public void setId(String id) { // this.id = id; // } // public Integer getUser_id() { // return user_id; // } // public void setUser_id(Integer user_id) { // this.user_id = user_id; // } // public Date getCreate_timestamp() { // return create_timestamp; // } // public void setCreate_timestamp(Date create_timestamp) { // this.create_timestamp = create_timestamp; // } // // public HashMap<String, Object> getSessionMap() // { // if (sessionMap == null) // { // sessionMap = new HashMap<String, Object>(); // } // return sessionMap; // } // public void setSessionMap(HashMap<String, Object> sessionMap) // { // this.sessionMap = sessionMap; // } // // } // Path: src/main/java/com/webpagebytes/wpbsample/controllers/LoginGetController.java import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import com.webpagebytes.cms.WPBForward; import com.webpagebytes.cms.WPBModel; import com.webpagebytes.cms.exception.WPBException; import com.webpagebytes.wpbsample.data.Session; /* * Copyright 2015 Webpagebytes * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. */ package com.webpagebytes.wpbsample.controllers; public class LoginGetController extends GenericController { public void handleRequest(HttpServletRequest request, HttpServletResponse response, WPBModel model, WPBForward forward) throws WPBException {
Session session = getSession(request, response);
masl123/YM2151-Midi-Controller
src/ym2151/DataModel/OPMFile.java
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // }
import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; import javax.swing.JOptionPane; import ym2151.Utils;
String name = instrHead.substring(instrHead.indexOf(' ')); var = Integer.parseInt(instrHead.substring(0, instrHead.indexOf(' '))); ins = new Instrument(name); opm.addInstrument(ins,var); }else if(!line.equals("")){ //everything else (parts of a Instrument) if(ins == null) { r.close(); throw new IOException("Could not Parse File"); } if(!ins.parseLine(line)){ r.close(); throw new IOException("Could not Parse File"); }; } } r.close(); return opm; } /** * Saves a OPMFile * @param file the File to save * @param path the path to save the file to. * */ public static void saveFile(OPMFile file, File path) throws IOException { //add right extension (if not existent)
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // } // Path: src/ym2151/DataModel/OPMFile.java import java.io.BufferedReader; import java.io.File; import java.io.FileReader; import java.io.FileWriter; import java.io.IOException; import java.net.URISyntaxException; import java.net.URL; import java.util.HashMap; import javax.swing.JOptionPane; import ym2151.Utils; String name = instrHead.substring(instrHead.indexOf(' ')); var = Integer.parseInt(instrHead.substring(0, instrHead.indexOf(' '))); ins = new Instrument(name); opm.addInstrument(ins,var); }else if(!line.equals("")){ //everything else (parts of a Instrument) if(ins == null) { r.close(); throw new IOException("Could not Parse File"); } if(!ins.parseLine(line)){ r.close(); throw new IOException("Could not Parse File"); }; } } r.close(); return opm; } /** * Saves a OPMFile * @param file the File to save * @param path the path to save the file to. * */ public static void saveFile(OPMFile file, File path) throws IOException { //add right extension (if not existent)
if(!Utils.getExtension(path).equalsIgnoreCase("opm")){
masl123/YM2151-Midi-Controller
src/ym2151/Swing/ListSelector.java
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // }
import javax.swing.DefaultListModel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JList; import ym2151.Utils; import java.awt.BorderLayout; import java.util.List;
/** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * A Swing Component to Select Items from a List (with Scrolling) * */ public class ListSelector<T> extends JPanel { private static final long serialVersionUID = -6729650486083511095L; private JList<T> list; //the JList we use /** * Create a ListSelector * @param data the Data to add. * */ public ListSelector(T[] data) {
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // } // Path: src/ym2151/Swing/ListSelector.java import javax.swing.DefaultListModel; import javax.swing.JPanel; import javax.swing.JScrollPane; import javax.swing.JList; import ym2151.Utils; import java.awt.BorderLayout; import java.util.List; /** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * A Swing Component to Select Items from a List (with Scrolling) * */ public class ListSelector<T> extends JPanel { private static final long serialVersionUID = -6729650486083511095L; private JList<T> list; //the JList we use /** * Create a ListSelector * @param data the Data to add. * */ public ListSelector(T[] data) {
this(Utils.getListModel(data));
masl123/YM2151-Midi-Controller
src/ym2151/Swing/OperatorPanel.java
// Path: src/ym2151/DataModel/Operator.java // public class Operator { // // /** // * A Map that holds the different Operator Values<br> // * There KEYs for the Different Knobs are:<br> // * AR, D1R,<br> // * D2R, RR,<br> // * D1L, TL <br> // * KS, MUL<br> // * DT1, DT2 // * */ // public final ListenerHashMap<String, Integer> map; // // /** // * Creates a new Operator Data Model for the representation of a Instrument in the Controller // * */ // protected Operator(){ // map = new ListenerHashMap<String, Integer>(); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 12){ // return false; // } // // map.put("AR", Integer.parseInt(s[1]) << 2); // map.put("D1R", Integer.parseInt(s[2]) << 2); // map.put("D2R", Integer.parseInt(s[3]) << 3); // map.put("RR", Integer.parseInt(s[4]) << 3); // map.put("D1L", Integer.parseInt(s[5]) << 3); // map.put("TL", Integer.parseInt(s[6])); // map.put("KS", Integer.parseInt(s[7]) << 5); // map.put("MUL", Integer.parseInt(s[8]) << 3); // map.put("DT1", Integer.parseInt(s[9]) << 4); // map.put("DT2", Integer.parseInt(s[10]) << 5); // //map.put("AMSEN", Integer.parseInt(s[11])); // // return true; // } // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // String sp = " "; // int AR = map.get("AR") >> 2; // int D1R = map.get("D1R") >> 2; // int D2R = map.get("D2R") >> 3; // int RR = map.get("RR") >> 3; // int D1L = map.get("D1L") >> 3; // int TL = map.get("TL") ; // int KS = map.get("KS") >> 5; // int MUL = map.get("MUL") >> 3; // int DT1 = map.get("DT1") >> 4; // int DT2 = map.get("DT2") >> 5; // // return AR+sp+D1R+sp+D2R+sp+RR+sp+D1L+sp+TL+sp+KS+sp+MUL+sp+DT1+sp+DT2+sp; // } // // // @Override // public String toString() { // return map.toString(); // } // }
import java.awt.Color; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.border.LineBorder; import ym2151.DataModel.Operator;
/** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * The Panel for the Controls of the Operator part of the YM2151 Chip * */ public class OperatorPanel extends JPanel { private static final long serialVersionUID = -8662494362584813994L; /** * Creates a new Operator Panel * @param op the Operator Data Model * */
// Path: src/ym2151/DataModel/Operator.java // public class Operator { // // /** // * A Map that holds the different Operator Values<br> // * There KEYs for the Different Knobs are:<br> // * AR, D1R,<br> // * D2R, RR,<br> // * D1L, TL <br> // * KS, MUL<br> // * DT1, DT2 // * */ // public final ListenerHashMap<String, Integer> map; // // /** // * Creates a new Operator Data Model for the representation of a Instrument in the Controller // * */ // protected Operator(){ // map = new ListenerHashMap<String, Integer>(); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 12){ // return false; // } // // map.put("AR", Integer.parseInt(s[1]) << 2); // map.put("D1R", Integer.parseInt(s[2]) << 2); // map.put("D2R", Integer.parseInt(s[3]) << 3); // map.put("RR", Integer.parseInt(s[4]) << 3); // map.put("D1L", Integer.parseInt(s[5]) << 3); // map.put("TL", Integer.parseInt(s[6])); // map.put("KS", Integer.parseInt(s[7]) << 5); // map.put("MUL", Integer.parseInt(s[8]) << 3); // map.put("DT1", Integer.parseInt(s[9]) << 4); // map.put("DT2", Integer.parseInt(s[10]) << 5); // //map.put("AMSEN", Integer.parseInt(s[11])); // // return true; // } // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // String sp = " "; // int AR = map.get("AR") >> 2; // int D1R = map.get("D1R") >> 2; // int D2R = map.get("D2R") >> 3; // int RR = map.get("RR") >> 3; // int D1L = map.get("D1L") >> 3; // int TL = map.get("TL") ; // int KS = map.get("KS") >> 5; // int MUL = map.get("MUL") >> 3; // int DT1 = map.get("DT1") >> 4; // int DT2 = map.get("DT2") >> 5; // // return AR+sp+D1R+sp+D2R+sp+RR+sp+D1L+sp+TL+sp+KS+sp+MUL+sp+DT1+sp+DT2+sp; // } // // // @Override // public String toString() { // return map.toString(); // } // } // Path: src/ym2151/Swing/OperatorPanel.java import java.awt.Color; import javax.swing.JPanel; import javax.swing.JLabel; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.border.LineBorder; import ym2151.DataModel.Operator; /** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * The Panel for the Controls of the Operator part of the YM2151 Chip * */ public class OperatorPanel extends JPanel { private static final long serialVersionUID = -8662494362584813994L; /** * Creates a new Operator Panel * @param op the Operator Data Model * */
public OperatorPanel(Operator op) {
masl123/YM2151-Midi-Controller
src/ym2151/Swing/Knob.java
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // }
import ym2151.Utils; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; import java.util.LinkedList; import javax.swing.JPanel;
/** * Removes all Listeners from this Knob * */ public void removeAllKnobListener(){ listeners = new LinkedList<KnobListener>(); } /** * Sends a Event to all the Listeners * */ private void dispatchEvent(){ for(KnobListener l : listeners){ l.knobTurned(var); } } @Override public void paintComponent (Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //get the Middle of the Panel int middle = Math.min(getWidth(), getHeight())/2; if(getWidth()<getHeight()){ //width g2d.rotate(Math.toRadians(((maxRotation)*(1/(max-min)))*var) - Math.toRadians(90), middle, getHeight()/2); //max roatation //draw filled part of the knob g2d.setColor(Color.DARK_GRAY);
// Path: src/ym2151/Utils.java // public class Utils { // // /** // * Get the extension of a file. // */ // public static String getExtension(File f) { // String ext = null; // String s = f.getName(); // int i = s.lastIndexOf('.'); // // if (i > 0 && i < s.length() - 1) { // ext = s.substring(i+1).toLowerCase(); // } // if(ext == null) { // return ""; // } // return ext; // } // // /** // * Adds all Elements from an Array to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, B[] o){ // for(int i = 0 ; i < o.length; i++){ // m.addElement(o[i]); // } // } // // /** // * Adds all Elements from a List to a DefaultListModel // * @param m the Model to add the Entries to // * @param o the Entries to add // * */ // public static <B> void addAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.addElement(o.get(i)); // } // } // // /** // * Removes all entries of the List from a DefaultListModel // * @param m the Model to remove the Entries from // * @param o the Entries to remove // * */ // public static <B> void removeAll(DefaultListModel<B> m, List<B> o){ // for(int i = 0 ; i < o.size(); i++){ // m.removeElement(o.get(i)); // } // } // // /** // * Fills a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void fillCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.fillOval(x,y,r,r); // } // // /** // * Draws a centered circle // * @param g the Graphics Context to draw to // * @param x the x-coordinate // * @param y the y-coordinate // * @param r the Radius // * */ // public static void drawCenteredCircle(Graphics2D g, int x, int y, int r) { // x = x-(r/2); // y = y-(r/2); // g.drawOval(x,y,r,r); // } // // // /** // * creates a DefaultListModel from an Array // * */ // public static<T> DefaultListModel<T> getListModel(T[] data){ // DefaultListModel<T> lm = new DefaultListModel<T>(); // for(T t : data){ // lm.addElement(t); // } // return lm; // } // } // Path: src/ym2151/Swing/Knob.java import ym2151.Utils; import java.awt.Color; import java.awt.Graphics; import java.awt.Graphics2D; import java.awt.Point; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; import java.awt.geom.AffineTransform; import java.util.LinkedList; import javax.swing.JPanel; /** * Removes all Listeners from this Knob * */ public void removeAllKnobListener(){ listeners = new LinkedList<KnobListener>(); } /** * Sends a Event to all the Listeners * */ private void dispatchEvent(){ for(KnobListener l : listeners){ l.knobTurned(var); } } @Override public void paintComponent (Graphics g) { super.paintComponent(g); Graphics2D g2d = (Graphics2D) g; //get the Middle of the Panel int middle = Math.min(getWidth(), getHeight())/2; if(getWidth()<getHeight()){ //width g2d.rotate(Math.toRadians(((maxRotation)*(1/(max-min)))*var) - Math.toRadians(90), middle, getHeight()/2); //max roatation //draw filled part of the knob g2d.setColor(Color.DARK_GRAY);
Utils.fillCenteredCircle(g2d,middle,getHeight()/2,middle*2);
masl123/YM2151-Midi-Controller
src/ym2151/Swing/LFOPanel.java
// Path: src/ym2151/DataModel/LFO.java // public class LFO { // // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are:<br> // * LFRQ,<br> // * AMD,<br> // * PMD,<br> // * WF,<br> // * NFRQ,<br> // * NE <br> // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new LFO Data Model for the representation of a Instrument in the Controller // * */ // protected LFO(){ // map = new ListenerHashMap<String, Integer>(); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 6){ // return false; // } // // map.put("LFRQ", Integer.parseInt(s[1]) >>> 1); // // map.put("AMD", Integer.parseInt(s[2])); // map.put("PMD", Integer.parseInt(s[3])); // // map.put("WF", Integer.parseInt(s[4]) << 5); // map.put("NFRQ", Integer.parseInt(s[5]) << 2); // // return true; // } // // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * */ // protected String toOPM(){ // String sp = " "; // // int LFRQ = map.get("LFRQ") << 1; // int AMD = map.get("AMD"); // int PMD = map.get("PMD"); // int WF = map.get("WF") >> 5; // int NFRQ = map.get("NFRQ") >> 2; // // return LFRQ+sp+AMD+sp+PMD+sp+WF+sp+NFRQ+"\n"; // } // // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // }
import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JToggleButton; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import ym2151.DataModel.LFO; import ym2151.Swing.ListenerHashMap.HashMapListener;
NamedKnob knobAmD = new NamedKnob(lfo.map, "AMD"); GridBagConstraints gbc_knobAP = new GridBagConstraints(); gbc_knobAP.insets = new Insets(0, 0, 5, 5); gbc_knobAP.fill = GridBagConstraints.BOTH; gbc_knobAP.gridx = 0; gbc_knobAP.gridy = 4; add(knobAmD, gbc_knobAP); final JToggleButton tglbtnEnableNoise = new JToggleButton("Enable Noise"); GridBagConstraints gbc_tglbtnEnableNoise = new GridBagConstraints(); gbc_tglbtnEnableNoise.insets = new Insets(0, 0, 5, 5); gbc_tglbtnEnableNoise.gridx = 1; gbc_tglbtnEnableNoise.gridy = 4; add(tglbtnEnableNoise, gbc_tglbtnEnableNoise); tglbtnEnableNoise.addActionListener(new ToggleButtonListener(lfo.map, "NE", tglbtnEnableNoise)); NamedKnob knobNoiseFreq = new NamedKnob(lfo.map, "NFRQ"); GridBagConstraints gbc_knobNoiseFreq = new GridBagConstraints(); gbc_knobNoiseFreq.insets = new Insets(0, 0, 5, 0); gbc_knobNoiseFreq.fill = GridBagConstraints.BOTH; gbc_knobNoiseFreq.gridx = 2; gbc_knobNoiseFreq.gridy = 4; add(knobNoiseFreq, gbc_knobNoiseFreq); } /** * Add a Listener, if the Noise Enable Button Changes * */
// Path: src/ym2151/DataModel/LFO.java // public class LFO { // // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are:<br> // * LFRQ,<br> // * AMD,<br> // * PMD,<br> // * WF,<br> // * NFRQ,<br> // * NE <br> // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new LFO Data Model for the representation of a Instrument in the Controller // * */ // protected LFO(){ // map = new ListenerHashMap<String, Integer>(); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 6){ // return false; // } // // map.put("LFRQ", Integer.parseInt(s[1]) >>> 1); // // map.put("AMD", Integer.parseInt(s[2])); // map.put("PMD", Integer.parseInt(s[3])); // // map.put("WF", Integer.parseInt(s[4]) << 5); // map.put("NFRQ", Integer.parseInt(s[5]) << 2); // // return true; // } // // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * */ // protected String toOPM(){ // String sp = " "; // // int LFRQ = map.get("LFRQ") << 1; // int AMD = map.get("AMD"); // int PMD = map.get("PMD"); // int WF = map.get("WF") >> 5; // int NFRQ = map.get("NFRQ") >> 2; // // return LFRQ+sp+AMD+sp+PMD+sp+WF+sp+NFRQ+"\n"; // } // // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // } // Path: src/ym2151/Swing/LFOPanel.java import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.JPanel; import javax.swing.JLabel; import javax.swing.JToggleButton; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import ym2151.DataModel.LFO; import ym2151.Swing.ListenerHashMap.HashMapListener; NamedKnob knobAmD = new NamedKnob(lfo.map, "AMD"); GridBagConstraints gbc_knobAP = new GridBagConstraints(); gbc_knobAP.insets = new Insets(0, 0, 5, 5); gbc_knobAP.fill = GridBagConstraints.BOTH; gbc_knobAP.gridx = 0; gbc_knobAP.gridy = 4; add(knobAmD, gbc_knobAP); final JToggleButton tglbtnEnableNoise = new JToggleButton("Enable Noise"); GridBagConstraints gbc_tglbtnEnableNoise = new GridBagConstraints(); gbc_tglbtnEnableNoise.insets = new Insets(0, 0, 5, 5); gbc_tglbtnEnableNoise.gridx = 1; gbc_tglbtnEnableNoise.gridy = 4; add(tglbtnEnableNoise, gbc_tglbtnEnableNoise); tglbtnEnableNoise.addActionListener(new ToggleButtonListener(lfo.map, "NE", tglbtnEnableNoise)); NamedKnob knobNoiseFreq = new NamedKnob(lfo.map, "NFRQ"); GridBagConstraints gbc_knobNoiseFreq = new GridBagConstraints(); gbc_knobNoiseFreq.insets = new Insets(0, 0, 5, 0); gbc_knobNoiseFreq.fill = GridBagConstraints.BOTH; gbc_knobNoiseFreq.gridx = 2; gbc_knobNoiseFreq.gridy = 4; add(knobNoiseFreq, gbc_knobNoiseFreq); } /** * Add a Listener, if the Noise Enable Button Changes * */
private class ToggleButtonListener implements ActionListener, HashMapListener<String, Integer>{
masl123/YM2151-Midi-Controller
src/ym2151/Swing/CommonPanel.java
// Path: src/ym2151/DataModel/Common.java // public class Common { // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are: // * <br><br> PAN, FL, CON, AMS, PMS, // * <br>OP1_EN, OP2_EN, OP3_EN, OP4_EN, // * <br>AMSEN_OP1, AMSEN_OP2, AMSEN_OP3, AMSEN_OP4 // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new Common Data Model for the representation of a Instrument in the Controller // * */ // protected Common(){ // map = new ListenerHashMap<String, Integer>(); // map.put("VOL", 63); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 8){ // return false; // } // // map.put("PAN", Integer.parseInt(s[1])); // // map.put("FL", Integer.parseInt(s[2]) << 4); //FB // // map.put("CON", Integer.parseInt(s[3]) << 4); //ALGO // // map.put("AMS", Integer.parseInt(s[4]) << 5);//AMS // // map.put("PMS", Integer.parseInt(s[5]) << 4);//PMS // // int slot = (Integer.parseInt(s[6]) >> 3) & 0x0F; // // map.put("OP1_EN", ((slot) & 0x01) * 127); // map.put("OP3_EN", ((slot >> 1) & 0x01) * 127); // map.put("OP2_EN", ((slot >> 2) & 0x01) * 127); // map.put("OP4_EN", ((slot >> 3) & 0x01) * 127); // // return true; // } // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // // String sp = " "; // int PAN = map.get("PAN"); // int FL = map.get("FL") >> 4; // int CON = map.get("CON") >> 4; // int AMS = map.get("AMS") >> 5; // int PMS = map.get("PMS") >> 4; // // // int OP1_EN = map.get("OP1_EN") >= 64 ? 1 : 0; // int OP3_EN = map.get("OP3_EN") >= 64 ? 1 : 0; // int OP2_EN = map.get("OP2_EN") >= 64 ? 1 : 0; // int OP4_EN = map.get("OP4_EN") >= 64 ? 1 : 0; // // int SLOT = ((OP1_EN) | (OP3_EN << 1) | (OP2_EN << 2) |(OP4_EN << 3)) << 3; // // return PAN+sp+FL+sp+CON+sp+AMS+sp+PMS+sp+SLOT+sp; // } // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // }
import ym2151.DataModel.Common; import ym2151.Swing.ListenerHashMap.HashMapListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridLayout; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton;
/** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * The Panel for the Controls of the Common part of the YM2151 Chip * */ public class CommonPanel extends JPanel { private AlgorithmSelector algorithmSelector; /** * Creates a new Common Panel * @param common the Common Data Model * * */
// Path: src/ym2151/DataModel/Common.java // public class Common { // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are: // * <br><br> PAN, FL, CON, AMS, PMS, // * <br>OP1_EN, OP2_EN, OP3_EN, OP4_EN, // * <br>AMSEN_OP1, AMSEN_OP2, AMSEN_OP3, AMSEN_OP4 // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new Common Data Model for the representation of a Instrument in the Controller // * */ // protected Common(){ // map = new ListenerHashMap<String, Integer>(); // map.put("VOL", 63); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 8){ // return false; // } // // map.put("PAN", Integer.parseInt(s[1])); // // map.put("FL", Integer.parseInt(s[2]) << 4); //FB // // map.put("CON", Integer.parseInt(s[3]) << 4); //ALGO // // map.put("AMS", Integer.parseInt(s[4]) << 5);//AMS // // map.put("PMS", Integer.parseInt(s[5]) << 4);//PMS // // int slot = (Integer.parseInt(s[6]) >> 3) & 0x0F; // // map.put("OP1_EN", ((slot) & 0x01) * 127); // map.put("OP3_EN", ((slot >> 1) & 0x01) * 127); // map.put("OP2_EN", ((slot >> 2) & 0x01) * 127); // map.put("OP4_EN", ((slot >> 3) & 0x01) * 127); // // return true; // } // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // // String sp = " "; // int PAN = map.get("PAN"); // int FL = map.get("FL") >> 4; // int CON = map.get("CON") >> 4; // int AMS = map.get("AMS") >> 5; // int PMS = map.get("PMS") >> 4; // // // int OP1_EN = map.get("OP1_EN") >= 64 ? 1 : 0; // int OP3_EN = map.get("OP3_EN") >= 64 ? 1 : 0; // int OP2_EN = map.get("OP2_EN") >= 64 ? 1 : 0; // int OP4_EN = map.get("OP4_EN") >= 64 ? 1 : 0; // // int SLOT = ((OP1_EN) | (OP3_EN << 1) | (OP2_EN << 2) |(OP4_EN << 3)) << 3; // // return PAN+sp+FL+sp+CON+sp+AMS+sp+PMS+sp+SLOT+sp; // } // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // } // Path: src/ym2151/Swing/CommonPanel.java import ym2151.DataModel.Common; import ym2151.Swing.ListenerHashMap.HashMapListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridLayout; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton; /** * YM2151 - Midi Controller Software for Arduino Shield * (C) 2016 Marcel Weiß * * This program is free software : you can redistribute it and / or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program 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 General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program.If not, see <http://www.gnu.org/licenses/>. */ package ym2151.Swing; /** * The Panel for the Controls of the Common part of the YM2151 Chip * */ public class CommonPanel extends JPanel { private AlgorithmSelector algorithmSelector; /** * Creates a new Common Panel * @param common the Common Data Model * * */
public CommonPanel(final Common common) {
masl123/YM2151-Midi-Controller
src/ym2151/Swing/CommonPanel.java
// Path: src/ym2151/DataModel/Common.java // public class Common { // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are: // * <br><br> PAN, FL, CON, AMS, PMS, // * <br>OP1_EN, OP2_EN, OP3_EN, OP4_EN, // * <br>AMSEN_OP1, AMSEN_OP2, AMSEN_OP3, AMSEN_OP4 // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new Common Data Model for the representation of a Instrument in the Controller // * */ // protected Common(){ // map = new ListenerHashMap<String, Integer>(); // map.put("VOL", 63); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 8){ // return false; // } // // map.put("PAN", Integer.parseInt(s[1])); // // map.put("FL", Integer.parseInt(s[2]) << 4); //FB // // map.put("CON", Integer.parseInt(s[3]) << 4); //ALGO // // map.put("AMS", Integer.parseInt(s[4]) << 5);//AMS // // map.put("PMS", Integer.parseInt(s[5]) << 4);//PMS // // int slot = (Integer.parseInt(s[6]) >> 3) & 0x0F; // // map.put("OP1_EN", ((slot) & 0x01) * 127); // map.put("OP3_EN", ((slot >> 1) & 0x01) * 127); // map.put("OP2_EN", ((slot >> 2) & 0x01) * 127); // map.put("OP4_EN", ((slot >> 3) & 0x01) * 127); // // return true; // } // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // // String sp = " "; // int PAN = map.get("PAN"); // int FL = map.get("FL") >> 4; // int CON = map.get("CON") >> 4; // int AMS = map.get("AMS") >> 5; // int PMS = map.get("PMS") >> 4; // // // int OP1_EN = map.get("OP1_EN") >= 64 ? 1 : 0; // int OP3_EN = map.get("OP3_EN") >= 64 ? 1 : 0; // int OP2_EN = map.get("OP2_EN") >= 64 ? 1 : 0; // int OP4_EN = map.get("OP4_EN") >= 64 ? 1 : 0; // // int SLOT = ((OP1_EN) | (OP3_EN << 1) | (OP2_EN << 2) |(OP4_EN << 3)) << 3; // // return PAN+sp+FL+sp+CON+sp+AMS+sp+PMS+sp+SLOT+sp; // } // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // }
import ym2151.DataModel.Common; import ym2151.Swing.ListenerHashMap.HashMapListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridLayout; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton;
//Button to increase the Selected Algorithm JButton buttonRight = new JButton(""); buttonRight.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int algorithm = algorithmSelector.getAlgorithm(); algorithm = (algorithm+1) % 8; algorithmSelector.setAlgorithm(algorithm); algorithmChanged(common.map); } }); pnlAlgControl.add(buttonRight); } /** * Change the Algorithm in the Data Model if the User Clicked on the Button * */ private void algorithmChanged(ListenerHashMap<String, Integer> map){ int algorithm = algorithmSelector.getAlgorithm(); if(map.get("CON")== null || !map.get("CON").equals(algorithm)){ map.put("CON", algorithm << 4); } } /** * Change the Algorithm in the algorithmSelector if it got Changed * */
// Path: src/ym2151/DataModel/Common.java // public class Common { // // /** // * A Map that holds the different Controller Values<br> // * There KEYs for the Different Knobs are: // * <br><br> PAN, FL, CON, AMS, PMS, // * <br>OP1_EN, OP2_EN, OP3_EN, OP4_EN, // * <br>AMSEN_OP1, AMSEN_OP2, AMSEN_OP3, AMSEN_OP4 // * */ // public final ListenerHashMap<String, Integer> map; // // // /** // * Creates a new Common Data Model for the representation of a Instrument in the Controller // * */ // protected Common(){ // map = new ListenerHashMap<String, Integer>(); // map.put("VOL", 63); // } // // // /** // * This is Part of the OPM File Parsing. Use OPMFile to Load a OPM File. // * @param s the String Values to parse. // * @return "true" if parsing went OK and "false" if else. // * */ // protected boolean setVars(String[] s){ // if(s.length != 8){ // return false; // } // // map.put("PAN", Integer.parseInt(s[1])); // // map.put("FL", Integer.parseInt(s[2]) << 4); //FB // // map.put("CON", Integer.parseInt(s[3]) << 4); //ALGO // // map.put("AMS", Integer.parseInt(s[4]) << 5);//AMS // // map.put("PMS", Integer.parseInt(s[5]) << 4);//PMS // // int slot = (Integer.parseInt(s[6]) >> 3) & 0x0F; // // map.put("OP1_EN", ((slot) & 0x01) * 127); // map.put("OP3_EN", ((slot >> 1) & 0x01) * 127); // map.put("OP2_EN", ((slot >> 2) & 0x01) * 127); // map.put("OP4_EN", ((slot >> 3) & 0x01) * 127); // // return true; // } // // /** // * This is Part of the OPM File Creation. Use OPMFile to Save a OPM File. // * @return the String to add to the OPM File // * */ // protected String toOPM(){ // // String sp = " "; // int PAN = map.get("PAN"); // int FL = map.get("FL") >> 4; // int CON = map.get("CON") >> 4; // int AMS = map.get("AMS") >> 5; // int PMS = map.get("PMS") >> 4; // // // int OP1_EN = map.get("OP1_EN") >= 64 ? 1 : 0; // int OP3_EN = map.get("OP3_EN") >= 64 ? 1 : 0; // int OP2_EN = map.get("OP2_EN") >= 64 ? 1 : 0; // int OP4_EN = map.get("OP4_EN") >= 64 ? 1 : 0; // // int SLOT = ((OP1_EN) | (OP3_EN << 1) | (OP2_EN << 2) |(OP4_EN << 3)) << 3; // // return PAN+sp+FL+sp+CON+sp+AMS+sp+PMS+sp+SLOT+sp; // } // // } // // Path: src/ym2151/Swing/ListenerHashMap.java // public interface HashMapListener<K,V>{ // public void valueChanged(K key, V value); // } // Path: src/ym2151/Swing/CommonPanel.java import ym2151.DataModel.Common; import ym2151.Swing.ListenerHashMap.HashMapListener; import java.awt.event.ActionListener; import java.awt.event.ActionEvent; import javax.swing.BoxLayout; import java.awt.Component; import javax.swing.JLabel; import javax.swing.JPanel; import javax.swing.SwingConstants; import javax.swing.border.LineBorder; import java.awt.Color; import java.awt.GridLayout; import java.awt.GridBagLayout; import java.awt.GridBagConstraints; import java.awt.Insets; import javax.swing.JButton; //Button to increase the Selected Algorithm JButton buttonRight = new JButton(""); buttonRight.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent arg0) { int algorithm = algorithmSelector.getAlgorithm(); algorithm = (algorithm+1) % 8; algorithmSelector.setAlgorithm(algorithm); algorithmChanged(common.map); } }); pnlAlgControl.add(buttonRight); } /** * Change the Algorithm in the Data Model if the User Clicked on the Button * */ private void algorithmChanged(ListenerHashMap<String, Integer> map){ int algorithm = algorithmSelector.getAlgorithm(); if(map.get("CON")== null || !map.get("CON").equals(algorithm)){ map.put("CON", algorithm << 4); } } /** * Change the Algorithm in the algorithmSelector if it got Changed * */
private class AlgorithmSelectorListener implements HashMapListener<String, Integer>{
googleworkspace/java-samples
vault/vault-hold-migration-api/src/main/java/com/google/vault/chatmigration/QuickStart.java
// Path: vault/vault-hold-migration-api/src/main/java/com/google/vault/chatmigration/MigrationHelper.java // enum MigrationOptions { // GENERATE_REPORT("a", "genholdreport", "Generate Hold Report"), // DUPLICATE_HOLDS("b", "duplicateholds", "Duplicate Gmail Holds to Hangouts Chat"), // REPORT_FILE("f", "reportfile", "Path to holds report file"), // ERROR_FILE("e", "errorfile", "Path to error report file"), // INCLUDE_ROOMS("g", "includerooms", "Include Rooms when duplicating holds to Hangouts Chat"), // HELP("h", "help", "Options Help"); // // private final String option; // private final String longOpt; // private final String description; // // MigrationOptions(String opt, String longOpt, String description) { // this.option = opt; // this.longOpt = longOpt; // this.description = description; // } // // public String getOption() { // return option; // } // }
import com.google.api.services.admin.directory.Directory; import com.google.api.services.vault.v1.Vault; import com.google.vault.chatmigration.MigrationHelper.MigrationOptions; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.Charset; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVPrinter;
package com.google.vault.chatmigration; public class QuickStart { private static final Logger LOGGER = Logger.getLogger(QuickStart.class.getName()); private static boolean hasHelpOption(String... args) throws ParseException { boolean hasHelp = false; Options helpOptions = new Options().addOption(MigrationHelper.helpOption); CommandLine cl = new DefaultParser().parse(helpOptions, args, true);
// Path: vault/vault-hold-migration-api/src/main/java/com/google/vault/chatmigration/MigrationHelper.java // enum MigrationOptions { // GENERATE_REPORT("a", "genholdreport", "Generate Hold Report"), // DUPLICATE_HOLDS("b", "duplicateholds", "Duplicate Gmail Holds to Hangouts Chat"), // REPORT_FILE("f", "reportfile", "Path to holds report file"), // ERROR_FILE("e", "errorfile", "Path to error report file"), // INCLUDE_ROOMS("g", "includerooms", "Include Rooms when duplicating holds to Hangouts Chat"), // HELP("h", "help", "Options Help"); // // private final String option; // private final String longOpt; // private final String description; // // MigrationOptions(String opt, String longOpt, String description) { // this.option = opt; // this.longOpt = longOpt; // this.description = description; // } // // public String getOption() { // return option; // } // } // Path: vault/vault-hold-migration-api/src/main/java/com/google/vault/chatmigration/QuickStart.java import com.google.api.services.admin.directory.Directory; import com.google.api.services.vault.v1.Vault; import com.google.vault.chatmigration.MigrationHelper.MigrationOptions; import java.io.File; import java.io.FileWriter; import java.io.IOException; import java.nio.charset.Charset; import java.util.logging.Level; import java.util.logging.Logger; import org.apache.commons.cli.CommandLine; import org.apache.commons.cli.DefaultParser; import org.apache.commons.cli.Options; import org.apache.commons.cli.ParseException; import org.apache.commons.csv.CSVFormat; import org.apache.commons.csv.CSVParser; import org.apache.commons.csv.CSVPrinter; package com.google.vault.chatmigration; public class QuickStart { private static final Logger LOGGER = Logger.getLogger(QuickStart.class.getName()); private static boolean hasHelpOption(String... args) throws ParseException { boolean hasHelp = false; Options helpOptions = new Options().addOption(MigrationHelper.helpOption); CommandLine cl = new DefaultParser().parse(helpOptions, args, true);
if (cl.hasOption(MigrationOptions.HELP.getOption())) {
wizzardo/epoll
src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // }
import com.wizzardo.epoll.readable.ReadableData; import java.nio.ByteBuffer;
package com.wizzardo.epoll; /** * @author: wizzardo * Date: 3/15/14 */ public class ByteBufferWrapper { private final ByteBuffer buffer; private int offset = 0; public final long address; public ByteBufferWrapper(ByteBuffer buffer) { if (!buffer.isDirect()) throw new IllegalArgumentException("byte buffer must be direct"); this.buffer = buffer; address = EpollCore.address(buffer); }
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // } // Path: src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java import com.wizzardo.epoll.readable.ReadableData; import java.nio.ByteBuffer; package com.wizzardo.epoll; /** * @author: wizzardo * Date: 3/15/14 */ public class ByteBufferWrapper { private final ByteBuffer buffer; private int offset = 0; public final long address; public ByteBufferWrapper(ByteBuffer buffer) { if (!buffer.isDirect()) throw new IllegalArgumentException("byte buffer must be direct"); this.buffer = buffer; address = EpollCore.address(buffer); }
public ByteBufferWrapper(ReadableData data) {
wizzardo/epoll
src/main/java/com/wizzardo/epoll/EpollCore.java
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // } // // Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readShort(byte[] b, int offset) { // // if (b.length - offset < 2 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 2 bytes"); // // return ((b[offset] & 0xff) << 8) + ((b[offset + 1] & 0xff)); // }
import com.wizzardo.tools.misc.Unchecked; import com.wizzardo.tools.reflection.FieldReflection; import com.wizzardo.tools.reflection.FieldReflectionFactory; import com.wizzardo.tools.reflection.UnsafeTools; import java.io.IOException; import java.net.InetAddress; import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.regex.Pattern; import static com.wizzardo.epoll.Utils.readInt; import static com.wizzardo.epoll.Utils.readShort;
ioThreads[i].start(); } ByteBuffer eventsBuffer = this.events; byte[] events = new byte[eventsBuffer.capacity()]; byte[] newConnections = new byte[eventsBuffer.capacity()]; if (ioThreadsCount == 0) { IOThread<? extends T> ioThread = createIOThread(1, 1); ioThreadsCount = 1; ioThread.scope = scope; ioThreads = new IOThread[]{ioThread}; ioThreads[0].setTTL(ttl); ioThreads[0].loadCertificates(sslConfig); long prev = System.nanoTime(); while (running) { try { eventsBuffer.position(0); long now = System.nanoTime() * 1000; long nowMinusSecond = now - 1_000_000_000_000L; // 1 sec int r = waitForEvents(500); eventsBuffer.limit(r); eventsBuffer.get(events, 0, r); int i = 0; while (i < r) { int event = events[i]; if (event == 0) { acceptConnections(newConnections); } else {
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // } // // Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readShort(byte[] b, int offset) { // // if (b.length - offset < 2 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 2 bytes"); // // return ((b[offset] & 0xff) << 8) + ((b[offset + 1] & 0xff)); // } // Path: src/main/java/com/wizzardo/epoll/EpollCore.java import com.wizzardo.tools.misc.Unchecked; import com.wizzardo.tools.reflection.FieldReflection; import com.wizzardo.tools.reflection.FieldReflectionFactory; import com.wizzardo.tools.reflection.UnsafeTools; import java.io.IOException; import java.net.InetAddress; import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.regex.Pattern; import static com.wizzardo.epoll.Utils.readInt; import static com.wizzardo.epoll.Utils.readShort; ioThreads[i].start(); } ByteBuffer eventsBuffer = this.events; byte[] events = new byte[eventsBuffer.capacity()]; byte[] newConnections = new byte[eventsBuffer.capacity()]; if (ioThreadsCount == 0) { IOThread<? extends T> ioThread = createIOThread(1, 1); ioThreadsCount = 1; ioThread.scope = scope; ioThreads = new IOThread[]{ioThread}; ioThreads[0].setTTL(ttl); ioThreads[0].loadCertificates(sslConfig); long prev = System.nanoTime(); while (running) { try { eventsBuffer.position(0); long now = System.nanoTime() * 1000; long nowMinusSecond = now - 1_000_000_000_000L; // 1 sec int r = waitForEvents(500); eventsBuffer.limit(r); eventsBuffer.get(events, 0, r); int i = 0; while (i < r) { int event = events[i]; if (event == 0) { acceptConnections(newConnections); } else {
int fd = readInt(events, i + 1);
wizzardo/epoll
src/main/java/com/wizzardo/epoll/EpollCore.java
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // } // // Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readShort(byte[] b, int offset) { // // if (b.length - offset < 2 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 2 bytes"); // // return ((b[offset] & 0xff) << 8) + ((b[offset + 1] & 0xff)); // }
import com.wizzardo.tools.misc.Unchecked; import com.wizzardo.tools.reflection.FieldReflection; import com.wizzardo.tools.reflection.FieldReflectionFactory; import com.wizzardo.tools.reflection.UnsafeTools; import java.io.IOException; import java.net.InetAddress; import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.regex.Pattern; import static com.wizzardo.epoll.Utils.readInt; import static com.wizzardo.epoll.Utils.readShort;
public void setTTL(long milliseconds) { ttl = milliseconds; } public long getTTL() { return ttl; } public void close() { synchronized (this) { if (running) { running = false; stopListening(scope); try { join(); } catch (InterruptedException ignored) { } } } } private void acceptConnections(byte[] buffer) throws IOException { int k; do { events.position(0); k = acceptConnections(scope, events.capacity() - 10); events.limit(k); events.get(buffer, 0, k); // eventCounter.addAndGet(k / 10); for (int j = 0; j < k; j += 10) {
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // } // // Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readShort(byte[] b, int offset) { // // if (b.length - offset < 2 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 2 bytes"); // // return ((b[offset] & 0xff) << 8) + ((b[offset + 1] & 0xff)); // } // Path: src/main/java/com/wizzardo/epoll/EpollCore.java import com.wizzardo.tools.misc.Unchecked; import com.wizzardo.tools.reflection.FieldReflection; import com.wizzardo.tools.reflection.FieldReflectionFactory; import com.wizzardo.tools.reflection.UnsafeTools; import java.io.IOException; import java.net.InetAddress; import java.nio.Buffer; import java.nio.ByteBuffer; import java.util.regex.Pattern; import static com.wizzardo.epoll.Utils.readInt; import static com.wizzardo.epoll.Utils.readShort; public void setTTL(long milliseconds) { ttl = milliseconds; } public long getTTL() { return ttl; } public void close() { synchronized (this) { if (running) { running = false; stopListening(scope); try { join(); } catch (InterruptedException ignored) { } } } } private void acceptConnections(byte[] buffer) throws IOException { int k; do { events.position(0); k = acceptConnections(scope, events.capacity() - 10); events.limit(k); events.get(buffer, 0, k); // eventCounter.addAndGet(k / 10); for (int j = 0; j < k; j += 10) {
putConnection(createConnection(readInt(buffer, j), readInt(buffer, j + 4), readShort(buffer, j + 8)));
wizzardo/epoll
src/main/java/com/wizzardo/epoll/IOThread.java
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // }
import java.io.IOException; import java.lang.reflect.Array; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static com.wizzardo.epoll.Utils.readInt;
package com.wizzardo.epoll; /** * @author: wizzardo * Date: 6/25/14 */ public class IOThread<T extends Connection> extends EpollCore<T> { protected final int number; protected final int divider; protected T[] connections = (T[]) new Connection[1000]; protected Map<Integer, T> newConnections = new ConcurrentHashMap<Integer, T>(); protected LinkedHashMap<Long, T> timeouts = new LinkedHashMap<Long, T>(); public IOThread(int number, int divider) { this.number = number; this.divider = divider; setName("IOThread-" + number); } @Override public void run() { byte[] events = new byte[this.events.capacity()]; // System.out.println("start new ioThread"); long prev = System.nanoTime(); while (running) { this.events.position(0); long now = System.nanoTime() * 1000; long nowMinusSecond = now - 1_000_000_000_000L;// 1 sec int r = waitForEvents(500); // System.out.println("events length: "+r); this.events.limit(r); this.events.get(events, 0, r); int i = 0; while (i < r) { int event = events[i];
// Path: src/main/java/com/wizzardo/epoll/Utils.java // public static int readInt(byte[] b, int offset) { // // if (b.length - offset < 4 || offset < 0) // // throw new IndexOutOfBoundsException("byte[].length = " + b.length + ", but offset = " + offset + " and we need 4 bytes"); // // return ((b[offset] & 0xff) << 24) + ((b[offset + 1] & 0xff) << 16) + ((b[offset + 2] & 0xff) << 8) + ((b[offset + 3] & 0xff)); // } // Path: src/main/java/com/wizzardo/epoll/IOThread.java import java.io.IOException; import java.lang.reflect.Array; import java.util.Iterator; import java.util.LinkedHashMap; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import static com.wizzardo.epoll.Utils.readInt; package com.wizzardo.epoll; /** * @author: wizzardo * Date: 6/25/14 */ public class IOThread<T extends Connection> extends EpollCore<T> { protected final int number; protected final int divider; protected T[] connections = (T[]) new Connection[1000]; protected Map<Integer, T> newConnections = new ConcurrentHashMap<Integer, T>(); protected LinkedHashMap<Long, T> timeouts = new LinkedHashMap<Long, T>(); public IOThread(int number, int divider) { this.number = number; this.divider = divider; setName("IOThread-" + number); } @Override public void run() { byte[] events = new byte[this.events.capacity()]; // System.out.println("start new ioThread"); long prev = System.nanoTime(); while (running) { this.events.position(0); long now = System.nanoTime() * 1000; long nowMinusSecond = now - 1_000_000_000_000L;// 1 sec int r = waitForEvents(500); // System.out.println("events length: "+r); this.events.limit(r); this.events.get(events, 0, r); int i = 0; while (i < r) { int event = events[i];
int fd = readInt(events, i + 1);
wizzardo/epoll
src/main/java/com/wizzardo/epoll/readable/ReadableBuilder.java
// Path: src/main/java/com/wizzardo/epoll/ByteBufferProvider.java // public interface ByteBufferProvider { // ByteBufferWrapper getBuffer(); // // /** // * @return result of casting Thread.currentThread() to {@link ByteBufferProvider} // * @throws ClassCastException if current thread doesn't implement {@link ByteBufferProvider} // **/ // static ByteBufferProvider current() { // return (ByteBufferProvider) Thread.currentThread(); // } // } // // Path: src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java // public class ByteBufferWrapper { // // private final ByteBuffer buffer; // private int offset = 0; // // public final long address; // // public ByteBufferWrapper(ByteBuffer buffer) { // if (!buffer.isDirect()) // throw new IllegalArgumentException("byte buffer must be direct"); // // this.buffer = buffer; // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(ReadableData data) { // this.buffer = ByteBuffer.allocateDirect((int) data.length()); // address = EpollCore.address(buffer); // data.read(buffer); // flip(); // } // // public ByteBufferWrapper(int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ByteBufferWrapper(byte[] bytes, int offset, int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // put(bytes, offset, length); // flip(); // } // // public int limit() { // return buffer.limit(); // } // // public ByteBufferWrapper position(int r) { // buffer.position(r); // return this; // } // // public ByteBufferWrapper flip() { // buffer.flip(); // return this; // } // // public ByteBufferWrapper put(byte[] b, int offset, int l) { // buffer.put(b, offset, l); // return this; // } // // public int remaining() { // return buffer.remaining(); // } // // public int position() { // return buffer.position(); // } // // public void clear() { // buffer.clear(); // } // // public ByteBuffer buffer() { // return buffer; // } // // public int capacity() { // return buffer.capacity(); // } // // public int offset() { // return offset; // } // // public void offset(int offset) { // //TODO check usage of offset // this.offset = offset; // } // // @Override // public String toString() { // int position = buffer.position(); // int limit = buffer.limit(); // buffer.position(0); // buffer.limit(buffer.capacity()); // byte[] bytes = new byte[buffer.limit()]; // buffer.get(bytes); // // buffer.clear(); // buffer.limit(limit); // buffer.position(position); // return new String(bytes); // } // }
import com.wizzardo.epoll.ByteBufferProvider; import com.wizzardo.epoll.ByteBufferWrapper; import java.io.IOException; import java.nio.ByteBuffer;
return append(bytes, 0, bytes.length); } public ReadableBuilder append(byte[] bytes, int offset, int length) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = new ReadableByteArray(bytes, offset, length); partsCount++; return this; } public ReadableBuilder append(ReadableData readableData) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = readableData; partsCount++; return this; } protected void increaseSize() { ReadableData[] temp = new ReadableData[Math.max(partsCount * 3 / 2, 2)]; System.arraycopy(parts, 0, temp, 0, partsCount); parts = temp; } @Override
// Path: src/main/java/com/wizzardo/epoll/ByteBufferProvider.java // public interface ByteBufferProvider { // ByteBufferWrapper getBuffer(); // // /** // * @return result of casting Thread.currentThread() to {@link ByteBufferProvider} // * @throws ClassCastException if current thread doesn't implement {@link ByteBufferProvider} // **/ // static ByteBufferProvider current() { // return (ByteBufferProvider) Thread.currentThread(); // } // } // // Path: src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java // public class ByteBufferWrapper { // // private final ByteBuffer buffer; // private int offset = 0; // // public final long address; // // public ByteBufferWrapper(ByteBuffer buffer) { // if (!buffer.isDirect()) // throw new IllegalArgumentException("byte buffer must be direct"); // // this.buffer = buffer; // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(ReadableData data) { // this.buffer = ByteBuffer.allocateDirect((int) data.length()); // address = EpollCore.address(buffer); // data.read(buffer); // flip(); // } // // public ByteBufferWrapper(int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ByteBufferWrapper(byte[] bytes, int offset, int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // put(bytes, offset, length); // flip(); // } // // public int limit() { // return buffer.limit(); // } // // public ByteBufferWrapper position(int r) { // buffer.position(r); // return this; // } // // public ByteBufferWrapper flip() { // buffer.flip(); // return this; // } // // public ByteBufferWrapper put(byte[] b, int offset, int l) { // buffer.put(b, offset, l); // return this; // } // // public int remaining() { // return buffer.remaining(); // } // // public int position() { // return buffer.position(); // } // // public void clear() { // buffer.clear(); // } // // public ByteBuffer buffer() { // return buffer; // } // // public int capacity() { // return buffer.capacity(); // } // // public int offset() { // return offset; // } // // public void offset(int offset) { // //TODO check usage of offset // this.offset = offset; // } // // @Override // public String toString() { // int position = buffer.position(); // int limit = buffer.limit(); // buffer.position(0); // buffer.limit(buffer.capacity()); // byte[] bytes = new byte[buffer.limit()]; // buffer.get(bytes); // // buffer.clear(); // buffer.limit(limit); // buffer.position(position); // return new String(bytes); // } // } // Path: src/main/java/com/wizzardo/epoll/readable/ReadableBuilder.java import com.wizzardo.epoll.ByteBufferProvider; import com.wizzardo.epoll.ByteBufferWrapper; import java.io.IOException; import java.nio.ByteBuffer; return append(bytes, 0, bytes.length); } public ReadableBuilder append(byte[] bytes, int offset, int length) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = new ReadableByteArray(bytes, offset, length); partsCount++; return this; } public ReadableBuilder append(ReadableData readableData) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = readableData; partsCount++; return this; } protected void increaseSize() { ReadableData[] temp = new ReadableData[Math.max(partsCount * 3 / 2, 2)]; System.arraycopy(parts, 0, temp, 0, partsCount); parts = temp; } @Override
public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) {
wizzardo/epoll
src/main/java/com/wizzardo/epoll/readable/ReadableBuilder.java
// Path: src/main/java/com/wizzardo/epoll/ByteBufferProvider.java // public interface ByteBufferProvider { // ByteBufferWrapper getBuffer(); // // /** // * @return result of casting Thread.currentThread() to {@link ByteBufferProvider} // * @throws ClassCastException if current thread doesn't implement {@link ByteBufferProvider} // **/ // static ByteBufferProvider current() { // return (ByteBufferProvider) Thread.currentThread(); // } // } // // Path: src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java // public class ByteBufferWrapper { // // private final ByteBuffer buffer; // private int offset = 0; // // public final long address; // // public ByteBufferWrapper(ByteBuffer buffer) { // if (!buffer.isDirect()) // throw new IllegalArgumentException("byte buffer must be direct"); // // this.buffer = buffer; // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(ReadableData data) { // this.buffer = ByteBuffer.allocateDirect((int) data.length()); // address = EpollCore.address(buffer); // data.read(buffer); // flip(); // } // // public ByteBufferWrapper(int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ByteBufferWrapper(byte[] bytes, int offset, int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // put(bytes, offset, length); // flip(); // } // // public int limit() { // return buffer.limit(); // } // // public ByteBufferWrapper position(int r) { // buffer.position(r); // return this; // } // // public ByteBufferWrapper flip() { // buffer.flip(); // return this; // } // // public ByteBufferWrapper put(byte[] b, int offset, int l) { // buffer.put(b, offset, l); // return this; // } // // public int remaining() { // return buffer.remaining(); // } // // public int position() { // return buffer.position(); // } // // public void clear() { // buffer.clear(); // } // // public ByteBuffer buffer() { // return buffer; // } // // public int capacity() { // return buffer.capacity(); // } // // public int offset() { // return offset; // } // // public void offset(int offset) { // //TODO check usage of offset // this.offset = offset; // } // // @Override // public String toString() { // int position = buffer.position(); // int limit = buffer.limit(); // buffer.position(0); // buffer.limit(buffer.capacity()); // byte[] bytes = new byte[buffer.limit()]; // buffer.get(bytes); // // buffer.clear(); // buffer.limit(limit); // buffer.position(position); // return new String(bytes); // } // }
import com.wizzardo.epoll.ByteBufferProvider; import com.wizzardo.epoll.ByteBufferWrapper; import java.io.IOException; import java.nio.ByteBuffer;
return append(bytes, 0, bytes.length); } public ReadableBuilder append(byte[] bytes, int offset, int length) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = new ReadableByteArray(bytes, offset, length); partsCount++; return this; } public ReadableBuilder append(ReadableData readableData) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = readableData; partsCount++; return this; } protected void increaseSize() { ReadableData[] temp = new ReadableData[Math.max(partsCount * 3 / 2, 2)]; System.arraycopy(parts, 0, temp, 0, partsCount); parts = temp; } @Override
// Path: src/main/java/com/wizzardo/epoll/ByteBufferProvider.java // public interface ByteBufferProvider { // ByteBufferWrapper getBuffer(); // // /** // * @return result of casting Thread.currentThread() to {@link ByteBufferProvider} // * @throws ClassCastException if current thread doesn't implement {@link ByteBufferProvider} // **/ // static ByteBufferProvider current() { // return (ByteBufferProvider) Thread.currentThread(); // } // } // // Path: src/main/java/com/wizzardo/epoll/ByteBufferWrapper.java // public class ByteBufferWrapper { // // private final ByteBuffer buffer; // private int offset = 0; // // public final long address; // // public ByteBufferWrapper(ByteBuffer buffer) { // if (!buffer.isDirect()) // throw new IllegalArgumentException("byte buffer must be direct"); // // this.buffer = buffer; // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(ReadableData data) { // this.buffer = ByteBuffer.allocateDirect((int) data.length()); // address = EpollCore.address(buffer); // data.read(buffer); // flip(); // } // // public ByteBufferWrapper(int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // } // // public ByteBufferWrapper(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ByteBufferWrapper(byte[] bytes, int offset, int length) { // this.buffer = ByteBuffer.allocateDirect(length); // address = EpollCore.address(buffer); // put(bytes, offset, length); // flip(); // } // // public int limit() { // return buffer.limit(); // } // // public ByteBufferWrapper position(int r) { // buffer.position(r); // return this; // } // // public ByteBufferWrapper flip() { // buffer.flip(); // return this; // } // // public ByteBufferWrapper put(byte[] b, int offset, int l) { // buffer.put(b, offset, l); // return this; // } // // public int remaining() { // return buffer.remaining(); // } // // public int position() { // return buffer.position(); // } // // public void clear() { // buffer.clear(); // } // // public ByteBuffer buffer() { // return buffer; // } // // public int capacity() { // return buffer.capacity(); // } // // public int offset() { // return offset; // } // // public void offset(int offset) { // //TODO check usage of offset // this.offset = offset; // } // // @Override // public String toString() { // int position = buffer.position(); // int limit = buffer.limit(); // buffer.position(0); // buffer.limit(buffer.capacity()); // byte[] bytes = new byte[buffer.limit()]; // buffer.get(bytes); // // buffer.clear(); // buffer.limit(limit); // buffer.position(position); // return new String(bytes); // } // } // Path: src/main/java/com/wizzardo/epoll/readable/ReadableBuilder.java import com.wizzardo.epoll.ByteBufferProvider; import com.wizzardo.epoll.ByteBufferWrapper; import java.io.IOException; import java.nio.ByteBuffer; return append(bytes, 0, bytes.length); } public ReadableBuilder append(byte[] bytes, int offset, int length) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = new ReadableByteArray(bytes, offset, length); partsCount++; return this; } public ReadableBuilder append(ReadableData readableData) { if (partsCount + 1 >= parts.length) increaseSize(); parts[partsCount] = readableData; partsCount++; return this; } protected void increaseSize() { ReadableData[] temp = new ReadableData[Math.max(partsCount * 3 / 2, 2)]; System.arraycopy(parts, 0, temp, 0, partsCount); parts = temp; } @Override
public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) {
wizzardo/epoll
src/main/java/com/wizzardo/epoll/Connection.java
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // } // // Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // }
import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.io.IOTools; import java.io.*; import java.nio.ByteBuffer; import java.util.Deque; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicReference;
package com.wizzardo.epoll; /** * @author: wizzardo * Date: 1/6/14 */ public class Connection implements Cloneable, Closeable { protected static final int EPOLLIN = 0x001; protected static final int EPOLLOUT = 0x004; protected int fd; protected int ip, port;
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // } // // Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // } // Path: src/main/java/com/wizzardo/epoll/Connection.java import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.io.IOTools; import java.io.*; import java.nio.ByteBuffer; import java.util.Deque; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicReference; package com.wizzardo.epoll; /** * @author: wizzardo * Date: 1/6/14 */ public class Connection implements Cloneable, Closeable { protected static final int EPOLLIN = 0x001; protected static final int EPOLLOUT = 0x004; protected int fd; protected int ip, port;
protected volatile Deque<ReadableData> sending;
wizzardo/epoll
src/main/java/com/wizzardo/epoll/Connection.java
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // } // // Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // }
import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.io.IOTools; import java.io.*; import java.nio.ByteBuffer; import java.util.Deque; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicReference;
long last = this.lastEvent; this.lastEvent = lastEvent; return last; } long getLastEvent() { return lastEvent; } public boolean isAlive() { return alive; } protected synchronized void setIsAlive(boolean isAlive) { alive = isAlive; } public boolean write(String s, ByteBufferProvider bufferProvider) { try { return write(s.getBytes("utf-8"), bufferProvider); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } public boolean write(byte[] bytes, ByteBufferProvider bufferProvider) { return write(bytes, 0, bytes.length, bufferProvider); } public boolean write(byte[] bytes, int offset, int length, ByteBufferProvider bufferProvider) {
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // } // // Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // } // Path: src/main/java/com/wizzardo/epoll/Connection.java import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.io.IOTools; import java.io.*; import java.nio.ByteBuffer; import java.util.Deque; import java.util.Queue; import java.util.concurrent.ConcurrentLinkedDeque; import java.util.concurrent.atomic.AtomicReference; long last = this.lastEvent; this.lastEvent = lastEvent; return last; } long getLastEvent() { return lastEvent; } public boolean isAlive() { return alive; } protected synchronized void setIsAlive(boolean isAlive) { alive = isAlive; } public boolean write(String s, ByteBufferProvider bufferProvider) { try { return write(s.getBytes("utf-8"), bufferProvider); } catch (UnsupportedEncodingException e) { throw new RuntimeException(e); } } public boolean write(byte[] bytes, ByteBufferProvider bufferProvider) { return write(bytes, 0, bytes.length, bufferProvider); } public boolean write(byte[] bytes, int offset, int length, ByteBufferProvider bufferProvider) {
return write(new ReadableByteArray(bytes, offset, length), bufferProvider);
wizzardo/epoll
src/test/java/com/wizzardo/epoll/SslServerTest.java
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // }
import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.http.*; import com.wizzardo.tools.security.MD5; import org.junit.Assert; import org.junit.Test; import javax.net.ssl.*; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger;
if (read >= image.length / 10) { Thread.sleep(2000); read = 0; } } Assert.assertEquals(MD5.create().update(image).asString(), MD5.create().update(out.toByteArray()).asString()); // Thread.sleep(25 * 60 * 1000); server.close(); } @Test public void testCloseReadable() throws NoSuchAlgorithmException, KeyManagementException { int port = 9090; final AtomicInteger onClose = new AtomicInteger(); final AtomicInteger onCloseResource = new AtomicInteger(); EpollServer server = new EpollServer(port) { @Override protected IOThread createIOThread(int number, int divider) { return new IOThread(number, divider) { @Override public void onDisconnect(Connection connection) { onClose.incrementAndGet(); } @Override public void onConnect(Connection connection) { byte[] data = ("HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: " + (1024 * 1024 * 1024) + "\r\nContent-Type: image/gif\r\n\r\n").getBytes(); connection.write(data, this);
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableData.java // public abstract class ReadableData implements Closeable { // // public ByteBufferWrapper getByteBuffer(ByteBufferProvider bufferProvider) { // return bufferProvider.getBuffer(); // } // // public void close() throws IOException { // } // // public abstract int read(ByteBuffer byteBuffer); // // public int read(ByteBufferWrapper wrapper) { // return read(wrapper.buffer()); // } // // public abstract void unread(int i); // // public abstract boolean isComplete(); // // public abstract long complete(); // // public abstract long length(); // // public abstract long remains(); // // public boolean hasOwnBuffer() { // return false; // } // // public void onComplete() { // } // } // Path: src/test/java/com/wizzardo/epoll/SslServerTest.java import com.wizzardo.epoll.readable.ReadableData; import com.wizzardo.tools.http.*; import com.wizzardo.tools.security.MD5; import org.junit.Assert; import org.junit.Test; import javax.net.ssl.*; import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.nio.ByteBuffer; import java.security.KeyManagementException; import java.security.NoSuchAlgorithmException; import java.security.SecureRandom; import java.security.cert.X509Certificate; import java.util.Random; import java.util.concurrent.atomic.AtomicInteger; if (read >= image.length / 10) { Thread.sleep(2000); read = 0; } } Assert.assertEquals(MD5.create().update(image).asString(), MD5.create().update(out.toByteArray()).asString()); // Thread.sleep(25 * 60 * 1000); server.close(); } @Test public void testCloseReadable() throws NoSuchAlgorithmException, KeyManagementException { int port = 9090; final AtomicInteger onClose = new AtomicInteger(); final AtomicInteger onCloseResource = new AtomicInteger(); EpollServer server = new EpollServer(port) { @Override protected IOThread createIOThread(int number, int divider) { return new IOThread(number, divider) { @Override public void onDisconnect(Connection connection) { onClose.incrementAndGet(); } @Override public void onConnect(Connection connection) { byte[] data = ("HTTP/1.1 200 OK\r\nConnection: Keep-Alive\r\nContent-Length: " + (1024 * 1024 * 1024) + "\r\nContent-Type: image/gif\r\n\r\n").getBytes(); connection.write(data, this);
connection.write(new ReadableData() {
wizzardo/epoll
src/test/java/com/wizzardo/epoll/EpollClientTest.java
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // }
import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.tools.misc.Unchecked; import java.io.IOException; import java.net.UnknownHostException; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger;
package com.wizzardo.epoll; /** * @author: wizzardo * Date: 5/5/14 */ public class EpollClientTest { // @Test public void simpleTest() throws UnknownHostException { final EpollCore epoll = new EpollCore<Connection>() { @Override protected IOThread createIOThread(int number, int divider) { return new IOThread(number, divider) { @Override public void onRead(Connection connection) { System.out.println("onRead " + connection); byte[] b = new byte[1024]; int r = 0; try { r = connection.read(b, 0, b.length, this); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } System.out.println(new String(b, 0, r)); } }; } }; epoll.start(); Connection connection = Unchecked.call(new Callable<Connection>() { @Override public Connection call() throws Exception { return epoll.connect("localhost", 8082); } });
// Path: src/main/java/com/wizzardo/epoll/readable/ReadableByteArray.java // public class ReadableByteArray extends ReadableData { // protected byte[] bytes; // protected int offset, length, position; // // public ReadableByteArray(byte[] bytes) { // this(bytes, 0, bytes.length); // } // // public ReadableByteArray(byte[] bytes, int offset, int length) { // this.bytes = bytes; // this.offset = offset; // this.length = length; // position = offset; // } // // @Override // public int read(ByteBuffer byteBuffer) { // int r = Math.min(byteBuffer.remaining(), length + offset - position); // byteBuffer.put(bytes, position, r); // position += r; // return r; // } // // @Override // public void unread(int i) { // if (i < 0) // throw new IllegalArgumentException("can't unread negative value: " + i); // if (position - i < offset) // throw new IllegalArgumentException("can't unread value bigger than offset (" + offset + "): " + i); // position -= i; // } // // @Override // public boolean isComplete() { // return length == position - offset; // } // // @Override // public long complete() { // return position - offset; // } // // @Override // public long length() { // return length; // } // // public long remains() { // return length + offset - position; // } // // @Override // public String toString() { // return new String(bytes, offset, length); // } // } // Path: src/test/java/com/wizzardo/epoll/EpollClientTest.java import com.wizzardo.epoll.readable.ReadableByteArray; import com.wizzardo.tools.misc.Unchecked; import java.io.IOException; import java.net.UnknownHostException; import java.util.concurrent.Callable; import java.util.concurrent.atomic.AtomicInteger; package com.wizzardo.epoll; /** * @author: wizzardo * Date: 5/5/14 */ public class EpollClientTest { // @Test public void simpleTest() throws UnknownHostException { final EpollCore epoll = new EpollCore<Connection>() { @Override protected IOThread createIOThread(int number, int divider) { return new IOThread(number, divider) { @Override public void onRead(Connection connection) { System.out.println("onRead " + connection); byte[] b = new byte[1024]; int r = 0; try { r = connection.read(b, 0, b.length, this); } catch (IOException e) { e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates. } System.out.println(new String(b, 0, r)); } }; } }; epoll.start(); Connection connection = Unchecked.call(new Callable<Connection>() { @Override public Connection call() throws Exception { return epoll.connect("localhost", 8082); } });
connection.write(new ReadableByteArray(("GET /1 HTTP/1.1\r\n" +
ArcBees/gwtquery
samples/src/main/java/gwtquery/samples/client/effects/SlideEffectsSample.java
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java // public static final Class<Effects> Effects = GQuery.registerPlugin( // Effects.class, new Plugin<Effects>() { // public Effects init(GQuery gq) { // return new Effects(gq); // } // }); // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static GQuery $() { // return new GQuery(JsNodeArray.create()); // }
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.GQuery.$;
/* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package gwtquery.samples.client.effects; public class SlideEffectsSample implements EntryPoint { public void onModuleLoad() { // SlideUp sample
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java // public static final Class<Effects> Effects = GQuery.registerPlugin( // Effects.class, new Plugin<Effects>() { // public Effects init(GQuery gq) { // return new Effects(gq); // } // }); // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static GQuery $() { // return new GQuery(JsNodeArray.create()); // } // Path: samples/src/main/java/gwtquery/samples/client/effects/SlideEffectsSample.java import com.google.gwt.core.client.EntryPoint; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.GQuery.$; /* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package gwtquery.samples.client.effects; public class SlideEffectsSample implements EntryPoint { public void onModuleLoad() { // SlideUp sample
$("#slideUp > button").click(new Function() {
ArcBees/gwtquery
samples/src/main/java/gwtquery/samples/client/effects/SlideEffectsSample.java
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java // public static final Class<Effects> Effects = GQuery.registerPlugin( // Effects.class, new Plugin<Effects>() { // public Effects init(GQuery gq) { // return new Effects(gq); // } // }); // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static GQuery $() { // return new GQuery(JsNodeArray.create()); // }
import com.google.gwt.core.client.EntryPoint; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.GQuery.$;
/* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package gwtquery.samples.client.effects; public class SlideEffectsSample implements EntryPoint { public void onModuleLoad() { // SlideUp sample $("#slideUp > button").click(new Function() { @Override public void f(Element e) {
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java // public static final Class<Effects> Effects = GQuery.registerPlugin( // Effects.class, new Plugin<Effects>() { // public Effects init(GQuery gq) { // return new Effects(gq); // } // }); // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static GQuery $() { // return new GQuery(JsNodeArray.create()); // } // Path: samples/src/main/java/gwtquery/samples/client/effects/SlideEffectsSample.java import com.google.gwt.core.client.EntryPoint; import com.google.gwt.dom.client.Element; import com.google.gwt.query.client.Function; import static com.google.gwt.query.client.plugins.Effects.Effects; import static com.google.gwt.query.client.GQuery.$; /* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package gwtquery.samples.client.effects; public class SlideEffectsSample implements EntryPoint { public void onModuleLoad() { // SlideUp sample $("#slideUp > button").click(new Function() { @Override public void f(Element e) {
$("#slideUp div.foo").as(Effects).slideUp();
ArcBees/gwtquery
gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java // public interface JsonBuilder extends IsProperties { // // /** // * parses a json string and loads the resulting properties object, // * if the param 'fix' is true, the syntax of the json string will be // * checked previously and fixed when possible. // */ // <J> J parse(String json, boolean fix); // // /** // * Returns the wrapped object, normally a Properties jso in client // * but can be used to return the underlying Json implementation in JVM. // * // * @deprecated use asObject() instead. // */ // <J> J getProperties(); // // /** // * return the short name of this class, to use in json structures. // */ // String getJsonName(); // } // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java // public interface JsonFactory { // <T extends JsonBuilder> T create(Class<T> clz); // // IsProperties create(String s); // // IsProperties create(); // }
import com.google.gwt.query.client.Function; import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.JsonFactory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import elemental.json.JsonObject; import elemental.json.impl.JreJsonNull;
/* * Copyright 2014, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.vm; /** * Factory class to create JsonBuilders in the JVM. * * It uses java.util.reflect.Proxy to implement JsonBuilders * and elemental light weight json to handle json data. */ public class JsonFactoryJre implements JsonFactory { /** * Although functions cannot be serialized to json we use JsonBuilders * or IsProperties objects which can be used as settings in Ajax. * Since Ajax and Promises are server side compatible, we need to handle * Functions in JVM. */ static class JreJsonFunction extends JreJsonNull { private final Function function; public JreJsonFunction(Function f) { function = f; } @Override public String toJson() { return function.toString(); } public Function getFunction() { return function; } } @SuppressWarnings("unchecked") public <T> T create(Class<T> clz, JsonObject jso) { InvocationHandler handler = new JsonBuilderHandler(jso); return (T) Proxy.newProxyInstance(clz.getClassLoader(), new Class[] {clz}, handler); } @SuppressWarnings("unchecked")
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java // public interface JsonBuilder extends IsProperties { // // /** // * parses a json string and loads the resulting properties object, // * if the param 'fix' is true, the syntax of the json string will be // * checked previously and fixed when possible. // */ // <J> J parse(String json, boolean fix); // // /** // * Returns the wrapped object, normally a Properties jso in client // * but can be used to return the underlying Json implementation in JVM. // * // * @deprecated use asObject() instead. // */ // <J> J getProperties(); // // /** // * return the short name of this class, to use in json structures. // */ // String getJsonName(); // } // // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java // public interface JsonFactory { // <T extends JsonBuilder> T create(Class<T> clz); // // IsProperties create(String s); // // IsProperties create(); // } // Path: gwtquery-core/src/main/java/com/google/gwt/query/vm/JsonFactoryJre.java import com.google.gwt.query.client.Function; import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.JsonFactory; import java.lang.reflect.InvocationHandler; import java.lang.reflect.Proxy; import elemental.json.JsonObject; import elemental.json.impl.JreJsonNull; /* * Copyright 2014, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.vm; /** * Factory class to create JsonBuilders in the JVM. * * It uses java.util.reflect.Proxy to implement JsonBuilders * and elemental light weight json to handle json data. */ public class JsonFactoryJre implements JsonFactory { /** * Although functions cannot be serialized to json we use JsonBuilders * or IsProperties objects which can be used as settings in Ajax. * Since Ajax and Promises are server side compatible, we need to handle * Functions in JVM. */ static class JreJsonFunction extends JreJsonNull { private final Function function; public JreJsonFunction(Function f) { function = f; } @Override public String toJson() { return function.toString(); } public Function getFunction() { return function; } } @SuppressWarnings("unchecked") public <T> T create(Class<T> clz, JsonObject jso) { InvocationHandler handler = new JsonBuilderHandler(jso); return (T) Proxy.newProxyInstance(clz.getClassLoader(), new Class[] {clz}, handler); } @SuppressWarnings("unchecked")
public <T extends JsonBuilder> T create(Class<T> clz) {
ArcBees/gwtquery
gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static final Console console = GWT.isClient() ? GWT.<Console>create(Console.class) : null;
import static com.google.gwt.query.client.GQuery.console; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList;
/* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.client.impl; /** * Runtime selector engine implementation for IE with native querySelectorAll * support (IE8 standards mode). * * In the case of QuerySelector were unavailable or unsupported selectors, it * will display an error message instead of falling back to js. */ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { public NodeList<Element> select(String selector, Node ctx) { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) {
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java // public static final Console console = GWT.isClient() ? GWT.<Console>create(Console.class) : null; // Path: gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java import static com.google.gwt.query.client.GQuery.console; import com.google.gwt.dom.client.Element; import com.google.gwt.dom.client.Node; import com.google.gwt.dom.client.NodeList; /* * Copyright 2011, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.client.impl; /** * Runtime selector engine implementation for IE with native querySelectorAll * support (IE8 standards mode). * * In the case of QuerySelector were unavailable or unsupported selectors, it * will display an error message instead of falling back to js. */ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { public NodeList<Element> select(String selector, Node ctx) { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) {
console.error("GwtQuery: Selector '" + selector
ArcBees/gwtquery
gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java // public interface JsonBuilder extends IsProperties { // // /** // * parses a json string and loads the resulting properties object, // * if the param 'fix' is true, the syntax of the json string will be // * checked previously and fixed when possible. // */ // <J> J parse(String json, boolean fix); // // /** // * Returns the wrapped object, normally a Properties jso in client // * but can be used to return the underlying Json implementation in JVM. // * // * @deprecated use asObject() instead. // */ // <J> J getProperties(); // // /** // * return the short name of this class, to use in json structures. // */ // String getJsonName(); // }
import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.DoNotRunWith; import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.Name; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List;
/* * Copyright 2013, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.client.dbinding; /** * Tests for Deferred which can run either in JVM and GWT */ public class DataBindingTestJre extends GWTTestCase { public String getModuleName() { return null; } public void testPropertiesCreate() { IsProperties p1 = GQ.create(); p1.set("a", "1"); p1.set("b", 1); p1.set("c", "null"); p1.set("d", null); p1.set("e", true); assertEquals("1", p1.get("a")); assertEquals(1d, p1.get("b")); assertEquals("null", p1.get("c")); assertNull(p1.get("d")); assertTrue((Boolean)p1.get("e")); p1 = GQ.create(p1.toJson()); assertEquals("1", p1.get("a")); assertEquals(1d, p1.get("b")); assertEquals("null", p1.get("c")); assertNull(p1.get("d")); }
// Path: gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilder.java // public interface JsonBuilder extends IsProperties { // // /** // * parses a json string and loads the resulting properties object, // * if the param 'fix' is true, the syntax of the json string will be // * checked previously and fixed when possible. // */ // <J> J parse(String json, boolean fix); // // /** // * Returns the wrapped object, normally a Properties jso in client // * but can be used to return the underlying Json implementation in JVM. // * // * @deprecated use asObject() instead. // */ // <J> J getProperties(); // // /** // * return the short name of this class, to use in json structures. // */ // String getJsonName(); // } // Path: gwtquery-core/src/test/java/com/google/gwt/query/client/dbinding/DataBindingTestJre.java import com.google.gwt.core.shared.GWT; import com.google.gwt.junit.DoNotRunWith; import com.google.gwt.junit.Platform; import com.google.gwt.junit.client.GWTTestCase; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQ; import com.google.gwt.query.client.IsProperties; import com.google.gwt.query.client.builders.JsonBuilder; import com.google.gwt.query.client.builders.Name; import java.util.Arrays; import java.util.Collections; import java.util.Date; import java.util.List; /* * Copyright 2013, The gwtquery team. * * Licensed under the Apache License, Version 2.0 (the "License"); you may not * use this file except in compliance with the License. You may obtain a copy of * the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the * License for the specific language governing permissions and limitations under * the License. */ package com.google.gwt.query.client.dbinding; /** * Tests for Deferred which can run either in JVM and GWT */ public class DataBindingTestJre extends GWTTestCase { public String getModuleName() { return null; } public void testPropertiesCreate() { IsProperties p1 = GQ.create(); p1.set("a", "1"); p1.set("b", 1); p1.set("c", "null"); p1.set("d", null); p1.set("e", true); assertEquals("1", p1.get("a")); assertEquals(1d, p1.get("b")); assertEquals("null", p1.get("c")); assertNull(p1.get("d")); assertTrue((Boolean)p1.get("e")); p1 = GQ.create(p1.toJson()); assertEquals("1", p1.get("a")); assertEquals(1d, p1.get("b")); assertEquals("null", p1.get("c")); assertNull(p1.get("d")); }
public interface Item extends JsonBuilder {
Russian-AI-Cup/notreal2d
src/main/java/com/codegame/codeseries/notreal2d/Body.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // }
import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow;
package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // } // Path: src/main/java/com/codegame/codeseries/notreal2d/Body.java import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow; package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */
private Form form;
Russian-AI-Cup/notreal2d
src/main/java/com/codegame/codeseries/notreal2d/Body.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // }
import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow;
package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */ private Form form; /** * The mass of this body. */ private double mass; /** * The inverted mass of this body. Used to speed up some calculations. */ private double invertedMass; /** * The relative loss of the speed per time unit. Should be in range [0, 1]. */ private double movementAirFrictionFactor; /** * The relative loss of the angular speed per time unit. Should be in range [0, 1]. */ private double rotationAirFrictionFactor; /** * The provider of the absolute loss of the speed. */
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // } // Path: src/main/java/com/codegame/codeseries/notreal2d/Body.java import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow; package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */ private Form form; /** * The mass of this body. */ private double mass; /** * The inverted mass of this body. Used to speed up some calculations. */ private double invertedMass; /** * The relative loss of the speed per time unit. Should be in range [0, 1]. */ private double movementAirFrictionFactor; /** * The relative loss of the angular speed per time unit. Should be in range [0, 1]. */ private double rotationAirFrictionFactor; /** * The provider of the absolute loss of the speed. */
private MovementFrictionProvider movementFrictionProvider = new ConstantMovementFrictionProvider(0.0D);
Russian-AI-Cup/notreal2d
src/main/java/com/codegame/codeseries/notreal2d/Body.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // }
import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow;
package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */ private Form form; /** * The mass of this body. */ private double mass; /** * The inverted mass of this body. Used to speed up some calculations. */ private double invertedMass; /** * The relative loss of the speed per time unit. Should be in range [0, 1]. */ private double movementAirFrictionFactor; /** * The relative loss of the angular speed per time unit. Should be in range [0, 1]. */ private double rotationAirFrictionFactor; /** * The provider of the absolute loss of the speed. */
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/Form.java // public abstract class Form { // @Nonnull // private final Shape shape; // // protected Form(@Nonnull Shape shape) { // Preconditions.checkNotNull(shape, "Argument 'shape' is null."); // // this.shape = shape; // } // // @Nonnull // public Shape getShape() { // return shape; // } // // public abstract double getCircumcircleRadius(); // // @Nonnull // public abstract Point2D getCenterOfMass(@Nonnull Point2D position, double angle); // // @Nonnull // public final Point2D getCenterOfMass(@Nonnull Body body) { // return getCenterOfMass(body.getPosition(), body.getAngle()); // } // // public abstract double getAngularMass(double mass); // // @Override // public abstract String toString(); // // @Nonnull // public static String toString(@Nullable Form form) { // return form == null ? "Form {null}" : form.toString(); // } // // @Contract(pure = true) // protected static double normalizeSinCos(double value, double epsilon) { // return abs(value) < epsilon ? 0.0D // : abs(1.0D - value) < epsilon ? 1.0D // : abs(-1.0D - value) < epsilon ? -1.0D // : value; // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/ConstantMovementFrictionProvider.java // public class ConstantMovementFrictionProvider implements MovementFrictionProvider { // private final double movementFrictionFactor; // // public ConstantMovementFrictionProvider(double movementFrictionFactor) { // if (movementFrictionFactor < 0.0D) { // throw new IllegalArgumentException("Argument 'movementFrictionFactor' should be zero or positive."); // } // // this.movementFrictionFactor = movementFrictionFactor; // } // // public double getMovementFrictionFactor() { // return movementFrictionFactor; // } // // @Override // public void applyFriction(Body body, double updateFactor) { // if (movementFrictionFactor <= 0.0D) { // return; // } // // double velocityLength = body.getVelocity().getLength(); // if (velocityLength <= 0.0D) { // return; // } // // double velocityChange = movementFrictionFactor * updateFactor; // // if (velocityChange >= velocityLength) { // body.setVelocity(0.0D, 0.0D); // } else if (velocityChange > 0.0D) { // body.getVelocity().multiply(1.0D - velocityChange / velocityLength); // } // } // } // // Path: src/main/java/com/codegame/codeseries/notreal2d/provider/MovementFrictionProvider.java // public interface MovementFrictionProvider { // void applyFriction(Body body, double updateFactor); // } // Path: src/main/java/com/codegame/codeseries/notreal2d/Body.java import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.form.Form; import com.codegame.codeseries.notreal2d.provider.ConstantMovementFrictionProvider; import com.codegame.codeseries.notreal2d.provider.MovementFrictionProvider; import org.jetbrains.annotations.Contract; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.Collections; import java.util.HashMap; import java.util.Map; import java.util.concurrent.atomic.AtomicLong; import static com.codeforces.commons.math.Math.pow; package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 02.06.2015 */ public class Body { private static final AtomicLong idGenerator = new AtomicLong(); /** * Unique ID. */ private final long id = idGenerator.incrementAndGet(); /** * The name of this body. */ private String name; /** * The form (shape and size) of this body. */ private Form form; /** * The mass of this body. */ private double mass; /** * The inverted mass of this body. Used to speed up some calculations. */ private double invertedMass; /** * The relative loss of the speed per time unit. Should be in range [0, 1]. */ private double movementAirFrictionFactor; /** * The relative loss of the angular speed per time unit. Should be in range [0, 1]. */ private double rotationAirFrictionFactor; /** * The provider of the absolute loss of the speed. */
private MovementFrictionProvider movementFrictionProvider = new ConstantMovementFrictionProvider(0.0D);
Russian-AI-Cup/notreal2d
src/main/java/com/codegame/codeseries/notreal2d/StaticState.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/listener/PositionListener.java // public interface PositionListener { // /** // * Physics engine iterates over all registered position listeners in some order and invokes this method before // * changing position. If any listener returns {@code false}, it cancels all remaining method calls and the change // * itself. // * <p> // * Any {@code oldPosition} changes in the method will be ignored. // * Any {@code newPosition} changes in the method will be saved and used to update associated object after last // * iteration (all listeners should return {@code true}). // * // * @param oldPosition current position // * @param newPosition next position // * @return {@code true} iff physics engine should continue to change position // */ // boolean beforeChangePosition(@Nonnull Point2D oldPosition, @Nonnull Point2D newPosition); // // /** // * Physics engine iterates over all registered position listeners in some order and invokes this method after // * changing position. // * <p> // * Any {@code oldPosition} changes in the method will be ignored. // * Any {@code newPosition} changes in the method will be ignored. // * // * @param oldPosition previous position // * @param newPosition current position // */ // void afterChangePosition(@Nonnull Point2D oldPosition, @Nonnull Point2D newPosition); // }
import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.listener.PositionListener; import javax.annotation.Nonnull; import java.util.*; import static com.codeforces.commons.math.Math.DOUBLE_PI; import static com.codeforces.commons.math.Math.PI;
} } this.position = this.new ListeningPoint2D(newPosition); if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { positionListenerEntry.listener.afterChangePosition(oldPosition.copy(), newPosition.copy()); } } } public double getAngle() { return angle; } public void setAngle(double angle) { this.angle = angle; } public void normalizeAngle() { while (angle > PI) { angle -= DOUBLE_PI; } while (angle < -PI) { angle += DOUBLE_PI; } }
// Path: src/main/java/com/codegame/codeseries/notreal2d/listener/PositionListener.java // public interface PositionListener { // /** // * Physics engine iterates over all registered position listeners in some order and invokes this method before // * changing position. If any listener returns {@code false}, it cancels all remaining method calls and the change // * itself. // * <p> // * Any {@code oldPosition} changes in the method will be ignored. // * Any {@code newPosition} changes in the method will be saved and used to update associated object after last // * iteration (all listeners should return {@code true}). // * // * @param oldPosition current position // * @param newPosition next position // * @return {@code true} iff physics engine should continue to change position // */ // boolean beforeChangePosition(@Nonnull Point2D oldPosition, @Nonnull Point2D newPosition); // // /** // * Physics engine iterates over all registered position listeners in some order and invokes this method after // * changing position. // * <p> // * Any {@code oldPosition} changes in the method will be ignored. // * Any {@code newPosition} changes in the method will be ignored. // * // * @param oldPosition previous position // * @param newPosition current position // */ // void afterChangePosition(@Nonnull Point2D oldPosition, @Nonnull Point2D newPosition); // } // Path: src/main/java/com/codegame/codeseries/notreal2d/StaticState.java import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.geometry.Vector2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.listener.PositionListener; import javax.annotation.Nonnull; import java.util.*; import static com.codeforces.commons.math.Math.DOUBLE_PI; import static com.codeforces.commons.math.Math.PI; } } this.position = this.new ListeningPoint2D(newPosition); if (positionListenerEntries != null) { for (PositionListenerEntry positionListenerEntry : positionListenerEntries) { positionListenerEntry.listener.afterChangePosition(oldPosition.copy(), newPosition.copy()); } } } public double getAngle() { return angle; } public void setAngle(double angle) { this.angle = angle; } public void normalizeAngle() { while (angle > PI) { angle -= DOUBLE_PI; } while (angle < -PI) { angle += DOUBLE_PI; } }
public void registerPositionListener(@Nonnull PositionListener listener, @Nonnull String name, double priority) {
Russian-AI-Cup/notreal2d
src/main/java/com/codegame/codeseries/notreal2d/form/ArcForm.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/util/GeometryUtil.java // public final class GeometryUtil { // private GeometryUtil() { // throw new UnsupportedOperationException(); // } // // @Contract(pure = true) // public static double normalizeAngle(double angle) { // while (angle > PI) { // angle -= DOUBLE_PI; // } // // while (angle < -PI) { // angle += DOUBLE_PI; // } // // return angle; // } // // @Contract(pure = true) // public static boolean isAngleBetween(double angle, double startAngle, double finishAngle) { // while (finishAngle < startAngle) { // finishAngle += DOUBLE_PI; // } // // while (finishAngle - DOUBLE_PI > startAngle) { // finishAngle -= DOUBLE_PI; // } // // while (angle < startAngle) { // angle += DOUBLE_PI; // } // // while (angle - DOUBLE_PI > startAngle) { // angle -= DOUBLE_PI; // } // // return angle >= startAngle && angle <= finishAngle; // } // // public static boolean isPointInsideConvexPolygon( // @Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes, double epsilon) { // for (int vertexIndex = 0, vertexCount = polygonVertexes.length; vertexIndex < vertexCount; ++vertexIndex) { // Point2D vertex1 = polygonVertexes[vertexIndex]; // Point2D vertex2 = polygonVertexes[vertexIndex == vertexCount - 1 ? 0 : vertexIndex + 1]; // // Line2D polygonEdge = Line2D.getLineByTwoPoints(vertex1, vertex2); // // if (polygonEdge.getSignedDistanceFrom(point) > -epsilon) { // return false; // } // } // // return true; // } // // public static boolean isPointInsideConvexPolygon(@Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes) { // return isPointInsideConvexPolygon(point, polygonVertexes, 0.0D); // } // // public static boolean isPointOutsideConvexPolygon( // @Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes, double epsilon) { // for (int vertexIndex = 0, vertexCount = polygonVertexes.length; vertexIndex < vertexCount; ++vertexIndex) { // Point2D vertex1 = polygonVertexes[vertexIndex]; // Point2D vertex2 = polygonVertexes[vertexIndex == vertexCount - 1 ? 0 : vertexIndex + 1]; // // Line2D polygonEdge = Line2D.getLineByTwoPoints(vertex1, vertex2); // // if (polygonEdge.getSignedDistanceFrom(point) >= epsilon) { // return true; // } // } // // return false; // } // // public static boolean isPointOutsideConvexPolygon(@Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes) { // return isPointOutsideConvexPolygon(point, polygonVertexes, 0.0D); // } // }
import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.util.GeometryUtil; import javax.annotation.Nonnull; import static com.codeforces.commons.math.Math.DOUBLE_PI;
package com.codegame.codeseries.notreal2d.form; /** * @author Maxim Shipko ([email protected]) * Date: 26.06.2015 */ public class ArcForm extends ThinForm { private final double radius; private final double angle; private final double sector; public ArcForm(double radius, double angle, double sector, boolean endpointCollisionEnabled) { super(Shape.ARC, endpointCollisionEnabled); if (Double.isNaN(radius) || Double.isInfinite(radius) || radius <= 0.0D) { throw new IllegalArgumentException(String.format( "Argument 'radius' should be a positive finite number but got %s.", radius )); } if (Double.isNaN(angle) || Double.isInfinite(angle)) { throw new IllegalArgumentException(String.format( "Argument 'angle' should be a finite number but got %s.", angle )); } if (Double.isNaN(sector) || Double.isInfinite(sector) || sector <= 0.0D || sector > DOUBLE_PI) { throw new IllegalArgumentException(String.format( "Argument 'sector' should be between 0.0 exclusive and 2 * PI inclusive but got %s.", sector )); }
// Path: src/main/java/com/codegame/codeseries/notreal2d/util/GeometryUtil.java // public final class GeometryUtil { // private GeometryUtil() { // throw new UnsupportedOperationException(); // } // // @Contract(pure = true) // public static double normalizeAngle(double angle) { // while (angle > PI) { // angle -= DOUBLE_PI; // } // // while (angle < -PI) { // angle += DOUBLE_PI; // } // // return angle; // } // // @Contract(pure = true) // public static boolean isAngleBetween(double angle, double startAngle, double finishAngle) { // while (finishAngle < startAngle) { // finishAngle += DOUBLE_PI; // } // // while (finishAngle - DOUBLE_PI > startAngle) { // finishAngle -= DOUBLE_PI; // } // // while (angle < startAngle) { // angle += DOUBLE_PI; // } // // while (angle - DOUBLE_PI > startAngle) { // angle -= DOUBLE_PI; // } // // return angle >= startAngle && angle <= finishAngle; // } // // public static boolean isPointInsideConvexPolygon( // @Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes, double epsilon) { // for (int vertexIndex = 0, vertexCount = polygonVertexes.length; vertexIndex < vertexCount; ++vertexIndex) { // Point2D vertex1 = polygonVertexes[vertexIndex]; // Point2D vertex2 = polygonVertexes[vertexIndex == vertexCount - 1 ? 0 : vertexIndex + 1]; // // Line2D polygonEdge = Line2D.getLineByTwoPoints(vertex1, vertex2); // // if (polygonEdge.getSignedDistanceFrom(point) > -epsilon) { // return false; // } // } // // return true; // } // // public static boolean isPointInsideConvexPolygon(@Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes) { // return isPointInsideConvexPolygon(point, polygonVertexes, 0.0D); // } // // public static boolean isPointOutsideConvexPolygon( // @Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes, double epsilon) { // for (int vertexIndex = 0, vertexCount = polygonVertexes.length; vertexIndex < vertexCount; ++vertexIndex) { // Point2D vertex1 = polygonVertexes[vertexIndex]; // Point2D vertex2 = polygonVertexes[vertexIndex == vertexCount - 1 ? 0 : vertexIndex + 1]; // // Line2D polygonEdge = Line2D.getLineByTwoPoints(vertex1, vertex2); // // if (polygonEdge.getSignedDistanceFrom(point) >= epsilon) { // return true; // } // } // // return false; // } // // public static boolean isPointOutsideConvexPolygon(@Nonnull Point2D point, @Nonnull Point2D[] polygonVertexes) { // return isPointOutsideConvexPolygon(point, polygonVertexes, 0.0D); // } // } // Path: src/main/java/com/codegame/codeseries/notreal2d/form/ArcForm.java import com.codeforces.commons.geometry.Point2D; import com.codeforces.commons.text.StringUtil; import com.codegame.codeseries.notreal2d.util.GeometryUtil; import javax.annotation.Nonnull; import static com.codeforces.commons.math.Math.DOUBLE_PI; package com.codegame.codeseries.notreal2d.form; /** * @author Maxim Shipko ([email protected]) * Date: 26.06.2015 */ public class ArcForm extends ThinForm { private final double radius; private final double angle; private final double sector; public ArcForm(double radius, double angle, double sector, boolean endpointCollisionEnabled) { super(Shape.ARC, endpointCollisionEnabled); if (Double.isNaN(radius) || Double.isInfinite(radius) || radius <= 0.0D) { throw new IllegalArgumentException(String.format( "Argument 'radius' should be a positive finite number but got %s.", radius )); } if (Double.isNaN(angle) || Double.isInfinite(angle)) { throw new IllegalArgumentException(String.format( "Argument 'angle' should be a finite number but got %s.", angle )); } if (Double.isNaN(sector) || Double.isInfinite(sector) || sector <= 0.0D || sector > DOUBLE_PI) { throw new IllegalArgumentException(String.format( "Argument 'sector' should be between 0.0 exclusive and 2 * PI inclusive but got %s.", sector )); }
this.angle = GeometryUtil.normalizeAngle(angle);
Russian-AI-Cup/notreal2d
src/test/java/com/codegame/codeseries/notreal2d/WorldTest.java
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/CircularForm.java // public class CircularForm extends Form { // private final double radius; // private final double angularMassFactor; // // public CircularForm(double radius) { // super(Shape.CIRCLE); // // if (Double.isNaN(radius) || Double.isInfinite(radius) || radius <= 0.0D) { // throw new IllegalArgumentException(String.format( // "Argument 'radius' should be positive finite number but got %s.", radius // )); // } // // this.radius = radius; // this.angularMassFactor = radius * radius / 2.0D; // } // // public double getRadius() { // return radius; // } // // @Override // public double getCircumcircleRadius() { // return radius; // } // // @Nonnull // @Override // public Point2D getCenterOfMass(@Nonnull Point2D position, double angle) { // return position; // } // // @Override // public double getAngularMass(double mass) { // return mass * angularMassFactor; // } // // @Override // public String toString() { // return StringUtil.toString(this, false, "radius"); // } // }
import com.codegame.codeseries.notreal2d.form.CircularForm; import org.junit.Assert; import org.junit.Test; import static com.codeforces.commons.math.Math.max; import static com.codeforces.commons.math.Math.pow;
package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 08.06.2015 */ @SuppressWarnings("OverlyLongMethod") public class WorldTest { @Test public void testMovement() throws Exception { int iterationCountPerStep = Defaults.ITERATION_COUNT_PER_STEP; int stepCountPerTimeUnit = 10; World world = new World(iterationCountPerStep, stepCountPerTimeUnit); Body body = new Body();
// Path: src/main/java/com/codegame/codeseries/notreal2d/form/CircularForm.java // public class CircularForm extends Form { // private final double radius; // private final double angularMassFactor; // // public CircularForm(double radius) { // super(Shape.CIRCLE); // // if (Double.isNaN(radius) || Double.isInfinite(radius) || radius <= 0.0D) { // throw new IllegalArgumentException(String.format( // "Argument 'radius' should be positive finite number but got %s.", radius // )); // } // // this.radius = radius; // this.angularMassFactor = radius * radius / 2.0D; // } // // public double getRadius() { // return radius; // } // // @Override // public double getCircumcircleRadius() { // return radius; // } // // @Nonnull // @Override // public Point2D getCenterOfMass(@Nonnull Point2D position, double angle) { // return position; // } // // @Override // public double getAngularMass(double mass) { // return mass * angularMassFactor; // } // // @Override // public String toString() { // return StringUtil.toString(this, false, "radius"); // } // } // Path: src/test/java/com/codegame/codeseries/notreal2d/WorldTest.java import com.codegame.codeseries.notreal2d.form.CircularForm; import org.junit.Assert; import org.junit.Test; import static com.codeforces.commons.math.Math.max; import static com.codeforces.commons.math.Math.pow; package com.codegame.codeseries.notreal2d; /** * @author Maxim Shipko ([email protected]) * Date: 08.06.2015 */ @SuppressWarnings("OverlyLongMethod") public class WorldTest { @Test public void testMovement() throws Exception { int iterationCountPerStep = Defaults.ITERATION_COUNT_PER_STEP; int stepCountPerTimeUnit = 10; World world = new World(iterationCountPerStep, stepCountPerTimeUnit); Body body = new Body();
body.setForm(new CircularForm(1.0D));
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2ReaderBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLStreamReader; import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.reader; public class JDom2ReaderBuilder<R> { private JDom2Reader<R> reader;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2ReaderBuilder.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLStreamReader; import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.reader; public class JDom2ReaderBuilder<R> { private JDom2Reader<R> reader;
private Parser<Element, R> parser;
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2ReaderBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLStreamReader; import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.reader; public class JDom2ReaderBuilder<R> { private JDom2Reader<R> reader; private Parser<Element, R> parser; private List<JDom2Reader<R>> readers = new ArrayList<>();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2ReaderBuilder.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.stream.XMLStreamReader; import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.reader; public class JDom2ReaderBuilder<R> { private JDom2Reader<R> reader; private Parser<Element, R> parser; private List<JDom2Reader<R>> readers = new ArrayList<>();
private List<ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>();
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2ItemWriterBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java // public class Jdom2WriterContext { // // private Element element; // private ParseContext context; // // public Jdom2WriterContext(ParseContext context, Element element) { // this.setContext(context); // this.setElement(element); // } // // public Element getElement() { // return element; // } // // public void setElement(Element element) { // this.element = element; // } // // public ParseContext getContext() { // return context; // } // // public void setContext(ParseContext context) { // this.context = context; // } // // }
import java.util.function.Consumer; import java.util.function.Function; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.writer.context.Jdom2WriterContext;
package com.giffing.easyxml.jdom2.writer; public class Jdom2ItemWriterBuilder<T extends ParseContext> { protected Function<T, Boolean> shouldHandle; protected boolean shouldRemove;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java // public class Jdom2WriterContext { // // private Element element; // private ParseContext context; // // public Jdom2WriterContext(ParseContext context, Element element) { // this.setContext(context); // this.setElement(element); // } // // public Element getElement() { // return element; // } // // public void setElement(Element element) { // this.element = element; // } // // public ParseContext getContext() { // return context; // } // // public void setContext(ParseContext context) { // this.context = context; // } // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2ItemWriterBuilder.java import java.util.function.Consumer; import java.util.function.Function; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.writer.context.Jdom2WriterContext; package com.giffing.easyxml.jdom2.writer; public class Jdom2ItemWriterBuilder<T extends ParseContext> { protected Function<T, Boolean> shouldHandle; protected boolean shouldRemove;
protected Consumer<Jdom2WriterContext> consumer;
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jaxb; public class JaxbReader<R> implements Reader<JAXBElement<R>, R> { private List<ItemReader<JAXBElement<R>, R>> readers = new ArrayList<>(); private Unmarshaller jaxbUnmarshaller; public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jaxb; public class JaxbReader<R> implements Reader<JAXBElement<R>, R> { private List<ItemReader<JAXBElement<R>, R>> readers = new ArrayList<>(); private Unmarshaller jaxbUnmarshaller; public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override
public TransformResult<JAXBElement<R>> transform(TransformContext<JAXBElement<R>, R> context) {
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jaxb; public class JaxbReader<R> implements Reader<JAXBElement<R>, R> { private List<ItemReader<JAXBElement<R>, R>> readers = new ArrayList<>(); private Unmarshaller jaxbUnmarshaller; public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jaxb; public class JaxbReader<R> implements Reader<JAXBElement<R>, R> { private List<ItemReader<JAXBElement<R>, R>> readers = new ArrayList<>(); private Unmarshaller jaxbUnmarshaller; public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override
public TransformResult<JAXBElement<R>> transform(TransformContext<JAXBElement<R>, R> context) {
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override public TransformResult<JAXBElement<R>> transform(TransformContext<JAXBElement<R>, R> context) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = null; XMLStreamReader streamReader = context.getStreamReader(); JaxbItemReader<JAXBElement<R>, R> itemReader = (JaxbItemReader<JAXBElement<R>, R>) context .getItemReader(); try { t = tf.newTransformer(); JAXBElement<R> jaxbElement; try { jaxbElement = jaxbUnmarshaller.unmarshal(streamReader, itemReader.getJaxbClass()); } catch (JAXBException e) { throw new IllegalStateException(e); }
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/context/JaxbTransformerResult.java // public class JaxbTransformerResult<R> implements TransformResult<JAXBElement<R>> { // // private final JAXBElement<R> element; // // public JaxbTransformerResult(JAXBElement<R> element) { // this.element = element; // } // // @Override // public JAXBElement<R> getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReader.java import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBContext; import javax.xml.bind.JAXBElement; import javax.xml.bind.JAXBException; import javax.xml.bind.Unmarshaller; import javax.xml.stream.XMLStreamReader; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jaxb.context.JaxbTransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; public JaxbReader(List<ItemReader<JAXBElement<R>, R>> readers, String jaxbContextPath) { this.readers = readers; try { jaxbUnmarshaller = JAXBContext.newInstance(jaxbContextPath).createUnmarshaller(); } catch (JAXBException e) { throw new IllegalStateException(e); } } @Override public List<ItemReader<JAXBElement<R>, R>> getItemReaders() { return readers; } @Override public TransformResult<JAXBElement<R>> transform(TransformContext<JAXBElement<R>, R> context) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = null; XMLStreamReader streamReader = context.getStreamReader(); JaxbItemReader<JAXBElement<R>, R> itemReader = (JaxbItemReader<JAXBElement<R>, R>) context .getItemReader(); try { t = tf.newTransformer(); JAXBElement<R> jaxbElement; try { jaxbElement = jaxbUnmarshaller.unmarshal(streamReader, itemReader.getJaxbClass()); } catch (JAXBException e) { throw new IllegalStateException(e); }
return new JaxbTransformerResult<R>(jaxbElement);
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbItemReaderBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReaderBuilder.java // public abstract class ItemReaderBuilder<T, R> { // // protected Function<ParseContext, Boolean> shouldHandle; // // protected Function<T, R> function; // // public ItemReaderBuilder<T, R> shouldHandle(Function<ParseContext, Boolean> shouldHandle) { // this.shouldHandle = shouldHandle; // return this; // } // // public ItemReaderBuilder<T, R> shouldHandle(String path) { // return this.shouldHandle((p) -> p.getPath().equals(path)); // } // // public ItemReaderBuilder<T, R> handle(Function<T, R> function) { // this.function = function; // return this; // } // // public ItemReader<T, R> build() { // return new ItemReader<T, R>() { // // @Override // public R read(T element) { // return function.apply(element); // } // // @Override // public boolean shouldHandle(ParseContext context) { // return shouldHandle.apply(context); // } // }; // } // }
import java.util.function.Function; import javax.xml.bind.JAXBElement; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReaderBuilder;
package com.giffing.easyxml.jaxb; public class JaxbItemReaderBuilder<R> extends ItemReaderBuilder<JAXBElement<R>, R> { private Class<?> jaxbClass; public JaxbItemReaderBuilder() { super.handle((e) -> e.getValue()); } @Override public JaxbItemReaderBuilder<R> shouldHandle(
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReaderBuilder.java // public abstract class ItemReaderBuilder<T, R> { // // protected Function<ParseContext, Boolean> shouldHandle; // // protected Function<T, R> function; // // public ItemReaderBuilder<T, R> shouldHandle(Function<ParseContext, Boolean> shouldHandle) { // this.shouldHandle = shouldHandle; // return this; // } // // public ItemReaderBuilder<T, R> shouldHandle(String path) { // return this.shouldHandle((p) -> p.getPath().equals(path)); // } // // public ItemReaderBuilder<T, R> handle(Function<T, R> function) { // this.function = function; // return this; // } // // public ItemReader<T, R> build() { // return new ItemReader<T, R>() { // // @Override // public R read(T element) { // return function.apply(element); // } // // @Override // public boolean shouldHandle(ParseContext context) { // return shouldHandle.apply(context); // } // }; // } // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbItemReaderBuilder.java import java.util.function.Function; import javax.xml.bind.JAXBElement; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReaderBuilder; package com.giffing.easyxml.jaxb; public class JaxbItemReaderBuilder<R> extends ItemReaderBuilder<JAXBElement<R>, R> { private Class<?> jaxbClass; public JaxbItemReaderBuilder() { super.handle((e) -> e.getValue()); } @Override public JaxbItemReaderBuilder<R> shouldHandle(
Function<ParseContext, Boolean> shouldHandle) {
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2ItemWriter.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java // public class Jdom2WriterContext { // // private Element element; // private ParseContext context; // // public Jdom2WriterContext(ParseContext context, Element element) { // this.setContext(context); // this.setElement(element); // } // // public Element getElement() { // return element; // } // // public void setElement(Element element) { // this.element = element; // } // // public ParseContext getContext() { // return context; // } // // public void setContext(ParseContext context) { // this.context = context; // } // // }
import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.writer.context.Jdom2WriterContext;
package com.giffing.easyxml.jdom2.writer; public interface Jdom2ItemWriter<T extends ParseContext> { boolean shouldHandle(T parseContext);
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java // public class Jdom2WriterContext { // // private Element element; // private ParseContext context; // // public Jdom2WriterContext(ParseContext context, Element element) { // this.setContext(context); // this.setElement(element); // } // // public Element getElement() { // return element; // } // // public void setElement(Element element) { // this.element = element; // } // // public ParseContext getContext() { // return context; // } // // public void setContext(ParseContext context) { // this.context = context; // } // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2ItemWriter.java import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.writer.context.Jdom2WriterContext; package com.giffing.easyxml.jdom2.writer; public interface Jdom2ItemWriter<T extends ParseContext> { boolean shouldHandle(T parseContext);
void handle(Jdom2WriterContext context);
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.context; public class TransformContext<T, R> { private XMLStreamReader streamReader;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.context; public class TransformContext<T, R> { private XMLStreamReader streamReader;
private ItemReader<T, R> itemReader;
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult;
package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult; package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>();
private ParseContext context;
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult;
package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>(); private ParseContext context; private Reader<T, R> currentReader;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult; package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>(); private ParseContext context; private Reader<T, R> currentReader;
private ItemReader<T, R> currentItemReader = null;
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult;
package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>(); private ParseContext context; private Reader<T, R> currentReader; private ItemReader<T, R> currentItemReader = null; private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { this.readers = readers; this.staxItemReaders = staxItemReaders; this.context = context; } public void setParseContext(ParseContext context) { this.context = context; } public R readNext() { return currentItemReader.read(currentReader.transform(
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult; package com.giffing.easyxml.reader; public class Parser<T, R> implements Iterable<R> { private XMLInputFactory xif = XMLInputFactory.newInstance(); private XMLStreamReader streamReader = null; private InputStream inputStream = null; private List<String> currentElementPath = new ArrayList<>(); private List<? extends Reader<T, R>> readers = new ArrayList<>(); private ParseContext context; private Reader<T, R> currentReader; private ItemReader<T, R> currentItemReader = null; private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { this.readers = readers; this.staxItemReaders = staxItemReaders; this.context = context; } public void setParseContext(ParseContext context) { this.context = context; } public R readNext() { return currentItemReader.read(currentReader.transform(
new TransformContext<T, R>(streamReader, currentItemReader))
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // }
import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult;
this.readers = readers; this.staxItemReaders = staxItemReaders; this.context = context; } public void setParseContext(ParseContext context) { this.context = context; } public R readNext() { return currentItemReader.read(currentReader.transform( new TransformContext<T, R>(streamReader, currentItemReader)) .getContent()); } public boolean hasNext() { if (streamReader == null) { doOpen(); } try { while (streamReader.hasNext()) { if (streamReader.isEndElement()) { removePath(); } if (streamReader.isStartElement()) { addPath(); context.setPath(StringUtils.join(currentElementPath, "/")); for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { if(staxItemReader.shouldHandle(context)) {
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/stax/reader/context/StaxTransformerResult.java // public class StaxTransformerResult implements TransformResult<XMLStreamReader> { // // private XMLStreamReader reader; // // public StaxTransformerResult(XMLStreamReader reader){ // this.reader = reader; // } // // @Override // public XMLStreamReader getContent() { // return reader; // } // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java import java.io.IOException; import java.io.InputStream; import java.util.ArrayList; import java.util.Iterator; import java.util.List; import javax.xml.stream.XMLInputFactory; import javax.xml.stream.XMLStreamException; import javax.xml.stream.XMLStreamReader; import org.apache.commons.lang3.StringUtils; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.reader.item.ItemReader; import com.giffing.easyxml.stax.reader.context.StaxTransformerResult; this.readers = readers; this.staxItemReaders = staxItemReaders; this.context = context; } public void setParseContext(ParseContext context) { this.context = context; } public R readNext() { return currentItemReader.read(currentReader.transform( new TransformContext<T, R>(streamReader, currentItemReader)) .getContent()); } public boolean hasNext() { if (streamReader == null) { doOpen(); } try { while (streamReader.hasNext()) { if (streamReader.isEndElement()) { removePath(); } if (streamReader.isStartElement()) { addPath(); context.setPath(StringUtils.join(currentElementPath, "/")); for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { if(staxItemReader.shouldHandle(context)) {
staxItemReader.read(new StaxTransformerResult(streamReader).getContent());
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReaderBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jaxb; public class JaxbReaderBuilder<R> { private JaxbReader<R> reader;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReaderBuilder.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jaxb; public class JaxbReaderBuilder<R> { private JaxbReader<R> reader;
private Parser<JAXBElement<R>, R> parser;
MarcGiffing/easyxml
easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReaderBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jaxb; public class JaxbReaderBuilder<R> { private JaxbReader<R> reader; private Parser<JAXBElement<R>, R> parser; private List<JaxbReader<R>> readers = new ArrayList<>();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Parser.java // public class Parser<T, R> implements Iterable<R> { // // private XMLInputFactory xif = XMLInputFactory.newInstance(); // private XMLStreamReader streamReader = null; // private InputStream inputStream = null; // // private List<String> currentElementPath = new ArrayList<>(); // // private List<? extends Reader<T, R>> readers = new ArrayList<>(); // // private ParseContext context; // // private Reader<T, R> currentReader; // // private ItemReader<T, R> currentItemReader = null; // // private List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>(); // // public Parser(List<? extends Reader<T, R>> readers, List<? extends ItemReader<XMLStreamReader, Void>> staxItemReaders, ParseContext context) { // this.readers = readers; // this.staxItemReaders = staxItemReaders; // this.context = context; // } // // public void setParseContext(ParseContext context) { // this.context = context; // } // // public R readNext() { // return currentItemReader.read(currentReader.transform( // new TransformContext<T, R>(streamReader, currentItemReader)) // .getContent()); // } // // public boolean hasNext() { // if (streamReader == null) { // doOpen(); // } // try { // while (streamReader.hasNext()) { // if (streamReader.isEndElement()) { // removePath(); // } // if (streamReader.isStartElement()) { // addPath(); // context.setPath(StringUtils.join(currentElementPath, "/")); // // for (ItemReader<XMLStreamReader, Void> staxItemReader : staxItemReaders) { // if(staxItemReader.shouldHandle(context)) { // staxItemReader.read(new StaxTransformerResult(streamReader).getContent()); // } // } // // for (Reader<T, R> reader : readers) { // for (ItemReader<T, R> itemReader : reader.getItemReaders()) { // if ((itemReader).shouldHandle(context)) { // if (currentElementPath.size() > 0) { // currentElementPath.remove(currentElementPath.size() - 1); // } // currentReader = reader; // currentItemReader = itemReader; // return true; // } // } // } // // } // streamReader.next(); // } // } catch (XMLStreamException e) { // throw new IllegalStateException(e); // } // // return false; // } // // private void addPath() { // String localName = streamReader.getLocalName(); // currentElementPath.add(localName); // } // // private void removePath() { // if (currentElementPath.size() > 0) { // int lastElementIndex = currentElementPath.size() - 1; // if (currentElementPath.get(lastElementIndex).equals(streamReader.getLocalName())) { // currentElementPath.remove(lastElementIndex); // // } // } // } // // public void close() { // if (streamReader != null) { // try { // streamReader.close(); // } catch (XMLStreamException e) { // } // } // if (inputStream != null) { // try { // inputStream.close(); // } catch (IOException e) { // } // } // } // // private void doOpen() { // try { // streamReader = xif.createXMLStreamReader(inputStream, "UTF-8"); // } catch (Exception e) { // e.printStackTrace(); // } // } // // public InputStream getInputStream() { // return inputStream; // } // // public void setInputStream(InputStream inputStream) { // this.inputStream = inputStream; // } // // @Override // public Iterator<R> iterator() { // return new Iterator<R>() { // // @Override // public boolean hasNext() { // return Parser.this.hasNext(); // } // // @Override // public R next() { // return Parser.this.readNext(); // } // }; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jaxb/src/main/java/com/giffing/easyxml/jaxb/JaxbReaderBuilder.java import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.InputStream; import java.util.ArrayList; import java.util.List; import javax.xml.bind.JAXBElement; import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.Parser; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jaxb; public class JaxbReaderBuilder<R> { private JaxbReader<R> reader; private Parser<JAXBElement<R>, R> parser; private List<JaxbReader<R>> readers = new ArrayList<>();
private List<ItemReader<XMLStreamReader, Void>> staxItemReaders = new ArrayList<>();
MarcGiffing/easyxml
easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/NoteItemReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/domain/Note.java // public class Note { // // private Long id; // // private String content; // // private Long groupId; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getContent() { // return content; // } // // public void setContent(String content) { // this.content = content; // } // // public Long getGroupId() { // return groupId; // } // // public void setGroupId(Long groupId) { // this.groupId = groupId; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.example.domain.Note; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.example; public class NoteItemReader implements ItemReader<Element, Note> { private NoteContext context; @Override public Note read(Element element) { Note note = new Note(); note.setId(Long.valueOf(element.getChildTextTrim("id"))); note.setContent(element.getChildTextTrim("content")); note.setGroupId(context.latestGroupId); return note; } @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/domain/Note.java // public class Note { // // private Long id; // // private String content; // // private Long groupId; // // public Long getId() { // return id; // } // // public void setId(Long id) { // this.id = id; // } // // public String getContent() { // return content; // } // // public void setContent(String content) { // this.content = content; // } // // public Long getGroupId() { // return groupId; // } // // public void setGroupId(Long groupId) { // this.groupId = groupId; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/NoteItemReader.java import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.jdom2.example.domain.Note; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.example; public class NoteItemReader implements ItemReader<Element, Note> { private NoteContext context; @Override public Note read(Element element) { Note note = new Note(); note.setId(Long.valueOf(element.getChildTextTrim("id"))); note.setContent(element.getChildTextTrim("content")); note.setGroupId(context.latestGroupId); return note; } @Override
public boolean shouldHandle(ParseContext context) {
MarcGiffing/easyxml
easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/GroupItemReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.example; public class GroupItemReader implements ItemReader<XMLStreamReader, Void> { private NoteContext context; @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2-example/src/main/java/com/giffing/easyxml/jdom2/example/GroupItemReader.java import javax.xml.stream.XMLStreamReader; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.example; public class GroupItemReader implements ItemReader<XMLStreamReader, Void> { private NoteContext context; @Override
public boolean shouldHandle(ParseContext context) {
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override
public TransformResult<Element> transform(TransformContext<Element, R> transformContext) {
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override
public TransformResult<Element> transform(TransformContext<Element, R> transformContext) {
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override public TransformResult<Element> transform(TransformContext<Element, R> transformContext) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = null; try { t = tf.newTransformer(); JDOMResult result = new JDOMResult(); t.transform(new StAXSource(transformContext.getStreamReader()), result); Document document = result.getDocument();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/context/JDom2TransformerResult.java // public class JDom2TransformerResult implements TransformResult<Element> { // // private final Element element; // // public JDom2TransformerResult(Element element){ // this.element = element; // } // // @Override // public Element getContent() { // return element; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java // public interface Reader<T, R> { // // List<ItemReader<T, R>> getItemReaders(); // // TransformResult<T> transform(TransformContext<T, R> transformContext); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/reader/JDom2Reader.java import java.util.ArrayList; import java.util.List; import javax.xml.transform.Transformer; import javax.xml.transform.TransformerException; import javax.xml.transform.TransformerFactory; import javax.xml.transform.stax.StAXSource; import org.jdom2.Document; import org.jdom2.Element; import org.jdom2.transform.JDOMResult; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.jdom2.reader.context.JDom2TransformerResult; import com.giffing.easyxml.reader.Reader; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.jdom2.reader; public class JDom2Reader<R> implements Reader<Element, R> { private List<ItemReader<Element, R>> readers = new ArrayList<>(); public JDom2Reader(List<ItemReader<Element, R>> readers) { this.readers = readers; } @Override public List<ItemReader<Element, R>> getItemReaders() { return readers; } @Override public TransformResult<Element> transform(TransformContext<Element, R> transformContext) { TransformerFactory tf = TransformerFactory.newInstance(); Transformer t = null; try { t = tf.newTransformer(); JDOMResult result = new JDOMResult(); t.transform(new StAXSource(transformContext.getStreamReader()), result); Document document = result.getDocument();
return new JDom2TransformerResult(document.getRootElement());
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // }
import com.giffing.easyxml.context.ParseContext;
package com.giffing.easyxml.reader.item; public interface ItemReader<T, R> { /** * @param t transform result */ R read(T t); /** * Indicates if the reader is responsible for the current context * * @param context */
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java import com.giffing.easyxml.context.ParseContext; package com.giffing.easyxml.reader.item; public interface ItemReader<T, R> { /** * @param t transform result */ R read(T t); /** * Indicates if the reader is responsible for the current context * * @param context */
boolean shouldHandle(ParseContext context);
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.List; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.reader; public interface Reader<T, R> { List<ItemReader<T, R>> getItemReaders();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java import java.util.List; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.reader; public interface Reader<T, R> { List<ItemReader<T, R>> getItemReaders();
TransformResult<T> transform(TransformContext<T, R> transformContext);
MarcGiffing/easyxml
easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.util.List; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.reader.item.ItemReader;
package com.giffing.easyxml.reader; public interface Reader<T, R> { List<ItemReader<T, R>> getItemReaders();
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformContext.java // public class TransformContext<T, R> { // // private XMLStreamReader streamReader; // // private ItemReader<T, R> itemReader; // // public TransformContext(XMLStreamReader streamReader, ItemReader<T, R> itemReader) { // this.streamReader = streamReader; // this.itemReader = itemReader; // } // // public XMLStreamReader getStreamReader() { // return streamReader; // } // // public void setStreamReader(XMLStreamReader streamReader) { // this.streamReader = streamReader; // } // // public ItemReader<T, R> getItemReader() { // return itemReader; // } // // public void setItemReader(ItemReader<T, R> itemReader) { // this.itemReader = itemReader; // } // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/context/TransformResult.java // public interface TransformResult<T> { // // /** // * @return the current result of an XML transformation // */ // T getContent(); // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/Reader.java import java.util.List; import com.giffing.easyxml.context.TransformContext; import com.giffing.easyxml.context.TransformResult; import com.giffing.easyxml.reader.item.ItemReader; package com.giffing.easyxml.reader; public interface Reader<T, R> { List<ItemReader<T, R>> getItemReaders();
TransformResult<T> transform(TransformContext<T, R> transformContext);
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // }
import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext;
package com.giffing.easyxml.jdom2.writer.context; public class Jdom2WriterContext { private Element element;
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/context/Jdom2WriterContext.java import org.jdom2.Element; import com.giffing.easyxml.context.ParseContext; package com.giffing.easyxml.jdom2.writer.context; public class Jdom2WriterContext { private Element element;
private ParseContext context;
MarcGiffing/easyxml
easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2WriterBuilder.java
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // }
import java.io.InputStream; import java.io.OutputStream; import javax.xml.stream.XMLStreamReader; import org.jdom2.output.Format; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReader;
public Writer build() { return writer; } public Jdom2WriterBuilder<C> setFormat(Format format) { this.writer.setFormat(format); return this; } public Jdom2WriterBuilder<C> setInputStream(InputStream inputStream) { this.writer.setInputStream(inputStream); return this; } public Jdom2WriterBuilder<C> setOutputStream(OutputStream outputStream) { this.writer.setOutputStream(outputStream); return this; } public Jdom2WriterBuilder<C> setNamespace(String namespace) { this.writer.setNamespace(namespace); return this; } public Jdom2WriterBuilder<C> addItemWriter(Jdom2ItemWriter<C> itemWriter) { this.writer.getItemWriter().add(itemWriter); return this; }
// Path: easyxml-core/src/main/java/com/giffing/easyxml/context/ParseContext.java // public class ParseContext { // // /** // * The current xml element path divided by slash // */ // private String path; // // public String getPath() { // return path; // } // // public void setPath(String path) { // this.path = path; // } // // } // // Path: easyxml-core/src/main/java/com/giffing/easyxml/reader/item/ItemReader.java // public interface ItemReader<T, R> { // // /** // * @param t transform result // */ // R read(T t); // // /** // * Indicates if the reader is responsible for the current context // * // * @param context // */ // boolean shouldHandle(ParseContext context); // // } // Path: easyxml-jdom2/src/main/java/com/giffing/easyxml/jdom2/writer/Jdom2WriterBuilder.java import java.io.InputStream; import java.io.OutputStream; import javax.xml.stream.XMLStreamReader; import org.jdom2.output.Format; import com.giffing.easyxml.context.ParseContext; import com.giffing.easyxml.reader.item.ItemReader; public Writer build() { return writer; } public Jdom2WriterBuilder<C> setFormat(Format format) { this.writer.setFormat(format); return this; } public Jdom2WriterBuilder<C> setInputStream(InputStream inputStream) { this.writer.setInputStream(inputStream); return this; } public Jdom2WriterBuilder<C> setOutputStream(OutputStream outputStream) { this.writer.setOutputStream(outputStream); return this; } public Jdom2WriterBuilder<C> setNamespace(String namespace) { this.writer.setNamespace(namespace); return this; } public Jdom2WriterBuilder<C> addItemWriter(Jdom2ItemWriter<C> itemWriter) { this.writer.getItemWriter().add(itemWriter); return this; }
public Jdom2WriterBuilder<C> addStaxItemReader(ItemReader<XMLStreamReader, Void> itemReader) {
kuri65536/python-for-android
android/Python3ForAndroid/src/com/googlecode/python3forandroid/Python3Installer.java
// Path: android/PythonCommon/src/com/googlecode/android_scripting/pythoncommon/PythonConstants.java // public class PythonConstants { // static public final String ACTION_FILE_BROWSER = "com.googlecode.pythonforandroid.action.FILEBROWSER"; // static public final String SL4A = "com.googlecode.android_scripting"; // static public final String SL4A_MANAGER = "com.googlecode.android_scripting.activity.ScriptManager"; // static public final String INSTALLED_VERSION_KEY = "py4a.installed.version"; // static public final String INSTALLED_EXTRAS_KEY = "py4a.installed.extras"; // static public final String INSTALLED_SCRIPTS_KEY = "py4a.installed.scripts"; // static public final String AVAIL_VERSION_KEY = "py4a.available.version"; // static public final String AVAIL_EXTRAS_KEY = "py4a.available.extras"; // static public final String AVAIL_SCRIPTS_KEY = "py4a.available.scripts"; // static public final String PREFFERED_PYEXT = "py4a.preffered.pyext"; // // static public final String ENV_HOME = "PYTHONHOME"; // static public final String ENV_PATH = "PYTHONPATH"; // static public final String ENV_TEMP = "TEMP"; // static public final String ENV_LD = "LD_LIBRARY_PATH"; // static public final String ENV_EXTRAS = "PY4A_EXTRAS"; // static public final String ENV_EGGS = "PYTHON_EGG_CACHE"; // static public final String ENV_USERBASE = "PYTHONUSERBASE"; // }
import java.io.File; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; import com.googlecode.android_scripting.AsyncTaskListener; import com.googlecode.android_scripting.InterpreterInstaller; import com.googlecode.android_scripting.Log; import com.googlecode.android_scripting.exception.Sl4aException; import com.googlecode.android_scripting.interpreter.InterpreterConstants; import com.googlecode.android_scripting.interpreter.InterpreterDescriptor; import com.googlecode.android_scripting.pythoncommon.PythonConstants;
} } @Override protected boolean isInstalled() { if (mPreferences == null) { mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); if (mDescriptor instanceof Python3Descriptor) { ((Python3Descriptor) mDescriptor).setSharedPreferences(mPreferences); } } return mPreferences.getBoolean(InterpreterConstants.INSTALLED_PREFERENCE_KEY, false); } @Override protected boolean setup() { File tmp = new File(InterpreterConstants.SDCARD_ROOT + getClass().getPackage().getName() + InterpreterConstants.INTERPRETER_EXTRAS_ROOT, mDescriptor.getName() + "/tmp"); if (tmp.isDirectory()) { // TODO: check some permissions. } else try { tmp.mkdir(); } catch (SecurityException e) { Log.e(mContext, "Setup failed.", e); return false; } if (mDescriptor instanceof Python3Descriptor) { Python3Descriptor descriptor = (Python3Descriptor) mDescriptor; Editor editor = mPreferences.edit();
// Path: android/PythonCommon/src/com/googlecode/android_scripting/pythoncommon/PythonConstants.java // public class PythonConstants { // static public final String ACTION_FILE_BROWSER = "com.googlecode.pythonforandroid.action.FILEBROWSER"; // static public final String SL4A = "com.googlecode.android_scripting"; // static public final String SL4A_MANAGER = "com.googlecode.android_scripting.activity.ScriptManager"; // static public final String INSTALLED_VERSION_KEY = "py4a.installed.version"; // static public final String INSTALLED_EXTRAS_KEY = "py4a.installed.extras"; // static public final String INSTALLED_SCRIPTS_KEY = "py4a.installed.scripts"; // static public final String AVAIL_VERSION_KEY = "py4a.available.version"; // static public final String AVAIL_EXTRAS_KEY = "py4a.available.extras"; // static public final String AVAIL_SCRIPTS_KEY = "py4a.available.scripts"; // static public final String PREFFERED_PYEXT = "py4a.preffered.pyext"; // // static public final String ENV_HOME = "PYTHONHOME"; // static public final String ENV_PATH = "PYTHONPATH"; // static public final String ENV_TEMP = "TEMP"; // static public final String ENV_LD = "LD_LIBRARY_PATH"; // static public final String ENV_EXTRAS = "PY4A_EXTRAS"; // static public final String ENV_EGGS = "PYTHON_EGG_CACHE"; // static public final String ENV_USERBASE = "PYTHONUSERBASE"; // } // Path: android/Python3ForAndroid/src/com/googlecode/python3forandroid/Python3Installer.java import java.io.File; import android.content.Context; import android.content.SharedPreferences; import android.content.SharedPreferences.Editor; import android.preference.PreferenceManager; import com.googlecode.android_scripting.AsyncTaskListener; import com.googlecode.android_scripting.InterpreterInstaller; import com.googlecode.android_scripting.Log; import com.googlecode.android_scripting.exception.Sl4aException; import com.googlecode.android_scripting.interpreter.InterpreterConstants; import com.googlecode.android_scripting.interpreter.InterpreterDescriptor; import com.googlecode.android_scripting.pythoncommon.PythonConstants; } } @Override protected boolean isInstalled() { if (mPreferences == null) { mPreferences = PreferenceManager.getDefaultSharedPreferences(mContext); if (mDescriptor instanceof Python3Descriptor) { ((Python3Descriptor) mDescriptor).setSharedPreferences(mPreferences); } } return mPreferences.getBoolean(InterpreterConstants.INSTALLED_PREFERENCE_KEY, false); } @Override protected boolean setup() { File tmp = new File(InterpreterConstants.SDCARD_ROOT + getClass().getPackage().getName() + InterpreterConstants.INTERPRETER_EXTRAS_ROOT, mDescriptor.getName() + "/tmp"); if (tmp.isDirectory()) { // TODO: check some permissions. } else try { tmp.mkdir(); } catch (SecurityException e) { Log.e(mContext, "Setup failed.", e); return false; } if (mDescriptor instanceof Python3Descriptor) { Python3Descriptor descriptor = (Python3Descriptor) mDescriptor; Editor editor = mPreferences.edit();
editor.putInt(PythonConstants.INSTALLED_VERSION_KEY, descriptor.getVersion());
kecskemeti/dissect-cf
src/main/java/hu/mta/sztaki/lpds/cloud/simulator/io/StorageObject.java
// Path: src/main/java/hu/mta/sztaki/lpds/cloud/simulator/util/SeedSyncer.java // public class SeedSyncer { // /** // * The random generator that will be used by the system components and that // * is recommended to be used by simulations built on top of DISSECT-CF // */ // public static final Random centralRnd; // /** // * The random seed for the central random generator. // * // * To set this seed, you must define the system property of // * "hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer.seed" before running // * any simulations. // */ // public static final int seed; // // static { // String seedText = System.getProperty("hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer.seed"); // if (seedText == null) { // seed = 1; // } else { // seed = Integer.parseInt(seedText); // } // centralRnd = new Random(seed); // } // // /** // * To restart the simulator's random generator // */ // public static void resetCentral() { // centralRnd.setSeed(seed); // } // }
import hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer;
/* * ======================================================================== * DIScrete event baSed Energy Consumption simulaTor * for Clouds and Federations (DISSECT-CF) * ======================================================================== * * This file is part of DISSECT-CF. * * DISSECT-CF 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, either version 3 of the License, or (at * your option) any later version. * * DISSECT-CF 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 DISSECT-CF. If not, see <http://www.gnu.org/licenses/>. * * (C) Copyright 2014, Gabor Kecskemeti ([email protected], * [email protected]) */ package hu.mta.sztaki.lpds.cloud.simulator.io; /** * Represents arbitrary data fragments (e.g. files) to be stored in a * repository. Also useful for modeling file transfers. * * @author "Gabor Kecskemeti, Distributed and Parallel Systems Group, University * of Innsbruck (c) 2013" "Gabor Kecskemeti, Laboratory of Parallel and * Distributed Systems, MTA SZTAKI (c) 2012" */ public class StorageObject { // TODO: think about if it would make things easier if we would refer here // the repository where this storage object is stored. /** * the identifier of the storage object. This might not be unique * everywhere. It is the user's responsibility to keep it unique with the * newcopy function. */ public final String id; /** * The actual size of the object. This is immutable, if a storage object * needs to increase in size in a repository, it is recommended to replace * it with a bigger one while holding the same name. * * unit: bytes */ public final long size; /** * Allows the creation of the storage object with unknown size (the * simulator will pick a random one! * * @param myid * the id of the new storage object */ public StorageObject(final String myid) { id = myid;
// Path: src/main/java/hu/mta/sztaki/lpds/cloud/simulator/util/SeedSyncer.java // public class SeedSyncer { // /** // * The random generator that will be used by the system components and that // * is recommended to be used by simulations built on top of DISSECT-CF // */ // public static final Random centralRnd; // /** // * The random seed for the central random generator. // * // * To set this seed, you must define the system property of // * "hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer.seed" before running // * any simulations. // */ // public static final int seed; // // static { // String seedText = System.getProperty("hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer.seed"); // if (seedText == null) { // seed = 1; // } else { // seed = Integer.parseInt(seedText); // } // centralRnd = new Random(seed); // } // // /** // * To restart the simulator's random generator // */ // public static void resetCentral() { // centralRnd.setSeed(seed); // } // } // Path: src/main/java/hu/mta/sztaki/lpds/cloud/simulator/io/StorageObject.java import hu.mta.sztaki.lpds.cloud.simulator.util.SeedSyncer; /* * ======================================================================== * DIScrete event baSed Energy Consumption simulaTor * for Clouds and Federations (DISSECT-CF) * ======================================================================== * * This file is part of DISSECT-CF. * * DISSECT-CF 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, either version 3 of the License, or (at * your option) any later version. * * DISSECT-CF 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 DISSECT-CF. If not, see <http://www.gnu.org/licenses/>. * * (C) Copyright 2014, Gabor Kecskemeti ([email protected], * [email protected]) */ package hu.mta.sztaki.lpds.cloud.simulator.io; /** * Represents arbitrary data fragments (e.g. files) to be stored in a * repository. Also useful for modeling file transfers. * * @author "Gabor Kecskemeti, Distributed and Parallel Systems Group, University * of Innsbruck (c) 2013" "Gabor Kecskemeti, Laboratory of Parallel and * Distributed Systems, MTA SZTAKI (c) 2012" */ public class StorageObject { // TODO: think about if it would make things easier if we would refer here // the repository where this storage object is stored. /** * the identifier of the storage object. This might not be unique * everywhere. It is the user's responsibility to keep it unique with the * newcopy function. */ public final String id; /** * The actual size of the object. This is immutable, if a storage object * needs to increase in size in a repository, it is recommended to replace * it with a bigger one while holding the same name. * * unit: bytes */ public final long size; /** * Allows the creation of the storage object with unknown size (the * simulator will pick a random one! * * @param myid * the id of the new storage object */ public StorageObject(final String myid) { id = myid;
size = 500000000L + (long) (SeedSyncer.centralRnd.nextDouble() * 19500000000L);
Tangyingqi/Jiemian
app/src/main/java/com/tyq/jiemian/ui/callback/ZhihuApi.java
// Path: app/src/main/java/com/tyq/jiemian/bean/NewsEntity.java // public class NewsEntity implements Parcelable { // // private String date; // // private ArrayList<StoriesEntity> stories; // // private List<TopStoriesEntity> top_stories; // // // public void setDate(String date) { // this.date = date; // } // // public void setStories(ArrayList<StoriesEntity> stories) { // this.stories = stories; // } // // public void setTop_stories(List<TopStoriesEntity> top_stories) { // this.top_stories = top_stories; // } // // public String getDate() { // return date; // } // // public ArrayList<StoriesEntity> getStories() { // return stories; // } // // public List<TopStoriesEntity> getTop_stories() { // return top_stories; // } // // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(this.date); // dest.writeList(this.stories); // dest.writeList(this.top_stories); // } // // public NewsEntity() { // } // // protected NewsEntity(Parcel in) { // this.date = in.readString(); // this.stories = new ArrayList<StoriesEntity>(); // in.readList(this.stories, List.class.getClassLoader()); // this.top_stories = new ArrayList<TopStoriesEntity>(); // in.readList(this.top_stories, List.class.getClassLoader()); // } // // public static final Creator<NewsEntity> CREATOR = new Creator<NewsEntity>() { // public NewsEntity createFromParcel(Parcel source) { // return new NewsEntity(source); // } // // public NewsEntity[] newArray(int size) { // return new NewsEntity[size]; // } // }; // // @Override // public String toString() { // return "NewsEntity{" + // "date='" + date + '\'' + // ", stories=" + stories + // ", top_stories=" + top_stories + // '}'; // } // } // // Path: app/src/main/java/com/tyq/jiemian/bean/StoryDetailsEntity.java // public class StoryDetailsEntity implements Parcelable { // // private String body; // private String image_source; // private String title; // private String image; // private String share_url; // private String ga_prefix; // private int type; // private int id; // private List<String> css; // // public void setBody(String body) { // this.body = body; // } // // public void setImage_source(String image_source) { // this.image_source = image_source; // } // // public void setTitle(String title) { // this.title = title; // } // // public void setImage(String image) { // this.image = image; // } // // public void setShare_url(String share_url) { // this.share_url = share_url; // } // // public void setGa_prefix(String ga_prefix) { // this.ga_prefix = ga_prefix; // } // // public void setType(int type) { // this.type = type; // } // // public void setId(int id) { // this.id = id; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public String getImage_source() { // return image_source; // } // // public String getTitle() { // return title; // } // // public String getImage() { // return image; // } // // public String getShare_url() { // return share_url; // } // // public String getGa_prefix() { // return ga_prefix; // } // // public int getType() { // return type; // } // // public int getId() { // return id; // } // // public List<String> getCss() { // return css; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(this.body); // dest.writeString(this.image_source); // dest.writeString(this.title); // dest.writeString(this.image); // dest.writeString(this.share_url); // dest.writeString(this.ga_prefix); // dest.writeInt(this.type); // dest.writeInt(this.id); // dest.writeStringList(this.css); // } // // public StoryDetailsEntity() { // } // // protected StoryDetailsEntity(Parcel in) { // this.body = in.readString(); // this.image_source = in.readString(); // this.title = in.readString(); // this.image = in.readString(); // this.share_url = in.readString(); // this.ga_prefix = in.readString(); // this.type = in.readInt(); // this.id = in.readInt(); // this.css = in.createStringArrayList(); // } // // public static final Creator<StoryDetailsEntity> CREATOR = new Creator<StoryDetailsEntity>() { // public StoryDetailsEntity createFromParcel(Parcel source) { // return new StoryDetailsEntity(source); // } // // public StoryDetailsEntity[] newArray(int size) { // return new StoryDetailsEntity[size]; // } // }; // }
import com.tyq.jiemian.bean.NewsEntity; import com.tyq.jiemian.bean.StoryDetailsEntity; import retrofit2.http.GET; import retrofit2.http.Path; import rx.Observable;
package com.tyq.jiemian.ui.callback; /** * Created by diff on 2016/2/16. */ public interface ZhihuApi { @GET("api/4/news/latest")
// Path: app/src/main/java/com/tyq/jiemian/bean/NewsEntity.java // public class NewsEntity implements Parcelable { // // private String date; // // private ArrayList<StoriesEntity> stories; // // private List<TopStoriesEntity> top_stories; // // // public void setDate(String date) { // this.date = date; // } // // public void setStories(ArrayList<StoriesEntity> stories) { // this.stories = stories; // } // // public void setTop_stories(List<TopStoriesEntity> top_stories) { // this.top_stories = top_stories; // } // // public String getDate() { // return date; // } // // public ArrayList<StoriesEntity> getStories() { // return stories; // } // // public List<TopStoriesEntity> getTop_stories() { // return top_stories; // } // // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(this.date); // dest.writeList(this.stories); // dest.writeList(this.top_stories); // } // // public NewsEntity() { // } // // protected NewsEntity(Parcel in) { // this.date = in.readString(); // this.stories = new ArrayList<StoriesEntity>(); // in.readList(this.stories, List.class.getClassLoader()); // this.top_stories = new ArrayList<TopStoriesEntity>(); // in.readList(this.top_stories, List.class.getClassLoader()); // } // // public static final Creator<NewsEntity> CREATOR = new Creator<NewsEntity>() { // public NewsEntity createFromParcel(Parcel source) { // return new NewsEntity(source); // } // // public NewsEntity[] newArray(int size) { // return new NewsEntity[size]; // } // }; // // @Override // public String toString() { // return "NewsEntity{" + // "date='" + date + '\'' + // ", stories=" + stories + // ", top_stories=" + top_stories + // '}'; // } // } // // Path: app/src/main/java/com/tyq/jiemian/bean/StoryDetailsEntity.java // public class StoryDetailsEntity implements Parcelable { // // private String body; // private String image_source; // private String title; // private String image; // private String share_url; // private String ga_prefix; // private int type; // private int id; // private List<String> css; // // public void setBody(String body) { // this.body = body; // } // // public void setImage_source(String image_source) { // this.image_source = image_source; // } // // public void setTitle(String title) { // this.title = title; // } // // public void setImage(String image) { // this.image = image; // } // // public void setShare_url(String share_url) { // this.share_url = share_url; // } // // public void setGa_prefix(String ga_prefix) { // this.ga_prefix = ga_prefix; // } // // public void setType(int type) { // this.type = type; // } // // public void setId(int id) { // this.id = id; // } // // public void setCss(List<String> css) { // this.css = css; // } // // public String getBody() { // return body; // } // // public String getImage_source() { // return image_source; // } // // public String getTitle() { // return title; // } // // public String getImage() { // return image; // } // // public String getShare_url() { // return share_url; // } // // public String getGa_prefix() { // return ga_prefix; // } // // public int getType() { // return type; // } // // public int getId() { // return id; // } // // public List<String> getCss() { // return css; // } // // @Override // public int describeContents() { // return 0; // } // // @Override // public void writeToParcel(Parcel dest, int flags) { // dest.writeString(this.body); // dest.writeString(this.image_source); // dest.writeString(this.title); // dest.writeString(this.image); // dest.writeString(this.share_url); // dest.writeString(this.ga_prefix); // dest.writeInt(this.type); // dest.writeInt(this.id); // dest.writeStringList(this.css); // } // // public StoryDetailsEntity() { // } // // protected StoryDetailsEntity(Parcel in) { // this.body = in.readString(); // this.image_source = in.readString(); // this.title = in.readString(); // this.image = in.readString(); // this.share_url = in.readString(); // this.ga_prefix = in.readString(); // this.type = in.readInt(); // this.id = in.readInt(); // this.css = in.createStringArrayList(); // } // // public static final Creator<StoryDetailsEntity> CREATOR = new Creator<StoryDetailsEntity>() { // public StoryDetailsEntity createFromParcel(Parcel source) { // return new StoryDetailsEntity(source); // } // // public StoryDetailsEntity[] newArray(int size) { // return new StoryDetailsEntity[size]; // } // }; // } // Path: app/src/main/java/com/tyq/jiemian/ui/callback/ZhihuApi.java import com.tyq.jiemian.bean.NewsEntity; import com.tyq.jiemian.bean.StoryDetailsEntity; import retrofit2.http.GET; import retrofit2.http.Path; import rx.Observable; package com.tyq.jiemian.ui.callback; /** * Created by diff on 2016/2/16. */ public interface ZhihuApi { @GET("api/4/news/latest")
Observable<NewsEntity> getLastestNews();