TranslationUtils.java 39.2 KB
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739
/*
 * Decompiled with CFR 0_118.
 * 
 * Could not load the following classes:
 *  com.adobe.cq.launches.api.Launch
 *  com.adobe.cq.projects.api.Project
 *  com.adobe.granite.translation.api.TranslationConfig
 *  com.adobe.granite.translation.api.TranslationException
 *  com.adobe.granite.translation.api.TranslationException$ErrorCode
 *  com.adobe.granite.translation.core.MachineTranslationCloudConfig
 *  com.adobe.granite.translation.core.MachineTranslationUtil
 *  com.day.cq.commons.Language
 *  com.day.cq.commons.LanguageUtil
 *  com.day.cq.dam.api.Asset
 *  com.day.cq.dam.commons.util.DamLanguageUtil
 *  com.day.cq.dam.commons.util.DamUtil
 *  com.day.cq.wcm.api.LanguageManager
 *  com.day.cq.wcm.api.Page
 *  com.day.cq.wcm.api.PageManagerFactory
 *  com.day.text.ISO9075
 *  javax.jcr.Node
 *  javax.jcr.NodeIterator
 *  javax.jcr.PathNotFoundException
 *  javax.jcr.Property
 *  javax.jcr.RepositoryException
 *  javax.jcr.Session
 *  javax.jcr.Value
 *  javax.jcr.ValueFactory
 *  javax.jcr.Workspace
 *  javax.jcr.query.Query
 *  javax.jcr.query.QueryManager
 *  javax.jcr.query.QueryResult
 *  org.apache.commons.lang3.StringUtils
 *  org.apache.sling.api.resource.Resource
 *  org.apache.sling.api.resource.ResourceResolver
 *  org.apache.sling.api.resource.ValueMap
 *  org.slf4j.Logger
 */
package com.adobe.cq.wcm.translation.impl;

