Dear All, Please see below code. It compiled and plugin is getting created. Since I am not having Debug version of InDesign CS4. So, I am not anle to get the problematic area. Please look into it and provide me the what dignosis I have to do.
#include "VCPlugInHeaders.h"
// Interface includes:
#include "ISignalMgr.h"
#include "IDocumentSignalData.h"
#include "INewStorySignalData.h"
#include "IUIDData.h"
#include "IObserver.h"
#include "IDocumentList.h"
#include "IApplication.h"
#include "IControlView.h"
#include "IActiveContext.h"
#include "IStoryList.h"
#include "ICommand.h"
#include <ILayoutUIUtils.h>
//#include "ISnpRunnableContext.h"
// General includes:
#include "CResponder.h"
#include "Utils.h"
#include "TextID.h"
#include "UIDList.h"
// Implementation includes:
//#include "SDKListBoxHelper.h"
#include "EntityID.h"
//#include "IBNotesUtils.h"
class CEntityRes : public CResponder
{
public:
/**
Constructor.
@param boss interface ptr from boss object on which this interface is aggregated.
*/
CEntityRes(IPMUnknown* boss);
/**
Handles the file action signals dispatched by the signal manager.
This implementation simply creates alerts to display each signal.
@param signalMgr Pointer back to the signal manager to get
additional information about the signal.
*/
virtual void Respond(ISignalMgr* signalMgr);
};
/* CREATE_PMINTERFACE
Binds the C++ implementation class onto its ImplementationID
making the C++ code callable by the application.
*/
CREATE_PMINTERFACE(CEntityRes, kCEntityResImpl)
/* Constructor
*/
CEntityRes::CEntityRes(IPMUnknown* boss) :
CResponder(boss)
{
}
/* Respond
*/
void CEntityRes::Respond(ISignalMgr* signalMgr)
{
do
{
ServiceID serviceTrigger = signalMgr->GetServiceID();
switch (serviceTrigger.Get())
{
case kAfterOpenDocSignalResponderService:
{
InterfacePtr<IDocumentSignalData> data(signalMgr, UseDefaultIID());
if (data == nil)
{
break;
}
InterfacePtr<IDocument> doc(data->GetDocument(), UseDefaultIID());
if (doc == nil)
{
break;
}
InterfacePtr<IStoryList> storyList(doc, IID_ISTORYLIST);
for(int32 i=0; i< storyList->GetUserAccessibleStoryCount(); i++)
{
UIDRef storyRef(storyList->GetNthUserAccessibleStoryUID(i));
InterfacePtr<IObserver>
bnStoryObserver(storyRef, IID_ICEntity);
bnStoryObserver->AutoAttach();
}
break;
}
case kBeforeCloseDocSignalResponderService:
{
InterfacePtr<IDocumentSignalData> data(signalMgr, UseDefaultIID());
if (data == nil)
{
break;
}
InterfacePtr<IDocument> doc(data->GetDocument(), UseDefaultIID());
if (doc == nil)
{
break;
}
InterfacePtr<IStoryList> storyList(doc, IID_ISTORYLIST);
for(int32 i=0; i< storyList->GetUserAccessibleStoryCount(); i++)
{
InterfacePtr<IObserver>
bnStoryObserver(storyList->GetNthUserAccessibleStoryUID(i), IID_ICEntity);
bnStoryObserver->AutoDetach();
}
break;
}
case kAfterCloseDocSignalResponderService:
{
UIDList delStoryList(nil, kInvalidUID);
IDocument* nodoc = nil;
TextIndex noteAnchorPos = 0;
break;
}
case kNewStorySignalResponderService:
{
InterfacePtr<INewStorySignalData> data(signalMgr, UseDefaultIID());
if (data == nil)
{
break;
}
UIDRef storyRef(data->GetTextModel());
InterfacePtr<IObserver> bnStoryObserver(storyRef, IID_ICEntity);
bnStoryObserver->AutoAttach();
break;
}
case kDeleteStoryRespService:
{
InterfacePtr<ICommand> deleteStoryCmd(signalMgr, UseDefaultIID());
if (deleteStoryCmd == nil)
{
break;
}
const UIDList* itemList = deleteStoryCmd->GetItemList();
InterfacePtr<IObserver>
bnStoryObserver(itemList->GetDataBase(), itemList->First(), IID_ICEntity);
bnStoryObserver->AutoDetach();
//IActiveContext* ac = gSession->GetActiveContext();
//IDocument* doc = ac->GetContextDocument();
IActiveContext* ac = GetExecutionContextSession()->GetActiveContext();
IDocument* doc = ac->GetContextDocument();
//InterfacePtr<IApplication> app(GetExecutionContextSession()->QueryApplication());
//IDocument* doc = Utils<ILayoutUIUtils>()->GetFrontDocument(); //app->GetFrontDocument();
TextIndex noteAnchorPos = 0;
break;
}
default:
break;
}
} while(kFalse);
}
// End, CEntityRes.cpp.
-------------------------------------------
#include "VCPlugInHeaders.h"
// Interface includes:
#include "ISubject.h"
#include "IControlView.h"
#include "IDataBase.h"
#include "IDocument.h"
#include "INoteUIUtils.h"
#include "ITextModelCmds.h"
#include "ITextStoryThreadDict.h"
#include "INoteSuiteUtils.h"
#include "ISelectionUtils.h"
#include "ITextSelectionSuite.h"
#include "ITextAttributeSuite.h"
#include "IStyleInfo.h"
#include "IStyleNameTable.h"
#include "ITextTarget.h"
#include "IXMLReferenceData.h"
#include "IXMLStyleToTagMap.h"
#include "IXMLTag.h"
#include "IXMLTagCommands.h"
#include "IXMLElementCommands.h"
#include "IXMLTagList.h"
#include "IXMLTagToStyleMap.h"
#include "IXMLUtils.h"
#include "IXMLReferenceData.h"
#include "IXMLAttributeCommands.h"
#include "IIDXMLElement.h"
#include "IStyleGroupManager.h"
// General includes:
#include "NoteID.h"
#include "TextID.h"
#include "InCopySharedID.h"
#include "CObserver.h"
#include "Utils.h"
#include "InCopyCoreID.h"
#include "UIDList.h"
#include "CAlert.h"
#include "TextIterator.h"
//#include "ITextHyperlinkOwnedItemData.h"
#include "ITextFocus.h"
// Project includes:
//#include "SDKListBoxHelper.h"
#include "EntityID.h"
//#include "IBNotesUtils.h"
#include "IComposeScanner.h"
#include "IDrawingStyle.h"
#include "IFontFamily.h"
#include "FileUtils.h"
#include "PMString.h"
//#include "SnpInsertGlyph.cpp"
# include <string.h>
# include <stdio.h>
# include <tchar.h>
#include <atlbase.h>
#import "msxml4.dll"
using namespace MSXML2;
# define MAXLEN 250
# define APPLYCHAR_SIZE 50
# define INSCHAR_SIZE 25
inline void TESTHR( HRESULT _hr )
{ if FAILED(_hr) throw(_hr); }
typedef struct tagENTITYINSCHAR
{
int CharCode;
char CStyle[MAXLEN];
}ENTITYINSCHAR, *LPENTITYINSCHAR;
typedef struct tagAPPLYCHAR
{
char FontFamily[MAXLEN];
char FontStyle[MAXLEN];
char CStyle[MAXLEN];
int InsCharLength;
ENTITYINSCHAR insChar[INSCHAR_SIZE];
public:
tagAPPLYCHAR()
{
FontFamily[0]='\0';
FontStyle[0]='\0';
CStyle[0]='\0';
InsCharLength=0;
}
void Clear()
{
strcpy(FontFamily,"");
strcpy(FontStyle,"");
strcpy(CStyle,"");
for (int i=0; i <INSCHAR_SIZE; i++)
{
insChar[i].CharCode = -1;
strcpy(insChar[i].CStyle,"");
}
}
}APPLYCHAR, *LPAPPLYCHAR;
class CEntity : public CObserver
{
private:
LPAPPLYCHAR lpacPre;
LPAPPLYCHAR lpacPost;
char *EntityPath;
public:
/**
Constructor.
@param boss interface ptr from boss object on which interface is aggregated.
*/
CEntity(IPMUnknown* boss);
/**
Destructor.
*/
~CEntity() {};
virtual void AutoAttach();
virtual void AutoDetach();
virtual void Update(
const ClassID& theChange,
ISubject* theSubject,
const PMIID& protocol,
void* changedBy);
PMString GetCharacter ( UTF32TextChar character );
int FindEntityPos(char *String, char *EnityName, int *pLength);
int GetStyleName(char *EntityName, char *cStyle, char *Unicode, int *CharCode, char *ffamily, char *fstyle);
LPAPPLYCHAR FillApplyChar(MSXML2::IXMLDOMNodePtr NodePtr, char *EntityName, char *fontFamily, char *fStyle, char *type);
char *ConstructXPath( char *EntityName, char *fontFamily, char *fStyle, char *);
UIDRef CEntity::AcquireTag(const UIDRef& documentUIDRef,
const PMString& tagName
);
ErrorCode CEntity::TagTextRange(const UIDRef& storyUIDRef,
const PMString& tagName,
const PMString attName,
const PMString attValue,
TextIndex startIndex,
TextIndex endIndex);
PMString CEntity::AsString(const XMLReference& xmlReference);
};
CREATE_PMINTERFACE(CEntity, kCEntityImpl)
/* Constructor
*/
CEntity::CEntity(IPMUnknown* boss)
: CObserver(boss)
{
EntityPath = new char[256];
PMString path("");
FileUtils::GetAppFolder(&path);
path.Append("\\Config\\Entity.xml");
strcpy(EntityPath,path.GrabCString());
}
/* AutoAttach
*/
void CEntity::AutoAttach()
{
do
{
InterfacePtr<ISubject> subject(this, IID_ISUBJECT);
if (subject != nil)
{
if (subject->IsAttached(this, IID_ITEXTMODEL, IID_ICEntity) == kFalse)
{
subject->AttachObserver(this, IID_ITEXTMODEL, IID_ICEntity);
}
}
} while(kFalse);
}
/* AutoDetach
*/
void CEntity::AutoDetach()
{
do
{
InterfacePtr<ISubject> subject(this, UseDefaultIID());
if (subject != nil)
{
if (subject->IsAttached(this, IID_ITEXTMODEL, IID_ICEntity) == kTrue)
{
subject->DetachObserver(this, IID_ITEXTMODEL, IID_ICEntity);
}
}
} while(kFalse);
}
/* Update
*/
void CEntity::Update(
const ClassID& theChange,
ISubject* theSubject,
const PMIID& protocol,
void* changedBy)
{
ErrorCode result = kFailure;
if (protocol == IID_ITEXTMODEL)
{
if (theChange.Get() == kDeleteTextCmdBoss ||
theChange.Get() == kInsertTextCmdBoss ||
theChange.Get() == kReplaceTextCmdBoss ||
theChange.Get() == kMultiReplaceTextCmdBoss ||
theChange.Get() == kTransposeCmdBoss ||
theChange.Get() == kTransposeHelperCmdBoss)
{
TextIndex focusStart = kInvalidTextIndex;
TextIndex acFocusStart = kInvalidTextIndex;
TextIndex focusEnd = kInvalidTextIndex;
UIDRef storyRef(nil, kInvalidUID);
Utils<INoteUIUtils>()->GetCurrentTextSelection_(
focusStart, focusEnd, &storyRef);
if(storyRef.GetUID() == kInvalidUID)
return;
InterfacePtr<ITextModel> textModel(storyRef, UseDefaultIID());
InterfacePtr<ITextModelCmds> textModelCmds(textModel, UseDefaultIID());
// kFalse means take ownership of the string
K2::shared_ptr<WideString> tempText (new WideString(""));
UTF32TextChar ch(65);
tempText->Append(ch);
if (focusStart > 15 )
{
focusStart -= 15;
}
else
{
focusStart = 0;
}
TextIterator begin(textModel, focusStart);
TextIterator end(textModel, focusEnd+15);
PMString str("");
for (TextIterator iter = begin; iter != end; iter++)
{
const UTF32TextChar characterCode = *iter;
PMString character;
character.AppendW(characterCode);
TextIndex position = iter.Position();
if (strlen(character.GrabCString()) > 2)
str.Append(" ");
else
str.Append(character.GrabCString());
}
bool bConvertEntity = false;
WideString glyph("");
int EntityLen=0;
char *EntityName = new char[120];
char *StyleName = new char[50];
char *UniCode = new char[50];
char *ffamily = new char[MAXLEN];
char *fstyle = new char[MAXLEN];
int chCode = -1;
//Modified on 11-Aug-09
char* string = (char *)str.GrabCString();
//Below line commented on 11-Aug-09
//int EntityPos = FindEntityPos(str.GrabCString(),EntityName,&EntityLen);
int EntityPos = FindEntityPos(string ,EntityName,&EntityLen);
InterfacePtr<IComposeScanner> scanner(textModel, UseDefaultIID());
IDrawingStyle* style = scanner->GetCompleteStyleAt(focusStart);
InterfacePtr<IPMFont> font(style->QueryFont());
PMString fontName;
font->AppendFamilyName(fontName);
strcpy(ffamily,fontName.GrabCString());
strcpy(fstyle,style->GetFontStyleName().GrabCString());
int RetCode = GetStyleName(EntityName,StyleName,UniCode,&chCode, ffamily,fstyle);
if (EntityPos != -1)
{
if (chCode !=-1)
{
//textModel->Delete(kTrue, focusStart + EntityPos -1, EntityLen);
textModel->Delete(focusStart + EntityPos -1, EntityLen);
UTF32TextChar ch(chCode);
glyph.Append(ch);
bConvertEntity = true;
}
}
if (bConvertEntity == true)
{
IDataBase* db = ::GetDataBase(theSubject);
InterfacePtr<IDocument> doc(db, db->GetRootUID(), UseDefaultIID());
InterfacePtr<IStyleGroupManager> charNameTable(doc->GetDocWorkSpace(), IID_ICHARSTYLEGROUPMANAGER);
if (charNameTable == nil)
{
return;
}
if (RetCode == 1 || RetCode == 0)
{
int TagChCount=0;
acFocusStart = focusStart;
if(lpacPre)
{
if (strcmp(lpacPre->CStyle,"")!=0)
{
strcpy(StyleName,lpacPre->CStyle);
}
}
if (lpacPre)
{
for(int i=0; i < lpacPre->InsCharLength;i++)
{
WideString ins("");
UTF32TextChar ch(lpacPre->insChar[i].CharCode);
if (ch==nil) continue;
ins.Append(ch);
Utils<INoteUIUtils>()->GetCurrentTextSelection_(
focusStart, focusEnd, &storyRef);
textModel->Insert(focusStart,&ins);
TagChCount++;
UID csUID = charNameTable->FindByName(lpacPre->insChar[i].CStyle);
}
}
Utils<INoteUIUtils>()->GetCurrentTextSelection_(
focusStart, focusEnd, &storyRef);
textModel->Insert(focusStart,&glyph);
TagChCount++;
UID csUID = charNameTable->FindByName(StyleName);
if (csUID != nil)
{
}
if (lpacPost)
{
for(int i=0; i < lpacPost->InsCharLength;i++)
{
WideString ins("");
UTF32TextChar ch(lpacPost->insChar[i].CharCode);
if (ch==nil) continue;
ins.Append(ch);
Utils<INoteUIUtils>()->GetCurrentTextSelection_(
focusStart, focusEnd, &storyRef);
textModel->Insert(focusStart,&ins);
TagChCount++;
UID csUID = charNameTable->FindByName(lpacPre->insChar[i].CStyle);
if (csUID != nil)
{
}
}
}
int focusCount = 0;
if (lpacPre)
{
for(int i=0; i < lpacPre->InsCharLength;i++)
{
WideString ins("");
UTF32TextChar ch(lpacPre->insChar[i].CharCode);
if (ch==nil) continue;
else focusCount++;
UID csUID = charNameTable->FindByName(lpacPre->insChar[i].CStyle);
acFocusStart = focusStart - (lpacPre->InsCharLength+lpacPost->InsCharLength) + i;
if (csUID != nil)
{
textModel->ApplyStyle(acFocusStart,1,csUID,kCharAttrStrandBoss,kFalse);
}
}
}
acFocusStart = focusStart - (lpacPost->InsCharLength);
csUID = charNameTable->FindByName(StyleName);
if (csUID != nil)
{
textModel->ApplyStyle(acFocusStart,1,csUID,kCharAttrStrandBoss,kFalse);
}
if (lpacPost)
{
for(int i=0; i <lpacPost->InsCharLength;i++)
{
WideString ins("");
UTF32TextChar ch(lpacPost->insChar[i].CharCode);
if (ch==nil) continue;
UID csUID = charNameTable->FindByName(lpacPost->insChar[i].CStyle);
acFocusStart = (focusStart - lpacPost->InsCharLength)+i+1;
if (csUID != nil)
{
textModel->ApplyStyle(acFocusStart,1,csUID,kCharAttrStrandBoss,kFalse);
}
}
}
if (TagChCount)
TagTextRange(storyRef,"aid:entity","name",EntityName,focusStart-TagChCount+1,focusStart+1 );
}
}
}
}
if(protocol == IID_INOTEDATA)
{
if (theChange.Get() == kCreateNoteCmdBoss ||
theChange.Get() == kDeleteNoteCmdBoss)
{
int n = 3;
}
}
}
PMString CEntity::GetCharacter ( UTF32TextChar character )
{
PMString result;
if (character == kTextChar_CR)
{
return result;
result.Append("<CR>");
}
else if (character == kTextChar_SoftCR)
{
return result;
result.Append("<SoftCR>");
}
else if (character == kTextChar_Table)
{
return result;
result.Append("<Table>");
}
else if (character == kTextChar_TableContinued)
{
return result;
result.Append("<TableContinued>");
}
else if (character == kTextChar_ObjectReplacementCharacter)
{
return result;
result.Append("<Object>");
}
else
{
return result;
result.AppendW(character);
}
return result;
}
// End CEntity.cpp
int CEntity::FindEntityPos(char *String, char *Entity, int *pLength=0)
{
int retPos = -1;
bool bEntity = false;
*pLength =0;
while (*String)
{
if (bEntity == false) retPos++;
else
{
*(Entity+*pLength-1) = *String;
*pLength+=1;
}
if (*String == '&')
{
*(Entity+*pLength) = *String;
*pLength+=1;
bEntity = true;
}
if (*String == ';' && bEntity == true)
{
*(Entity+*pLength-2) = '\0';
return retPos+1;
}
String++;
}
*(Entity+0)= '\0';
return -1;
}
int CEntity::GetStyleName(char *EntityName, char *cStyle, char *Unicode, int *CharCode, char *ffamily, char *fstyle)
{
try {
MSXML2::IXMLDOMDocumentPtr docPtr;
MSXML2::IXMLDOMNodePtr DOMNodePtr;
MSXML2::IXMLDOMNodePtr NodePtr;
MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr;
VARIANT uCode;
VARIANT chCode;
//init
*CharCode = -1;
*cStyle ='\0';
*Unicode = '\0';
TESTHR(CoInitialize(NULL));
TESTHR(docPtr.CreateInstance("Msxml2.DOMDocument.4.0"));
// load a document
_variant_t varXml(EntityPath);
_variant_t varOut((bool)TRUE);
varOut = docPtr->load(varXml);
if ((bool)varOut == FALSE)
throw(0);
// creating xPath string
char *xPath = new char[125];
strcpy(xPath,"//entity[@name='");
strcat(xPath,EntityName);
strcat(xPath,"']");
NodePtr = docPtr->selectSingleNode (xPath);
DOMNamedNodeMapPtr = NodePtr->attributes;
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("cstyle"));
if (NodePtr)
{
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("cstyle"));
VARIANT varCStyle;
NodePtr->get_nodeValue(&varCStyle);
strcpy(cStyle,_bstr_t(varCStyle));
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("charcode"));
NodePtr->get_nodeValue(&chCode);
*CharCode = atoi(_bstr_t(chCode));
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("unicode"));
NodePtr->get_nodeValue(&uCode);
strcpy(Unicode,_bstr_t(uCode));
lpacPre=FillApplyChar(NodePtr,EntityName,ffamily,fstyle,"pre");
lpacPost=FillApplyChar(NodePtr,EntityName,ffamily,fstyle,"post");
return 1;
}
else
{
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("charcode"));
NodePtr->get_nodeValue(&chCode);
*CharCode = atoi(_bstr_t(chCode));
NodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("unicode"));
NodePtr->get_nodeValue(&uCode);
strcpy(Unicode,_bstr_t(uCode));
lpacPre=FillApplyChar(NodePtr,EntityName,ffamily,fstyle,"pre");
lpacPost=FillApplyChar(NodePtr,EntityName,ffamily,fstyle,"post");
//*CharCode = -1;
return 0;
}
} catch(...)
{
return -1;
}
CoUninitialize();
return -1;
}
UIDRef CEntity::AcquireTag(const UIDRef& documentUIDRef,
const PMString& tagName
)
{
UIDRef retval;
do {
InterfacePtr<IDocument> document(documentUIDRef, UseDefaultIID());
if(!document) {
break;
}
InterfacePtr<IXMLTagList> tagList(Utils<IXMLUtils>()->QueryXMLTagList(documentUIDRef.GetDataBase()));
ASSERT(tagList);
if(!tagList) {
break;
}
WideString WSTagName =(WideString)tagName;
//UID existingTagUID = tagList->GetTag(tagName);
UID existingTagUID = tagList->GetTag(WSTagName);
if(existingTagUID == kInvalidUID) {
UID createdTagUID = kInvalidUID;
//ErrorCode err = Utils<IXMLTagCommands>()->CreateTag (::GetUIDRef(tagList),
// tagName,
// kInvalidUID,
// &createdTagUID);
ErrorCode err = Utils<IXMLTagCommands>()->CreateTag (::GetUIDRef(tagList),
WSTagName,
kInvalidUID,
&createdTagUID);
ASSERT(err == kSuccess);
ASSERT(createdTagUID != kInvalidUID);
retval = UIDRef(::GetDataBase(tagList), createdTagUID);
} else {
retval = UIDRef(::GetDataBase(tagList), existingTagUID);
}
} while(kFalse);
return retval;
}
ErrorCode CEntity::TagTextRange(const UIDRef& storyUIDRef,
const PMString& tagName,
const PMString attName,
const PMString attValue,
TextIndex startIndex,
TextIndex endIndex)
{
ErrorCode err = kFailure;
do {
InterfacePtr<ITextModel> textModel(storyUIDRef, UseDefaultIID());
ASSERT(textModel != nil);
if(!textModel) {
break;
}
IDataBase* database = storyUIDRef.GetDataBase();
UIDRef rootDocumentUIDRef(database,database->GetRootUID());
UIDRef tagUIDRef = this->AcquireTag(rootDocumentUIDRef,
tagName);
XMLReference aidElement;
err = Utils<IXMLElementCommands>()->CreateElement(tagUIDRef.GetUID(), storyUIDRef,
startIndex, endIndex,kInvalidXMLReference,&aidElement);
WideString WSAttName =(WideString)attName;
WideString WSAttValue = (WideString)attValue;
Utils<IXMLAttributeCommands>()->CreateAttribute(aidElement,WSAttName,WSAttValue);
//Utils<IXMLAttributeCommands>()->CreateAttribute(aidElement,attName,attValue);
err = kSuccess;
} while(kFalse);
return err;
}
/*
*/
PMString CEntity::AsString(const XMLReference& xmlReference)
{
PMString retval;
do {
InterfacePtr<IIDXMLElement> element(xmlReference.Instantiate());
// This can legimately be nil sometimes so don't assert
//
if(!element) {
break;
}
ClassID elementClassID = ::GetClass(element);
//PMString elementClassName = sSnpXMLResolutionHelper.ResolveClass(elementClassID.Get());
UID contentItem = element->GetContentItem(); // content Item UID
XMLReference xmlRef = element->GetXMLReference(); // XMLReference
UID xmlRefUID = xmlRef.GetUID(); // UID of XMLReference
LSID xmlRefLSID = xmlRef.GetLogicalID(); // Logical ID of XMLReference
PMString tagString = element->GetTagString(); // tag
IDataBase* dataBase = xmlRef.GetDataBase();
ClassID backClassID = dataBase->GetClass(xmlRefUID);
ClassID contentClassID = dataBase->GetClass(contentItem);
//PMString backClassStr = sSnpXMLResolutionHelper.ResolveClass(backClassID.Get());
//PMString contentClassStr = sSnpXMLResolutionHelper.ResolveClass(contentClassID.Get());
retval += "Element: <";
retval += tagString;
retval += "> (class ";
//retval += elementClassName;
retval += "), \n BkStore UID=";
retval.AppendNumber(xmlRefUID.Get());
retval += " (class ";
//retval += backClassStr;
retval += "), LSID=";
retval.AppendNumber(xmlRefLSID);
retval += ", \n ContentItem UID=";
retval.AppendNumber(contentItem.Get());
retval += " (";
//retval += contentClassStr;
retval += ")\n";
for (int32 attrIndex = 0 ; attrIndex < element->GetAttributeCount() ; attrIndex++)
{
PMString attributeName = element->GetAttributeNameAt(attrIndex);
WideString WSArrtribName=(WideString)attributeName;
//PMString attributeValue = element->GetAttributeValue(attributeName);
PMString attributeValue = element->GetAttributeValue(WSArrtribName);
retval +="\t+Attr=";
retval += attributeName;
retval += ", val=\"";
retval += attributeValue;
retval += "\"";
}
XMLContentReference contentRef = element->GetContentReference();
retval += "\nContentReference UID = ";
retval.AppendNumber(contentRef.GetUID().Get());
ClassID cid = dataBase->GetClass(contentRef.GetUID());
//PMString bcstr = sSnpXMLResolutionHelper.ResolveClass(cid.Get());
retval += "(";
//retval += bcstr;
retval += ") ";
if(contentRef.IsTable()) {
retval += ", Table Content\n";
} else if(contentRef.IsTableCell()) {
retval += ", Table Cell\n";
}
} while(kFalse);
return retval;
}
LPAPPLYCHAR CEntity::FillApplyChar(MSXML2::IXMLDOMNodePtr NodePtr, char *EntityName, char *fontFamily, char *fStyle,char *type)
{
MSXML2::IXMLDOMNodePtr ResultNodePtr;
MSXML2::IXMLDOMNamedNodeMapPtr DOMNamedNodeMapPtr;
MSXML2::IXMLDOMNodeList *DOMNodeListPtr;
MSXML2::IXMLDOMNode* pXMLNode;
//MSXML2::IXMLDOMNodeList *pInsNodeList;
MSXML2::IXMLDOMNamedNodeMap *InsAttList;
LPAPPLYCHAR lpApplyChar = new APPLYCHAR();
lpApplyChar->Clear();
HRESULT hr;
char *xPath = new char[250];
strcpy(xPath,ConstructXPath(EntityName,fontFamily,fStyle,type));
// char aStyle[125];
ResultNodePtr = NodePtr->selectSingleNode (xPath);
if (ResultNodePtr == NULL)
{
strcpy(xPath,ConstructXPath(EntityName,"",fStyle,type));
ResultNodePtr = NodePtr->selectSingleNode (xPath);
}
if (ResultNodePtr == NULL)
{
strcpy(xPath,ConstructXPath(EntityName,"","",type));
ResultNodePtr = NodePtr->selectSingleNode (xPath);
}
if (ResultNodePtr == NULL)
return lpApplyChar;
DOMNamedNodeMapPtr = ResultNodePtr->attributes;
ResultNodePtr->get_childNodes(&DOMNodeListPtr);
long Len = -1;
DOMNodeListPtr->get_length(&Len);
ResultNodePtr=DOMNamedNodeMapPtr->getNamedItem(_bstr_t("cstyle"));
VARIANT varCStyle;
ResultNodePtr->get_nodeValue(&varCStyle);
strcpy(lpApplyChar->CStyle,_bstr_t(varCStyle));
CComBSTR bstrName;
int j=0;
for (int i = 0; i <Len ; i++)
{
hr = DOMNodeListPtr->get_item(i, &pXMLNode);
if (FAILED(hr)) return lpApplyChar;
hr = pXMLNode->get_nodeName(&bstrName);
if (FAILED(hr)) return lpApplyChar;
if (bstrName == "ins")
{
CComBSTR bstrAttVal;
VARIANT varCStyle;
MSXML2::IXMLDOMNodePtr AttNodePtr;
pXMLNode->get_attributes(&InsAttList);
AttNodePtr=InsAttList->getNamedItem(_bstr_t("charcode"));
AttNodePtr->get_nodeValue(&varCStyle);
char temp[250];
strcpy(temp,_bstr_t(varCStyle));
if (atoi(temp) == 0) continue;
lpApplyChar->insChar[j].CharCode = atoi(temp);
AttNodePtr=InsAttList->getNamedItem(_bstr_t("cstyle"));
AttNodePtr->get_nodeValue(&varCStyle);
strcpy(lpApplyChar->insChar[j].CStyle,_bstr_t(varCStyle));
j++;
lpApplyChar->InsCharLength = j;
}
// Release temporary COM objects.
pXMLNode->Release();
}
return lpApplyChar;
}
char *CEntity::ConstructXPath( char *EntityName, char *fontFamily, char *fStyle, char *type)
{
char *xPath = new char[250];
//XPath: .//applychar[@type='pre' and @ffamily='' and @fstyle='']
strcpy(xPath,"//entity[@name='");
strcat(xPath,EntityName);
strcat(xPath,"']");
strcat(xPath,"/applychar[@type='");
strcat(xPath,type);
strcat(xPath,"' and @ffamily='");
strcat(xPath,fontFamily);
strcat(xPath,"' and @fstyle='");
strcat(xPath,fStyle);
strcat(xPath,"']");
return xPath;
}