Processes the Topics in the BuildDatabase and builds up the images found within the topics XML. If the image reference is
blank or invalid it is replaced by the fail penguin image.

@param buildData Information and data structures for the build.
427941
@SuppressWarnings("unchecked")
    private void processImageLocations(final BuildData buildData) {
        final List<Integer> topicIds = buildData.getBuildDatabase().getTopicIds();
        for (final Integer topicId : topicIds) {
            final ITopicNode topicNode = buildData.getBuildDatabase().getTopicNodesForTopicID(topicId).get(0);
            final BaseTopicWrapper<?> topic = topicNode.getTopic();

            if (log.isDebugEnabled()) log.debug("\tProcessing SpecTopic " + topicNode.getId() + (topicNode.getRevision() != null ? (", " +
                    "Revision " + topicNode.getRevision()) : ""));

            /*
             * Images have to be in the image folder in Publican. Here we loop through all the imagedata elements and fix up any
             * reference to an image that is not in the images folder.
             */
            final List<Node> images = XMLUtilities.getChildNodes(topicNode.getXMLDocument(), "imagedata", "inlinegraphic");

            for (final Node imageNode : images) {
                final NamedNodeMap attributes = imageNode.getAttributes();
                if (attributes != null) {
                    final Node fileRefAttribute = attributes.getNamedItem("fileref");

                    if (fileRefAttribute != null && (fileRefAttribute.getNodeValue() == null || fileRefAttribute.getNodeValue().isEmpty()
                    )) {
                        fileRefAttribute.setNodeValue("images/" + BuilderConstants.FAILPENGUIN_PNG_NAME + ".jpg");
                        buildData.getImageLocations().add(new TopicImageData(topic, fileRefAttribute.getNodeValue()));
                    } else if (fileRefAttribute != null && fileRefAttribute.getNodeValue() != null) {
                        final String fileRefValue = fileRefAttribute.getNodeValue();
                        if (BuilderConstants.IMAGE_FILE_REF_PATTERN.matcher(fileRefValue).matches()) {
                            if (fileRefValue.startsWith("./images/")) {
                                fileRefAttribute.setNodeValue(fileRefValue.substring(2));
                            } else if (!fileRefValue.startsWith("images/")) {
                                fileRefAttribute.setNodeValue("images/" + fileRefValue);
                            }

                            buildData.getImageLocations().add(new TopicImageData(topic, fileRefAttribute.getNodeValue()));
                        } else if (!BuilderConstants.COMMON_CONTENT_FILE_REF_PATTERN.matcher(fileRefValue).matches()) {
                            // The file isn't common content or a pressgang image so mark it as a missing image.
                            fileRefAttribute.setNodeValue("images/" + BuilderConstants.FAILPENGUIN_PNG_NAME + ".jpg");
                            buildData.getImageLocations().add(new TopicImageData(topic, fileRefAttribute.getNodeValue()));
                        }
                    }
                }
            }
        }
    }
