I am using this code placed in beforeRenderResponse event of an XPage in a notes 8.5.3 application:
function overrideFileDownloadAction( fDownload ){
if( fDownload === null )
return;
rekOverrideFileDownloadAction( fDownload, fDownload );
}
function rekOverrideFileDownloadAction( component:javax.faces.component.UIOutput, fDownload:com.ibm.xsp.component.UIFileDownload ){
try{
var children:java.util.List = component.getChildren();
var it:java.util.Iterator = children.iterator();
var curChild:javax.faces.component.UIOutput;
while( it.hasNext() ){
curChild = it.next();
if( typeof( curChild ) === 'com.ibm.xsp.component.xp.XspEventHandler' ){
var group = new com.ibm.xsp.actions.ActionGroup();
var list = new java.util.ArrayList();
group.setComponent( fDownload );
list.add( curChild.getAction() );
list.add( mBinding );
group.setActions( list );
curChild.setAction(group);
}
rekOverrideFileDownloadAction( curChild , fDownload );
}
}catch(e){}
}
viewScope.flag_remove = false;
var code = "#{javascript:var fileDownload1:com.ibm.xsp.component.xp.XspFileDownload = getComponent('fileDownload1');var index = fileDownload1.getRowIndex(); if(viewScope.flag_remove == false){viewScope.types.removeElementAt(index); viewScope.flag_remove = true}}";
var mBinding = facesContext.getApplication().createMethodBinding(code, null );
overrideFileDownloadAction( getComponent( 'fileDownload1' ) );
I use this in order to save some info together with the file (i.e i have a drop down to select the type of file that i upload). So i want this info to be deleted and added together with the uploaded file.
I found the code above by googling and it works normally.
Now i installed Notes 9 and i want to test my app for potential issues.
I get this error:
com.ibm.xsp.actions.ActionGroup incompatible with
com.ibm.xsp.actions.DeleteAttachmentsAction
when switching a document to edit mode.
Does anyone have the same problem? Any solutions?
Related
I am new to Three.js (3D) and have a simple question. I have the following code that will work properly, but I think the result lost their colors because I open the test.obj file whith 3D Buidler(WIN10), there are lots of colors on ther surface of model. why?
The Code
var loader = new THREE.OBJLoader()
loader.load( 'test.obj', function ( object ) {
object.position.y = 0;
scene.add( object );
} );
I think it's vertex color, How to show it's vertex color?
var loader = new THREE.OBJLoader2()
loader.load( 'test.obj', function ( object ) {
object.position.y = 0;
scene.add( object );
} );
I have tryed OBJLoader2.js , but it doesn't work, need some settings?
The result loaded by Three.js:
The result loaded by 3D Builder:
The obj file
use the .mtl file along with the .obj file.
var onProgress = function ( xhr ) {
if ( xhr.lengthComputable ) {
var percentComplete = xhr.loaded / xhr.total * 100;
console.log( Math.round(percentComplete, 2) + '% downloaded' );
}
};
var onError = function ( xhr ) { };
THREE.Loader.Handlers.add( /\.dds$/i, new THREE.DDSLoader() );
//Car model
var mtlLoader = new THREE.MTLLoader();
mtlLoader.setPath( '../materials/car/' );
mtlLoader.load( 'car.mtl', function( materials ) {
materials.preload();
var objLoader = new THREE.OBJLoader();
objLoader.setMaterials( materials );
objLoader.setPath( '../materials/car/' );
objLoader.load( 'car.obj', carObject, onProgress, onError );
});
function carObject(object){
object.rotation.y = 1.55;
object.position.z = 105;
object.position.y = 1.15;
object.scale.x = object.scale.y = object.scale.z = 0.15;
//object.rotation.x = 6.5;
//object.position.z = 50;
scene.add( object );
}
//end car model
Finally I found it out :
I changed OBJLoader2.js's version to 1.3.0.
My goal is to stream a large response to the browser. I need to minimise the memory use of the XPage so that multiple hits don't bring the server down.
The XPages are set up "XAgent" style with rendering=false.
Has anyone got this working?
Attempt 1
According to various HttpServletResponse posts it should be as simple as flushing the writer as you proceed but that wasn't the case. The code below includes a commented section called Experiment1 that I used to deliberately break the response. My logic being that the resetBuffer call should not impact the content I've already "flushed" - but it did. The broken response only included the error message and none of the chunks.There's a good chance that my assumption is wrong of course.The code ran in the afterRenderResponse event.
importPackage(java.util);
importPackage(java.io);
importPackage(java.lang);
var ec=facesContext.getExternalContext();
var response=ec.getResponse();
var request=ec.getRequest();
var writer=facesContext.getResponseWriter();
try{
response.setHeader("Content-Type","text/plain; charset=utf-8");
for(var i=0;i<100;i++){
var s="CHUNKCHUNKCHUNK"+i;
writer.write(s);
writer.flush();
response.flushBuffer();
//EXPERIMENT1
//if(i==50){
//throw new Error("FAIL ON PURPOSE")
//}
}
}catch(e){
//EXPERIMENT1
//response.resetBuffer()
var errorObj={};
response.setStatus(500);
var errorMessage = e.message;
if( typeof e.printStackTrace !== 'undefined' ){
var stringWriter = new java.io.StringWriter();
e.printStackTrace( new java.io.PrintWriter( stringWriter ) );
errorMessage = stringWriter.toString();
}
if( typeof e === 'com.ibm.jscript.InterpretException' ){
errorMessage = e.getNode().getTraceString() + '\n\n' + errorMessage;
}
errorObj.status="error";
errorObj.message=errorMessage;
writer.write(toJson(errorObj));
}finally{
if(creport!=null){
if(debug){
creport.close(true);
}else{
creport.closeOnlyIfIssue(true);
}
}
facesContext.responseComplete();
}
Attempt 2
My second attempt was pure desperation. It uses the beforeRenderResponse event and writes the chunks according to the HTML1.1 spec. The code below shows the "Transfer-Encoding" header commented out because it results in a zero byte payload. The headers make it though..
importPackage(java.util);
importPackage(java.io);
importPackage(java.lang)
var ec=facesContext.getExternalContext();
var response=ec.getResponse();
var request=ec.getRequest();
var writer=response.getOutputStream();
try{
response.setHeader("Content-Type","text/plain; charset=utf-8");
//response.setHeader("Transfer-Encoding","chunked")
response.setBufferSize(1024);
for(var i=0;i<100;i++){
var s="CHUNKCHUNKCHUNK"+i;
writer.write((Integer.toHexString(s.length())+"\r\n").getBytes("utf-8"));
writer.write((s+"\r\n").getBytes("utf-8"));
writer.flush();
response.flushBuffer();
}
writer.write("0\r\n\r\n".getBytes("utf-8"))
}catch(e){
var errorObj={};
//response.resetBuffer();
response.setStatus(500);
var errorMessage = e.message;
if( typeof e.printStackTrace !== 'undefined' ){
var stringWriter = new java.io.StringWriter();
e.printStackTrace( new java.io.PrintWriter( stringWriter ) );
errorMessage = stringWriter.toString();
}
if( typeof e === 'com.ibm.jscript.InterpretException' ){
errorMessage = e.getNode().getTraceString() + '\n\n' + errorMessage;
}
errorObj.status="error";
errorObj.message=errorMessage;
writer.write(toJson(errorObj).getBytes("utf-8"));
}finally{
facesContext.responseComplete();
}
When accessing the response with
var response=ec.getResponse()
you are getting an instance of com.ibm.xsp.webapp.XspHttpServletResponse. It uses internally a buffer/block-mechanism for a better performance, that's why your first experiment does not work as expected.
But if you access the underlying LCDAdapterHttpServletResponse directly, it is possible to get the full control for the outputstream:
var response=ec.getResponse().getDelegate();
importPackage(java.util);
importPackage(java.io);
importPackage(java.lang);
importPackage(imtk);
var ec=facesContext.getExternalContext();
var response=ec.getResponse().getDelegate();
var request=ec.getRequest();
var writer=response.getWriter();
try{
response.setHeader("Content-Type","application/json; charset=utf-8");
response.setHeader("Transfer-Encoding","chunked");
response.flushBuffer();
for(var i=0;i<100;i++){
var s="CHUNK"+i;
writer.println(Integer.toHexString(s.length()));
writer.println(s);
writer.flush();
}
writer.print("0\r\n");
writer.print("\r\n");
writer.flush();
}catch(e){
var errorObj={};
response.setStatus(500);
var errorMessage = e.message;
if( typeof e.printStackTrace !== 'undefined' ){
var stringWriter = new java.io.StringWriter();
e.printStackTrace( new java.io.PrintWriter( stringWriter ) );
errorMessage = stringWriter.toString();
}
if( typeof e === 'com.ibm.jscript.InterpretException' ){
errorMessage = e.getNode().getTraceString() + '\n\n' + errorMessage;
}
errorObj.status="error";
errorObj.message=errorMessage;
var json=toJson(errorObj);
writer.println(Integer.toHexString(json.length()))
writer.println(json);
writer.flush();
writer.print("0\r\n");
writer.print("\r\n");
writer.flush();
}finally{
if(creport!=null){
if(debug){
creport.close(true);
}else{
creport.closeOnlyIfIssue(true);
}
}
facesContext.responseComplete();
}
I am using MFC MDI application and i am adding two doc templates as shown in code below:
BOOL CEmuDiagnosticsClientApp::InitInstance()
{
INITCOMMONCONTROLSEX InitCtrls;
InitCtrls.dwSize = sizeof(InitCtrls);
// Set this to include all the common control classes you want to use
// in your application.
InitCtrls.dwICC = ICC_WIN95_CLASSES;
InitCommonControlsEx(&InitCtrls);
CWinAppEx::InitInstance();
// Initialize OLE libraries
if (!AfxOleInit())
{
AfxMessageBox(IDP_OLE_INIT_FAILED);
return FALSE;
}
AfxEnableControlContainer();
//Added new code
CMultiDocTemplate* pDocTemplate;
pDocTemplate = new CMultiDocTemplate(IDR_STRING_FILTERWINDOW,
RUNTIME_CLASS(CEmuDiagnosticsClientDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CFilterWindow));
if (!pDocTemplate)
return FALSE;
AddDocTemplate(pDocTemplate);
SetRegistryKey(_T("Local AppWizard-Generated Applications"));
LoadStdProfileSettings(4); // Load standard INI file options (including MRU)
InitContextMenuManager();
InitKeyboardManager();
InitTooltipManager();
CMFCToolTipInfo ttParams;
ttParams.m_bVislManagerTheme = TRUE;
theApp.GetTooltipManager()->SetTooltipParams(AFX_TOOLTIP_TYPE_ALL,
RUNTIME_CLASS(CMFCToolTipCtrl), &ttParams);
AddDocTemplate(new CMultiDocTemplate(IDR_STRING_SIGNALWINDOW,
RUNTIME_CLASS(CEmuDiagnosticsClientDoc),
RUNTIME_CLASS(CChildFrame), // custom MDI child frame
RUNTIME_CLASS(CSignalWindow)));
// create main MDI Frame window
CMainFrame* pMainFrame = new CMainFrame;
if (!pMainFrame || !pMainFrame->LoadFrame(IDR_MAINFRAME))
{
delete pMainFrame;
return FALSE;
}
m_pMainWnd = pMainFrame;
// Parse command line for standard shell commands, DDE, file open
CCommandLineInfo cmdInfo;
ParseCommandLine(cmdInfo);
// Dispatch commands specified on the command line. Will return FALSE if
// app was launched with /RegServer, /Register, /Unregserver or /Unregister.
if (!ProcessShellCommand(cmdInfo))
return FALSE;
// The main window has been initialized, so show and update it
pMainFrame->ShowWindow(m_nCmdShow);
pMainFrame->UpdateWindow();
return TRUE;
}
I am using this code to iterate over documents and get view classes's reference in my CMainFrame class.
CFilterWindow* p = NULL;
CSignalWindow* p1 = NULL;
for( POSITION pos = AfxGetApp()->GetFirstDocTemplatePosition(); pos != NULL; )
{
CDocTemplate* pTempl = AfxGetApp()->GetNextDocTemplate( pos );
for( POSITION pos1 = pTempl->GetFirstDocPosition(); pos!= NULL; )
{
CDocument* pDoc = pTempl->GetNextDoc( pos1 );
for( POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
{
CView* pView = pDoc->GetNextView( pos2 );
if( pView->IsKindOf( RUNTIME_CLASS(CFilterWindow) ) )
{
p = (CFilterWindow*)pView;
p->UpdateUI();
// Do what you need with the view...
}
else
{
p1 = (CSignalWindow*)pView;
p1->UpdateUI();
}
}
}
}
Problem is with loop for( POSITION pos2 = pDoc->GetFirstViewPosition(); pos2 != NULL; )
as pDoc->GetFirstViewPosition(); always returning NULL.
It is puzzling me why it is returning NULL.
Can anybody suggest where I am wrong?
I have a list named "Discussions List". I want to bring all columns from the list.
I want to know how to do it SharePoint Client Object Model.
OK. Found the solution. Answer Here using a list I'm getting by title, but will work with any method:
// Get your ClientContext for your site in 'clientContext'
SP.List oList = clientContext.Web.Lists.GetByTitle("List Title Here");
SP.FieldCollection fieldColl = oList.Fields;
clientContext.Load(fieldColl);
clientContext.ExecuteQuery();
foreach (SP.Field fieldTemp in fieldColl)
{
MessageBox.Show(fieldTemp.InternalName.ToString()); //I used MessageBox to show, but you can do whatever you like with it here.
}
Bingo. You're going to love this. Thank goodness for generics and Linq!
// return all rows and (selected) fields of a list--fields are included dynamically
private Dictionary<string,Dictionary<string,object>> getListData( ClientContext ctx )
{
Log.LogMessage( "Fetching {0}{1}", ctx.Url, ListName );
var list = ctx.Web.Lists.GetByTitle( ListName );
// fetch the fields from this list
FieldCollection fields = list.Fields;
ctx.Load( fields );
ctx.ExecuteQuery();
// dynamically build a list of fields to get from this list
var columns = new List<string> { "ID" }; // always include the ID field
foreach( var f in fields )
{
// Log.LogMessage( "\t\t{0}: {1} of type {2}", f.Title, f.InternalName, f.FieldTypeKind );
if( f.InternalName.StartsWith( "_" ) || f.InternalName.StartsWith( "ows" ) ) continue; // skip these
if( f.FieldTypeKind == FieldType.Text ) // get Text fields only... but you can get other types too by uncommenting below
// || f.FieldTypeKind == FieldType.Counter
// || f.FieldTypeKind == FieldType.User
// || f.FieldTypeKind == FieldType.Integer
// || f.FieldTypeKind == FieldType.Number
// || f.FieldTypeKind == FieldType.DateTime
// || f.FieldTypeKind == FieldType.Lookup
// || f.FieldTypeKind == FieldType.Computed
// || f.FieldTypeKind == FieldType.Boolean )
{
columns.Add( f.InternalName );
}
}
// build the include expression of which fields to fetch
List<Expression<Func<ListItemCollection, object>>> allIncludes = new List<Expression<Func<ListItemCollection, object>>>();
foreach( var c in columns )
{
// Log.LogMessage( "Fetching column {0}", c );
allIncludes.Add( items => items.Include( item => item[ c ] ) );
}
// get all the items in the list with the fields
ListItemCollection listItems = list.GetItems( CamlQuery.CreateAllItemsQuery() );
ctx.Load( listItems, allIncludes.ToArray() );
ctx.ExecuteQuery();
var sd = listItems.ToDictionary( k => k["Title"] as string, v => v.FieldValues ); // FieldValues is a Dictionary<string,object>
// show the fields
foreach( var i in sd.Keys )
{
Log.LogMessage( "\tItem: {0}", i );
foreach( var c in columns )
{
Log.LogMessage( "\t\t{0}: {1}", c, sd[ i ][ c ] );
}
}
return sd;
}
Do you guys see any issues with this C# code? It gets email notifications from gmail and then prints to CMD how many unread mails are waiting:
Unread Mails: 10
Unread Mails: 10
and then sends how many mails over serial too. But after it says "unread mails:" twice i get:
Operation Timed Out.
Unread Mails: 0
and it repeats.
Iv'e tried this on different computers and ISPs so its definitely something in the code.
The C# program. I also have tried changing the Thread.Sleep value so that it takes longer before it does it again, but still doesn't work.
Thanks!
public static void Main(string[] args)
{
try
{
SerialPort port = new SerialPort( "COM1", 9600, Parity.None, 8, StopBits.One );
port.Open();
string Unreadz = "0";
while ( true )
{
Unreadz = CheckMail();
Console.WriteLine("Unread Mails: " + Unreadz);
if (Convert.ToInt32(Unreadz) < 10) port.Write("0" + Unreadz);
else port.Write("" + Unreadz);
System.Threading.Thread.Sleep( 10000 );
}
} catch ( Exception ee ) { Console.WriteLine( ee.Message ); }
}
public static string TextToBase64( string sAscii )
{
System.Text.ASCIIEncoding encoding = new System.Text.ASCIIEncoding();
byte[] bytes = encoding.GetBytes( sAscii );
return System.Convert.ToBase64String( bytes, 0, bytes.Length );
}
public static string CheckMail()
{
string result = "0";
try
{
var url = #"https://gmail.google.com/gmail/feed/atom";
var USER = "USER";
var PASS = "PASS";
var encoded = TextToBase64( USER + ":" + PASS );
var myWebRequest = HttpWebRequest.Create( url );
myWebRequest.Method = "POST";
myWebRequest.ContentLength = 0;
myWebRequest.Headers.Add( "Authorization", "Basic " + encoded );
var response = myWebRequest.GetResponse();
var stream = response.GetResponseStream();
XmlReader reader = XmlReader.Create( stream );
while ( reader.Read())
if ( reader.NodeType == XmlNodeType.Element )
if ( reader.Name == "fullcount" )
{
result = reader.ReadElementContentAsString();
return result;
}
} catch ( Exception ee ) { Console.WriteLine( ee.Message ); }
return result;
}
}
}
well i seemed to fix it. since i was just looping it every 10 seconds for testing, i put it to 5 minutes. 5 minutes is more realistic for my needs.