/* (non-Javadoc)
@see com.ibm.g11n.pipeline.client.ServiceClient#getXliffFromDocuments(java.lang.String, java.lang.String, java.util.Map, java.io.OutputStream)
431964
@Override
    public void getXliffFromDocuments(String srcLanguage, String trgLanguage,
            Map<DocumentType, Set<String>> documentsMap,
            OutputStream outputXliff) throws ServiceException, IOException {

        if (srcLanguage == null || srcLanguage.isEmpty()) {
            throw new IllegalArgumentException("Non-empty srcLanguage must be specified.");
        }
        if (trgLanguage == null || trgLanguage.isEmpty()) {
            throw new IllegalArgumentException("Non-empty trgLanguage must be specified.");
        }

        StringBuilder urlBuf = new StringBuilder();
        urlBuf
            .append(escapePathSegment(account.getInstanceId()))
            .append("/v2/doc-xliff/")
            .append(srcLanguage)
            .append("/")
            .append(trgLanguage);

        if (documentsMap != null && !documentsMap.isEmpty()) {
            urlBuf.append("?");
            int count = documentsMap.size();
            for (Map.Entry<DocumentType, Set<String>> entry : documentsMap.entrySet()) {
                DocumentType type = entry.getKey();
                Set<String> documentIds = entry.getValue();
                urlBuf.append(type.toString().toLowerCase()).append("=");
                boolean first = true;
                for (String docId : documentIds) {
                    if (first) {
                        first = false;
                    } else {
                        urlBuf.append(",");
                    }
                    urlBuf.append(docId);
                }
                count--;
            }
            if (count != 0) {
                urlBuf.append("&");
            }
        }

        ApiResponse resp = null;
        try {
            resp = invokeApi("GET", urlBuf.toString(), null, null, false);
        } catch (Exception e) {
            String errMsg = "Error while processing API request GET " + urlBuf;
            throw new ServiceException(errMsg, e);
        }
        assert resp != null;

        if (resp.contentType == null || !resp.contentType.equalsIgnoreCase("application/xliff+xml")) {
            throw new ServiceException("Received HTTP status: " + resp.status
                    + " with non-XLIFF response (" + resp.contentType + ") from GET"
                    + " " + urlBuf.toString());
        }
        assert resp.body != null;
        outputXliff.write(resp.body);
    }
319595
function getXmlElementFromRawIndexes(root, indexInfo) {
  let parentPackage = root;
  for (let j = 0; j < indexInfo.path.length; j++) {
    parentPackage = parentPackage.packagedElement[indexInfo.path[j]];
  }
  return parentPackage.packagedElement[indexInfo.index];
}
849302
@SuppressWarnings("unchecked")
	@Override
	public Collection<String> getCopyFields() {

		Indexed indexedAnnotation = getIndexAnnotation();
		if (indexedAnnotation != null && indexedAnnotation.copyTo().length > 0) {
			return CollectionUtils.arrayToList(indexedAnnotation.copyTo());
		}
		return Collections.emptyList();
	}
1041592
static KAFDocument load(Reader stream) throws IOException, JDOMException, KAFNotValidException {
	SAXBuilder builder = new SAXBuilder();
	Document document = (Document) builder.build(stream);
	Element rootElem = document.getRootElement();
	return DOMToKAF(document);
    }
927720
public static String getSREAsXML(ISREInstall sre) throws CoreException {
		try {
			final DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
			final DocumentBuilder builder = factory.newDocumentBuilder();
			final Document xmldocument = builder.newDocument();

			final Element sreNode = xmldocument.createElement("SRE"); //$NON-NLS-1$
			sreNode.setAttribute("platform", Boolean.toString(isPlatformSRE(sre))); //$NON-NLS-1$
			sreNode.setAttribute("id", sre.getId()); //$NON-NLS-1$
			sreNode.setAttribute("class", sre.getClass().getName()); //$NON-NLS-1$
			sre.getAsXML(xmldocument, sreNode);
			xmldocument.appendChild(sreNode);

			final TransformerFactory transFactory = TransformerFactory.newInstance();
			final Transformer trans = transFactory.newTransformer();
			try (ByteArrayOutputStream baos = new ByteArrayOutputStream()) {
				final DOMSource source = new DOMSource(xmldocument);
				final PrintWriter flot = new PrintWriter(baos);
				final StreamResult xmlStream = new StreamResult(flot);
				trans.transform(source, xmlStream);
				return new String(baos.toByteArray());
			}
		} catch (Throwable e) {
			throw new CoreException(SARLEclipsePlugin.getDefault().createStatus(IStatus.ERROR, e));
		}
	}
856518
static Document loadDocument(Resource xmlFile) throws SAXException, IOException {
	InputStream is = null;
	try {
	    return _loadDocument(is = IOUtil.toBufferedInputStream(xmlFile.getInputStream()));
	}
	finally {
	    IOUtil.closeEL(is);
	}
    }
93575
private static Document _loadDocument(InputStream is) throws SAXException, IOException {
	InputSource source = new InputSource(is);

	return XMLUtil.parse(source, null, false);
    }
436967
public static boolean list2Xls(List<?> list, String xmlPath, OutputStream outputStream) throws Exception {
        try {
            ExcelConfig config = getEasyExcel(xmlPath);
            return list2Xls(config, list, outputStream);
        } catch (Exception e1) {
            return false;
        }
    }
591169
public Path getTransformedXSLTPath(FileModel payload)
    {
        ReportService reportService = new ReportService(getGraphContext());
        Path outputPath = reportService.getReportDirectory();
        outputPath = outputPath.resolve(this.getRelativeTransformedXSLTPath(payload));
        if (!Files.isDirectory(outputPath))
        {
            try
            {
                Files.createDirectories(outputPath);
            }
            catch (IOException e)
            {
                throw new WindupException("Failed to create output directory at: " + outputPath + " due to: "
                            + e.getMessage(), e);
            }
        }
        return outputPath;
    }
2131
public String getSortedXml(Document newDocument) {
        try (ByteArrayOutputStream sortedXml = new ByteArrayOutputStream()) {
            BufferedLineSeparatorOutputStream bufferedLineOutputStream =
                    new BufferedLineSeparatorOutputStream(lineSeparatorUtil.toString(), sortedXml);

            XMLOutputter xmlOutputter = new PatchedXMLOutputter(bufferedLineOutputStream, indentBlankLines);
            xmlOutputter.setFormat(createPrettyFormat());
            xmlOutputter.output(newDocument, bufferedLineOutputStream);

            bufferedLineOutputStream.close();
            return sortedXml.toString(encoding);
        } catch (IOException ioex) {
            throw new FailureException("Could not format pom files content", ioex);
        }
    }
148121
public static XlsxWorkbook getWorkbook(InputStream stream) throws IOException
    {
        try
        {
            return new XlsxWorkbook(stream);
        }
        catch(Docx4JException e)
        {
            throw new IOException(e);
        }
    }
477645
public Result<String> extractRawText(InputStream stream) throws IOException {
        return new InternalDocumentConverter(options).extractRawText(stream).toResult();
    }
432309
private static DocumentType getDocType(final InputStream body)
        throws IOException {
        final DocumentBuilderFactory factory =
            DocumentBuilderFactory.newInstance();
        try {
            factory.setFeature(RsPrettyXml.LOAD_EXTERNAL_DTD, false);
            final DocumentBuilder builder = factory.newDocumentBuilder();
            return builder.parse(body).getDoctype();
        } catch (final ParserConfigurationException | SAXException ex) {
            throw new IOException(ex);
        }
    }
1257244
private Document getFogbugzDocument(Map<String, String> parameters) throws IOException, ParserConfigurationException, SAXException {
        URL uri = new URL(this.mapToFogbugzUrl(parameters));
        HttpURLConnection con = (HttpURLConnection) uri.openConnection();
        DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
        DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
        return dBuilder.parse(con.getInputStream());
    }
99765
static OutputStream toXlsxFile(final IDataModel dataModel) {
        ByteArrayOutputStream xlsx = new ByteArrayOutputStream();
        
        try { toWorkbook(dataModel, (Workbook) null).write(xlsx); }
        catch (IOException e) { throw new CalculationEngineException(e); }
        
        return xlsx;
    }
356258
public static String[] getXlsxWorksheets(File file) 
        throws IOException
    {
        XlsxWorkbook workbook = XlsxWorkbook.getWorkbook(file);
        String[] sheets = workbook.getSheetNames();
        workbook.close();
        return sheets;
    }
705098
@Override
    public Map<String, DocumentTranslationRequestData> getDocumentTranslationRequests()
            throws ServiceException {

        GetDocumentTranslationRequestsResponse resp = invokeApiJson(
                "GET",
                escapePathSegment(account.getInstanceId()) + "/v2/doc-trs",
                null,
                GetDocumentTranslationRequestsResponse.class);

        if (resp.getStatus() == Status.ERROR) {
            throw new ServiceException(resp.getMessage());
        }

        Map<String, DocumentTranslationRequestData> resultTRs = new TreeMap<>();
        for (Entry<String, RestDocumentTranslationRequest> trEntry : resp.translationRequests.entrySet()) {
            String id = trEntry.getKey();
            RestDocumentTranslationRequest tr = trEntry.getValue();
            resultTRs.put(id, new DocumentTranslationRequestDataImpl(id, tr));
        }

        return resultTRs;
    
    }