COpcPackageRelationship::COpcPackageRelationship(_In_ std::wstring sID, _In_ std::wstring sType, _In_ std::wstring sTargetPartURI)
	{
		m_sID = sID;
		m_sType = sType;
		if ( sTargetPartURI.empty()) {	// || (sTargetPartURI[0] != L'/')
			// must not be emtpy
			throw CNMRException(NMR_ERROR_INVALIDOPCPARTURI);
		}
		std::wstring sName = fnExtractFileName(sTargetPartURI);
		if ( sName.empty() || (sName[0] == L'.') ) {
			// must not be emtpy or start with a '.'
			throw CNMRException(NMR_ERROR_INVALIDOPCPARTURI);
		}
		m_sTargetPartURI = sTargetPartURI;
	}
Esempio n. 2
0
	void COpcPackageWriter::finishPackage()
	{
		writeContentTypes();
		writeRootRelationships();
		auto iIterator = m_Parts.begin();
		while (iIterator != m_Parts.end()) {
			POpcPackagePart pPart = *iIterator;
			if (pPart->hasRelationships()) {
				std::wstring sURI = pPart->getURI();
				std::wstring sName = fnExtractFileName(sURI);
				std::wstring sPath = sURI.substr(0, sURI.length() - sName.length());
				sPath += L"_rels/";
				sPath += sName;
				sPath += std::wstring(L".")+PACKAGE_3D_RELS_EXTENSION;

				PExportStream pStream = m_pZIPWriter->createEntry(sPath, fnGetUnixTime());
				pPart->writeRelationships(pStream);
			}
			iIterator++;
		}

	}
Esempio n. 3
0
	POpcPackagePart COpcPackageReader::createPart(_In_ std::wstring sPath)
	{
		std::wstring sRealPath = fnRemoveLeadingPathDelimiter (sPath);
		auto iPartIterator = m_Parts.find(sRealPath);
		if (iPartIterator != m_Parts.end()) {
			return iPartIterator->second;
		}

		PImportStream pStream = openZIPEntry(sRealPath);
		if (pStream.get() == nullptr)
			throw CNMRException(NMR_ERROR_COULDNOTCREATEOPCPART);

		POpcPackagePart pPart = std::make_shared<COpcPackagePart>(sRealPath, pStream);
		m_Parts.insert(std::make_pair(sRealPath, pPart));

		std::wstring sRelationShipName = fnExtractFileName(sRealPath);
		std::wstring sRelationShipPath = sRealPath.substr(0, sRealPath.length() - sRelationShipName.length());
		sRelationShipPath += L"_rels/";
		sRelationShipPath += sRelationShipName;
		sRelationShipPath += L".rels";

		PImportStream pRelStream = openZIPEntry(sRelationShipPath);

		if (pRelStream.get() != nullptr) {
		    POpcPackageRelationshipReader pReader = std::make_shared<COpcPackageRelationshipReader>(pRelStream);

		    nfUint32 nCount = pReader->getCount();
		    nfUint32 nIndex;

		    for (nIndex = 0; nIndex < nCount; nIndex++) {
		    	POpcPackageRelationship pRelationShip = pReader->getRelationShip(nIndex);
		    	pPart->addRelationship(pRelationShip->getID(), pRelationShip->getType(), pRelationShip->getTargetPartURI());
		    }
		}


		return pPart;
	}