Skip to content

Commit

Permalink
rename syntax highlight to pretty logger
Browse files Browse the repository at this point in the history
minor refactoring on date and i18n projects.
  • Loading branch information
alvinrdeleon committed Dec 30, 2012
1 parent 826b3ed commit 38e31a4
Show file tree
Hide file tree
Showing 23 changed files with 168 additions and 66 deletions.
2 changes: 1 addition & 1 deletion jspringbot-config/pom.xml
Expand Up @@ -45,7 +45,7 @@
<dependencies>
<dependency>
<groupId>org.jspringbot</groupId>
<artifactId>jspringbot-syntax-highlight</artifactId>
<artifactId>jspringbot-pretty-logger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
2 changes: 1 addition & 1 deletion jspringbot-csv/pom.xml
Expand Up @@ -45,7 +45,7 @@
<dependencies>
<dependency>
<groupId>org.jspringbot</groupId>
<artifactId>jspringbot-syntax-highlight</artifactId>
<artifactId>jspringbot-pretty-logger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
12 changes: 6 additions & 6 deletions jspringbot-csv/src/main/resources/libdoc.intro
Expand Up @@ -2,15 +2,15 @@ Contains keywords to parse and query a CSV string or resource.

*Example CSV Resource (classpath:employee.csv)*

| *Name* | *Department* | *Position* | *Age* |
| Alvin | Development | CEO | 29 |
| Shiela | Development | Developer | 27 |
| Master | Development | CFO | 23 |
| Warren | Research | QA | 21 |
| *Name* | *Department* | *Position* | *Age* |
| Alvin | Development | CEO | 29 |
| Shiela | Development | Developer | 27 |
| Master | Development | CFO | 23 |
| Warren | Research | QA | 21 |

*Example CSV Resource (classpath:department.csv)*

| *Name* | *Description* |
| *Name* | *Description* |
| Development | This is the development department. |
| Research | This is the research department. |

Expand Down
4 changes: 2 additions & 2 deletions jspringbot-date/pom.xml
Expand Up @@ -64,14 +64,14 @@
</dependency>
<dependency>
<groupId>org.jspringbot</groupId>
<artifactId>jspringbot-syntax-highlight</artifactId>
<artifactId>jspringbot-pretty-logger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>${junit.version}</version>
<optional>true</optional>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
Expand Down
Expand Up @@ -18,13 +18,11 @@

package org.jspringbot.keyword.date;

import org.jspringbot.Keyword;
import org.jspringbot.syntax.AbstractHighlightKeyword;
import org.springframework.beans.factory.annotation.Autowired;

