Added a new Mini-language element - <now> - that replaces the <now-timestamp> and <now-date-to-env> elements. It is a drop-in replacement for <now-timestamp>.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@1330902 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -57,6 +57,22 @@ under the License.
|
||||
</xs:choice>
|
||||
</xs:group>
|
||||
|
||||
<xs:attribute name="field">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The name of the field to set. The target of the assignment.
|
||||
<br/><br/>
|
||||
Required. Attribute type: expression.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:string">
|
||||
<xs:whiteSpace value="collapse" />
|
||||
<xs:minLength value="1" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
|
||||
<xs:attributeGroup name="attlist.propertyInfoOptional">
|
||||
<xs:attribute type="xs:string" name="resource"/>
|
||||
<xs:attribute type="xs:string" name="property"/>
|
||||
@@ -1341,15 +1357,7 @@ under the License.
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:attributeGroup name="attlist.set">
|
||||
<xs:attribute type="xs:string" name="field" use="required">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The name of the field to set. The target of the assignment.
|
||||
<br/><br/>
|
||||
Required. Attribute type: expression.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
<xs:attribute ref="field" use="required" />
|
||||
<xs:attribute type="xs:string" name="from-field">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
@@ -4416,43 +4424,52 @@ under the License.
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="now-timestamp" substitutionGroup="OtherOperations">
|
||||
<xs:element name="now" substitutionGroup="OtherOperations">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The now-timestamp tag creates a java.sql.Timestamp object with the current date and time in it and puts it in a field in the method environment.
|
||||
Sets a field to the current system time.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:attributeGroup ref="attlist.now-timestamp"/>
|
||||
<xs:attribute ref="field" use="required" />
|
||||
<xs:attribute name="type">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The field data type. Defaults to java.sql.Timestamp.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:simpleType>
|
||||
<xs:restriction base="xs:token">
|
||||
<xs:enumeration value="java.sql.Timestamp"/>
|
||||
<xs:enumeration value="java.sql.Date" />
|
||||
<xs:enumeration value="java.sql.Time" />
|
||||
<xs:enumeration value="java.util.Date" />
|
||||
<xs:enumeration value="java.lang.Long" />
|
||||
</xs:restriction>
|
||||
</xs:simpleType>
|
||||
</xs:attribute>
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:element name="now-timestamp" substitutionGroup="OtherOperations">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
Deprecated - use <now>.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:attribute ref="field" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:attributeGroup name="attlist.now-timestamp">
|
||||
<xs:attribute type="xs:string" name="field" use="required">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The name of the method environment field the timestamp will be put in.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="now-date-to-env" substitutionGroup="OtherOperations">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The now-date-to-env tag creates a java.sql.Date object with the current date in it and puts it in a field in the method environment.
|
||||
Deprecated - use <now>.
|
||||
</xs:documentation>
|
||||
</xs:annotation><xs:complexType>
|
||||
<xs:attributeGroup ref="attlist.now-date-to-env"/>
|
||||
</xs:annotation>
|
||||
<xs:complexType>
|
||||
<xs:attribute ref="field" use="required" />
|
||||
</xs:complexType>
|
||||
</xs:element>
|
||||
<xs:attributeGroup name="attlist.now-date-to-env">
|
||||
<xs:attribute type="xs:string" name="field" use="required">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
The name of the method environment field the date will be put in.
|
||||
</xs:documentation>
|
||||
</xs:annotation>
|
||||
</xs:attribute>
|
||||
</xs:attributeGroup>
|
||||
<xs:element name="property-to-field" substitutionGroup="OtherOperations">
|
||||
<xs:annotation>
|
||||
<xs:documentation>
|
||||
|
||||
+1
-1
@@ -49,7 +49,6 @@ org.ofbiz.minilang.method.entityops.GetRelatedOne$GetRelatedOneFactory
|
||||
org.ofbiz.minilang.method.entityops.MakeNextSeqId$MakeNextSeqIdFactory
|
||||
org.ofbiz.minilang.method.entityops.MakeValue$MakeValueFactory
|
||||
org.ofbiz.minilang.method.entityops.NowDateToEnv$NowDateToEnvFactory
|
||||
org.ofbiz.minilang.method.entityops.NowTimestampToEnv$NowTimestampToEnvFactory
|
||||
org.ofbiz.minilang.method.entityops.NowTimestampToEnv$NowTimestampFactory
|
||||
org.ofbiz.minilang.method.entityops.OrderValueList$OrderValueListFactory
|
||||
org.ofbiz.minilang.method.entityops.RefreshValue$RefreshValueFactory
|
||||
@@ -77,6 +76,7 @@ org.ofbiz.minilang.method.envops.IterateMap$IterateMapFactory
|
||||
org.ofbiz.minilang.method.envops.ListToList$ListToListFactory
|
||||
org.ofbiz.minilang.method.envops.Loop$LoopFactory
|
||||
org.ofbiz.minilang.method.envops.MapToMap$MapToMapFactory
|
||||
org.ofbiz.minilang.method.envops.Now$NowFactory
|
||||
org.ofbiz.minilang.method.envops.OrderMapList$OrderMapListFactory
|
||||
org.ofbiz.minilang.method.envops.SetCalendar$SetCalendarFactory
|
||||
org.ofbiz.minilang.method.envops.SetOperation$SetOperationFactory
|
||||
|
||||
@@ -18,51 +18,57 @@
|
||||
*******************************************************************************/
|
||||
package org.ofbiz.minilang.method.entityops;
|
||||
|
||||
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
|
||||
import org.ofbiz.base.util.string.FlexibleStringExpander;
|
||||
import org.ofbiz.minilang.MiniLangException;
|
||||
import org.ofbiz.minilang.MiniLangValidate;
|
||||
import org.ofbiz.minilang.SimpleMethod;
|
||||
import org.ofbiz.minilang.method.ContextAccessor;
|
||||
import org.ofbiz.minilang.method.MethodContext;
|
||||
import org.ofbiz.minilang.method.MethodOperation;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Creates a java.sql.Date with the current date and puts it in the env
|
||||
* Creates a <code>java.sql.Timestamp</code> object that is set to the current system time.
|
||||
*/
|
||||
public class NowDateToEnv extends MethodOperation {
|
||||
|
||||
ContextAccessor<java.sql.Date> envAcsr;
|
||||
private final FlexibleMapAccessor<Object> fieldFma;
|
||||
|
||||
public NowDateToEnv(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
super(element, simpleMethod);
|
||||
envAcsr = new ContextAccessor<java.sql.Date>(element.getAttribute("field"), element.getAttribute("env-name"));
|
||||
if (MiniLangValidate.validationOn()) {
|
||||
MiniLangValidate.handleError("Deprecated - use <now>", simpleMethod, element);
|
||||
MiniLangValidate.attributeNames(simpleMethod, element, "field");
|
||||
MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
|
||||
MiniLangValidate.noChildElements(simpleMethod, element);
|
||||
}
|
||||
this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exec(MethodContext methodContext) throws MiniLangException {
|
||||
envAcsr.put(methodContext, new java.sql.Date(System.currentTimeMillis()));
|
||||
this.fieldFma.put(methodContext.getEnvMap(), new java.sql.Date(System.currentTimeMillis()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String expandedString(MethodContext methodContext) {
|
||||
// TODO: something more than a stub/dummy
|
||||
return this.rawString();
|
||||
return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rawString() {
|
||||
// TODO: something more than the empty tag
|
||||
return "<now-date-to-env/>";
|
||||
return toString();
|
||||
}
|
||||
|
||||
public static final class NowDateFactory implements Factory<NowDateToEnv> {
|
||||
public NowDateToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
return new NowDateToEnv(element, simpleMethod);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "now-date";
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("<now-date-to-env ");
|
||||
if (!this.fieldFma.isEmpty()) {
|
||||
sb.append("field=\"").append(this.fieldFma).append("\" ");
|
||||
}
|
||||
sb.append("/>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final class NowDateToEnvFactory implements Factory<NowDateToEnv> {
|
||||
|
||||
@@ -18,41 +18,57 @@
|
||||
*******************************************************************************/
|
||||
package org.ofbiz.minilang.method.entityops;
|
||||
|
||||
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
|
||||
import org.ofbiz.base.util.string.FlexibleStringExpander;
|
||||
import org.ofbiz.minilang.MiniLangException;
|
||||
import org.ofbiz.minilang.MiniLangValidate;
|
||||
import org.ofbiz.minilang.SimpleMethod;
|
||||
import org.ofbiz.minilang.method.ContextAccessor;
|
||||
import org.ofbiz.minilang.method.MethodContext;
|
||||
import org.ofbiz.minilang.method.MethodOperation;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Creates a java.sql.Timestamp with the current date/time in it and puts it in the env
|
||||
* Creates a <code>java.sql.Timestamp</code> object that is set to the current system time.
|
||||
*/
|
||||
public class NowTimestampToEnv extends MethodOperation {
|
||||
public final class NowTimestampToEnv extends MethodOperation {
|
||||
|
||||
ContextAccessor<java.sql.Timestamp> envAcsr;
|
||||
private final FlexibleMapAccessor<Object> fieldFma;
|
||||
|
||||
public NowTimestampToEnv(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
super(element, simpleMethod);
|
||||
envAcsr = new ContextAccessor<java.sql.Timestamp>(element.getAttribute("field"), element.getAttribute("env-name"));
|
||||
if (MiniLangValidate.validationOn()) {
|
||||
// MiniLangValidate.handleError("Deprecated - use <now>", simpleMethod, element);
|
||||
MiniLangValidate.attributeNames(simpleMethod, element, "field");
|
||||
MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
|
||||
MiniLangValidate.noChildElements(simpleMethod, element);
|
||||
}
|
||||
this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exec(MethodContext methodContext) throws MiniLangException {
|
||||
envAcsr.put(methodContext, new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
this.fieldFma.put(methodContext.getEnvMap(), new java.sql.Timestamp(System.currentTimeMillis()));
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String expandedString(MethodContext methodContext) {
|
||||
// TODO: something more than a stub/dummy
|
||||
return this.rawString();
|
||||
return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rawString() {
|
||||
// TODO: something more than the empty tag
|
||||
return "<now-timestamp-to-env/>";
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("<now-timestamp ");
|
||||
if (!this.fieldFma.isEmpty()) {
|
||||
sb.append("field=\"").append(this.fieldFma).append("\" ");
|
||||
}
|
||||
sb.append("/>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
public static final class NowTimestampFactory implements Factory<NowTimestampToEnv> {
|
||||
@@ -64,14 +80,4 @@ public class NowTimestampToEnv extends MethodOperation {
|
||||
return "now-timestamp";
|
||||
}
|
||||
}
|
||||
|
||||
public static final class NowTimestampToEnvFactory implements Factory<NowTimestampToEnv> {
|
||||
public NowTimestampToEnv createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
return new NowTimestampToEnv(element, simpleMethod);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "now-timestamp-to-env";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,112 @@
|
||||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF 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.ofbiz.minilang.method.envops;
|
||||
|
||||
import org.ofbiz.base.conversion.ConversionException;
|
||||
import org.ofbiz.base.conversion.Converter;
|
||||
import org.ofbiz.base.conversion.Converters;
|
||||
import org.ofbiz.base.util.ObjectType;
|
||||
import org.ofbiz.base.util.collections.FlexibleMapAccessor;
|
||||
import org.ofbiz.base.util.string.FlexibleStringExpander;
|
||||
import org.ofbiz.minilang.MiniLangException;
|
||||
import org.ofbiz.minilang.MiniLangRuntimeException;
|
||||
import org.ofbiz.minilang.MiniLangValidate;
|
||||
import org.ofbiz.minilang.SimpleMethod;
|
||||
import org.ofbiz.minilang.ValidationException;
|
||||
import org.ofbiz.minilang.method.MethodContext;
|
||||
import org.ofbiz.minilang.method.MethodOperation;
|
||||
import org.w3c.dom.Element;
|
||||
|
||||
/**
|
||||
* Sets a field to the current system time.
|
||||
*/
|
||||
public final class Now extends MethodOperation {
|
||||
|
||||
private final FlexibleMapAccessor<Object> fieldFma;
|
||||
private final String type;
|
||||
private final Converter<Long, Object> converter;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public Now(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
super(element, simpleMethod);
|
||||
if (MiniLangValidate.validationOn()) {
|
||||
MiniLangValidate.attributeNames(simpleMethod, element, "field", "type");
|
||||
MiniLangValidate.requiredAttributes(simpleMethod, element, "field");
|
||||
MiniLangValidate.noChildElements(simpleMethod, element);
|
||||
}
|
||||
this.fieldFma = FlexibleMapAccessor.getInstance(element.getAttribute("field"));
|
||||
this.type = element.getAttribute("type");
|
||||
Class<?> targetClass = null;
|
||||
try {
|
||||
if (this.type.length() > 0) {
|
||||
targetClass = ObjectType.loadClass(this.type);
|
||||
}
|
||||
if (targetClass == null) {
|
||||
targetClass = java.sql.Timestamp.class;
|
||||
}
|
||||
this.converter = (Converter<Long, Object>) Converters.getConverter(Long.class, targetClass);
|
||||
} catch (ClassNotFoundException e) {
|
||||
throw new ValidationException(e.getMessage(), simpleMethod, element);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean exec(MethodContext methodContext) throws MiniLangException {
|
||||
try {
|
||||
this.fieldFma.put(methodContext.getEnvMap(), this.converter.convert(System.currentTimeMillis()));
|
||||
} catch (ConversionException e) {
|
||||
throw new MiniLangRuntimeException(e.getMessage(), this);
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String expandedString(MethodContext methodContext) {
|
||||
return FlexibleStringExpander.expandString(toString(), methodContext.getEnvMap());
|
||||
}
|
||||
|
||||
@Override
|
||||
public String rawString() {
|
||||
return toString();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder("<now ");
|
||||
if (!this.fieldFma.isEmpty()) {
|
||||
sb.append("field=\"").append(this.fieldFma).append("\" ");
|
||||
}
|
||||
if (this.type.length() > 0) {
|
||||
sb.append("type=\"").append(this.type).append("\" ");
|
||||
}
|
||||
sb.append("/>");
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
|
||||
public static final class NowFactory implements Factory<Now> {
|
||||
public Now createMethodOperation(Element element, SimpleMethod simpleMethod) throws MiniLangException {
|
||||
return new Now(element, simpleMethod);
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return "now";
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user