Example usage for javax.xml.parsers FactoryConfigurationError getMessage

List of usage examples for javax.xml.parsers FactoryConfigurationError getMessage

Introduction

In this page you can find the example usage for javax.xml.parsers FactoryConfigurationError getMessage.

Prototype


public String getMessage() 

Source Link

Document

Return the message (if any) for this error .

Usage

From source file:Main.java

/**
 * This will parse an XML stream and create a DOM document.
 *
 * @param is The stream to get the XML from.
 * @return The DOM document./* w w  w .  ja  va2  s .  co m*/
 * @throws IOException It there is an error creating the dom.
 */
public static Document parse(InputStream is) throws IOException {
    try {
        DocumentBuilderFactory builderFactory = DocumentBuilderFactory.newInstance();
        builderFactory.setFeature("http://apache.org/xml/features/disallow-doctype-decl", true);
        builderFactory.setFeature("http://xml.org/sax/features/external-general-entities", false);
        builderFactory.setFeature("http://xml.org/sax/features/external-parameter-entities", false);
        builderFactory.setFeature("http://apache.org/xml/features/nonvalidating/load-external-dtd", false);
        builderFactory.setXIncludeAware(false);
        builderFactory.setExpandEntityReferences(false);
        DocumentBuilder builder = builderFactory.newDocumentBuilder();
        return builder.parse(is);
    } catch (FactoryConfigurationError e) {
        throw new IOException(e.getMessage(), e);
    } catch (ParserConfigurationException e) {
        throw new IOException(e.getMessage(), e);
    } catch (SAXException e) {
        throw new IOException(e.getMessage(), e);
    }
}

From source file:com.aurel.track.exchange.docx.exporter.CustomXML.java

public static Document convertToDOM(TWorkItemBean documentItem, Integer personID, Locale locale) {
    Document dom = null;/*from  ww w  . j  av  a2s. com*/
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        dom = builder.newDocument();
    } catch (FactoryConfigurationError e) {
        LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage());
        return null;
    } catch (ParserConfigurationException e) {
        LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage());
        return null;
    }
    Element root = dom.createElement(CUSTOM_XML_ELEMENTS.MAIN_ELEMENT);
    if (documentItem != null) {
        Integer itemID = documentItem.getObjectID();
        List<TWorkItemBean> itemList = new LinkedList<TWorkItemBean>();
        itemList.add(documentItem);
        List<ReportBean> reportBeansList = LoadItemIDListItems.getReportBeansByWorkItems(itemList, personID,
                locale, true, false, false, false, false, false, false, false, false);
        ReportBean showableWorkItem = reportBeansList.get(0);
        Map<Integer, String> showValuesMap = showableWorkItem.getShowValuesMap();
        if (showValuesMap != null) {
            List<TFieldBean> fieldBeansList = FieldBL.loadAll();
            for (TFieldBean fieldBean : fieldBeansList) {
                Integer fieldID = fieldBean.getObjectID();
                String fieldName = fieldBean.getName();
                String showValue = showValuesMap.get(fieldID);
                if (showValue != null && !"".equals(showValue)) {
                    IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID);
                    if (fieldTypeRT != null) {
                        if (fieldTypeRT.isLong()) {
                            showValue = StringEscapeUtils.escapeHtml4(showValue);
                        }
                    }
                    appendChild(root, fieldName, showValue, dom);
                    appendChild(root, fieldName + CUSTOM_XML_ELEMENTS.PRESENT_SUFFIX, Boolean.TRUE.toString(),
                            dom);
                } else {
                    appendChild(root, fieldName + CUSTOM_XML_ELEMENTS.PRESENT_SUFFIX, Boolean.FALSE.toString(),
                            dom);
                    appendChild(root, fieldName, "", dom);
                }
            }

            List<TPersonBean> consultedPersonBeans = PersonBL.getDirectConsultants(itemID);
            addWatcherNodes(consultedPersonBeans, root, dom, CUSTOM_XML_ELEMENTS.CONSULTED_LIST,
                    CUSTOM_XML_ELEMENTS.CONSULTED_PERSON);
            List<TPersonBean> informedPersonBeans = PersonBL.getDirectInformants(itemID);
            addWatcherNodes(informedPersonBeans, root, dom, CUSTOM_XML_ELEMENTS.INFORMED_LIST,
                    CUSTOM_XML_ELEMENTS.INFORMED_PERSON);

            List<HistoryValues> comments = HistoryLoaderBL.getRestrictedWorkItemComments(personID, itemID,
                    locale, false, /*LONG_TEXT_TYPE.ISPLAIN*/ LONG_TEXT_TYPE.ISFULLHTML);
            addCommentNodes(comments, root, dom, locale);

        }
    }
    dom.appendChild(root);
    return dom;
}

From source file:com.aurel.track.exchange.track.exporter.TrackExportBL.java

