How can I make a simpler javascript function for the following: - replace

There has to be a function that can be used that will greatly simplify, codewise, all these very similar replacements. Would like to be able to make a function that could handle this fall all contractions including I've, Could've etc.
// for can't
s = s.replace(/cant/g, "ca{n't|n{| }not}");
s = s.replace(/can't/g, "ca{n't|n{| }not}");
s = s.replace(/Cant/g, "Ca{n't|n{| }not}");
s = s.replace(/Can't/g, "Ca{n't|n{| }not}");
//for can not
s = s.replace(/can not/g, "ca{n't|{| }not}");
s = s.replace(/Can not/g, "Ca{n't|{| }not}");
// for won't
s = s.replace(/wont/g, "w{on't|ill not}");
s = s.replace(/won't/g, "w{on't|ill not}");
s = s.replace(/Wont/g, "W{on't|ill not}");
s = s.replace(/Won't/g, "W{on't|ill not}");
// for will not
s = s.replace(/will not/g, "w{on't|ill not}");
s = s.replace(/Will not/g, "W{on't|ill not}");
// for hasn't
s = s.replace(/hasnt/g, "has{n't| not}");
s = s.replace(/hasn't/g, "has{n't| not}");
s = s.replace(/Hasnt/g, "Has{n't| not}");
s = s.replace(/Hasn't/g, "Has{n't| not}");
// for has not
s = s.replace(/has not/g, "has{n't| not}");
s = s.replace(/Has not/g, "Has{n't| not}");