import com.adobe.cq.launches.api.Launch;
import com.adobe.cq.projects.api.Project;
import com.adobe.cq.wcm.translation.impl.TranslationObjectImpl;
import com.adobe.cq.wcm.translation.impl.TranslationPodImpl;
import com.adobe.granite.translation.api.TranslationConfig;
import com.adobe.granite.translation.api.TranslationException;
import com.adobe.granite.translation.core.MachineTranslationCloudConfig;
import com.adobe.granite.translation.core.MachineTranslationUtil;
import com.day.cq.commons.Language;
import com.day.cq.commons.LanguageUtil;
import com.day.cq.dam.api.Asset;
import com.day.cq.dam.commons.util.DamLanguageUtil;
import com.day.cq.dam.commons.util.DamUtil;
import com.day.cq.wcm.api.LanguageManager;
import com.day.cq.wcm.api.Page;
import com.day.cq.wcm.api.PageManagerFactory;
import com.day.text.ISO9075;
import java.io.BufferedWriter;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.OutputStreamWriter;
import java.io.StringWriter;
import java.io.Writer;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Collection;
import java.util.Date;
import java.util.Map;
import java.util.Set;
import javax.jcr.Node;
import javax.jcr.NodeIterator;
import javax.jcr.PathNotFoundException;
import javax.jcr.Property;
import javax.jcr.RepositoryException;
import javax.jcr.Session;
import javax.jcr.Value;
import javax.jcr.ValueFactory;
import javax.jcr.Workspace;
import javax.jcr.query.Query;
import javax.jcr.query.QueryManager;
import javax.jcr.query.QueryResult;
import javax.xml.transform.Result;
import javax.xml.transform.Source;
import javax.xml.transform.Transformer;
import javax.xml.transform.TransformerException;
import javax.xml.transform.TransformerFactory;
import javax.xml.transform.dom.DOMSource;
import javax.xml.transform.stream.StreamResult;
import org.apache.commons.lang3.StringUtils;
import org.apache.sling.api.resource.Resource;
import org.apache.sling.api.resource.ResourceResolver;
import org.apache.sling.api.resource.ValueMap;
import org.slf4j.Logger;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class TranslationUtils {
    private static final String[] TEMP_STRING_ARRAY = new String[1];
    private static final String ETC_TAGS_PATH = "/etc/tags/";
    public static final long MAX_FILE_IMPORT_SIZE = 314572800;
    public static final long MAX_FILE_UNZIP_SIZE = 629145600;
    public static final String CQ_ASSET_TYPE = "dam:Asset";
    public static final String CQ_SLING_FOLDER = "sling:Folder";
    public static final String CQ_SLING_ORDERED_FOLDER = "sling:OrderedFolder";
    public static final String DEFAULT_CONTENT_CATEGORY = "general";
    public static final String META_LANGUAGE = "language";
    public static final String CQ_TAG_NAME = "cq:tags";
    public static final String CQ_TEMPLATE_TYPE = "cq:template";
    public static final String CQ_LAUNCH_TEMPLATE_OUTOFSCOPE = "/libs/launches/templates/outofscope";
    public static final String CQ_LAUNCH_COMPONENT_OUTOFSCOPE = "launches/components/outofscope";
    public static final String CQ_LAUNCH_SOURCES = "jcr:content/sources";
    public static final String CQ_PROJECT_FOLDER_RESOURCE_TYPE = "cq/gui/components/projects/admin/card/foldercard";
    public static final String CQ_PARAM_TEMPLATE = "cq:template";
    public static final String CQ_PAGE_TYPE = "cq:Page";
    public static final String CQ_TAG_TYPE = "cq:Tag";
    public static final String UTF_8_ENCODING = "UTF-8";
    public static final String JCR_PRIMARY_TYPE = "jcr:primaryType";
    public static final String CQ_LASTMODIFIED = "cq:lastModified";
    public static final String SLING_RESOURCE_TYPE = "sling:resourceType";
    public static final String SLING_RESOURCE_SUPER_TYPE = "sling:resourceSuperType";
    public static final String GUIDE_CONTAINER_LANGUAGE_ARRAY = "languages";
    public static final String GUIDE_CONTAINER_DICTIONARY_ARRAY = "dicts";
    public static final String SLING_MESSAGE = "sling:message";
    public static final String SLING_MESSAGE_ENTRY = "sling:MessageEntry";
    public static final String SLING_KEY = "sling:key";
    public static final String SLING_MESSAGE_MIXIN = "sling:Message";
    public static final String SLING_BASENAME = "sling:basename";
    public static final String CONTENT_PATH = "/content/";
    public static final String APPS_PATH = "/apps/";
    public static final String APPS_I18N_DICT_PARENT_PATH = "/apps/i18n/";
    public static final String MIX_LANGUAGE_TYPE = "mix:language";
    public static final String MIME_APPLICATION_JSON_TYPE = "application/json";
    public static final String EXTENSION_JSON = ".json";
    public static final String EXTENSION_JSP = ".jsp";
    public static final String EXTENSION_HTML = ".html";
    public static final String EXTENSION_JAVASCRIPT = ".js";
    public static final String EXTENSION_HANDLEBARS = ".hbs";
    public static final String ATTRIBUTE_SV_NAME = "sv:name";
    public static final String ELEMENT_SV_PROPERTY = "sv:property";
    public static final String ELEMENT_SV_NODE = "sv:node";
    public static final String GADGETS_NODE_RELATIVE_PATH = "jcr:content/dashboard/gadgets";
    public static final String PROJECT_DUE_DATE = "project.dueDate";
    public static final String PROJECT_PARAMETER_THUMBNAIL = "coverImage";
    public static final String PROJECT_PARAMETER_TEAM_MEMBER_USER_ID = "teamMemberUserId";
    public static final String PROJECT_PARAMETER_TEAM_MEMBER_ROLE_ID = "teamMemberRoleId";
    public static final String ATTRIBUTE_ASSET_REFERENCE_NAME = "assetReferenceAttribute";
    public static final String ATTRIBUTE_RESOURCE_TYPE = "resourceType";
    public static final String ATTRIBUTE_PARENT_REFERENCE_LIST = "parentReferenceList";
    public static final String ATTRIBUTE_INDEPENDENT_OBJECT = "independentObject";
    public static final String ATTRIBUTE_TITLE = "jcr:title";
    public static final String ATTRIBUTE_DESCRIPTION = "jcr:description";
    public static final String ATTRIBUTE_CHILD_PAGES = "child_pages";
    public static final String ATTRIBUTE_CHILD_DATA = "child_data";
    public static final String ATTRIBUTE_COVER_URL = "coverUrl";
    public static final String ATTRIBUTE_ACTIVE = "active";
    public static final String ATTRIBUTE_NAME = "name";
    public static final String ATTRIBUTE_DUE_DATE = "dueDate";
    public static final String ATTRIBUTE_TRANSLATION_OBJECT_ID = "translationObjectID";
    public static final String ATTRIBUTE_DESTINATION_LANGUAGE = "destinationLanguage";
    public static final String ATTRIBUTE_SOURCE_LANGUAGE = "sourceLanguage";
    public static final String ATTRIBUTE_CONTENT_CATEGORY = "contentCategory";
    public static final String ATTRIBUTE_MACHINE_TRANS_PROVIDER = "machineTranslationProvider";
    public static final String ATTRIBUTE_HUMAN_TRANS_PROVIDER = "humanTranslationProvider";
    public static final String ATTRIBUTE_TRANSLATION_PROVIDER = "translationProvider";
    public static final String ATTRIBUTE_TRANSLATION_CLOUD_CONFIG_PATH = "translationCloudConfigPath";
    public static final String ATTRIBUTE_TRANSLATION_CLOUD_CONFIG_NAME = "translationCloudConfigName";
    public static final String ATTRIBUTE_TRANSLATION_METHOD = "translationMethod";
    public static final String ATTRIBUTE_PROJECT_AUTO_CREATED = "translationProjectAutoCreated";
    public static final String ATTRIBUTE_TRANSLATION_ERROR = "translationError";
    public static final String TRANSLATION_ERROR_LANGUAGE_COPY_EXISTS = "LANGUAGE_COPY_EXISTS";
    public static final String TRANSLATION_ERROR_NOTHING_TO_TRANSLATE = "NOTHING_TO_TRANSLATE";
    public static final String ATTRIBUTE_SOURCE_PATH = "sourcePath";
    public static final String ATTRIBUTE_TARGET_PATH = "targetPath";
    public static final String ATTRIBUTE_FILE_TYPE = "fileType";
    public static final String ATTRIBUTE_MIME_TYPE = "mimeType";
    public static final String ATTRIBUTE_IS_EMBEDDED = "isEmbedded";
    public static final String ATTRIBUTE_PARENT_PATH = "parentPath";
    public static final String ATTRIBUTE_TRANSLATION_FILE_TYPE = "translationFileType";
    public static final String ATTRIBUTE_TRANSLATION_IN_PROGRESS = "translationInProgress";
    public static final String ATTRIBUTE_DESTINATION_LANGUAGE_COPY_PATH = "dam:destinationLanguageCopy";
    public static final String ATTRIBUTE_SMART_ASSET_UPDATE_SOURCE = "dam:smartAssetUpdateSource";
    public static final String ATTRIBUTE_SYNC_TRANSLATION_STATE_IN_PROGRESS = "syncTranslationStateInProgress";
    public static final String ATTRIBUTE_SYNC_TRANSLATION_STATE_START_SINCE = "syncTranslationStartSince";
    public static final String ATTRIBUTE_AUTO_EXECUTE_TRANSLATION = "autoExecuteTranslationWorkflow";
    public static final String ATTRIBUTE_SUPPORTING_TRANSLATION_OBJECT_COUNT = "supportedTranslationObjectCount";
    public static final String ATTRIBUTE_SOURCE_VERSION = "sourceVersion";
    public static final String ATTRIBUTE_CURRENT_POLLER_ACTION = "currentPollerAction";
    public static final String ATTRIBUTE_CURRENT_ACTION_IN_PROGRESS = "currentActionInProgress";
    public static final String ATTRIBUTE_JOB_CANCELLATION_PENDING = "jobCancellationPending";
    public static final String ATTRIBUTE_PENDING_CANCELLATION_OBJECT_LIST = "pendingCancellationObjectList";
    public static final String ATTRIBUTE_WORKFLOW_OPERATION_ERROR = "workflowOperationError";
    public static final String ATTRIBUTE_EXPORTED_FILE_CONTENT = "exportNode";
    public static final String ATTRIBUTE_IMPORTED_FILE_CONTENT = "importNode";
    public static final String ATTRIBUTE_CQ_TRANSLATION_PROJECT = "cq:translationProject";
    public static final String ATTRIBUTE_CQ_TRANSLATION_LAST_UPDATE = "cq:lastTranslationUpdate";
    public static final String ATTRIBUTE_CQ_TRANSLATION_METHOD_NAME = "cq:translationMethod";
    public static final String ATTRIBUTE_CQ_TRANSLATION_PROVIDER_NAME = "cq:translationProviderName";
    public static final String ATTRIBUTE_FILE_UNIQUE_ID = "fileUniqueID";
    public static final String ATTRIBUTE_STATUS = "translationStatus";
    public static final String ATTRIBUTE_TRANSLATION_REQUIRED = "translationRequired";
    public static final String ATTRIBUTE_METADATA_TRANSLATION_REQUIRED = "metadataTranslationRequired";
    public static final String ATTRIBUTE_SUPPORTING_OBJECT_TRANSLATION_REQUIRED = "supportingObjectTranslationRequired";
    public static final String ATTRIBUTE_PERCENTAGE_COMPLETE = "percentageComplete";
    public static String ATTRIBUTE_TRANSLATION_MULTI_VALUE = "isMultiValue";
    public static String ATTRIBUTE_TRANSLATION_NODE_PATH = "nodePath";
    public static String ATTRIBUTE_TRANSLATION_PROPERTY_NAME = "propertyName";
    public static String ATTRIBUTE_TRANSLATION_ORDER = "order";
    public static String ATTRIBUTE_TRANSLATION_RELATED_OBJECTS = "relatedTranslationObjects";
    public static final String ATTRIBUTE_SCOPE_COMPLETE = "scopeComplete";
    public static final String ATTRIBUTE_SCOPE_MAP_COUNT = "scopeMapCount";
    public static final String ATTRIBUTE_SCOPE_KEY = "scopeMapKey_%d";
    public static final String ATTRIBUTE_SCOPE_KEY_VALUE = "scopeMapValue_%d";
    public static final String ATTRIBUTE_HIDE_GADGET = "hideGadget";
    public static final String ATTRIBUTE_PAGE_TAG_TRANSLATION = "pageTagTranslation";
    public static final String ATTRIBUTE_ASSET_TAG_TRANSLATION = "assetTagTranslation";
    public static final String LAUNCH_RESOURCE_TYPE_OUT_OF_SCOPE = "launches/components/outofscope";
    public static final String WCM_LAUNCH_RESOURCE_TYPE = "wcm/launches/components/launch";
    public static final String RESOURCE_TYPE_TRANSLATION_OBJECT = "cq/gui/components/projects/admin/card/translation_object";
    public static final String RESOURCE_TYPE_TRANSLATION_JOB = "cq/gui/components/projects/admin/pod/translationjobpod";
    public static final String RESOURCE_TYPE_TRANSLATION_SUMMARY = "cq/gui/components/projects/admin/pod/translationprojectsummarypod";
    public static final String RESOURCE_TYPE_TRANSLATION_SUPPORT = "cq/gui/components/projects/admin/translation";
    public static final String TRANSLATION_SYNC_WORKFLOW_PATH = "/etc/workflow/models/wcm-translation/sync_translation_job/jcr:content/model";
    public static final String TRANSLATION_XML_FILE_TEMPLATE = "<CQTranslationXMLFile/>";
    public static final String TRANSLATION_PROJECT_PATH = "/libs/cq/core/content/projects/templates/create-translation-project";
    public static final String RESOURCE_TYPE_PROJECT_CARD = "cq/gui/components/projects/admin/card/projectcard";
    public static final String PROJECTS_PATH = "/content/projects";
    public static final String TRANSALTION_ASSET_METADATA_FILE_NAME = "translation_asset_metadata.xml";
    public static final String TRANSALTION_TAG_METADATA_FILE_NAME = "translation_tag_metadata.xml";
    public static final String TRANSALTION_COMPONENT_STRINGS_FILE_NAME = "translation_component_strings.xml";
    public static final String INTIAL_PREFIX = "initial_";
    public static final String FINAL_PREFIX = "final_";
    public static String TRANSLATION_OBJECT_FILE_NODE = "translationObjectFile";
    public static String TRANSLATION_OBJECT_PROPERTIES_NODE = "translationObjectProperties";
    public static String TRANSLATION_OBJECT_PROPERTY_NODE = "property";
    public static String TRANSLATION_OBJECT_VALUE_NODE = "value";
    public static final String BACKSLASH = "/";
    public static final String ELEMENT_NODE_NAME = "node";
    public static final String ELEMENT_ASSET_NODE_NAME = "assetNode";
    public static final String ELEMENT_PROPERTY_NAME = "property";
    public static final String ELEMENT_FILTER_NAME = "filter";
    public static final String ATTRIBUTE_PATH = "path";
    public static final String ATTRIBUTE_PATH_CONTAINS = "pathContains";
    public static final String ATTRIBUTE_CONTAINS_PROPERTY = "containsProperty";
    public static final String ATTRIBUTE_PROPERTY_VALUE = "propertyValue";
    public static final String ATTRIBUTE_TRANSLATE = "translate";
    public static final String ATTRIBUTE_UPDATE_DESTINATION_LANGUAGE = "updateDestinationLanguage";
    public static final String ATTRIBUTE_INHERIT = "inherit";
    public static final String ATTRIBUTE_PROPERTY_ISDEEP = "isDeep";
    public static final String PROPERTY_SCHEDULING_FORMAT = "syncTranslationState.schedulingFormat";
    public static final String SCHEDULING_DEFAULT_VALUE = "0 0 1 1/1 * ? *";
    public static final String PROPERTY_SYNC_TIMEOUT_FORMAT = "syncTranslationState.lockTimeoutInMinutes";
    public static final String SYNC_TIMEOUT_DEFAULT_VALUE = "1440";
    public static final String TYPE_JCR_PATH = "JCR_PATH";
    public static final String PARAM_PROJECT_TITLE = "projectTitle";
    public static final String PARAM_PROJECT_TYPE = "projectType";
    public static final String PARAM_PROJECT_PATH = "projectPath";
    public static final String PARAM_PROJECT_FOLDER_PATH = "projectFolderPath";
    public static final String PARAM_PROJECT_FOLDER_LANG_REF_COUNT = "projectFolderLanguageRefCount";
    public static final String PARAM_SOURCE_CONTENT_PATH = "projectSourcePath";
    public static final String PARAM_EXISTING_PROJECT = "add_existing";
    public static final String PARAM_INITIATOR_USER_ID = "initiatorUserId";
    public static final String PARAM_WORKFLOW_CLOUD_CONFIG_PATH = "configuration";
    public static final String PARAM_ADD_ASSET = "addAsset";
    public static final String PARAM_ADD_EMBEDDED_ASSETS = "addEmbeddedAssets";
    public static final String RULES_FILE_PATH = "/etc/workflow/models/translation/translation_rules.xml";
    public static final String VALUE_OWNER_ROLE = "owner";
    public static final String ATTRIBUTE_DELETE_LAUNCH_PAGES = "deleteLaunchPages";
    public static final String TRANSLATION_JOB_SERVICE_USER = "translation-job";
    public static final String TRANSLATION_PROJECT_ADMIN_SERVICE_USER = "translation-project-admin";
    public static final String DO_NOT_RETRY = "noretry";
    public static final String TRANSLATION_REJECTED_COMMENT_ANNOTATION = "translationRejected";
    public static final String EXPORT_FORMAT_FIELD = "export.format";
    public static final String EXPORT_FORMAT_XML = "xml";
    public static final String EXPORT_FORMAT_XLIFF_1_2 = "xliff_1.2";
    public static final String EXPORT_FORMAT_XLIFF_2_0 = "xliff_2.0";

    public static String getStringAttribute(Logger logger, Node node, String strAttributeName, String strDefaultValue) {
        block3 : {
            try {
                Property property;
                if (node.hasProperty(strAttributeName) && (property = node.getProperty(strAttributeName)) != null) {
                    return property.getString();
                }
            }
            catch (RepositoryException ex) {
                if (logger == null) break block3;
                logger.error("Error while fetching string attribute " + strAttributeName, (Throwable)ex);
            }
        }
        return strDefaultValue;
    }

    public static <T> T getAttribute(Resource resource, String strAttributeName, Class<T> type) {
        if (resource != null) {
            ValueMap properties = (ValueMap)resource.adaptTo(ValueMap.class);
            return (T)properties.get(strAttributeName, type);
        }
        return null;
    }

    public static Calendar getCalendarAttribute(Logger logger, Resource resource, String strAttributeName) {
        ValueMap contentVM = (ValueMap)resource.adaptTo(ValueMap.class);
        return (Calendar)contentVM.get(strAttributeName, Calendar.class);
    }

    public static String getMimeTypeAttribute(ResourceResolver resourceResolver, String strNodePath) {
        Node node;
        String strMimeType = null;
        Resource resource = resourceResolver.getResource(strNodePath);
        if (resource != null && (node = (Node)resource.adaptTo(Node.class)) != null) {
            strMimeType = TranslationUtils.getStringAttribute(null, node, "jcr:mimeType", null);
        }
        return strMimeType;
    }

    public static String getResourceType(ResourceResolver resourceResolver, String strNodePath) {
        Resource resource = resourceResolver.getResource(strNodePath);
        return resource.getResourceType();
    }

    public static boolean isContentFragment(Node resourceNode) {
        String contentFragmentProperty = "contentFragment";
        try {
            Node resourceNodeContent;
            if (resourceNode.hasNode("jcr:content") && (resourceNodeContent = resourceNode.getNode("jcr:content")) != null && resourceNodeContent.hasProperty(contentFragmentProperty)) {
                return resourceNodeContent.getProperty(contentFragmentProperty).getBoolean();
            }
        }
        catch (Exception e) {
            // empty catch block
        }
        return false;
    }

    public static String writeToFile(File tempDir, String strFileName, String strExtension, String strOutput) throws IOException {
        File file = new File(tempDir, strFileName + strExtension);
        file.getParentFile().mkdirs();
        if (!file.exists()) {
            file.createNewFile();
        }
        OutputStreamWriter osw = new OutputStreamWriter((OutputStream)new FileOutputStream(file.getAbsoluteFile()), "UTF-8");
        BufferedWriter bw = new BufferedWriter(osw);
        bw.write(strOutput);
        bw.close();
        return file.getAbsolutePath();
    }

    /*
     * WARNING - Removed try catching itself - possible behaviour change.
     */
    public static void writeStreamToFile(File destFile, InputStream inputStream) throws IOException {
        try {
            byte[] buffer = new byte[8192];
            FileOutputStream output = new FileOutputStream(destFile.getAbsolutePath());
            try {
                int bytesRead;
                while ((bytesRead = inputStream.read(buffer)) != -1) {
                    output.write(buffer, 0, bytesRead);
                }
            }
            finally {
                output.close();
            }
        }
        finally {
            inputStream.close();
        }
    }

    public static String writeToFile(File tempDir, String strFileName, String strExtension, InputStream stream) throws IOException {
        File file = new File(tempDir, strFileName + strExtension);
        file.getParentFile().mkdirs();
        if (!file.exists()) {
            file.createNewFile();
        }
        TranslationUtils.writeStreamToFile(file, stream);
        return file.getAbsolutePath();
    }

    public static boolean isTranslationProject(Project project) throws PathNotFoundException, RepositoryException {
        Property prop;
        Node projectJCRNode;
        boolean bRetVal = false;
        Resource projectResource = (Resource)project.adaptTo(Resource.class);
        Resource projectJCRResource = projectResource.getChild("jcr:content");
        if (projectJCRResource != null && (projectJCRNode = (Node)projectJCRResource.adaptTo(Node.class)) != null && projectJCRNode.hasProperty("cq:template") && (prop = projectJCRNode.getProperty("cq:template")) != null && "/libs/cq/core/content/projects/templates/create-translation-project".equals(prop.getString())) {
            bRetVal = true;
        }
        return bRetVal;
    }

    public static Calendar parseDate(String dueDateString) throws ParseException {
        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss");
        Date dueDate = formatter.parse(dueDateString);
        Calendar cal = null;
        if (dueDate != null) {
            cal = Calendar.getInstance();
            cal.setTime(dueDate);
        }
        return cal;
    }

    public static boolean isETCTagsPath(String nodePath) {
        return nodePath != null && nodePath.indexOf("/etc/tags/") != -1;
    }

    public static MachineTranslationCloudConfig getMachineCloudConfigFromResource(MachineTranslationUtil mtu, Resource pageResource) {
        Launch topLaunch;
        MachineTranslationCloudConfig retVal = null;
        if (mtu != null && (retVal = mtu.getAppliedMachineTranslationCloudConfigs(pageResource)) == null && (topLaunch = TranslationUtils.getLaunchFromResource(pageResource)) != null) {
            Resource sourceRootResource = topLaunch.getSourceRootResource();
            retVal = mtu.getAppliedMachineTranslationCloudConfigs(sourceRootResource);
        }
        return retVal;
    }

    public static Resource getSourceResourceFromLaunch(Resource pageResource) {
        Launch launch;
        Resource retVal = pageResource;
        if (pageResource != null && (launch = TranslationUtils.getLaunchFromResource(pageResource)) != null) {
            Resource rootResource = launch.getSourceRootResource();
            String strRelativePath = pageResource.getPath().substring(launch.getResource().getPath().length());
            retVal = rootResource.getChild(strRelativePath);
        }
        return retVal;
    }

    public static String getNodeResourceType(Logger logger, Node node, String strDefaultValue) {
        return TranslationUtils.getStringAttribute(logger, node, "sling:resourceType", strDefaultValue);
    }

    public static Launch getLaunchFromResource(Resource pageResource) {
        Launch retVal = null;
        if (pageResource != null && (retVal = (Launch)pageResource.adaptTo(Launch.class)) == null) {
            retVal = TranslationUtils.getLaunchFromResource(pageResource.getParent());
        }
        return retVal;
    }

    public static boolean isAssetNode(Resource pageResource) throws RepositoryException {
        boolean bRetVal = false;
        if (pageResource != null) {
            Asset damAsset = (Asset)pageResource.adaptTo(Asset.class);
            boolean bl = bRetVal = damAsset != null;
            if (!bRetVal) {
                bRetVal = TranslationUtils.isBinaryNode((Node)pageResource.adaptTo(Node.class));
            }
        }
        return bRetVal;
    }

    public static String getResourceLanguage(ResourceResolver resourceResolver, Resource resource, LanguageManager languageManager) {
        String strRetVal = null;
        Language lang = languageManager.getCqLanguage(resource);
        if (lang != null) {
            strRetVal = lang.toString();
        }
        return strRetVal;
    }

    public static String getResourceLanguageRoot(Resource resource) {
        String langRoot = LanguageUtil.getLanguageRoot((String)resource.getPath());
        if (langRoot != null) {
            return langRoot.substring(langRoot.lastIndexOf(47) + 1);
        }
        return "";
    }

    public static boolean isBinaryNode(ResourceResolver resourceResolver, String strNodePath) throws RepositoryException {
        Resource resource = resourceResolver.getResource(strNodePath);
        if (resource != null) {
            return TranslationUtils.isBinaryNode((Node)resource.adaptTo(Node.class));
        }
        return false;
    }

    public static boolean isBinaryNode(Node node) throws RepositoryException {
        Property prop;
        boolean bBinaryNode = false;
        if (node != null && node.hasProperty("jcr:data") && (prop = node.getProperty("jcr:data")) != null && prop.getType() == 2) {
            bBinaryNode = true;
        }
        return bBinaryNode;
    }

    public static String getFileExtension(String strFileName, String strMimeType) {
        int index;
        String strExtension = "";
        if (strFileName != null) {
            index = strFileName.lastIndexOf("/");
            if (index != -1) {
                strFileName = strFileName.substring(index);
            }
            if ((index = strFileName.lastIndexOf(".")) != -1) {
                strExtension = strFileName.substring(index);
            }
        }
        if (StringUtils.isEmpty((CharSequence)strExtension) && !StringUtils.isEmpty((CharSequence)strMimeType) && (index = strMimeType.lastIndexOf("/")) != -1) {
            strExtension = "." + strMimeType.substring(index + 1);
        }
        return strExtension;
    }

    public static <E> E[] getArrayFromArrayList(ArrayList<E> arrayList, E[] inputArray) {
        return arrayList.toArray(inputArray);
    }

    public static String[] getStringArray(ArrayList<String> strOutputArray) {
        return TranslationUtils.getArrayFromArrayList(strOutputArray, TEMP_STRING_ARRAY);
    }

    public static boolean isDestinationLanguageSupported(String strDestinationLanguage, TranslationConfig transConfig) throws TranslationException {
        boolean bRetVal = false;
        if (transConfig != null) {
            Map availableLanguageMap = transConfig.getLanguages();
            if (availableLanguageMap.containsKey(strDestinationLanguage)) {
                bRetVal = true;
            } else {
                for (String code : availableLanguageMap.keySet()) {
                    if (StringUtils.equalsIgnoreCase((CharSequence)strDestinationLanguage, (CharSequence)code)) {
                        bRetVal = true;
                        break;
                    }
                    if (!StringUtils.equalsIgnoreCase((CharSequence)strDestinationLanguage, (CharSequence)((CharSequence)availableLanguageMap.get(code)))) continue;
                    bRetVal = true;
                    break;
                }
            }
        }
        return bRetVal;
    }

    public static boolean checkFileExtension(Node node, String extension) {
        try {
            return node.isNodeType("nt:file") && StringUtils.endsWithIgnoreCase((CharSequence)node.getPath(), (CharSequence)extension);
        }
        catch (RepositoryException ignored) {
            return false;
        }
    }

    public static String convertDOMDocumentToString(Document doc, boolean bXMLFormat) throws TransformerException {
        TransformerFactory tf = TransformerFactory.newInstance();
        if (bXMLFormat) {
            tf.setFeature("http://javax.xml.XMLConstants/feature/secure-processing", true);
        }
        Transformer transformer = tf.newTransformer();
        if (bXMLFormat) {
            transformer.setOutputProperty("indent", "yes");
            transformer.setOutputProperty("encoding", "UTF-8");
            transformer.setOutputProperty("{http://xml.apache.org/xslt}indent-amount", "2");
            doc.setXmlStandalone(true);
        }
        StringWriter writer = new StringWriter();
        transformer.transform(new DOMSource(doc), new StreamResult(writer));
        return writer.getBuffer().toString();
    }

    public static boolean isPageNode(Resource pageResource) {
        boolean bRetVal = false;
        if (pageResource != null) {
            Page page = (Page)pageResource.adaptTo(Page.class);
            bRetVal = page != null;
        }
        return bRetVal;
    }

    public static boolean isFolderNode(Resource resource) {
        boolean bRetVal = false;
        if (resource != null) {
            String strType = resource.getResourceType();
            bRetVal = "sling:Folder".equals(strType) || "sling:OrderedFolder".equals(strType);
        }
        return bRetVal;
    }

    public static void updateLastModifiedTime(Page page) throws RepositoryException {
        Node contentNode;
        Resource contentResource;
        if (page != null && (contentResource = page.getContentResource()) != null && (contentNode = (Node)contentResource.adaptTo(Node.class)) != null) {
            Calendar lastModified = Calendar.getInstance();
            contentNode.setProperty("cq:lastModified", lastModified);
        }
    }

    public static NodeIterator getAllNtFilesAtPath(ResourceResolver resolver, String path, Logger logger) {
        logger.trace("In function: getAllNtFilesAtPath path:{}", (Object)path);
        try {
            Session session = (Session)resolver.adaptTo(Session.class);
            QueryManager qm = session.getWorkspace().getQueryManager();
            QueryResult result = qm.createQuery("/jcr:root" + ISO9075.encodePath((String)path) + "//element(*, " + "nt:file" + ")", "xpath").execute();
            return result.getNodes();
        }
        catch (RepositoryException e) {
            logger.error("Can't get nt:file from {}", (Object)path, (Object)e);
            return null;
        }
    }

    public static boolean isContentFragmentVariationNode(org.w3c.dom.Node node) {
        boolean bRetVal = false;
        if (node != null && TRANSLATION_OBJECT_PROPERTY_NODE.equals(node.getNodeName())) {
            Element childElement = (Element)node;
            String propertyName = childElement.getAttribute(ATTRIBUTE_TRANSLATION_PROPERTY_NAME);
            bRetVal = propertyName.equals("nt:file");
        }
        return bRetVal;
    }

    public static void addOrUpdateRelatedTranslationObjectsProperty(TranslationObjectImpl translationObject, ArrayList<TranslationObjectImpl> relatedObjectArray, ValueFactory valueFactory) throws RepositoryException {
        String translationObjectPath = translationObject.getPath();
        ArrayList<String> relatedObjectPaths = new ArrayList<String>();
        for (TranslationObjectImpl relatedObject : relatedObjectArray) {
            Node currentNode = relatedObject.getNode();
            TranslationUtils.addOrUpdateMultiValueProperty(currentNode, ATTRIBUTE_TRANSLATION_RELATED_OBJECTS, valueFactory, translationObjectPath);
            relatedObjectPaths.add(relatedObject.getPath());
        }
        String[] relatedObjectsArray = new String[relatedObjectPaths.size()];
        relatedObjectPaths.toArray(relatedObjectsArray);
        TranslationUtils.addOrUpdateMultiValueProperty(translationObject.getNode(), ATTRIBUTE_TRANSLATION_RELATED_OBJECTS, valueFactory, relatedObjectsArray);
    }

    private static void addOrUpdateMultiValueProperty(Node currentNode, String property, ValueFactory valueFactory, String newValue) throws RepositoryException {
        Value[] newValues = new Value[]{valueFactory.createValue(newValue)};
        TranslationUtils.addOrUpdateMultiValueProperty(currentNode, property, newValues);
    }

    private static void addOrUpdateMultiValueProperty(Node currentNode, String property, ValueFactory valueFactory, String[] newStringValues) throws RepositoryException {
        ArrayList<Value> newValuesList = new ArrayList<Value>();
        for (String stringValue : newStringValues) {
            newValuesList.add(valueFactory.createValue(stringValue));
        }
        Value[] newValues = new Value[newStringValues.length];
        newValuesList.toArray((T[])newValues);
        TranslationUtils.addOrUpdateMultiValueProperty(currentNode, property, newValues);
    }

    private static void addOrUpdateMultiValueProperty(Node currentNode, String property, Value[] newValues) throws RepositoryException {
        if (currentNode.hasProperty(property)) {
            Property currentProperty = currentNode.getProperty(property);
            Value[] currentPropertyValues = currentProperty.getValues();
            ArrayList<Value> updatedValues = new ArrayList<Value>();
            updatedValues.addAll(Arrays.asList(currentPropertyValues));
            for (Value value : newValues) {
                if (updatedValues.contains((Object)value)) continue;
                updatedValues.add(value);
            }
            currentNode.setProperty(property, updatedValues.toArray((T[])new Value[updatedValues.size()]), currentProperty.getType());
        } else {
            currentNode.setProperty(property, newValues);
        }
    }

    public static void updateTemporaryAsset(TranslationObjectImpl translationObject, ResourceResolver resourceResolver, TranslationPodImpl translationPod, Session userSession, PageManagerFactory pageManagerFactory) throws RepositoryException, TranslationException {
        String translationPodPath;
        String updateAssetPath = translationObject.getStringAttribute("sourcePath");
        if (updateAssetPath != null && updateAssetPath.startsWith((translationPodPath = translationPod.getPath()) + "/content/dam")) {
            String destinationPath = null;
            Resource updateAssetResource = resourceResolver.getResource(updateAssetPath);
            if (null != updateAssetResource) {
                Node content;
                Node updateAssetNode = (Node)updateAssetResource.adaptTo(Node.class);
                if (null != updateAssetNode && updateAssetNode.hasNode("jcr:content") && (content = updateAssetNode.getNode("jcr:content")).hasProperty("dam:destinationLanguageCopy")) {
                    destinationPath = content.getProperty("dam:destinationLanguageCopy").getString();
                }
                if (DamUtil.isAsset((Resource)resourceResolver.getResource(destinationPath))) {
                    DamLanguageUtil.replaceUpdatedAsset((String)updateAssetPath, (String)destinationPath, (Session)userSession, (PageManagerFactory)pageManagerFactory, (ResourceResolver)resourceResolver);
                } else {
                    throw new TranslationException("Destination Asset Language copy does not exist", TranslationException.ErrorCode.MISSING_PARAMETER);
                }
            }
        }
    }

    public static String getUpdateAssetDestinationNodePath(Node temporaryNode) throws RepositoryException {
        Node content;
        String destinationLanguageCopyPath = null;
        if (null != temporaryNode && temporaryNode.hasNode("jcr:content") && (content = temporaryNode.getNode("jcr:content")).hasProperty("dam:destinationLanguageCopy")) {
            destinationLanguageCopyPath = content.getProperty("dam:destinationLanguageCopy").getString();
        }
        return destinationLanguageCopyPath;
    }

    public static boolean isSmartUpdateRequired(Asset sourceAsset, Asset destinationAsset) {
        return sourceAsset.getLastModified() > destinationAsset.getLastModified();
    }

    public static void addSmartAssetUpdateSource(Asset destinationAsset, String sourcePath) throws RepositoryException {
        Node assetNode = (Node)destinationAsset.adaptTo(Node.class);
        if (!assetNode.hasNode("jcr:content")) {
            assetNode.addNode("jcr:content", "nt:unstructured");
        }
        Node assetContentNode = assetNode.getNode("jcr:content");
        assetContentNode.setProperty("dam:smartAssetUpdateSource", sourcePath);
    }

    public static String getSmartUpdateAssetNodeSourcePath(Node node) throws RepositoryException {
        Node assetContentNode;
        if (node.isNodeType("dam:Asset") && node.hasNode("jcr:content") && (assetContentNode = node.getNode("jcr:content")).hasProperty("dam:smartAssetUpdateSource")) {
            return assetContentNode.getProperty("dam:smartAssetUpdateSource").getValue().getString();
        }
        return null;
    }

    public static Node getSmartUpdateAssetNode(Node node, ResourceResolver resourceResolver, PageManagerFactory pageManagerFactory, String destinationLanguage, String translationPodPath) throws RepositoryException {
        Node smartUpdateAssetNode = null;
        String smartUpdateAssetNodeSource = TranslationUtils.getSmartUpdateAssetNodeSourcePath(node);
        if (smartUpdateAssetNodeSource != null) {
            String smartUpdateAssetNodePath = DamLanguageUtil.createUpdateLanguageCopy((ResourceResolver)resourceResolver, (PageManagerFactory)pageManagerFactory, (String)smartUpdateAssetNodeSource, (String)destinationLanguage, (String)translationPodPath);
            smartUpdateAssetNode = (Node)resourceResolver.getResource(smartUpdateAssetNodePath).adaptTo(Node.class);
            TranslationUtils.deleteSmartUpdateAssetNodeSourcePath(node, resourceResolver);
        }
        return smartUpdateAssetNode;
    }

    public static void deleteSmartUpdateAssetNodeSourcePath(Node node, ResourceResolver resourceResolver) throws RepositoryException {
        Node assetContentNode;
        if (node.isNodeType("dam:Asset") && node.hasNode("jcr:content") && (assetContentNode = node.getNode("jcr:content")).hasProperty("dam:smartAssetUpdateSource")) {
            assetContentNode.getProperty("dam:smartAssetUpdateSource").remove();
        }
        Session session = (Session)resourceResolver.adaptTo(Session.class);
        session.save();
    }

    public static boolean isTemporaryAssetNode(Node node) throws RepositoryException {
        Node assetContentNode;
        if (null != node && node.isNodeType("dam:Asset") && node.hasNode("jcr:content") && (assetContentNode = node.getNode("jcr:content")).hasProperty("dam:destinationLanguageCopy")) {
            return true;
        }
        return false;
    }
}