// // Copyright 2003 Perforce Software. All rights reserved. // // This file is part of Perforce - the FAST SCM System. // // p4wReadLocalPane: // Displays the file text of the client file on local workspace #include <p4wp4.h> #include "p4wStrBuf.h" #include "p4wHtml.h" #include "p4wPane.h" #include "p4wReadLocalPane.h" #include "p4wMimeContentPane.h" p4wReadLocalPane::p4wReadLocalPane( p4wView & ParentView, p4wRequest & Request ) : p4wPane( ParentView, Request ), fSeenData(0), linecounter(1) { const StrPtr *lno = fRequest.GetStateArg( "lno" ); bShowLineNo = ( lno && *lno == "y" ) ? 1 : 0; } p4wReadLocalPane::~p4wReadLocalPane() { } // ------------------------------------- // Render functions. // void p4wReadLocalPane::Begin() { // // Begin the pane. p4wHtml htm; htm.comment( "BEGIN READ LOCAL PANE" ); fSeenOutputStat = 1; fRequest << htm; } void p4wReadLocalPane::Render( StrDict * varList ) { if( varList->GetVar( "clientFile" ) == NULL ) return; RenderFileContents(varList->GetVar( "clientFile" ), varList->GetVar( "headType" )); } void p4wReadLocalPane::RenderFileContents(StrPtr *clientFile, StrPtr *headType) { Error e; StrBuf data; CharSetCvt *cvt; CharSetCvt::CharSet cs; FileSys *f; // // If this is a utf16 filetype, we need to use // the correct type to translate it to utf8 if (headType && !strcmp(headType->Text(), "utf16")) { f = FileSys::Create( FST_UTF16 ); // // If we are in unicode mode, we need to translate // file to UTF-8 so that it is displayed correctly } else if( Unicode() ) { f = FileSys::Create( FST_UNICODE ); cs = CharSetCvt::Lookup( fRequest.GetClientApi().GetCharset().Text() ); cvt = CharSetCvt::FindCvt( cs, CharSetCvt::UTF_8 ); f->Translator( cvt ); } else { f = FileSys::Create( FST_TEXT ); } f->Set( *clientFile ); f->Open( FOM_READ, &e ); if(!e.Test()) f->ReadWhole( &data, &e ); if(!e.Test()) f->Close( &e ); delete f; if( Unicode() ) delete cvt; if( !e.Test() && data.Length() ) { if( !fSeenData ) { fSeenData = 1; p4wHtml htm; p4wURL urlMaker; StrBuf clearIcon; urlMaker.ConstructURL( clearIcon, "/clearpixelIcon", AC_ICON, NULL ); htm.beginTRow(); htm.beginCol(); htm.icon( clearIcon.Text(), "10", "10", "", 1 ); htm.linebreak(); htm.icon( clearIcon.Text(), "1", "10", "", 1 ); htm.beginSpan("fSmaller"); AllCommands ac = fRequest.GetCmd(); StrBuf path; path.Set( fRequest.GetReturnURL( ac ).Text() ); StrBuf base; StrBuf url; StrBuf dyn; StrBufDict args; if (!bShowLineNo) { fRequest.UseNewBase( base, NULL, "lno", "y" ); fRequest.UseNewBase( base, base.Text(), "path", path.Text() ); urlMaker.ConstructURL( url, base.Text(), ac, &args, fRequest.GetUnicode() ); dyn.Set(fRequest.GetDynURL()); char *p = strchr(dyn.Text(), '&'); if (p) url << p; htm.beginLink(url.Text()); htm << "Show line numbers"; htm.endLink(); // htm.text(" or Hover your mouse over a line to see its line number."); } else { fRequest.UseNewBase( base, NULL, "lno", NULL ); fRequest.UseNewBase( base, base.Text(), "path", path.Text() ); urlMaker.ConstructURL( url, base.Text(), ac, &args, fRequest.GetUnicode() ); dyn.Set(fRequest.GetDynURL()); char *p = strchr(dyn.Text(), '&'); if (p) url << p; htm.beginLink(url.Text()); htm << "Hide line numbers"; htm.endLink(); } htm.endSpan(); htm.endCol(); htm.endTRow(); htm.beginTRow(); htm.beginCol(); htm.beginTable( "0", "100%", "8", "1", "#7F7F7F" ); htm.beginTRow( NULL, NULL, "#FFFFFF" ); htm.beginCol(); htm.beginTable( "0", NULL, bShowLineNo ? "0" : "2", "0", "#FFFFFF" ); htm.beginTRow(); htm.beginCol(0,0,0,0,0,0,0,0,"pre"); htm.beginUnformatted(0, "code"); if (bShowLineNo) { htm << " 1.\t"; htm << "<a name=\"1\">"; } else htm << "<a name=\"1\" title=\"ln:1\">"; fRequest << htm; } if( !PageLimitExceeded() ) { StrBuf buf; buf.Set(p4wStrBuf().EscapeHTML( StrRef(data), Unicode() )); char *p = buf.Text(); char *q = p + buf.Length(); while (p < q) { if (*p == '\n') fRequest << "</a>"; fRequest << *p; if (*p++ == '\n') { char buf2[128]; ++linecounter; if (p < q) { if (bShowLineNo) { sprintf(buf2, "%5d.\t", linecounter); fRequest << buf2; sprintf(buf2, "<a name=\"%d\">", linecounter); } else sprintf(buf2, "<a name=\"%d\" title=\"ln:%d\">", linecounter, linecounter); fRequest << buf2; } } } } } } void p4wReadLocalPane::End() { // // End the pane. p4wHtml htm; if( fSeenData ) { htm << "</a><a name=\"end\"></a>"; htm.endUnformatted(); htm.endCol(); htm.endTRow(); htm.endTable(); htm.endCol(); htm.endTRow(); htm.endTable(); } else { htm.beginTRow(); htm.beginCol(); htm.text( " File not found, or file is empty." ); htm.endCol(); htm.endTRow(); } htm.comment( "END READ LOCAL PANE" ); fRequest << htm; } void p4wReadLocalPane::HandleError(Error *err) { // // Generate a ::Begin() call if necessary. if( !fSeenOutputStat ) { Begin(); fSeenOutputStat = 1; } StrBuf errMsg; err->Fmt(&errMsg); if (strstr(errMsg.Text(), " - no such file(s).")) { StrBuf root; root.Set(fRequest.GetClientRoot()); if (root.Length()) { #ifdef OS_NT char slash = '\\'; #else char slash = '/'; #endif if (!strncmp(root.Text(), fRequest.GetPath().Text(), root.Length()) && !strstr(fRequest.GetPath().Text(), "..") && *(fRequest.GetPath().Text() + root.Length()) == slash) { StrPtr clientFile; clientFile = fRequest.GetPath(); RenderFileContents(&clientFile, NULL); return; } } } // // Default error processing: output all errors without // special filtering any out DoHandleError( err, 0 ); }
# | Change | User | Description | Committed | |
---|---|---|---|---|---|
#1 | 12234 | Matt Attaway |
Rejigger P4Web project in preparation for official sunsetting The bin directory contains the last official builds of P4Web from the Perforce download site. P4Web is soon to be completely sunsetted; these builds are here for folks who don't want to build their own. To better handle the archived builds the source code has been moved into a separate src directory. |
||
//guest/perforce_software/p4web/Panes/p4wReadLocalPane.cpp | |||||
#1 | 8914 | Matt Attaway | Initial add of the P4Web source code |