/**
 * Exports the reportBeans to an xml file
 * @param reportBeans/*w  w  w .ja  v  a 2s  . c o m*/
 * @param personID
 * @return
 */
private static Document exportWorkItems(List<ReportBean> reportBeansList, Integer personID) {
    Document dom = null;
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        dom = builder.newDocument();
    } catch (FactoryConfigurationError e) {
        LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    } catch (ParserConfigurationException e) {
        LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
    //create the DOM object
    Element root = dom.createElement(ExchangeFieldNames.TRACKPLUS_EXCHANGE);
    dom.appendChild(root);
    if (reportBeansList == null || reportBeansList.isEmpty()) {
        return dom;
    }
    LOGGER.info("Number of workItems exported: " + reportBeansList.size());
    //load also the full history 
    List<ReportBeanWithHistory> reportBeansWithHistoryList = ReportBeanHistoryLoader
            .getReportBeanWithHistoryList(reportBeansList, Locale.ENGLISH, true, false, true, null, true, true,
                    true, true, true, personID, null, null, null, true, LONG_TEXT_TYPE.ISFULLHTML);

    //get the workItemIDs
    List<Integer> workItemIDsList = new ArrayList<Integer>();
    Set<Integer> issueTypeSet = new HashSet<Integer>();
    Set<Integer> projectTypeSet = new HashSet<Integer>();
    Set<Integer> projectSet = new HashSet<Integer>();
    for (ReportBean reportBean : reportBeansWithHistoryList) {
        TWorkItemBean workItemBean = reportBean.getWorkItemBean();
        workItemIDsList.add(workItemBean.getObjectID());
        issueTypeSet.add(workItemBean.getListTypeID());
        projectSet.add(workItemBean.getProjectID());
    }
    List<TProjectBean> projectBeans = ProjectBL.loadByProjectIDs(GeneralUtils.createListFromSet(projectSet));
    if (projectBeans != null) {
        for (TProjectBean projectBean : projectBeans) {
            projectTypeSet.add(projectBean.getProjectType());
        }
    }

    //load the dropdown container based on the workItemIDsList
    DropDownContainer dropDownContainer = HistoryDropdownContainerLoader
            .loadExporterDropDownContainer(GeneralUtils.createIntArrFromIntegerList(workItemIDsList));

    /**
     * fieldType based lookup values will be gathered in the lookup map:
     * fieldID_parametercode keyed -> lookup objectID keyed -> attribute name to attribute string value map
     */
    Map<Integer, ILabelBean> personBeansMap = dropDownContainer
            .getDataSourceMap(MergeUtil.mergeKey(SystemFields.INTEGER_PERSON, null));
    Map<String, Map<Integer, Map<String, String>>> serializedLookupsMap = new HashMap<String, Map<Integer, Map<String, String>>>();
    //initialize the serialized person map explicitly because it will be loaded also 
    //from other parts (consultants/informants, budget, cost etc.)
    Map<Integer, Map<String, String>> serializedPersonsMap = new HashMap<Integer, Map<String, String>>();
    serializedLookupsMap.put(MergeUtil.mergeKey(SystemFields.INTEGER_PERSON, null), serializedPersonsMap);

    /**
     * gather all non-fieldType based lookup values in the additionalSerializedEntitiesMap map: 
     *    accounts, costcenteres, departments, system states, projectTypes and lists     
     */
    Map<String, Map<Integer, Map<String, String>>> additionalSerializedLookupsMap = new HashMap<String, Map<Integer, Map<String, String>>>();

    Map<Integer, TCostCenterBean> costCentersMap = GeneralUtils
            .createMapFromList(AccountBL.getAllCostcenters());
    Map<Integer, TAccountBean> accountsMap = GeneralUtils.createMapFromList(AccountBL.getAllAccounts());

    //get the custom fields map
    Map<Integer, ISerializableLabelBean> customFieldBeansMap = GeneralUtils
            .createMapFromList(FieldBL.loadCustom());

    Set<Integer> pseudoHistoryFields = HistoryLoaderBL.getPseudoHistoryFields();
    /**
     * add the actual attribute values 
     */
    Set<Integer> nonNullFields = new HashSet<Integer>();
    //linked through parent, issueNos in descriptions/comments and later issueLinks
    Set<Integer> linkedWorkItemIDs = new HashSet<Integer>();
    for (int n = 0; n < reportBeansWithHistoryList.size(); n++) {
        ReportBean reportBean = (ReportBean) reportBeansWithHistoryList.get(n);
        TWorkItemBean workItemBean = reportBean.getWorkItemBean();
        Map<String, String> attributes = new HashMap<String, String>();
        attributes.put(ExchangeFieldNames.UUID, workItemBean.getUuid());
        attributes.put(ExchangeFieldNames.WORKITEMID, workItemBean.getObjectID().toString());
        Element itemElement = createElementWithAttributes(ExchangeFieldNames.ITEM, null, false, attributes,
                dom);
        //system field nodes
        for (int i = 0; i < SystemFields.getSystemFieldsArray().length; i++) {
            Integer fieldID = Integer.valueOf(SystemFields.getSystemFieldsArray()[i]);
            if (!fieldID.equals(SystemFields.INTEGER_ISSUENO)) { //the issueNo is added directly to item element  {
                Object workItemAttribute = workItemBean.getAttribute(fieldID, null);
                if (workItemAttribute != null) {
                    IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID);
                    if (fieldTypeRT != null) {
                        nonNullFields.add(fieldID);
                        gatherLinkedWorkItems(workItemAttribute, fieldTypeRT, linkedWorkItemIDs);
                        Map<String, String> fieldAndParameterCodeAttributes = new HashMap<String, String>();
                        fieldAndParameterCodeAttributes.put(ExchangeFieldNames.FIELDID, fieldID.toString());
                        appendAttributeElement(ExchangeFieldNames.ITEM_ATTRIBUTE, itemElement,
                                workItemAttribute, fieldTypeRT, fieldID, null, dropDownContainer,
                                serializedLookupsMap, additionalSerializedLookupsMap,
                                fieldAndParameterCodeAttributes, dom);
                    }
                }
            }
        }
        //custom field nodes
        Map<String, Object> customAttributes = workItemBean.getCustomAttributeValues();
        Integer parameterCode;
        if (customAttributes != null && !customAttributes.isEmpty()) {
            Iterator<String> iterator = customAttributes.keySet().iterator();
            while (iterator.hasNext()) {
                String key = iterator.next();
                String[] splittedKey = MergeUtil.splitKey(key);
                String strFieldID = splittedKey[0].substring(1); //get rid of "f"
                Integer fieldID = Integer.valueOf(strFieldID);
                String strParameterCode = null;
                parameterCode = null;
                if (splittedKey.length > 1) {
                    //whether the workItemAttribute is a part of a composite custom field
                    strParameterCode = splittedKey[1];
                    if (strParameterCode != null && !"null".equals(strParameterCode)) {
                        try {
                            parameterCode = Integer.valueOf(strParameterCode);
                        } catch (Exception e) {
                            LOGGER.error("Converting the parameterCode " + strParameterCode
                                    + " to an integer failed with " + e.getMessage());
                            LOGGER.debug(ExceptionUtils.getStackTrace(e));
                        }
                    }
                }
                //add to custom field beans
                addToAdditionalSerializedLookupsMap(customFieldBeansMap.get(fieldID), ExchangeFieldNames.FIELD,
                        additionalSerializedLookupsMap);
                Object workItemAttribute = workItemBean.getAttribute(fieldID, parameterCode);
                if (workItemAttribute != null) {
                    IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID, parameterCode);
                    nonNullFields.add(fieldID);
                    gatherLinkedWorkItems(workItemAttribute, fieldTypeRT, linkedWorkItemIDs);
                    Map<String, String> fieldAndParameterCodeAttributes = new HashMap<String, String>();
                    if (strFieldID != null) {
                        fieldAndParameterCodeAttributes.put(ExchangeFieldNames.FIELDID, strFieldID);
                    }
                    if (strParameterCode != null) {
                        fieldAndParameterCodeAttributes.put(ExchangeFieldNames.PARAMETERCODE, strParameterCode);
                    }
                    appendAttributeElement(ExchangeFieldNames.ITEM_ATTRIBUTE, itemElement, workItemAttribute,
                            fieldTypeRT, fieldID, parameterCode, dropDownContainer, serializedLookupsMap,
                            additionalSerializedLookupsMap, fieldAndParameterCodeAttributes, dom);
                }
            }
        }
        /**
         * add the consulted and informed nodes
         */
        Set<Integer> consultedList = reportBean.getConsultedList();
        if (consultedList != null && !consultedList.isEmpty()) {
            itemElement.appendChild(createConsInfElement(ExchangeFieldNames.CONSULTANT_LIST,
                    ExchangeFieldNames.CONSULTANT, consultedList, personBeansMap, serializedPersonsMap, dom));
        }
        Set<Integer> informedList = reportBean.getInformedList();
        if (informedList != null && !informedList.isEmpty()) {
            itemElement.appendChild(createConsInfElement(ExchangeFieldNames.INFORMANT_LIST,
                    ExchangeFieldNames.INFORMANT, informedList, personBeansMap, serializedPersonsMap, dom));
        }
        /**
         * add the history nodes
         */
        ReportBeanWithHistory reportBeanWithHistory = (ReportBeanWithHistory) reportBean;
        Element historyElement = createHistoryElement(reportBeanWithHistory.getHistoryValuesMap(),
                dropDownContainer, dom, serializedLookupsMap, additionalSerializedLookupsMap,
                pseudoHistoryFields, linkedWorkItemIDs);
        if (historyElement != null) {
            itemElement.appendChild(historyElement);
        }
        /**
         * add the budget nodes
         */
        Element budgetElement = createBudgetPlanElement(reportBeanWithHistory.getBudgetHistory(),
                personBeansMap, serializedPersonsMap, dom, false);
        if (budgetElement != null) {
            itemElement.appendChild(budgetElement);
        }
        Element plannedValueElement = createBudgetPlanElement(reportBeanWithHistory.getPlannedValueHistory(),
                personBeansMap, serializedPersonsMap, dom, true);
        if (plannedValueElement != null) {
            itemElement.appendChild(plannedValueElement);
        }

        if (budgetElement != null) {
            //do not add estimated remaining budget element if no budget exists
            Element remainingBudgetElement = createRemainingBudgetElement(
                    reportBeanWithHistory.getActualEstimatedBudgetBean(), personBeansMap, serializedPersonsMap,
                    dom);
            if (remainingBudgetElement != null) {
                itemElement.appendChild(remainingBudgetElement);
            }
        }
        /**
         * add the expense nodes
         */
        Element costElement = createExpenseElement(reportBeanWithHistory.getCosts(), personBeansMap,
                accountsMap, costCentersMap, serializedPersonsMap, dom, additionalSerializedLookupsMap);
        if (costElement != null) {
            itemElement.appendChild(costElement);
        }

        List<TAttachmentBean> existingAttachments = AttachBL
                .getExistingAttachments(reportBeanWithHistory.getAttachments());
        Element attachmentElement = createAttachmentElement(existingAttachments, personBeansMap,
                serializedPersonsMap, dom);
        if (attachmentElement != null) {
            itemElement.appendChild(attachmentElement);
        }
        root.appendChild(itemElement);
    }

    /**
     * load the not explicitly exported linked workItems
     */
    linkedWorkItemIDs.removeAll(workItemIDsList);
    if (!linkedWorkItemIDs.isEmpty()) {
        List<TWorkItemBean> workItemBeanList = ItemBL
                .loadByWorkItemKeys(GeneralUtils.createIntArrFromSet(linkedWorkItemIDs));
        if (workItemIDsList != null) {
            Iterator<TWorkItemBean> itrWorkItemBean = workItemBeanList.iterator();
            while (itrWorkItemBean.hasNext()) {
                TWorkItemBean workItemBean = itrWorkItemBean.next();
                Map<String, String> attributeValues = workItemBean.serializeBean();
                root.appendChild(createElementWithAttributes(ExchangeFieldNames.LINKED_ITEMS, "", false,
                        attributeValues, dom));
            }
        }
    }

    /**
     * add the systemState entries to the additionalSerializedEntitiesMap
     */
    Map<Integer, Map<String, String>> serializedProjectMap = serializedLookupsMap
            .get(MergeUtil.mergeKey(SystemFields.INTEGER_PROJECT, null));
    Map<Integer, Map<String, String>> serializedReleaseMap = serializedLookupsMap
            .get(MergeUtil.mergeKey(SystemFields.RELEASE, null));
    Map<Integer, Map<String, String>> serializedAccountsMap = additionalSerializedLookupsMap
            .get(ExchangeFieldNames.ACCOUNT);
    Map<Integer, TSystemStateBean> systemStateMap = GeneralUtils.createMapFromList(SystemStatusBL.loadAll());
    addSystemState(serializedProjectMap, systemStateMap, additionalSerializedLookupsMap);
    addSystemState(serializedReleaseMap, systemStateMap, additionalSerializedLookupsMap);
    addSystemState(serializedAccountsMap, systemStateMap, additionalSerializedLookupsMap);
    /**
     * add each option for the list (which have at least one option set on an issue)
     */
    Map<Integer, Map<String, String>> serializedListMap = additionalSerializedLookupsMap
            .get(ExchangeFieldNames.LIST);
    addListAdditional(serializedListMap, dropDownContainer, serializedLookupsMap,
            additionalSerializedLookupsMap);
    /**
     * add the project related additional entities to serializedEntitiesMap and additionalSerializedEntitiesMap 
     */
    Map<Integer, TProjectTypeBean> projetcTypesMap = GeneralUtils.createMapFromList(ProjectTypesBL.loadAll());
    addProjectAdditional(serializedProjectMap, projetcTypesMap, serializedLookupsMap,
            additionalSerializedLookupsMap, accountsMap, costCentersMap);
    /**
     * add field related entities: the owners
     */
    Map<Integer, Map<String, String>> serializedCustomFields = additionalSerializedLookupsMap
            .get(ExchangeFieldNames.FIELD);
    addFieldAdditional(serializedCustomFields, serializedLookupsMap);
    /**
     * add the used fieldConfigs
     */
    List<TFieldConfigBean> fieldConfigBeans = FieldConfigBL.loadAllForFields(nonNullFields);
    for (Iterator<TFieldConfigBean> iterator = fieldConfigBeans.iterator(); iterator.hasNext();) {
        //remove the field configurations for not used issueTypes, projectTypes and projects 
        TFieldConfigBean fieldConfigBean = iterator.next();
        Integer issueTypeID = fieldConfigBean.getIssueType();
        Integer projectTypeID = fieldConfigBean.getProjectType();
        Integer projectID = fieldConfigBean.getProject();
        if (issueTypeID != null && !issueTypeSet.contains(issueTypeID)) {
            iterator.remove();
            continue;
        }
        if (projectTypeID != null && !projectTypeSet.contains(projectTypeID)) {
            iterator.remove();
            continue;
        }
        if (projectID != null && !projectSet.contains(projectID)) {
            iterator.remove();
            continue;
        }
    }

    //comment this and uncomment the coming block to add fewer field configs
    addToAdditionalSerializedLookupsMap((List) fieldConfigBeans, ExchangeFieldNames.FIELDCONFIG,
            additionalSerializedLookupsMap);
    Map<Integer, Map<String, String>> serializedFieldConfigs = additionalSerializedLookupsMap
            .get(ExchangeFieldNames.FIELDCONFIG);
    addFieldConfigsAdditional(serializedFieldConfigs, projetcTypesMap, serializedLookupsMap,
            additionalSerializedLookupsMap);
    /**
     * add the field settings
     */
    List<Integer> userFieldConfigIDs = GeneralUtils.createListFromSet(serializedFieldConfigs.keySet());
    //option settings
    List<ISerializableLabelBean> optionSettingsList = (List) OptionSettingsBL
            .loadByConfigList(userFieldConfigIDs);
    if (optionSettingsList != null) {
        Iterator<ISerializableLabelBean> itrOptionSettings = optionSettingsList.iterator();
        while (itrOptionSettings.hasNext()) {
            TOptionSettingsBean optionSettingsBean = (TOptionSettingsBean) itrOptionSettings.next();
            Integer listID = optionSettingsBean.getList();
            if (serializedListMap == null || !serializedListMap.containsKey(listID)) {
                //do not export the option settings if the corresponding list is not exported 
                //(none of the selected workItems has a value from this list)
                //because creating the optionSetings will fail without the listID 
                itrOptionSettings.remove();
            }

        }
    }
    addToAdditionalSerializedLookupsMap(optionSettingsList, ExchangeFieldNames.OPTIONSETTINGS,
            additionalSerializedLookupsMap);
    //textbox settings
    List<ISerializableLabelBean> textBoxSettingsList = (List) TextBoxSettingsBL
            .loadByConfigList(userFieldConfigIDs);
    addToAdditionalSerializedLookupsMap(textBoxSettingsList, ExchangeFieldNames.TEXTBOXSETTINGS,
            additionalSerializedLookupsMap);
    //general settings
    List<ISerializableLabelBean> generalSettingsList = (List) GeneralSettingsBL
            .loadByConfigList(userFieldConfigIDs);
    addToAdditionalSerializedLookupsMap(generalSettingsList, ExchangeFieldNames.GENERALSETTINGS,
            additionalSerializedLookupsMap);

    /**
     * add the person related additional entities to serializedEntitiesMap and additionalSerializedEntitiesMap 
     */
    addPersonAdditional(serializedPersonsMap, GeneralUtils.createMapFromList(DepartmentBL.getAllDepartments()),
            costCentersMap, serializedLookupsMap, additionalSerializedLookupsMap);

    /**
     * add the role assignments and the roles
     * the role assignments cannot be added to the additionalSerializedLookupsMap because they have no objectID
     * consequently they will be serialized directly
     */
    List<ISerializableLabelBean> accessControlListBeanList = (List) AccessControlBL.loadByPersonsAndProjects(
            GeneralUtils.createIntegerListFromCollection(serializedPersonsMap.keySet()),
            GeneralUtils.createIntegerListFromCollection(serializedProjectMap.keySet()));
    if (accessControlListBeanList != null) {
        Map<Integer, TRoleBean> roleMap = GeneralUtils.createMapFromList(RoleBL.loadAll());
        Iterator<ISerializableLabelBean> iterator = accessControlListBeanList.iterator();
        while (iterator.hasNext()) {
            TAccessControlListBean accessControlListBean = (TAccessControlListBean) iterator.next();
            //serialize the role assignment directly        
            root.appendChild(createElementWithAttributes(ExchangeFieldNames.ACL, null, false,
                    accessControlListBean.serializeBean(), dom));
            Integer role = accessControlListBean.getRoleID();
            TRoleBean roleBean = roleMap.get(role);
            if (roleBean != null) {
                //add the roles which are present in the role assignments
                addToAdditionalSerializedLookupsMap(roleBean, ExchangeFieldNames.ROLE,
                        additionalSerializedLookupsMap);
            }
        }
    }

    /**
     * first add the additional serialized entities first because the fieldID mapping is needed by parsing the serialized entities
     */
    Iterator<String> iterator = additionalSerializedLookupsMap.keySet().iterator();
    while (iterator.hasNext()) {
        String entityName = iterator.next();
        Map<Integer, Map<String, String>> lookupEntityMap = additionalSerializedLookupsMap.get(entityName);
        if (lookupEntityMap != null && !lookupEntityMap.isEmpty()) {
            Iterator<Integer> itrObjectID = lookupEntityMap.keySet().iterator();
            while (itrObjectID.hasNext()) {
                Integer objectID = itrObjectID.next();
                Map<String, String> attributes = lookupEntityMap.get(objectID);
                if (attributes != null && !attributes.isEmpty()) {
                    root.appendChild(createElementWithAttributes(entityName, null, false, attributes, dom));
                }
            }
        }
    }

    /**
     * add the serialized entities
     */
    iterator = serializedLookupsMap.keySet().iterator();
    while (iterator.hasNext()) {
        String mergedKey = iterator.next();
        Integer[] parts = MergeUtil.getParts(mergedKey);
        Integer fieldID = parts[0];
        Integer parameterCode = parts[1];
        Map<Integer, Map<String, String>> lookupEntityMap = serializedLookupsMap.get(mergedKey);
        if (lookupEntityMap != null && !lookupEntityMap.isEmpty()) {
            Iterator<Integer> itrObjectID = lookupEntityMap.keySet().iterator();
            while (itrObjectID.hasNext()) {
                Integer objectID = itrObjectID.next();
                Map<String, String> attributes = lookupEntityMap.get(objectID);
                if (attributes != null && !attributes.isEmpty()) {
                    if (fieldID != null) {
                        attributes.put(ExchangeFieldNames.FIELDID, fieldID.toString());
                    }
                    if (parameterCode != null) {
                        attributes.put(ExchangeFieldNames.PARAMETERCODE, parameterCode.toString());
                    }
                    root.appendChild(createElementWithAttributes(ExchangeFieldNames.DROPDOWN_ELEMENT, null,
                            false, attributes, dom));
                }
            }
        }
    }
    return dom;
}