For can not and can't, it could be done in a single step:
s = s.replace(/(C|c)an(?:'?t| not)/g, "ca{n't|n{| }not}");
Or, if you want to match also cannot
s = s.replace(/(C|c)an(?:'?t| ?not)/g, "ca{n't|n{| }not}");
Same principle can be applied for the other has not and will not

Related

"Module already present - choose a different name." vtiger 6.4

I followed all the steps mentioned on create custom module in vtiger 6 to create custom module but I am getting the error Module already present - choose a different name
Please advice.
As your are using vtiger 6.4 , there are lot of difference between vTiger 6 and vtiger6.4.
Try with the below script as I am using same for new module creation. Use new module name. And change the UI Types and field labels as per your requirement.
<?php
$Vtiger_Utils_Log = true;
include_once('vtlib/Vtiger/Menu.php');
include_once('vtlib/Vtiger/Module.php');
$module = new Vtiger_Module();
$module->name = 'Your_MODULE_NAME';
$module->parent = 'Tools';
$module->save();
$module->initTables();
$module->initWebservice();
$block = new Vtiger_Block();
$block->label = 'LBL_INFORMATION_DETAIL';
$module->addBlock($block); //to create a new block
$field1 = new Vtiger_Field();
$field1->name = 'browse';
$field1->table=$module->basetable;
$field1->label= 'Upload Csv';
$field1->column = 'browse';
$field1->columntype = 'VARCHAR(255)';
$field1->uitype= 28;
$field1->typeofdata = 'V~O';
$block->addField($field1);
$field2 = new Vtiger_Field();
$field2->name = 'fieldid';
$field2->table=$module->basetable;
$field2->label= 'Record ID';
$field2->uitype= 4;
$field2->column = 'fieldid';
$field2->columntype = 'VARCHAR(255)';
$field2->typeofdata = 'V~M';
$block->addField($field2);
$module->setEntityIdentifier($field2);
$field3 = new Vtiger_Field();
$field3->name = 'age';
$field3->table=$module->basetable;
$field3->label= 'Age';
$field3->uitype= 1;
$field3->column = 'age';
$field3->columntype = 'VARCHAR(100)';
$field3->typeofdata = 'V~O';
$block->addField($field3);
$field4 = new Vtiger_Field();
$field4->name = 'statusrecord';
$field4->table=$module->basetable;
$field4->label= 'Status';
$field4->uitype= 15;
$field4->column = 'statusrecord';
$field4->columntype = 'VARCHAR(255)';
$field4->setPicklistValues( Array('new','closed','closedwithfailure','inprogress'));
$field4->typeofdata = 'V~M';
$block->addField($field4);
// Recommended common fields every Entity module should have (linked to core table)
$field5 = new Vtiger_Field();
$field5->name = 'assigned_user_id';
$field5->label = 'Assigned To';
$field5->table = 'Vtiger_crmentity';
$field5->column = 'smownerid';
$field5->uitype = 53;
$field5->typeofdata = 'V~M';
$block->addField($field5);
$field6 = new Vtiger_Field();
$field6->name = 'CreatedTime';
$field6->label= 'Created Time';
$field6->table = 'Vtiger_crmentity';
$field6->column = 'createdtime';
$field6->uitype = 70;
$field6->typeofdata = 'T~O';
$field6->displaytype= 2;
$block->addField($field6);
$field7 = new Vtiger_Field();
$field7->name = 'ModifiedTime';
$field7->label= 'Modified Time';
$field7->table = 'Vtiger_crmentity';
$field7->column = 'modifiedtime';
$field7->uitype = 70;
$field7->typeofdata = 'T~O';
$field7->displaytype= 2;
$block->addField($field7);
// Filter Setup
$filter1 = new Vtiger_Filter();
$filter1->name = 'All';
$filter1->isdefault = true;
$module->addFilter($filter1);
// Add fields to the filter create
$filter1->addField($field7, 2);
$filter1->addField($field3, 3);
$filter1->addField($field4, 5);
/** Set sharing access of this module */
$module->setDefaultSharing();
/** Enable and Disable available tools */
$module->enableTools(Array('Import', 'Export'));
$module->disableTools('Merge');
?>
You can also refer Entity-Module-Documentation

How to Know Timezone for a record created by user in sharepoint 2010

I have a application which is in sharepoint 2010. actually application users works in that application from multiple locations.. and if one user is working for 15 days in IST time (UTC+5:30) and for next 10 days goes to US then he works in CST or EST timezone... so my user changes his timezone as per his location... but now problem is.. when he go to generate his report.. which does not show correct for date time fields....
if he is correctly selected IST timezone then all data shows by IST timezone... the EST and CST doest not show correct also user can not segregate his different - 2 timezone data...
actually i have provided a report by asmx webservices.. Please find below code which i have written..
using System;
using System.Collections;
using System.Text;
using System.Data;
using System.Data.SqlTypes;
using Microsoft.SqlServer.Server;
using System.Security.Principal;
using System.Net;
using System.Xml;
public class SharePointActivities
{
[SqlFunction(SystemDataAccess = SystemDataAccessKind.Read, FillRowMethodName = "GetActivitiesItemInfo")]
public static IEnumerable GetActivitiesItems(SqlString url, SqlString listName, SqlString viewName, SqlString Query)
{
DataTable t = new DataTable();
WindowsImpersonationContext ctx = null;
WindowsIdentity id = SqlContext.WindowsIdentity;
try
{
ctx = id.Impersonate();
WSS.Lists svc = new WSS.Lists();
svc.Url = url.ToString();
//svc.Credentials = new NetworkCredential("krishna", "google#123", "WKS10953");
//Or
//svc.Credentials = new System.Net.NetworkCredential("krishna", "google#123", "WKS10953");
//Or
svc.Credentials = CredentialCache.DefaultNetworkCredentials;
//Or
//svc.UseDefaultCredentials = true;
//svc.PreAuthenticate = true;
//Or
//oServices.Credentials = new NetworkCredential("krishna", "google#123", "wks10953");
//Query
XmlDocument xmlDoc = new XmlDocument();
XmlNode query = xmlDoc.CreateElement("Query");
query.InnerXml = Query.ToString();//"<Where><Gt><FieldRef Name=\"ID\" /><Value Type=\"Counter\">3</Value></Gt></Where>";
//ViewFields
XmlElement viewFields = xmlDoc.CreateElement("ViewFields");
viewFields.InnerXml = "";// "<FieldRef Name=\"Title\" />";
//QueryOptions
XmlElement queryOptions = xmlDoc.CreateElement("QueryOptions");
queryOptions.InnerXml = "";
XmlNode node = svc.GetListItems(listName.ToString(), viewName.ToString(), query, viewFields, "500000", queryOptions, null);
XmlTextReader rdr = new XmlTextReader(node.OuterXml,
XmlNodeType.Element, null);
DataSet ds = new DataSet();
ds.ReadXml(rdr);
t = ds.Tables[1];
}
finally
{
if (ctx != null)
ctx.Undo();
}
return t.Rows;
}
public static void GetActivitiesItemInfo(
object obj,
out SqlString ID,
out SqlString Title,
out SqlString RecordDate,
out SqlString ClientVertical,
out SqlString Client,
out SqlString StoreUnits,
out SqlString Process,
out SqlString MainActivity,
out SqlString SubActivity,
out SqlString PeriodStartDate,
out SqlString PeriodEndDate,
out SqlString NoOfPeriod,
out SqlString EntryType,
out SqlString StartTime,
out SqlString StopTime,
out SqlString TimeTaken,
//out SqlString VolumeCount,
//out SqlString InputMode,
//out SqlString Category,
out SqlString Remarks)
{
DataRow r = (DataRow)obj;
ID = new SqlString(Convert.ToString(r["ows_ID"]));
Title = new SqlString(Convert.ToString(r["ows_Title"]));
RecordDate = new SqlString(Convert.ToString(r["ows_RecordDate"]));
ClientVertical = new SqlString(Convert.ToString(r["ows_ClientVertical"]));
Client = new SqlString(Convert.ToString(r["ows_Client"]));
StoreUnits = new SqlString(Convert.ToString(r["ows_StoreUnits"]));
Process = new SqlString(Convert.ToString(r["ows_Process"]));
MainActivity = new SqlString(Convert.ToString(r["ows_MainActivity"]));
SubActivity = new SqlString(Convert.ToString(r["ows_SubActivity"]));
PeriodStartDate = new SqlString(Convert.ToString(r["ows_PeriodStartDate"]));
PeriodEndDate = new SqlString(Convert.ToString(r["ows_PeriodEndDate"]));
NoOfPeriod = new SqlString(Convert.ToString(r["ows_NoOfPeriod"]));
EntryType = new SqlString(Convert.ToString(r["ows_EntryType"]));
StartTime = new SqlString(Convert.ToString(r["ows_StartTime"]));
StopTime = new SqlString(Convert.ToString(r["ows_StopTime"]));
TimeTaken = new SqlString(Convert.ToString(r["ows_TimeTaken"]));
//VolumeCount = new SqlString(Convert.ToString(r["ows_VolumeCount"]));
//InputMode = new SqlString(Convert.ToString(r["ows_InputMode"]));
//Category = new SqlString(Convert.ToString(r["ows_Category"]));
Remarks = new SqlString(Convert.ToString(r["ows_Remarks"]));
}
}
in this code for my report gets parameters start date and end date from Recorddate field.. but if user selected currently IST timezone.. then CST and EST recorded data shows 1 day before which does't work..
so may i know record created timezone and utc value of record data to find in every timezone... or any other solution to find actual date..

gSoap Exchange Web Services Connection

I'm trying to write an application that would work with the EWS proxy classes. To generate proxy classes I used gsoap (compiled OpenSSL).
I have implemented a library that works with EWS, but. Net.
The problem is this: I have no idea how to implement a connection to the server.
Doing the following:
ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy("https://192.168.0.49/EWS/exchange.asmx");
soap *pSoap = proxy->soap;
pSoap->userid = "user1";
pSoap->passwd = "password1";
pSoap->recv_timeout = 300;
pSoap->send_timeout = 300;
SOAP_ENV__Header *header = new SOAP_ENV__Header();
header->ns3__RequestServerVersion = new _ns3__RequestServerVersion();
header->ns3__RequestServerVersion->soap = pSoap;
header->ns3__RequestServerVersion->Version = ns3__ExchangeVersionType__Exchange2010;
pSoap->header = header;
//get root folder ID
ns3__DistinguishedFolderIdType *dfit = new ns3__DistinguishedFolderIdType();
dfit->Id = ns3__DistinguishedFolderIdNameType__inbox;
//set the props that we want to retrieve
ns3__FolderResponseShapeType *frst = new ns3__FolderResponseShapeType();
frst->BaseShape = ns3__DefaultShapeNamesType__AllProperties;
//get folder
ns1__GetFolderType *gftRoot = new ns1__GetFolderType();
gftRoot->FolderIds = new ns3__NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType = new __ns3__union_NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderShape = frst;
__ns1__GetFolderResponse response;
int error = proxy->GetFolder(gftRoot, response);
As a result, getting the error: SLL_ERROR.
I know, that i`m doing something wrong. But what? What i should to do, to use proxy classes functions?
I resolved it by myself:
Added to project LibNTLM and added to preprocessor WITH_NTLM.
Also changed code, a little bit:
ExchangeServiceBindingProxy *proxy = new ExchangeServiceBindingProxy(endpoint.c_str());
soap *pSoap = proxy->soap;
pSoap->userid = "Ivan1";
pSoap->passwd = "1";
pSoap->ntlm_challenge = "";
pSoap->authrealm = "Ursa-Minor";
pSoap->ssl_flags = SOAP_SSL_NO_AUTHENTICATION;
//pSoap->keep_alive = true;
pSoap->mode = SOAP_IO_KEEPALIVE;
//get root folder ID
ns3__DistinguishedFolderIdType *dfit = new ns3__DistinguishedFolderIdType();
dfit->Id = ns3__DistinguishedFolderIdNameType__inbox;
//set the props that we want to retrieve
ns3__FolderResponseShapeType *frst = new ns3__FolderResponseShapeType();
frst->BaseShape = ns3__DefaultShapeNamesType__AllProperties;
//get folder
ns1__GetFolderType *gftRoot = new ns1__GetFolderType();
gftRoot->FolderIds = new ns3__NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__size_NonEmptyArrayOfBaseFolderIdsType = 1;
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType = new __ns3__union_NonEmptyArrayOfBaseFolderIdsType();
gftRoot->FolderIds->__union_NonEmptyArrayOfBaseFolderIdsType->union_NonEmptyArrayOfBaseFolderIdsType.DistinguishedFolderId = dfit;
gftRoot->FolderIds = (ns3__NonEmptyArrayOfBaseFolderIdsType*)dfit;
gftRoot->FolderShape = frst;
__ns1__GetFolderResponse response;
int qq = proxy->GetFolder(gftRoot, response);
return true;
But now i have enother problems: Error 500: Internal Server Error

How to load .jar file in C++ using JNI

I am trying to load a method present in a .jar. Following is code snippet
JavaVMInitArgs vm_args;
memset(&vm_args, 0, sizeof(vm_args));
JavaVMOption* options = new JavaVMOption[1];
options[0].optionString =
"- Djava.class.path=C:\\Users\\Desktop\\POC\\POC\\Debug\\Sample2.jar;
vm_args.version = JNI_VERSION_1_6;
vm_args.nOptions = 1;
vm_args.options = options;
vm_args.ignoreUnrecognized = 0;
JNI_GetDefaultJavaVMInitArgs(&vm_args);
m_Status = JNI_CreateJavaVM_ptr (&m_JVM, (void**)&m_JavaEnv, &vm_args);
But when I use the
classForJava = m_JavaEnv->FindClass ("Sample2");
classForJava contains 0.
Specify full name of the class including package name with . replaced with /.
For exampe if your Sample2 class is in org.test package, use m_JavaEnv->FindClass ("org/test/Sample2");
By the way, it might be a typo but the optionString space between - and Djava.class.path should be removed.

saaj exception - Unable to parse content type: null

I'm fairly new to webservices and working through a SAAJ example of sending and recieving attachments (binary files). I can get it to work when the client sends the file but not when it requests it. I get an exception on the client side:
ERROR: 'Content is not allowed in prolog.'
24-Oct-2012 13:59:28 com.sun.xml.internal.messaging.saaj.soap.EnvelopeFactory createEnvelope
SEVERE: SAAJ0511: Unable to create envelope from given source
com.sun.xml.internal.messaging.saaj.SOAPExceptionImpl: Unable to create envelope from given source
Anybody have any ideas???my client code is as follows:
SOAPConnectionFactory scf = SOAPConnectionFactory.newInstance();
SOAPConnection con = scf.createConnection();
SOAPFactory soapFactory = SOAPFactory.newInstance();
MessageFactory mf = MessageFactory.newInstance();
SOAPMessage msg = mf.createMessage();
SOAPHeader header = msg.getSOAPHeader();
header.detachNode();
SOAPBody body = msg.getSOAPBody();
Name bodyName = soapFactory.createName(
"remoteOpen", "remoteOpen",
"http://schemas.remoteOpen.com/remoteOpen");
SOAPBodyElement bodyElement = body.addBodyElement(bodyName);
SOAPElement projectName = bodyElement.addChildElement("projectName");
projectName.addTextNode("filename");
msg.saveChanges();
// create the endpoint and send the message
URL endpoint = new URL("http://localhost:8080/RemoteSaveProject/OpenServlet");
SOAPMessage response = con.call(msg, endpoint);
con.close();
SOAPBody responseBody = response.getSOAPBody();
SOAPElement ackElem = (SOAPElement)responseBody.getFirstChild();
String acknowledgement = ackElem.getValue();
the server code looks like this:
MimeHeaders mimeHeaders = new MimeHeaders();
Enumeration en = request.getHeaderNames();
while (en.hasMoreElements())
{
String headerName = (String)en.nextElement();
String headerVal = request.getHeader(headerName);
StringTokenizer tk = new StringTokenizer(headerVal, ",");
while (tk.hasMoreTokens()){
mimeHeaders.addHeader(headerName, tk.nextToken().trim());
}
}
SOAPMessage message = mf.createMessage(mimeHeaders, request.getInputStream());
SOAPBody body = message.getSOAPBody();
Name bodyName = soapFactory.createName(
"remoteOpen", "remoteOpen",
"http://schemas.remoteOpen.com/remoteOpen");
Iterator projects = body.getChildElements(bodyName);
SOAPElement project = (SOAPElement)projects.next();
Iterator projectNameIter = project.getChildElements(soapFactory.createName("projectName"));
SOAPElement projectNameEle = (SOAPElement)projectNameIter.next();
String projectName = projectNameEle.getValue();
File file = new File(projectName);
SOAPMessage reply = mf.createMessage();
SOAPHeader header = reply.getSOAPHeader();
header.detachNode();
SOAPBody replyBody = reply.getSOAPBody();
SOAPBodyElement bodyElement = replyBody.addBodyElement(soapFactory.createName("ack"));
bodyElement.addTextNode("OK");
DataHandler dh = new DataHandler(new FileDataSource(file));
AttachmentPart attachment = reply.createAttachmentPart(dh);
attachment.setContentId("123");
reply.addAttachmentPart(attachment);
reply.saveChanges();
response.setStatus(HttpServletResponse.SC_OK);
putHeaders(reply.getMimeHeaders(), response);
response.setContentType("text/xml");
ServletOutputStream replyOS = response.getOutputStream();
reply.writeTo(replyOS);
replyOS.flush();
replyOS.close();
putHeaders looks like:
Iterator it = headers.getAllHeaders();
while (it.hasNext())
{
MimeHeader header = (MimeHeader) it.next();
String[] values = headers.getHeader(header.getName());
if (values.length == 1)
{
res.setHeader( header.getName(), header.getValue());
}
else
{
StringBuffer concat = new StringBuffer();
int i = 0;
while (i < values.length)
{
if (i != 0)
{
concat.append(',');
}
concat.append(values[i++]);
}
res.setHeader(header.getName(), concat.toString());
}
}
If you are using Google app engine, like me, the problem is that GAE doesn't support com.sun.xml.internal.messaging.saaj.packaging.mime.internet.ParameterList which is used internally somewhere in the call chain of javax.xml.soap.SOAPConnection.call(). So you must use a workaround.
I personally did it by using java.net.HttpURLConnection instead of javax.xml.soap.SOAPConnection and manually sending and parsing SOAP messages.