public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(GetType());

            if (package.GetByName(Package.OutputName) == null)
            {
                log.Error("Could not find \"Output\" item in Package. This template building block should be the last TBB in your template.");
                return;
            }
            Item output = package.GetByName(Package.OutputName);

            string outputText = output.GetAsString();

            bool outputchanged = false;

            foreach (Match m in TcmUriRegEx.Matches(outputText))
            {
                log.Debug("Found " + m.Value);
                TcmUri uri = new TcmUri(m.Value);
                if (uri.GetVersionlessUri().ToString().Equals(m.Value))
                {
                    continue;
                }
                log.Debug("Found version information on uri " + m.Value + ". Removing.");
                outputText    = outputText.Replace(m.Value, uri.GetVersionlessUri().ToString());
                outputchanged = true;
            }
            if (outputchanged)
            {
                output.SetAsString(outputText);
                package.Remove(output);
                package.PushItem(Package.OutputName, output);
            }
        }
        public void Transform(Engine engine, Package package)
        {
            TemplatingLogger log = TemplatingLogger.GetLogger(GetType());
            if (package.GetByName(Package.OutputName) == null)
            {
                log.Error("Could not find \"Output\" item in Package. This template building block should be the last TBB in your template.");
                return;
            }
            Item output = package.GetByName(Package.OutputName);

            string outputText = output.GetAsString();

            bool outputchanged = false;
            foreach (Match m in TcmUriRegEx.Matches(outputText))
            {
                log.Debug("Found " + m.Value);
                TcmUri uri = new TcmUri(m.Value);
                if(uri.GetVersionlessUri().ToString().Equals(m.Value)) continue;
                log.Debug("Found version information on uri " + m.Value + ". Removing.");
                outputText = outputText.Replace(m.Value, uri.GetVersionlessUri().ToString());
                outputchanged = true;
            }
            if (outputchanged)
            {
                output.SetAsString(outputText);
                package.Remove(output);
                package.PushItem(Package.OutputName, output);
            }
        }
Ejemplo n.º 3
0
        private TcmUri GetTcmUri(string fieldName, ItemFields fields, TcmUri contextPublicationUri)
        {
            TcmUri uri = GetTcmUriFromField(fieldName, fields);

            if (!TcmUri.IsNullOrUriNull(contextPublicationUri))
            {
                uri = TransformTcmUri(uri, contextPublicationUri);
            }

            if (TcmUri.IsNullOrUriNull(uri))
            {
                IsValid = false;
            }

            return(uri.GetVersionlessUri());
        }