From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToXML.java

public Document convertToDOM(List<ReportBean> items, boolean withHistory, Locale locale, String personName,
        String filterName, String filterExpression, boolean useProjectSpecificID) {
    boolean budgetActive = ApplicationBean.getInstance().getBudgetActive();
    Document dom = null;//w w  w  . j  a v  a 2s  . c om
    try {
        DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
        DocumentBuilder builder = factory.newDocumentBuilder();
        dom = builder.newDocument();
    } catch (FactoryConfigurationError e) {
        LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    } catch (ParserConfigurationException e) {
        LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }
    Element root = dom.createElement("track-report");
    appendChild(root, "createdBy", personName, dom);
    Element filter = dom.createElement("filter");
    appendChild(filter, "name", filterName, dom);
    appendChild(filter, "expression", filterExpression, dom);
    root.appendChild(filter);
    Map<Integer, ILinkType> linkTypeIDToLinkTypeMap = LinkTypeBL.getLinkTypeIDToLinkTypeMap();
    List<TFieldBean> fields = FieldBL.loadAll();
    String issueNoName = null;
    if (useProjectSpecificID) {
        for (Iterator<TFieldBean> iterator = fields.iterator(); iterator.hasNext();) {
            TFieldBean fieldBean = iterator.next();
            if (SystemFields.INTEGER_ISSUENO.equals(fieldBean.getObjectID())) {
                issueNoName = fieldBean.getName();
                break;
            }
        }
    }
    for (Iterator<TFieldBean> iterator = fields.iterator(); iterator.hasNext();) {
        //only one from INTEGER_ISSUENO and INTEGER_PROJECT_SPECIFIC_ISSUENO should be shown
        TFieldBean fieldBean = iterator.next();
        if (useProjectSpecificID) {
            if (SystemFields.INTEGER_ISSUENO.equals(fieldBean.getObjectID())) {
                iterator.remove();
            }
            if (SystemFields.INTEGER_PROJECT_SPECIFIC_ISSUENO.equals(fieldBean.getObjectID())) {
                fieldBean.setName(issueNoName);
            }
        } else {
            if (SystemFields.INTEGER_PROJECT_SPECIFIC_ISSUENO.equals(fieldBean.getObjectID())) {
                iterator.remove();
            }
        }
    }
    String unavailable = LocalizeUtil.getLocalizedTextFromApplicationResources("itemov.lbl.unavailable",
            locale);
    for (ReportBean reportBean : items) {
        Element item = dom.createElement("item");
        TWorkItemBean workItemBean = reportBean.getWorkItemBean();
        for (TFieldBean fieldBean : fields) {
            Integer fieldID = fieldBean.getObjectID();
            String fieldName = fieldBean.getName();
            Object attributeValue = workItemBean.getAttribute(fieldID);
            if (attributeValue != null) {
                IFieldTypeRT fieldTypeRT = FieldTypeManager.getFieldTypeRT(fieldID);
                if (fieldTypeRT != null) {
                    if (fieldTypeRT.isLong()) {
                        String isoValue = (String) reportBean.getShowISOValue(fieldID);
                        if (isoValue != null && !isoValue.equals(unavailable)) {
                            String plainDescription = (String) workItemBean.getAttribute(fieldID);
                            try {
                                plainDescription = Html2Text.getNewInstance().convert((String) attributeValue);
                            } catch (Exception e) {
                                LOGGER.info("Transforming the HTML to plain text for workItemID "
                                        + workItemBean.getObjectID() + " and field " + fieldID + " failed with "
                                        + e);
                            }
                            appendChild(item, fieldName + PLAIN_SUFFIX, plainDescription, dom);
                            appendChild(item, fieldName, HTMLSanitiser.stripHTML((String) attributeValue), dom);
                        }
                    } else {
                        String isoValue = (String) reportBean.getShowISOValue(fieldID);
                        appendChild(item, fieldName, isoValue, dom);
                    }
                    if (fieldTypeRT.getValueType() == ValueType.CUSTOMOPTION || fieldTypeRT.isComposite()) {
                        //add custom list sortOrder
                        appendChild(item,
                                fieldBean.getName()
                                        + TReportLayoutBean.PSEUDO_COLUMN_NAMES.CUSTOM_OPTION_SYMBOL,
                                (String) reportBean.getShowISOValue(Integer.valueOf(-fieldID)), dom);
                    }
                    if (hasExtraSortField(fieldID)) {
                        Comparable sortOrder = reportBean.getSortOrder(fieldID);
                        if (sortOrder != null) {
                            appendChild(item, fieldBean.getName() + TReportLayoutBean.PSEUDO_COLUMN_NAMES.ORDER,
                                    sortOrder.toString(), dom);
                        }
                    }
                }
            }
        }
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.GLOBAL_ITEM_NO,
                workItemBean.getObjectID().toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PROJECT_TYPE, reportBean.getProjectType(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.STATUS_FLAG,
                reportBean.getStateFlag().toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.COMMITTED_DATE_CONFLICT,
                new Boolean(reportBean.isCommittedDateConflict()).toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.TARGET_DATE_CONFLICT,
                new Boolean(reportBean.isTargetDateConflict()).toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PLANNED_VALUE_CONFLICT,
                new Boolean(reportBean.isPlannedValueConflict()).toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_CONFLICT,
                new Boolean(reportBean.isBudgetConflict()).toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.SUMMARY,
                new Boolean(reportBean.isSummary()).toString(), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.INDENT_LEVEL,
                String.valueOf(reportBean.getLevel()), dom);
        String consultants = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.CONSULTANT_LIST);
        if (consultants != null && !"".equals(consultants)) {
            appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.CONSULTANT_LIST, consultants, dom);
        }
        String informed = (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.INFORMANT_LIST);
        if (informed != null && !"".equals(informed)) {
            appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.INFORMANT_LIST, informed, dom);
        }
        String linkedItems = (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.LINKED_ITEMS);
        if (linkedItems != null && !"".equals(linkedItems)) {
            appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.LINKED_ITEMS, linkedItems, dom);
        }
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PRIVATE_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.PRIVATE_SYMBOL), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.OVERFLOW_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.OVERFLOW_ICONS), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.PRIORITY_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.PRIORITY_SYMBOL), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.SEVERITY_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.SEVERITY_SYMBOL), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.STATUS_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.STATUS_SYMBOL), dom);
        appendChild(item, TReportLayoutBean.PSEUDO_COLUMN_NAMES.ISSUETYPE_SYMBOL,
                (String) reportBean.getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.ISSUETYPE_SYMBOL), dom);
        String valueAndMeasurementUnit;
        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_EXPENSE_COST);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_EXPENSE_COST,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_EXPENSE_TIME);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_EXPENSE_TIME,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.MY_EXPENSE_COST);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.MY_EXPENSE_COST,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.MY_EXPENSE_TIME);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.MY_EXPENSE_TIME,
                valueAndMeasurementUnit, dom, item);
        if (budgetActive) {
            valueAndMeasurementUnit = (String) reportBean
                    .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_COST);
            createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_COST,
                    valueAndMeasurementUnit, dom, item);

            valueAndMeasurementUnit = (String) reportBean
                    .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_TIME);
            createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_TIME,
                    valueAndMeasurementUnit, dom, item);
        }
        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_PLANNED_COST);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_PLANNED_COST,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.TOTAL_PLANNED_TIME);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.TOTAL_PLANNED_TIME,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.REMAINING_PLANNED_COST);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.REMAINING_PLANNED_COST,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.REMAINING_PLANNED_TIME);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.REMAINING_PLANNED_TIME,
                valueAndMeasurementUnit, dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_COST);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_COST, valueAndMeasurementUnit,
                dom, item);

        valueAndMeasurementUnit = (String) reportBean
                .getShowISOValue(TReportLayoutBean.PSEUDO_COLUMNS.BUDGET_TIME);
        createComputedValueElement(TReportLayoutBean.PSEUDO_COLUMN_NAMES.BUDGET_TIME, valueAndMeasurementUnit,
                dom, item);

        Element links = createLinkElement(reportBean.getReportBeanLinksSet(), linkTypeIDToLinkTypeMap, locale,
                dom);
        if (links != null) {
            item.appendChild(links);
        }
        if (withHistory) {
            ReportBeanWithHistory reportBeanWithHistory = (ReportBeanWithHistory) reportBean;
            Element historyElement = createHistoryElement(reportBeanWithHistory.getHistoryValuesMap(), dom);
            if (historyElement != null) {
                item.appendChild(historyElement);
            }
            Element commentElement = createCommentElement(reportBeanWithHistory.getComments(), dom);
            if (commentElement != null) {
                item.appendChild(commentElement);
            }
            Element budgetElement = createBudgetElement(reportBeanWithHistory.getBudgetHistory(), dom, locale);
            if (budgetElement != null) {
                item.appendChild(budgetElement);
            }
            Element plannedValueElement = createBudgetElement(reportBeanWithHistory.getPlannedValueHistory(),
                    dom, locale);
            if (plannedValueElement != null) {
                item.appendChild(plannedValueElement);
            }
            if (plannedValueElement != null) {
                //do not add estimated remaining budget element if no budget exists
                Element remainingBudgetElement = createRemainingBudgetElement(
                        reportBeanWithHistory.getActualEstimatedBudgetBean(), dom, locale);
                if (remainingBudgetElement != null) {
                    item.appendChild(remainingBudgetElement);
                }
            }
            Element costElement = createExpenseElement(reportBeanWithHistory.getCosts(), dom, locale);
            if (costElement != null) {
                item.appendChild(costElement);
            }
        }
        root.appendChild(item);
    }
    dom.appendChild(root);
    return dom;
}