381270
protected void buildAdditionalPublicanCfg(final BuildData buildData) throws BuildProcessingException {
        final ContentSpec contentSpec = buildData.getContentSpec();
        final Map<String, String> overrides = buildData.getBuildOptions().getOverrides();
        final Map<String, String> additionalPublicanCfgs = contentSpec.getAllAdditionalPublicanCfgs();

        for (final Map.Entry<String, String> entry : additionalPublicanCfgs.entrySet()) {
            final String brandOverride = overrides.containsKey(CSConstants.BRAND_OVERRIDE) ? overrides.get(
                    CSConstants.BRAND_OVERRIDE) : (overrides.containsKey(CSConstants.BRAND_ALT_OVERRIDE) ? overrides.get(
                    CSConstants.BRAND_ALT_OVERRIDE) : null);
            final String brand = brandOverride != null ? brandOverride : (contentSpec.getBrand() == null ? getDefaultBrand(
                    buildData) : contentSpec.getBrand());

            // Setup publican.cfg
            final StringBuilder publicanCfg = new StringBuilder("xml_lang: ").append(buildData.getOutputLocale()).append("\n");
            publicanCfg.append("type: ").append(contentSpec.getBookType().toString().replaceAll("-Draft", "") + "\n");
            publicanCfg.append("brand: ").append(brand).append("\n");

            // Add the custom content
            publicanCfg.append(DocBookBuildUtilities.cleanUserPublicanCfg(entry.getValue()));

            // Add the dtdver property
            if (buildData.getDocBookVersion() == DocBookVersion.DOCBOOK_50) {
                publicanCfg.append("dtdver: \"5.0\"\n");
            }

            // Add docname if it wasn't specified and the escaped title is valid
            Matcher m = null;
            if (BuilderConstants.VALID_PUBLICAN_DOCNAME_PATTERN.matcher(buildData.getEscapedBookTitle()).matches()) {
                m = DOCNAME_PATTERN.matcher(publicanCfg);
                if (!m.find()) {
                    publicanCfg.append("docname: ").append(buildData.getEscapedBookTitle().replaceAll("_", " ")).append("\n");
                }
            }

            // Add product if it wasn't specified
            m = PRODUCT_PATTERN.matcher(publicanCfg);
            if (!m.find()) {
                publicanCfg.append("product: ").append(escapeProduct(buildData.getOriginalBookProduct())).append("\n");
            }

            // Add the mainfile attribute
            publicanCfg.append("mainfile: ").append(buildData.getRootBookFileName()).append("\n");

            // Add version if it wasn't specified
            m = VERSION_PATTERN.matcher(publicanCfg);
            if (!m.find()) {
                String version = contentSpec.getBookVersion();
                if (isNullOrEmpty(version)) {
                    version = DocBookBuildUtilities.getKeyValueNodeText(buildData, contentSpec.getVersionNode());
                }
                if (isNullOrEmpty(version)) {
                    version = BuilderConstants.DEFAULT_VERSION;
                }
                publicanCfg.append("version: ").append(escapeVersion(version)).append("\n");
            }

            String fixedPublicanCfg = publicanCfg.toString();

            if (buildData.getBuildOptions().getPublicanShowRemarks()) {
                // Remove any current show_remarks definitions
                if (publicanCfg.indexOf("show_remarks") != -1) {
                    fixedPublicanCfg = fixedPublicanCfg.replaceAll("show_remarks\\s*:\\s*\\d+\\s*(\\r)?(\\n)?", "");
                }
                fixedPublicanCfg += "show_remarks: 1\n";
            }

            addToZip(buildData.getRootBookFolder() + entry.getKey(), fixedPublicanCfg, buildData);
        }
    }
775907
private void processCalendarData(ProjectCalendar calendar, List<ResultSetRow> calendarData)
   {
      for (ResultSetRow row : calendarData)
      {
         processCalendarData(calendar, row);
      }
   }
503916
private void pushMetadata(final Map<URI, Map<String, Element>> mapSet) {
        if (!mapSet.isEmpty()) {
            //process map first
            final DitaMapMetaWriter mapInserter = new DitaMapMetaWriter();
            mapInserter.setLogger(logger);
            mapInserter.setJob(job);
            for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
                final URI key = stripFragment(entry.getKey());
                final FileInfo fi = job.getFileInfo(key);
                if (fi == null) {
                    logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
                    continue;
                }
                final URI targetFileName = job.tempDirURI.resolve(fi.uri);
                assert targetFileName.isAbsolute();
                if (fi.format != null && ATTR_FORMAT_VALUE_DITAMAP.equals(fi.format)) {
                    mapInserter.setMetaTable(entry.getValue());
                    if (toFile(targetFileName).exists()) {
                        logger.info("Processing " + targetFileName);
                        mapInserter.read(toFile(targetFileName));
                    } else {
                        logger.error("File " + targetFileName + " does not exist");
                    }

                }
            }
            //process topic
            final DitaMetaWriter topicInserter = new DitaMetaWriter();
            topicInserter.setLogger(logger);
            topicInserter.setJob(job);
            for (final Entry<URI, Map<String, Element>> entry : mapSet.entrySet()) {
                final URI key = stripFragment(entry.getKey());
                final FileInfo fi = job.getFileInfo(key);
                if (fi == null) {
                    logger.error("File " + new File(job.tempDir, key.getPath()) + " was not found.");
                    continue;
                }
                final URI targetFileName = job.tempDirURI.resolve(fi.uri);
                assert targetFileName.isAbsolute();
                if (fi.format == null || fi.format.equals(ATTR_FORMAT_VALUE_DITA)) {
                    final String topicid = entry.getKey().getFragment();
                    topicInserter.setTopicId(topicid);
                    topicInserter.setMetaTable(entry.getValue());
                    if (toFile(targetFileName).exists()) {
                        topicInserter.read(toFile(targetFileName));
                    } else {
                        logger.error("File " + targetFileName + " does not exist");
                    }

                }
            }
        }
    }