public abstract class AbstractDateKeyword implements Keyword {
public abstract class AbstractDateKeyword extends AbstractHighlightKeyword {

@Autowired
protected DateHelper helper;

public abstract Object execute(Object[] objects) throws Exception;
}
Expand Up @@ -28,7 +28,7 @@
public class AddDateTimeDays extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
helper.plusDays(Integer.parseInt(String.valueOf(params[0])));

return null;
Expand Down
Expand Up @@ -34,68 +34,75 @@ public class DateHelper {
private String formatterPattern = "yyyy-MM-dd HH:mm:ss zz";

public void setDateTimeZone(String timeZoneId) {

LOG.createAppender()
.appendBold("Set Date Time Zone:")
.appendProperty("Time Zone ID", timeZoneId)
.log();
LOG.keywordAppender().appendProperty("Time Zone ID", timeZoneId);

currentTimeZone = DateTimeZone.forID(timeZoneId);
}

public void setDateTimeFormat(String pattern) {
LOG.createAppender()
.appendBold("Set Date Time Format:")
.appendProperty("Pattern", pattern)
.log();
LOG.keywordAppender().appendProperty("Pattern", pattern);

DateTimeFormat.forPattern(pattern);
}

public String printDateTime() {
DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(formatterPattern);
public void parseDateTime(String dateStr) {
parseDateTime(dateStr, formatterPattern);
}

public void parseDateTime(String dateStr, String pattern) {
LOG.keywordAppender()
.appendProperty("Date String", dateStr)
.appendProperty("Parse Pattern", pattern);

DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
current = dateTimeFormatter.parseDateTime(dateStr);

// show the log for print
printDateTime();
}

public String printDateTime(String pattern) {
LOG.keywordAppender()
.appendProperty("Print Pattern", formatterPattern)
.appendProperty("Print Time Zone ID", currentTimeZone.getID());

DateTimeFormatter dateTimeFormatter = DateTimeFormat.forPattern(pattern);
DateTime dt = current.withZone(currentTimeZone);

String formattedValue = dateTimeFormatter.print(dt);

LOG.createAppender()
.appendBold("Print Date Time:")
.appendProperty("Pattern", formatterPattern)
.appendProperty("Time Zone ID", currentTimeZone.getID())
.appendProperty("Print", formattedValue)
.log();
LOG.keywordAppender().appendProperty("Print Value", formattedValue);

return formattedValue;
}


public String printDateTime() {
return printDateTime(formatterPattern);
}

public void resetDateTime() {
current = new DateTime();

LOG.createAppender()
.appendBold("Reset Date Time:")
.appendProperty("Pattern", formatterPattern)
.appendProperty("Time Zone ID", currentTimeZone.getID())
.appendProperty("Print", printDateTime())
.log();
// show the log for print
printDateTime();
}

public void plusDays(int days) {
LOG.keywordAppender().appendProperty("Added Days", days);

current = current.plusDays(days);

LOG.createAppender()
.appendBold("Add Date Time Days:")
.appendProperty("Days", days)
.appendProperty("Print", printDateTime())
.log();
// show the log for print
printDateTime();
}

public void minusDays(int days) {
LOG.keywordAppender().appendProperty("Subtract Days", days);

current = current.minusDays(days);

LOG.createAppender()
.appendBold("Subtract Date Time Days:")
.appendProperty("Days", days)
.appendProperty("Print", printDateTime())
.log();
// show the log for print
printDateTime();
}
}
@@ -0,0 +1,41 @@
/*
* Copyright (c) 2012. JSpringBot. All Rights Reserved.
*
* See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The JSpringBot licenses this file to You 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 org.jspringbot.keyword.date;

import org.jspringbot.Keyword;
import org.jspringbot.KeywordInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@KeywordInfo(
name = "Format Date Time",
parameters = {"format=Default"},
description = "Format the date time to string given the set format."
)
public class FormatDateTime implements Keyword {

@Autowired
private PrintDateTime printer;

@Override
public Object execute(Object[] params) throws Exception {
return printer.execute(params);
}
}
@@ -0,0 +1,46 @@
/*
* Copyright (c) 2012. JSpringBot. All Rights Reserved.
*
* See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The JSpringBot licenses this file to You 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 org.jspringbot.keyword.date;

import org.jspringbot.KeywordInfo;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
@KeywordInfo(
name = "Parse Date Time",
parameters = {"dateString", "format=Default"},
description = "Parses the given date time."
)
public class ParseDateTime extends AbstractDateKeyword {

@Override
public Object executeInternal(Object[] params) throws IOException {
if(params.length > 1) {
helper.parseDateTime(String.valueOf(params[0]), String.valueOf(params[1]));

return null;
}

helper.parseDateTime(String.valueOf(params[0]));

return null;
}
}
Expand Up @@ -24,11 +24,19 @@
import java.io.IOException;

@Component
@KeywordInfo(name = "Print Date Time", description = "Prints the date time to string given the set format.")
@KeywordInfo(
name = "Print Date Time",
parameters = {"format=default"},
description = "Prints the date time to string given the set format."
)
public class PrintDateTime extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
if(params.length > 0) {
return helper.printDateTime(String.valueOf(params[0]));
}

return helper.printDateTime();
}
}
Expand Up @@ -28,7 +28,7 @@
public class ResetDateTime extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
helper.resetDateTime();

return null;
Expand Down
Expand Up @@ -28,7 +28,7 @@
public class SetDateTimeFormat extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
helper.setDateTimeFormat(String.valueOf(params[0]));

return null;
Expand Down
Expand Up @@ -28,7 +28,7 @@
public class SetDateTimeZone extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
helper.setDateTimeZone(String.valueOf(params[0]));

return null;
Expand Down
Expand Up @@ -28,7 +28,7 @@
public class SubtractDateTimeDays extends AbstractDateKeyword {

@Override
public Object execute(Object[] params) throws IOException {
public Object executeInternal(Object[] params) throws IOException {
helper.minusDays(Integer.parseInt(String.valueOf(params[0])));

return null;
Expand Down
Expand Up @@ -24,6 +24,8 @@
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

import static junit.framework.Assert.assertNotNull;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations={"classpath:spring-date.xml"})
public class DateHelperTest {
Expand All @@ -33,6 +35,6 @@ public class DateHelperTest {

@Test
public void testPrint() throws Exception {
System.out.println(helper.printDateTime());
assertNotNull(helper.printDateTime());
}
}
2 changes: 1 addition & 1 deletion jspringbot-db/pom.xml
Expand Up @@ -73,7 +73,7 @@
</dependency>
<dependency>
<groupId>org.jspringbot</groupId>
<artifactId>jspringbot-syntax-highlight</artifactId>
<artifactId>jspringbot-pretty-logger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down
Expand Up @@ -22,8 +22,8 @@
import org.springframework.stereotype.Component;

@Component
@KeywordInfo(name = "Get Message", description = "Get Message.", parameters = {"code"})
public class GetMessage extends Abstracti18nKeyword {
@KeywordInfo(name = "Get i18n Message", description = "Get Message.", parameters = {"code"})
public class GetI18nMessage extends Abstracti18nKeyword {

@Override
public Object execute(Object[] params) {
Expand Down
Expand Up @@ -23,8 +23,8 @@


@Component
@KeywordInfo(name = "Set Language", description = "Set Language.", parameters = {"language"})
public class SetLanguage extends Abstracti18nKeyword {
@KeywordInfo(name = "Set i18n Language", description = "Set Language.", parameters = {"language"})
public class SetI18nLanguage extends Abstracti18nKeyword {

@Override
public Object execute(Object[] params) {
Expand Down
2 changes: 1 addition & 1 deletion jspringbot-json/pom.xml
Expand Up @@ -45,7 +45,7 @@
<dependencies>
<dependency>
<groupId>org.jspringbot</groupId>
<artifactId>jspringbot-syntax-highlight</artifactId>
<artifactId>jspringbot-pretty-logger</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
Expand Down

0 comments on commit 38e31a4

Please sign in to comment.