Ejemplo n.º 4
0
 /// <summary>
 /// Remove container index from Template TCM-URI
 /// </summary>
 /// <param name="templateUri"></param>
 /// <returns></returns>
 static public TcmUri RemoveContainerIndex(TcmUri templateUri)
 {
     return(templateUri.GetVersionlessUri());
 }
        internal void AddSiteEditToTemplate(string templateId)
        {
            TcmUri uri = new TcmUri(templateId);

            templateId = uri.GetVersionlessUri();
            TemplateData template = (TemplateData)_client.Read(templateId, _readOptions);
            // find siteedit templates
            string context = template.BluePrintInfo.OwningRepository.IdRef;
            TemplateBuildingBlockData tbb;

            // If this is Tridion 6.1 there won't be a building block for SiteEdit yet
            if (Configuration.ServerVersion == ServerVersion.Version6)
            {
                if (!_client.IsExistingObject(Configuration.UrlEnableInlineEditingForContentTbb))
                {
                    string tridionHome      = Environment.GetEnvironmentVariable("TRIDION_CM_HOME");
                    string siteEditAssembly = Path.Combine(tridionHome, "bin", "Tridion.SiteEdit.Templating.dll");
                    if (File.Exists(siteEditAssembly))
                    {
                        string defaultTbbFolder = null;
                        OrganizationalItemItemsFilterData filter = new OrganizationalItemItemsFilterData();
                        filter.ItemTypes = new[] { ItemType.Folder };
                        foreach (
                            XElement node in
                            _client.GetListXml(
                                GetUriInBlueprintContext(Configuration.BuildingBlocksFolderId,
                                                         Configuration.TopPublicationId), filter).Nodes())
                        {
                            if (node.Attribute("Title").Value.Equals("Default Templates"))
                            {
                                defaultTbbFolder = node.Attribute("ID").Value;
                                break;
                            }
                        }
                        if (defaultTbbFolder != null)
                        {
                            Console.WriteLine("Uploading SiteEdit TBB Assembly");
                            string tcmUpload  = Path.Combine(tridionHome, "bin", "client", "TcmUploadAssembly.exe");
                            string parameters = string.Format("/folder:{0} /targeturl:{1} \"{2}\"", defaultTbbFolder,
                                                              "http://localhost", siteEditAssembly);
                            Process          process   = new Process();
                            ProcessStartInfo startInfo = new ProcessStartInfo
                            {
                                WindowStyle = ProcessWindowStyle.Minimized,
                                FileName    = tcmUpload,
                                Arguments   = parameters
                            };
                            process.StartInfo = startInfo;
                            process.Start();
                            process.WaitForExit();
                        }
                    }
                }
            }

            if (template is ComponentTemplateData)
            {
                tbb =
                    (TemplateBuildingBlockData)
                    _client.Read(Configuration.UrlEnableInlineEditingForContentTbb, _readOptions);
            }
            else
            {
                tbb = (TemplateBuildingBlockData)_client.Read(Configuration.UrlEnableInlineEditingForPagesTbb, _readOptions);
            }

            string    tbbId   = GetUriInBlueprintContext(tbb.Id, context);
            XDocument content = XDocument.Parse(template.Content);
            // Find default finish actions
            XElement   dfa             = null;
            XNamespace xlink           = XNamespace.Get("http://www.w3.org/1999/xlink");
            XNamespace modularTemplate = XNamespace.Get("http://www.tridion.com/ContentManager/5.3/CompoundTemplate");

            foreach (XElement node in content.Root.Nodes())
            {
                if (node.Element(modularTemplate + "Template").Attribute(xlink + "title").Value.Equals("Default Finish Actions"))
                {
                    dfa = node;
                    break;
                }
            }
            if (dfa != null)
            {
                // Must create Element and insert before
                //  <TemplateInvocation><Template xlink:href="tcm:3-32-2048" xmlns:xlink="http://www.w3.org/1999/xlink" xlink:title="Default Finish Actions" /></TemplateInvocation>

                string fakeSe =
                    "<TemplateInvocation xmlns=\"http://www.tridion.com/ContentManager/5.3/CompoundTemplate\"><Template xlink:href=\"##TBBID##\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:title=\"##TBBTITLE##\" /></TemplateInvocation>";
                if (template is PageTemplateData)
                {
                    fakeSe = "<TemplateInvocation xmlns=\"http://www.tridion.com/ContentManager/5.3/CompoundTemplate\"><Template xlink:href=\"##TBBID##\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xlink:title=\"##TBBTITLE##\"/><TemplateParameters><Parameters xmlns=\"##PARAMETERSCHEMANAMESPACE##\"><SiteEditURL>http://localhost/WebUI/Editors/SiteEdit/</SiteEditURL></Parameters></TemplateParameters></TemplateInvocation>";
                    string     schemaId = tbb.ParameterSchema.IdRef;
                    SchemaData schema   = (SchemaData)_client.Read(schemaId, _readOptions);
                    fakeSe = fakeSe.Replace("##PARAMETERSCHEMANAMESPACE##", schema.NamespaceUri);
                }
                fakeSe = fakeSe.Replace("##TBBID##", tbbId);
                fakeSe = fakeSe.Replace("##TBBTITLE##", tbb.Title);
                //Avoid adding SiteEdit TBB a million times...
                if (!template.Content.Contains(tbb.Title))
                {
                    XElement element = XElement.Parse(fakeSe);
                    dfa.AddBeforeSelf(element);
                    template.Content = content.ToString();
                    _client.CheckOut(template.Id, false, null);
                    _client.Save(template, null);
                    _client.CheckIn(template.Id, null);
                }
            }
        }
        /// <summary>
        /// Gets an imported template's content. Works with tcm uri's, web dav urls, or physical file paths.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <param name="engine"></param>
        /// <returns></returns>
        private string GetImportTemplateContent(string path)
        {
            TcmUri templateID = new TcmUri(_templateID);

            if (path.ToLower().StartsWith("tcm:") || path.ToLower().StartsWith("/webdav/") || !path.Contains("\\"))
            {
                if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
                {
                    path = GetRelativeImportPath(path);
                }

                TemplateBuildingBlock template;
                try
                {
                    template = Session.GetObject(path) as TemplateBuildingBlock;
                }
                catch (Exception ex)
                {
                    _logger.Warning("Error import of '" + path + "'. " + ex.ToString());
                    return(String.Empty);
                }

                if (template == null)
                {
                    _logger.Warning("Import of '" + path + "' not found.");
                    return(String.Empty);
                }

                _logger.Debug("Comaring import template " + template.Id + " to razor tbb ID " + templateID);
                // Get local copy of the imported template if possible.

                int publicationID = templateID.PublicationId;

                if (TcmUri.IsNullOrUriNull(templateID))
                {
                    // Is new item, so templateID is tcm:0-0-0.  We need to grab the pub id manually.
                    string[] webDav    = _webDavUrl.Split('/');
                    string   pubWebDav = "/webdav/" + webDav[2];

                    publicationID = Session.GetObject(pubWebDav).Id.ItemId;
                }

                if (template.Id.PublicationId != publicationID)
                {
                    // If import is from diff publication, try to grab local copy.
                    try
                    {
                        template = (TemplateBuildingBlock)Session.GetObject(TemplateUtilities.CreateTcmUriForPublication(publicationID, template.Id));
                    }
                    catch
                    {
                        _logger.Warning("Error trying to get local copy of template '" + template.Id + "' for Publication ID '" + publicationID + "'");
                    }
                }

                // Don't import itself
                if (template.Id.GetVersionlessUri().Equals(templateID.GetVersionlessUri()))
                {
                    return(String.Empty);
                }

                return(template.Content);
            }
            else
            {
                // If its a file path, get the contents of the file and return.
                return(File.ReadAllText(path));
            }
        }
        /// <summary>
        /// Gets an imported template's content. Works with tcm uri's, web dav urls, or physical file paths.
        /// </summary>
        /// <param name="path">The path to check.</param>
        /// <param name="engine"></param>
        /// <returns></returns>
        private string GetImportTemplateContent(string path)
        {
            TcmUri templateID = new TcmUri(_templateID);

            if (path.ToLower().StartsWith("tcm:") || path.ToLower().StartsWith("/webdav/") || !path.Contains("\\"))
            {
                if (!path.ToLower().StartsWith("tcm:") && !path.ToLower().StartsWith("/webdav/"))
                {
                    path = GetRelativeImportPath(path);
                }

                TemplateBuildingBlock template;
                try
                {
                    template = Session.GetObject(path) as TemplateBuildingBlock;

                }
                catch (Exception ex)
                {
                    _logger.Warning("Error import of '" + path + "'. " + ex.ToString());
                    return String.Empty;
                }

                if (template == null)
                {
                    _logger.Warning("Import of '" + path + "' not found.");
                    return String.Empty;
                }

                _logger.Debug("Comaring import template " + template.Id + " to razor tbb ID " + templateID);
                // Get local copy of the imported template if possible.

                int publicationID = templateID.PublicationId;

                if (TcmUri.IsNullOrUriNull(templateID))
                {
                    // Is new item, so templateID is tcm:0-0-0.  We need to grab the pub id manually.
                    string[] webDav = _webDavUrl.Split('/');
                    string pubWebDav = "/webdav/" + webDav[2];

                    publicationID = Session.GetObject(pubWebDav).Id.ItemId;
                }

                if (template.Id.PublicationId != publicationID)
                {
                    // If import is from diff publication, try to grab local copy.
                    try
                    {
                        template = (TemplateBuildingBlock)Session.GetObject(TemplateUtilities.CreateTcmUriForPublication(publicationID, template.Id));
                    }
                    catch
                    {
                        _logger.Warning("Error trying to get local copy of template '" + template.Id + "' for Publication ID '" + publicationID + "'");
                    }
                }

                // Don't import itself
                if (template.Id.GetVersionlessUri().Equals(templateID.GetVersionlessUri()))
                {
                    return String.Empty;
                }

                return template.Content;
            }
            else
            {
                // If its a file path, get the contents of the file and return.
                return File.ReadAllText(path);
            }
        }