1009103
protected void addToZip(final String path, final byte[] data, final BuildData buildData) {
        buildData.getOutputFiles().put(path, data);
    }
516980
private function processFeaturedArticle($articleData)
    {
        if ($articleData) {
            $article = Article::get()->filter(['HailID' => $articleData['id']])->first();
            if (!$article) {
                $article = new Article();
                $article->importHailData($articleData);
            }

            $heroImage = $article->HeroImageID;
            $heroVideo = $article->HeroVideoID;

            $article = $article->ID;
        } else {
            $article = null;
        }

        $this->FeaturedArticleID = $article;

        if (isset($heroImage) && $heroImage) {
            $this->HeroImageID = $heroImage;
        }

        if (isset($heroVideo) && $heroVideo) {
            $this->HeroVideoID = $heroVideo;
        }

    }
570156
private void buildName(EventData data, EventData result, DataMediaPair pair) {
        DataMedia targetDataMedia = pair.getTarget();
        DataMedia sourceDataMedia = pair.getSource();
        String schemaName = buildName(data.getSchemaName(),
            sourceDataMedia.getNamespaceMode(),
            targetDataMedia.getNamespaceMode());
        String tableName = buildName(data.getTableName(), sourceDataMedia.getNameMode(), targetDataMedia.getNameMode());
        result.setSchemaName(schemaName);
        result.setTableName(tableName);
    }
501544
public static void processTopicID(final BuildData buildData, final ITopicNode topicNode, final Document doc) {
        final BaseTopicWrapper<?> topic = topicNode.getTopic();

        // Ignore info topics
        if (!topic.hasTag(buildData.getServerEntities().getInfoTagId())) {
            // Get the id value
            final String errorXRefID = ((SpecNode) topicNode).getUniqueLinkId(buildData.isUseFixedUrls());

            // Set the id
            setDOMElementId(buildData.getDocBookVersion(), doc.getDocumentElement(), errorXRefID);
        }

        // Add the remap parameter
        final Integer topicId = topicNode.getDBId();
        doc.getDocumentElement().setAttribute("remap", "TID_" + topicId);
    }
511188
@Override
    public void sendData(TreeSet<Data> data) {
        if (data == null) {
            throw new IllegalArgumentException("Data must be not null");
        }
        if (data.isEmpty()) {
            return;
        }

        addData(data);

        if (distributed) {
            partitionManager.notifyData(new ArrayList<>(data));
        }
    }