From source file:com.aurel.track.admin.customize.category.report.execute.ReportBeansToLaTeXConverter.java

/**
 * Convert the result set into an XML structure.
 *
 * @param items/* w w  w  .  jav a 2s .  c o  m*/
 * @param withHistory
 * @param locale
 * @param personBean
 * @param filterName
 * @param filterExpression
 * @param useProjectSpecificID
 * @param outfileName
 * @return
 */
public Document convertToDOM(List<ReportBean> items, boolean withHistory, Locale locale, TPersonBean personBean,
        String filterName, String filterExpression, boolean useProjectSpecificID, String outfileName) {
    Document doc = null;

    try {

        DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder docBuilder = docFactory.newDocumentBuilder();

        // root elements
        doc = docBuilder.newDocument();
        Element rootElement = doc.createElement("pdfFile");
        doc.appendChild(rootElement);

        // set attribute to staff element
        Attr attr = doc.createAttribute("file");
        outfileName = outfileName.replace(".tex", ".pdf");
        attr.setValue(latexTmpDir + File.separator + outfileName);
        rootElement.setAttributeNode(attr);

    } catch (FactoryConfigurationError e) {
        LOGGER.error("Creating the DOM document failed with FactoryConfigurationError:" + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    } catch (ParserConfigurationException e) {
        LOGGER.error("Creating the DOM document failed with ParserConfigurationException: " + e.getMessage());
        LOGGER.debug(ExceptionUtils.getStackTrace(e));
        return null;
    }

    return doc;
}

From source file:org.apache.fop.complexscripts.fonts.ttx.TTXFile.java

public void parse(File f) {
    assert f != null;
    try {//from   w  w w. j  a  v a2 s . c o m
        SAXParserFactory spf = SAXParserFactory.newInstance();
        SAXParser sp = spf.newSAXParser();
        sp.parse(f, new Handler());
    } catch (FactoryConfigurationError e) {
        throw new RuntimeException(e.getMessage());
    } catch (ParserConfigurationException e) {
        throw new RuntimeException(e.getMessage());
    } catch (SAXException e) {
        throw new RuntimeException(e.getMessage());
    } catch (IOException e) {
        throw new RuntimeException(e.getMessage());
    }
}