use of java.text.Format in project instructure-android by instructure.
the class DateHelpers method getShortDate.
public static String getShortDate(Context context, Date date) {
if (context == null) {
return null;
}
Format format = getShortDateFormat(context);
String sFormat = format.format(date.getTime());
return sFormat;
}
use of java.text.Format in project dbeaver by dbeaver.
the class ObjectPropertyDescriptor method readValue.
public Object readValue(Object object, @Nullable DBRProgressMonitor progressMonitor) throws IllegalAccessException, IllegalArgumentException, InvocationTargetException {
if (object == null) {
return null;
}
Object value;
if (getParent() != null) {
object = getParent().getGroupObject(object, progressMonitor);
if (object == null) {
return null;
}
}
Method getter = getGetter();
Object[] params = null;
if (getter.getParameterCount() > 0) {
params = new Object[getter.getParameterCount()];
}
if (isLazy() && params != null) {
// Lazy (probably cached)
if (isLazy(object, true) && progressMonitor == null && !supportsPreview()) {
throw new IllegalAccessException("Lazy property can't be read with null progress monitor");
}
params[0] = progressMonitor;
}
value = getter.invoke(object, params);
if (valueRenderer != null) {
value = valueRenderer.transform(object, value);
}
if (value instanceof Number) {
final Format displayFormat = getDisplayFormat();
if (displayFormat != null) {
return displayFormat.format(value);
}
}
return value;
}
use of java.text.Format in project instructure-android by instructure.
the class DateHelper method getShortDate.
public static String getShortDate(Context context, Date date) {
if (context == null) {
return null;
}
Format format = getShortDateFormat(context);
String sFormat = format.format(date.getTime());
return sFormat;
}
use of java.text.Format in project wso2-synapse by wso2.
the class GetPropertyFunction method evaluate.
/**
* Returns the string value of the property using arg one as key and arg two as scope
*
* @param scopeObject scope will decide from where property will be picked up from
* i.e. axis2, transport, default/synapse
* @param keyObject the key of the property
* @param navigator object model which can be used for navigation around
* @param dateformat The dateformat that need to convert
* @return The String value of property using arg one as key and arg two as scope
*/
public Object evaluate(Object scopeObject, Object keyObject, Object dateformat, Navigator navigator) {
boolean traceOn = synCtx.getTracingState() == SynapseConstants.TRACING_ON;
boolean traceOrDebugOn = traceOn || log.isDebugEnabled();
String scope = StringFunction.evaluate(scopeObject, navigator);
String key = StringFunction.evaluate(keyObject, navigator);
if (key == null || "".equals(key)) {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "property-name should be provided when executing synapse:get-property" + "(scope,prop-name) or synapse:get-property(prop-name) Xpath function");
}
return NULL_STRING;
}
if (SynapseConstants.SYSTEM_DATE.equals(key)) {
if (dateformat != null) {
Format formatter = new SimpleDateFormat(dateformat.toString());
return formatter.format(new java.util.Date());
} else {
Format formatter = new SimpleDateFormat();
return formatter.format(new java.util.Date());
}
}
// return the current system time as a string , don't care scope
if (SynapseConstants.SYSTEM_TIME.equals(key)) {
return Long.toString(System.currentTimeMillis());
}
if (XMLConfigConstants.SCOPE_DEFAULT.equals(scope)) {
if (SynapseConstants.HEADER_TO.equals(key)) {
EndpointReference toEPR = synCtx.getTo();
if (toEPR != null) {
return toEPR.getAddress();
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_FROM.equals(key)) {
EndpointReference fromEPR = synCtx.getFrom();
if (fromEPR != null) {
return fromEPR.getAddress();
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_ACTION.equals(key)) {
String wsaAction = synCtx.getWSAAction();
if (wsaAction != null) {
return wsaAction;
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_FAULT.equals(key)) {
EndpointReference faultEPR = synCtx.getFaultTo();
if (faultEPR != null) {
return faultEPR.getAddress();
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_REPLY_TO.equals(key)) {
EndpointReference replyToEPR = synCtx.getReplyTo();
if (replyToEPR != null) {
return replyToEPR.getAddress();
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_RELATES_TO.equals(key)) {
RelatesTo relatesTo = synCtx.getRelatesTo();
if (relatesTo != null) {
return relatesTo.getValue();
} else {
return NULL_STRING;
}
} else if (SynapseConstants.HEADER_MESSAGE_ID.equals(key)) {
String messageID = synCtx.getMessageID();
if (messageID != null) {
return messageID;
} else {
return NULL_STRING;
}
} else if (SynapseConstants.PROPERTY_FAULT.equals(key)) {
if (synCtx.getEnvelope().hasFault()) {
return SynapseConstants.TRUE;
} else if (synCtx instanceof Axis2MessageContext) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
if (axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE) != null && SynapseConstants.TRUE.equals(axis2MessageContext.getProperty(BaseConstants.FAULT_MESSAGE))) {
return SynapseConstants.TRUE;
}
} else {
return NULL_STRING;
}
} else if (SynapseConstants.PROPERTY_MESSAGE_FORMAT.equals(key)) {
if (synCtx.isDoingPOX())
return SynapseConstants.FORMAT_POX;
else if (synCtx.isDoingGET())
return SynapseConstants.FORMAT_GET;
else if (synCtx.isSOAP11())
return SynapseConstants.FORMAT_SOAP11;
else
return SynapseConstants.FORMAT_SOAP12;
} else if (SynapseConstants.PROPERTY_OPERATION_NAME.equals(key) || SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
if (synCtx instanceof Axis2MessageContext) {
AxisOperation axisOperation = ((Axis2MessageContext) synCtx).getAxis2MessageContext().getAxisOperation();
if (axisOperation != null) {
if (SynapseConstants.PROPERTY_OPERATION_NAMESPACE.equals(key)) {
return axisOperation.getName().getNamespaceURI();
} else {
return axisOperation.getName().getLocalPart();
}
}
}
} else {
Object result = synCtx.getProperty(key);
if (result != null) {
return result;
} else {
return synCtx.getLocalEntry(key);
}
}
} else if (XMLConfigConstants.SCOPE_AXIS2.equals(scope) && synCtx instanceof Axis2MessageContext) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
return axis2MessageContext.getProperty(key);
} else if (XMLConfigConstants.SCOPE_FUNC.equals(scope)) {
Stack<TemplateContext> functionStack = (Stack) synCtx.getProperty(SynapseConstants.SYNAPSE__FUNCTION__STACK);
TemplateContext topCtxt = functionStack.peek();
if (topCtxt != null) {
return topCtxt.getParameterValue(key);
}
} else if (XMLConfigConstants.SCOPE_TRANSPORT.equals(scope) && synCtx instanceof Axis2MessageContext) {
org.apache.axis2.context.MessageContext axis2MessageContext = ((Axis2MessageContext) synCtx).getAxis2MessageContext();
Object headers = axis2MessageContext.getProperty(org.apache.axis2.context.MessageContext.TRANSPORT_HEADERS);
if (headers != null && headers instanceof Map) {
Map headersMap = (Map) headers;
return headersMap.get(key);
}
} else if (XMLConfigConstants.SCOPE_OPERATION.equals(scope) && synCtx instanceof Axis2MessageContext) {
Axis2MessageContext axis2smc = (Axis2MessageContext) synCtx;
org.apache.axis2.context.MessageContext axis2MessageCtx = axis2smc.getAxis2MessageContext();
return axis2smc.getAxis2MessageContext().getOperationContext().getProperty(key);
} else if (XMLConfigConstants.SCOPE_REGISTRY.equals(scope)) {
String[] regParam = key.split("@");
String regPath = null;
String propName = null;
if (regParam.length == 2) {
regPath = regParam[0];
propName = regParam[1];
} else if (regParam.length == 1) {
regPath = regParam[0];
}
Entry propEntry = synCtx.getConfiguration().getEntryDefinition(regPath);
if (propEntry == null) {
propEntry = new Entry();
propEntry.setType(Entry.REMOTE_ENTRY);
propEntry.setKey(key);
}
Registry registry = synCtx.getConfiguration().getRegistry();
if (registry != null) {
registry.getResource(propEntry, new Properties());
if (propName != null) {
Properties reqProperties = propEntry.getEntryProperties();
if (reqProperties != null) {
if (reqProperties.get(propName) != null) {
return reqProperties.getProperty(propName);
}
}
} else if (propEntry.getValue() != null) {
if (propEntry.getValue() instanceof OMText) {
return ((OMText) propEntry.getValue()).getText();
}
return propEntry.getValue().toString();
}
}
} else if (XMLConfigConstants.SCOPE_SYSTEM.equals(scope)) {
String propVal = System.getProperty(key);
if (propVal != null) {
return propVal;
} else {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "System property " + key + " not found");
}
return NULL_STRING;
}
} else {
if (traceOrDebugOn) {
traceOrDebug(traceOn, "Invalid scope : '" + scope + "' has been set for the " + "synapse:get-property(scope,prop-name) XPath function");
}
}
return NULL_STRING;
}
use of java.text.Format in project pentaho-platform by pentaho.
the class SQLBaseComponent method executeAction.
/**
* determines state of component, and executes accordingly.
*
* various inputs that impact the state include:
*
* live - returns a live result set vs. an in memory copy transform - transform a result set based on additional
* inputs prepared_component - if available, use existing connection from prepared component max_rows - sets the
* number of rows that should be returned in result sets
*
* The specified output also impacts the state of the execution. If prepared_component is defined as an output, setup
* the query but delay execution.
*/
@Override
protected boolean executeAction() {
IActionDefinition actionDefinition = getActionDefinition();
try {
if (actionDefinition instanceof AbstractRelationalDbAction) {
AbstractRelationalDbAction relationalDbAction = (AbstractRelationalDbAction) actionDefinition;
// Added by Arijit Chatterjee
IActionInput queryTimeoutInput = relationalDbAction.getQueryTimeout();
IActionInput maxRowsInput = relationalDbAction.getMaxRows();
IActionInput readOnlyInput = relationalDbAction.getReadOnly();
String baseQuery = getQuery();
if (baseQuery == null) {
error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0001_QUERY_NOT_SPECIFIED", // $NON-NLS-1$
actionDefinition.getDescription()));
return false;
}
IPreparedComponent sharedConnection = (IPreparedComponent) relationalDbAction.getSharedConnection().getValue();
if (readOnlyInput != ActionInputConstant.NULL_INPUT) {
this.setReadOnly(readOnlyInput.getBooleanValue());
}
if (sharedConnection != null) {
connectionOwner = false;
IPentahoConnection conn = sharedConnection.shareConnection();
if (conn == null) {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0002_CONNECTION_NOT_AVAILABLE", // $NON-NLS-1$
getActionName()));
return false;
} else if (conn.getDatasourceType() == IPentahoConnection.SQL_DATASOURCE) {
connection = conn;
} else {
error(Messages.getInstance().getErrorString("IPreparedComponent.ERROR_0001_INVALID_CONNECTION_TYPE", // $NON-NLS-1$
getActionName()));
return false;
}
} else {
dispose();
connection = getDatasourceConnection();
}
if (connection == null) {
return false;
}
// query and set this component as the output. This query will be run later from a subreport.
if (relationalDbAction.getOutputPreparedStatement() != null) {
prepareQuery(baseQuery);
IActionOutput actionOutput = relationalDbAction.getOutputPreparedStatement();
if (actionOutput != null) {
actionOutput.setValue(this);
}
return true;
}
// int maxRows = relationalDbAction.getMaxRows().getIntValue(-1);
if (maxRowsInput != ActionInputConstant.NULL_INPUT) {
this.setMaxRows(maxRowsInput.getIntValue());
}
// Added by Arijit Chatterjee.Sets the value of timeout. Default is -1, if parameter not found.
if (queryTimeoutInput != ActionInputConstant.NULL_INPUT) {
this.setQueryTimeout(queryTimeoutInput.getIntValue());
}
if (relationalDbAction.getPerformTransform().getBooleanValue(false)) {
// The side effect of
runQuery(baseQuery, false);
// transform rSet here
rSet = PentahoDataTransmuter.crossTab(rSet, relationalDbAction.getTransformPivotColumn().getIntValue(-1) - 1, relationalDbAction.getTransformMeasuresColumn().getIntValue(-1) - 1, relationalDbAction.getTransformSortColumn().getIntValue(0) - 1, (Format) relationalDbAction.getTransformPivotDataFormat().getValue(), (Format) relationalDbAction.getTransformSortDataFormat().getValue(), relationalDbAction.getTransformOrderOutputColumns().getBooleanValue(false));
IActionOutput actionOutput = relationalDbAction.getOutputResultSet();
if (actionOutput != null) {
actionOutput.setValue(rSet);
}
return true;
} else {
return runQuery(baseQuery, relationalDbAction.getLive().getBooleanValue(false));
}
} else if (actionDefinition instanceof SqlConnectionAction) {
SqlConnectionAction sqlConnectionAction = (SqlConnectionAction) actionDefinition;
dispose();
connection = getDatasourceConnection();
if (connection == null) {
return false;
} else {
IActionOutput actionOutput = sqlConnectionAction.getOutputConnection();
if (actionOutput != null) {
actionOutput.setValue(this);
return true;
} else {
return false;
}
}
}
} catch (Exception e) {
// $NON-NLS-1$
error(Messages.getInstance().getErrorString("SQLBaseComponent.ERROR_0006_EXECUTE_FAILED", getActionName()), e);
}
return false;
}
Aggregations