1101821
protected void buildBookPreface(final BuildData buildData) throws BuildProcessingException {
        final ContentSpec contentSpec = buildData.getContentSpec();

        // Check that should actually use the preface
        if (contentSpec.getUseDefaultPreface()) {
            final Map<String, String> overrides = buildData.getBuildOptions().getOverrides();
            final Map<String, byte[]> overrideFiles = buildData.getOverrideFiles();

            final Document prefaceDoc;
            try {
                prefaceDoc = XMLUtilities.convertStringToDocument("<preface></preface>");
            } catch (Exception e) {
                throw new BuildProcessingException(e);
            }

            // Add the title
            final String prefaceTitleTranslation = buildData.getConstants().getString("PREFACE");
            final Element titleEle = prefaceDoc.createElement("title");
            titleEle.setTextContent(prefaceTitleTranslation);
            prefaceDoc.getDocumentElement().appendChild(titleEle);

            // Add the Conventions.xml
            final Element conventions = XMLUtilities.createXIInclude(prefaceDoc, "Common_Content/Conventions.xml");
            prefaceDoc.getDocumentElement().appendChild(conventions);

            // Add the Feedback.xml
            if (overrides.containsKey(CSConstants.FEEDBACK_OVERRIDE) && overrideFiles.containsKey(
                    CSConstants.FEEDBACK_OVERRIDE) || contentSpec.getFeedback() != null) {
                final Element xinclude = XMLUtilities.createXIInclude(prefaceDoc, "Feedback.xml");
                prefaceDoc.getDocumentElement().appendChild(xinclude);
            } else {
                final Element xinclude = XMLUtilities.createXIInclude(prefaceDoc, "Common_Content/Feedback.xml");
                prefaceDoc.getDocumentElement().appendChild(xinclude);
            }

            final String prefaceXml = DocBookBuildUtilities.convertDocumentToDocBookFormattedString(buildData.getDocBookVersion(),
                    prefaceDoc, "preface", buildData.getEntityFileName(), getXMLFormatProperties());
            addToZip(buildData.getBookLocaleFolder() + PREFACE_FILE_NAME, prefaceXml, buildData);
        }
    }
512508
public void onReceiveVfsPreloadData(CmsVfsEntryBean vfsPreloadData) {

        String siteRoot = vfsPreloadData.getSiteRoot();
        fillInitially(Collections.singletonList(vfsPreloadData), siteRoot);
    }
523035
public void initFromAnnotation(final Data pData) {
		dateStandard = pData.dateStandard();
		format = pData.format();
		index = pData.index();
		readHexa = pData.readHexa();
		size = pData.size();
		if (pData.tag() != null) {
			tag = EmvTags.find(BytesUtils.fromString(pData.tag()));
		}
	}
1351753
protected void buildBookBase(final BuildData buildData) throws BuildProcessingException {
        final ContentSpec contentSpec = buildData.getContentSpec();

        // Get the template from the server
        final String bookXmlTemplate;
        if (contentSpec.getBookType() == BookType.ARTICLE || contentSpec.getBookType() == BookType.ARTICLE_DRAFT) {
            bookXmlTemplate = stringConstantProvider.getStringConstant(
                    buildData.getServerEntities().getArticleStringConstantId()).getValue();
        } else {
            bookXmlTemplate = stringConstantProvider.getStringConstant(buildData.getServerEntities().getBookStringConstantId()).getValue();
        }

        // Setup the basic book.xml
        String basicBook = bookXmlTemplate.replaceAll(BuilderConstants.ESCAPED_TITLE_REGEX, buildData.getEscapedBookTitle());
        basicBook = basicBook.replaceAll(BuilderConstants.PRODUCT_REGEX,
                DocBookBuildUtilities.getKeyValueNodeText(buildData, contentSpec.getProductNode()));
        basicBook = basicBook.replaceAll(BuilderConstants.VERSION_REGEX,
                DocBookBuildUtilities.getKeyValueNodeText(buildData, contentSpec.getVersionNode()));
        basicBook = basicBook.replaceAll(BuilderConstants.DRAFT_REGEX, buildData.getBuildOptions().getDraft() ? "status=\"draft\"" : "");

        if (contentSpec.getUseDefaultPreface()) {
            // Add the preface to the book.xml
            basicBook = basicBook.replaceAll(BuilderConstants.PREFACE_REGEX,
                    "<xi:include href=\"Preface.xml\" xmlns:xi=\"http://www.w3.org/2001/XInclude\" />");
        }

        // Remove the Injection sequence as we'll add the revision history and xiinclude element later
        basicBook = basicBook.replaceAll(BuilderConstants.XIINCLUDES_INJECTION_STRING, "");
        basicBook = basicBook.replaceAll(BuilderConstants.REV_HISTORY_REGEX, "");

        // Create the Book.xml DOM Document
        Document bookBase = null;
        try {
            // Find and Remove the Doctype first
            final String doctype = XMLUtilities.findDocumentType(basicBook);

            bookBase = XMLUtilities.convertStringToDocument(doctype == null ? basicBook : basicBook.replace(doctype, ""));
        } catch (Exception e) {
            throw new BuildProcessingException(e);
        }

        boolean flattenStructure = buildData.getBuildOptions().isServerBuild() || buildData.getBuildOptions().getFlatten();
        final List<org.jboss.pressgang.ccms.contentspec.Node> levelData = contentSpec.getBaseLevel().getChildNodes();

        // Loop through and create each chapter and the topics inside those chapters
        log.info("\tBuilding Level and Topic XML Files");

        for (final org.jboss.pressgang.ccms.contentspec.Node node : levelData) {
            // Check if the app should be shutdown
            if (isShuttingDown.get()) {
                return;
            }

            if (node instanceof Level) {
                final Level level = (Level) node;

                if (level instanceof InitialContent && (level.hasSpecTopics() || level.hasCommonContents())) {
                    addLevelsInitialContent(buildData, (InitialContent) level, bookBase, bookBase.getDocumentElement(), false);
                } else if (level.hasSpecTopics() || level.hasCommonContents()) {
                    // If the book is an article than just include it directly and don't create a new file
                    if (contentSpec.getBookType() == BookType.ARTICLE || contentSpec.getBookType() == BookType.ARTICLE_DRAFT) {
                        // Create the section and its title
                        final Element sectionNode = bookBase.createElement("section");
                        setUpRootElement(buildData, level, bookBase, sectionNode);

                        createContainerXML(buildData, level, bookBase, sectionNode, buildData.getBookTopicsFolder(), flattenStructure);

                        bookBase.getDocumentElement().appendChild(sectionNode);
                    } else {
                        final Element xiInclude = createRootContainerXML(buildData, bookBase, level, flattenStructure);
                        if (xiInclude != null) {
                            bookBase.getDocumentElement().appendChild(xiInclude);
                        }
                    }
                } else if (buildData.getBuildOptions().isAllowEmptySections()) {
                    final Element para = bookBase.createElement("para");
                    para.setTextContent("No Content");
                    bookBase.getDocumentElement().appendChild(para);
                }
            } else if (node instanceof SpecTopic) {
                final SpecTopic specTopic = (SpecTopic) node;
                final Node topicNode = createTopicDOMNode(specTopic, bookBase, flattenStructure, buildData.getBookTopicsFolder());

                // Add the node to the Book
                if (topicNode != null) {
                    bookBase.getDocumentElement().appendChild(topicNode);
                }
            } else if (node instanceof CommonContent) {
                final Node xiInclude = XMLUtilities.createXIInclude(bookBase, "Common_Content/" + ((CommonContent) node).getFixedTitle());
                bookBase.getDocumentElement().appendChild(xiInclude);
            }
        }

        // Insert the editor link for the content spec if it's a translation
        if (buildData.getBuildOptions().getInsertEditorLinks() && buildData.isTranslationBuild()) {
            final String translateLinkChapter = buildTranslateCSChapter(buildData);
            buildData.getOutputFiles().put(buildData.getBookLocaleFolder() + "Translate.xml", StringUtilities.getStringBytes(
                    StringUtilities.cleanTextForXML(translateLinkChapter == null ? "" : translateLinkChapter)));

            // Create and append the XI Include element
            final Element translateXMLNode = XMLUtilities.createXIInclude(bookBase, "Translate.xml");
            bookBase.getDocumentElement().appendChild(translateXMLNode);
        }

        // Add any compiler errors
        if (!buildData.getBuildOptions().getSuppressErrorsPage() && buildData.getErrorDatabase().hasItems(buildData.getBuildLocale())) {
            final String compilerOutput = buildErrorChapter(buildData);
            buildData.getOutputFiles().put(buildData.getBookLocaleFolder() + "Errors.xml",
                    StringUtilities.getStringBytes(StringUtilities.cleanTextForXML(compilerOutput == null ? "" : compilerOutput)));

            // Create and append the XI Include element
            final Element translateXMLNode = XMLUtilities.createXIInclude(bookBase, "Errors.xml");
            bookBase.getDocumentElement().appendChild(translateXMLNode);
        }

        // Add the report chapter
        if (buildData.getBuildOptions().getShowReportPage()) {
            final String compilerOutput = buildReportChapter(buildData);
            buildData.getOutputFiles().put(buildData.getBookLocaleFolder() + "Report.xml",
                    StringUtilities.getStringBytes(StringUtilities.cleanTextForXML(compilerOutput == null ? "" : compilerOutput)));

            // Create and append the XI Include element
            final Element translateXMLNode = XMLUtilities.createXIInclude(bookBase, "Report.xml");
            bookBase.getDocumentElement().appendChild(translateXMLNode);
        }

        // Build the content specification page
        if (!buildData.getBuildOptions().getSuppressContentSpecPage()) {
            final String contentSpecPage = DocBookUtilities.buildAppendix(DocBookUtilities.wrapInPara(
                    "<programlisting>" + XMLUtilities.wrapStringInCDATA(contentSpec.toString(INCLUDE_CHECKSUMS)) + "</programlisting>"),
                    "Build Content Specification");
            addToZip(buildData.getBookLocaleFolder() + "Build_Content_Specification.xml",
                    DocBookBuildUtilities.addDocBookPreamble(buildData.getDocBookVersion(), contentSpecPage, "appendix",
                            buildData.getEntityFileName()), buildData);

            // Create and append the XI Include element
            final Element translateXMLNode = XMLUtilities.createXIInclude(bookBase, "Build_Content_Specification.xml");
            bookBase.getDocumentElement().appendChild(translateXMLNode);
        }

        // Add the revision history to the book.xml
        final Element revisionHistoryXMLNode = XMLUtilities.createXIInclude(bookBase, "Revision_History.xml");
        bookBase.getDocumentElement().appendChild(revisionHistoryXMLNode);

        // Add the index node if required
        if (contentSpec.getIncludeIndex()) {
            final Element indexNode = bookBase.createElement("index");
            bookBase.getDocumentElement().appendChild(indexNode);
        }

        // Change the DOM Document into a string so it can be added to the ZIP
        final String rootElementName = contentSpec.getBookType().toString().toLowerCase().replace("-draft", "");
        final String book = DocBookBuildUtilities.convertDocumentToDocBookFormattedString(buildData.getDocBookVersion(), bookBase,
                rootElementName, buildData.getEntityFileName(), getXMLFormatProperties());
        addToZip(buildData.getBookLocaleFolder() + buildData.getRootBookFileName() + ".xml", book, buildData);
    }
717947
public void setTemplatesMetadata(java.util.Collection<TemplateMetadata> templatesMetadata) {
        if (templatesMetadata == null) {
            this.templatesMetadata = null;
            return;
        }

        this.templatesMetadata = new com.amazonaws.internal.SdkInternalList<TemplateMetadata>(templatesMetadata);
    }
411743
public function setNodeData(NodeData $nodeData): void
    {
        $this->nodeData = $nodeData;
        $this->nodeDataIsMatchingContext = null;
    }
750858
private void buildStructure() throws DevFailed {
        DbServer    server;
        if (tgHost ==null || tgPort ==null)
            server = new DbServer(serverName);
        else {
            server = new DbServer(serverName, tgHost, tgPort);
        }

        //  Check if server defined in database.
        String  adminName = (tgHost ==null)? "" : "tango://"+ tgHost +":"+ tgPort +"/";
        adminName += "dserver/"+serverName.toLowerCase();
        new DeviceProxy(adminName);

        //  Build Server classes
        String[]    classNames = server.get_class_list();
        classes.add(new TangoClass("DServer"));
        for (String className : classNames) {
             classes.add(new TangoClass(className));
        }
	}
1010672
public function setBackgroundImage(string $imageData) : void
    {
        $url = $this->uploadImage('communityBackgroundImage', $imageData);

        $this->set([
            'backgroundImage' => [
                'sourceUrl' => $url
            ]
        ]);
    }