/*
(non-Javadoc)

@see com.ibm.ws.wim.xpath.util.XPathTranslateHelper#genSearchString(java.lang.StringBuffer, com.ibm.ws.wim.xpath.mapping.datatype.LogicalNode)
429827
private void genSearchString(StringBuffer searchExpBuffer, LogicalNode logicalNode) throws WIMException {
        boolean write = false;

        if (logOps.isEmpty()) {
            write = true;
            logOps.push(logicalNode.getOperator());
        } else if ((logOps.peek()) != logicalNode.getOperator()) {
            write = true;
            logOps.push(logicalNode.getOperator());
        }

        if (write) {
            if (logicalNode.getOperator().equals(XPathLogicalNode.OP_AND)) {

                searchExpBuffer.append("(&");
            } else {
                searchExpBuffer.append("(|");
            }
        }

        genStringChild(searchExpBuffer, (XPathNode) logicalNode.getLeftChild());
        genStringChild(searchExpBuffer, (XPathNode) logicalNode.getRightChild());

        if (write) {
            searchExpBuffer.append(')');
            logOps.pop();
        }

    }
857209
public static List<String> selectNodeValues(Node node, String xpathQuery, Map<String, String> namespaceUris) {
        List<Node> resultNodes = selectNodes(node, xpathQuery, namespaceUris);

        return extractNodeValues(resultNodes);
    }
273178
public static void generateResourceTypeXml(
        Element startNode,
        List<I_CmsResourceType> resourceTypes,
        boolean module) {

        for (int i = 0; i < resourceTypes.size(); i++) {
            I_CmsResourceType resType = resourceTypes.get(i);
            // only add this resource type to the xml output, if it is no additional type defined
            // in a module
            if (resType.isAdditionalModuleResourceType() == module) {
                Element resourceType = startNode.addElement(N_TYPE).addAttribute(A_CLASS, resType.getClassName());
                // add type id and type name
                resourceType.addAttribute(A_NAME, resType.getTypeName());
                resourceType.addAttribute(A_ID, String.valueOf(resType.getTypeId()));
                // add resource mappings
                List<String> mappings = resType.getConfiguredMappings();
                if ((mappings != null) && (mappings.size() > 0)) {
                    Element mappingsNode = resourceType.addElement(N_MAPPINGS);
                    for (int j = 0; j < mappings.size(); j++) {
                        Element mapping = mappingsNode.addElement(N_MAPPING);
                        mapping.addAttribute(A_SUFFIX, mappings.get(j));
                    }
                }
                // add default properties
                List<CmsProperty> properties = resType.getConfiguredDefaultProperties();
                if (properties != null) {
                    if (properties.size() > 0) {
                        Element propertiesNode = resourceType.addElement(N_PROPERTIES);
                        Iterator<CmsProperty> p = properties.iterator();
                        while (p.hasNext()) {
                            CmsProperty property = p.next();
                            Element propertyNode = propertiesNode.addElement(N_PROPERTY);
                            propertyNode.addElement(N_NAME).addText(property.getName());
                            if (property.getStructureValue() != null) {
                                propertyNode.addElement(N_VALUE).addCDATA(property.getStructureValue());
                            }
                            if (property.getResourceValue() != null) {
                                propertyNode.addElement(N_VALUE).addAttribute(A_TYPE, CmsProperty.TYPE_SHARED).addCDATA(
                                    property.getResourceValue());
                            }
                        }
                    }
                }
                // add copy resources
                List<CmsConfigurationCopyResource> copyRes = resType.getConfiguredCopyResources();
                if ((copyRes != null) && (copyRes.size() > 0)) {
                    Element copyResNode = resourceType.addElement(N_COPY_RESOURCES);
                    Iterator<CmsConfigurationCopyResource> p = copyRes.iterator();
                    String adjustLinksFolder = resType.getAdjustLinksFolder();
                    if (adjustLinksFolder != null) {
                        copyResNode.addAttribute(A_ADJUST_LINKS_FOLDER, adjustLinksFolder);
                    }
                    while (p.hasNext()) {
                        CmsConfigurationCopyResource cRes = p.next();
                        Element cNode = copyResNode.addElement(N_COPY_RESOURCE);
                        cNode.addAttribute(A_SOURCE, cRes.getSource());
                        if (!cRes.isTargetWasNull()) {
                            cNode.addAttribute(A_TARGET, cRes.getTarget());
                        }
                        if (!cRes.isTypeWasNull()) {
                            cNode.addAttribute(A_TYPE, cRes.getTypeString());
                        }
                    }
                }
                // add optional parameters
                CmsParameterConfiguration configuration = resType.getConfiguration();
                if (configuration != null) {
                    List<String> ignore = null;
                    if ((resType instanceof CmsResourceTypeXmlContainerPage)) {
                        ignore = new ArrayList<String>(1);
                        ignore.add(CmsResourceTypeXmlContent.CONFIGURATION_SCHEMA);
                    }
                    configuration.appendToXml(resourceType, ignore);
                }
            }
        }
    }
377355
private static void checkStringExprNode(@Nullable Node node) {
    if (node == null) {
      throw new IllegalArgumentException("Expected a string; found: null");
    }
    switch (node.getToken()) {
      case STRING:
      case TEMPLATELIT:
        break;
      case ADD:
        Node c = node.getFirstChild();
        checkStringExprNode(c);
        checkStringExprNode(c.getNext());
        break;
      default:
        throw new IllegalArgumentException("Expected a string; found: " + node.getToken());
    }
  }
954979
private void menuGoToFileActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_menuGoToFileActionPerformed
    final GoToFilePanel panel = new GoToFilePanel(this.explorerTree, JOptionPane.OK_OPTION);
    if (DialogProviderManager.getInstance().getDialogProvider().msgOkCancel(null, "Go To File", panel)) {
      final NodeFileOrFolder selected = panel.getSelected();
      if (selected != null) {
        final File file = selected.makeFileForNode();
        if (file != null) {
          this.focusInTree(file);
          ensureTreePanelVisible();
          SwingUtilities.invokeLater(() -> {
            explorerTree.requestFocus();
          });
        }
      }
    }
  }
495972
private void menuValidateBodyActionPerformed(java.awt.event.ActionEvent evt) {// GEN-FIRST:event_menuValidateBodyActionPerformed
		final MappingValidationDialog outputField = new MappingValidationDialog(mappingsTree);

		outputField.setLocationRelativeTo(getParent());
		Runnable action = () -> {
            canceled = false;
            final List path = mappingList.getSelectedValuesList();
            if (path == null) {
                JOptionPane.showMessageDialog(MappingManagerPanel.this, "Select at least one mapping");
                return;
            }
            outputField.addText("Validating " + path.size() + " SQL queries.\n", outputField.NORMAL);
            for (int i = 0; i < path.size(); i++) {
                SQLPPTriplesMap o = (SQLPPTriplesMap) path.get(i);
                String id = o.getId();
                outputField.addText("  id: '" + id + "'... ", outputField.NORMAL);
                OntopSQLCredentialConfiguration config = OntopSQLCredentialConfiguration.defaultBuilder()
                        .properties(DataSource2PropertiesConvertor.convert(selectedSource))
                        .build();
                validator = new SQLSourceQueryValidator(config.getSettings(), o.getSourceQuery());
                long timestart = System.nanoTime();

                if (canceled) {
                    return;
                }
                if (validator.validate()) {
                    long timestop = System.nanoTime();
                    String output = " valid  \n";
                    outputField.addText("Time to query: " + ((timestop - timestart) / 1000) + " ns. Result: ", outputField.NORMAL);
                    outputField.addText(output, outputField.VALID);
                } else {
                    long timestop = System.nanoTime();
                    String output = " invalid Reason: " + validator.getReason().getMessage() + " \n";
                    outputField.addText("Time to query: " + ((timestop - timestart) / 1000) + " ns. Result: ", outputField.NORMAL);
                    outputField.addText(output, outputField.CRITICAL_ERROR);
                }

                if (canceled) {
                    return;
                }
            }
            outputField.setVisible(true);
        };
		validatorThread = new Thread(action);
		validatorThread.start();

		Thread cancelThread = new Thread(() -> {
            while (!outputField.closed) {
                try {
                    Thread.currentThread();
                    Thread.sleep(100);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            if (validatorThread.isAlive()) {
                try {
                    Thread.currentThread();
                    Thread.sleep(250);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                try {
                    canceled = true;
                    if(validator !=null) {
                        validator.cancelValidation();
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        });
		cancelThread.start();

	}
312275
@Override
  protected Expression visitVarRefNode(VarRefNode node) {
    Expression translation = variableMappings.maybeGet(node.getName());
    if (translation != null) {
      // Case 1: In-scope local var.
      return translation;
    } else {
      // Case 2: Data reference.
      return genCodeForParamAccess(node.getName(), node.getDefnDecl());
    }
  }
694929
public String genId() {
        S.Buffer sb = S.newBuffer();
        sb.a(longEncoder.longToStr(nodeIdProvider.nodeId()))
          .a(longEncoder.longToStr(startIdProvider.startId()))
          .a(longEncoder.longToStr(sequenceProvider.seqId()));
        return sb.toString();
    }
1298740
protected Expression genGoogMsgPlaceholder(MsgPlaceholderNode msgPhNode) {

    List<Expression> contentChunks = new ArrayList<>();

    for (StandaloneNode contentNode : msgPhNode.getChildren()) {

      if (contentNode instanceof MsgHtmlTagNode
          && !isComputableAsJsExprsVisitor.exec(contentNode)) {
        // This is a MsgHtmlTagNode that is not computable as JS expressions. Visit it to
        // generate code to define the 'htmlTag<n>' variable.
        visit(contentNode);
        contentChunks.add(id("htmlTag" + contentNode.getId()));

      } else if (contentNode instanceof CallNode) {
        // If the CallNode has any CallParamContentNode children that are not computable as JS
        // expressions, visit them to generate code to define their respective 'param<n>' variables.

        CallNode callNode = (CallNode) contentNode;
        for (CallParamNode grandchild : callNode.getChildren()) {
          if (grandchild instanceof CallParamContentNode
              && !isComputableAsJsExprsVisitor.exec(grandchild)) {
            visit(grandchild);
          }
        }

        Expression call =
            genCallCodeUtils.gen(
                callNode,
                templateAliases,
                translationContext,
                errorReporter,
                master.getExprTranslator());
        contentChunks.add(call);
      } else {
        List<Expression> chunks = genJsExprsVisitor.exec(contentNode);
        contentChunks.add(CodeChunkUtils.concatChunks(chunks));
      }
    }

    return CodeChunkUtils.concatChunks(contentChunks);
  }
548425
public String traceFormatGenData(GenericData genData) {

        KeyValuePair[] pairs = genData.getPairs();
        KeyValuePair kvp = null;
        String txt = null;
        Integer id = null;
        String objId;
        Integer levelVal = null;
        String name;

        String className = null;
        String method = null;
        String loggerName = null;
        Long ibm_datetime = null;

        String corrId = null;
        String org = null;
        String prod = null;
        String component = null;

        String sym = null;
        String logLevel = null;

        String threadName = null;
        String stackTrace = null;
        for (KeyValuePair p : pairs) {

            if (p != null && !p.isList()) {

                kvp = p;
                if (kvp.getKey().equals(LogFieldConstants.MESSAGE)) {
                    txt = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.IBM_DATETIME)) {
                    ibm_datetime = kvp.getLongValue();
                } else if (kvp.getKey().equals(LogFieldConstants.SEVERITY)) {
                    sym = " " + kvp.getStringValue() + " ";
                } else if (kvp.getKey().equals(LogFieldConstants.IBM_CLASSNAME)) {
                    className = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.IBM_METHODNAME)) {
                    method = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.MODULE)) {
                    loggerName = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.OBJECT_ID)) {
                    id = kvp.getIntValue();
                } else if (kvp.getKey().equals(LogFieldConstants.CORRELATION_ID)) {
                    corrId = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.ORG)) {
                    org = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.PRODUCT)) {
                    prod = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.COMPONENT)) {
                    component = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.LOGLEVEL)) {
                    logLevel = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.THREADNAME)) {
                    threadName = kvp.getStringValue();
                } else if (kvp.getKey().equals(LogFieldConstants.LEVELVALUE)) {
                    levelVal = kvp.getIntValue();
                } else if (kvp.getKey().equals(LogFieldConstants.THROWABLE)) {
                    stackTrace = kvp.getStringValue();
                }

            }
        }

        StringBuilder sb = new StringBuilder(256);

        // Common header
        sb.append('[').append(DateFormatHelper.formatTime(ibm_datetime, useIsoDateFormat)).append("] ");
        sb.append(DataFormatHelper.getThreadId());

        switch (traceFormat) {
            default:
            case ENHANCED:
                objId = generateObjectId(id, true);
                name = nonNullString(className, loggerName);

                sb.append(" id=").append(objId).append(' ');
                formatFixedString(sb, name, enhancedNameLength);
                sb.append(sym); // sym has built-in padding
                if (method != null) {
                    sb.append(method).append(' ');
                }

                // append formatted message -- txt includes formatted args
                sb.append(txt);
                if (stackTrace != null)
                    sb.append(LoggingConstants.nl).append(stackTrace);
                break;
            case BASIC:
                name = nonNullString(loggerName, className);

                sb.append(' '); // pad after thread id
                fixedClassString(sb, name, basicNameLength);
                sb.append(sym);

                if (className != null)
                    sb.append(className);
                sb.append(' '); // yes, this space is always there.

                if (method != null)
                    sb.append(method);
                sb.append(' '); // yes, this space is always there.

                // append formatted message -- includes formatted args
                sb.append(txt);
                if (stackTrace != null)
                    sb.append(nlBasicPadding).append(stackTrace);
                break;
            case ADVANCED:
                objId = generateObjectId(id, false);
                name = nonNullString(loggerName, null);

                sb.append(' '); // pad after thread id
                sb.append(sym);

                // next append the correlation id.
                sb.append("UOW=");
                if (corrId != null)
                    sb.append(corrId);

                // next enter the logger name.
                sb.append(" source=").append(name);

                // append className if non-null
                if (className != null)
                    sb.append(" class=").append(className);

                // append methodName if non-null
                if (method != null)
                    sb.append(" method=").append(method);

                if (id != null)
                    sb.append(" id=").append(objId);

                //check the comparison to WsLogRecord
                if (org != null && prod != null && component != null) {
                    // next append org, prod, component, if set. Reference equality check is ok here.
                    sb.append(" org=");
                    sb.append(org);
                    sb.append(" prod=");
                    sb.append(prod);
                    sb.append(" component=");
                    sb.append(component);

                    //get thread name
                } else {
                    //ibm_threadId replace check if you can use this as the thread
                    sb.append(" thread=[").append(threadName).append("]");
                }

                // append formatted message -- txt includes formatted args
                sb.append(nlAdvancedPadding).append(txt);
                if (stackTrace != null)
                    sb.append(nlAdvancedPadding).append(stackTrace);
                break;
        }
        return sb.toString();
    }
851433
public static void tagToJson(JsonGenerator gen, Tag tag) throws IOException {
    final String key = tag.getKey();
    if (RELAXED_GROUP_KEYS.contains(key)) {
      gen.writeStringField(key, toValidCharsetTable(CHARS_ALLOWED_GROUPS, tag.getValue()));
    } else {
      gen.writeStringField(toValidCharset(tag.getKey()), toValidCharset(tag.getValue()));
    }
  }
329435
@SuppressWarnings("unchecked")
    private <T extends XPathBuilder> T setSearchLabelType(SearchType... searchLabelTypes) {
        this.searchLabelType = new ArrayList<>();
        if (searchLabelTypes != null) {
            this.searchLabelType.addAll(0, Arrays.asList(searchLabelTypes));
        }
        this.searchLabelType = cleanUpSearchType(this.searchLabelType);
        return (T) this;
    }
1057034
protected void parse(Node node) {
		queryable = isQueryable(node);
		styleInfo.clear();

		NodeList childNodes = node.getChildNodes();
		for (int i = 0; i < childNodes.getLength(); i++) {
			Node child = childNodes.item(i);
			String nodeName = child.getNodeName();
			if ("Name".equalsIgnoreCase(nodeName)) {
				name = getValueRecursive(child);
			} else if ("Title".equalsIgnoreCase(nodeName)) {
				title = getValueRecursive(child);
			} else if ("Abstract".equalsIgnoreCase(nodeName)) {
				abstractt = getValueRecursive(child);
			} else if ("KeywordList".equalsIgnoreCase(nodeName)) {
				addKeyWords(child);
			} else if ("SRS".equalsIgnoreCase(nodeName)) {
				crs.add(getValueRecursive(child));
			} else if ("BoundingBox".equalsIgnoreCase(nodeName)) {
				addBoundingBox(child);
			} else if ("LatLonBoundingBox".equalsIgnoreCase(nodeName)) {
				addLatLonBoundingBox(child);
			} else if ("MetadataURL".equalsIgnoreCase(nodeName)) {
				metadataUrls.add(new WmsLayerMetadataUrlInfo111(child));
			} else if ("Style".equalsIgnoreCase(nodeName)) {
				styleInfo.add(new WmsLayerStyleInfo111(child));
			} else if ("ScaleHint".equalsIgnoreCase(nodeName)) {
				if (hasAttribute(child, "min")) {
					minScaleDenominator = getAttributeAsDouble(child, "min");
				}
				if (hasAttribute(child, "max")) {
					maxScaleDenominator = getAttributeAsDouble(child, "max");
				}
			}
		}
		parsed = true;
	}
555153
private void buttonCollapseAllActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_buttonCollapseAllActionPerformed
    Utils.foldUnfoldTree(this.treeMindMap, false);
  }
821571
private void genSearchString(StringBuffer searchExpBuffer, PropertyNode propNode) throws WIMException {
        String propName = propNode.getName();
        String ldapAttrName = null;
        String dataType = null;
        Set<String> attrs = ldapConfigMgr.getAttributeNames(entityTypes, propName);
        // attrs known to be non-null as getAttributesNames creates a new set
        if (attrs.size() == 1) {
            ldapAttrName = (String) attrs.toArray()[0];

            Object value = null;

            for (String entityType : entityTypes) {
                Entity entity = null;
                if (entityType != null) {
                    if (entityType.equalsIgnoreCase("PersonAccount") || entityType.equalsIgnoreCase("LoginAccount"))
                        entity = new PersonAccount();
                    else if (entityType.equalsIgnoreCase("Person"))
                        entity = new Person();
                    else if (entityType.equalsIgnoreCase("Group"))
                        entity = new Group();
                    else
                        entity = new Entity();

                    dataType = entity.getDataType(propName);
                }

                if (dataType != null) {
                    value = ldapConfigMgr.getLdapValue(propNode.getValue(), dataType, ldapAttrName);
                } else {
                    throw new PropertyNotDefinedException(WIMMessageKey.PROPERTY_NOT_DEFINED, Tr.formatMessage(tc, WIMMessageKey.PROPERTY_NOT_DEFINED,
                                                                                                               WIMMessageHelper.generateMsgParms(propName)));
                }
            }

            short operator = ldapConfigMgr.getOperator(propNode.getOperator());
            value = ldapConfigMgr.escapeSpecialCharacters((String) value);
            Object[] arguments = { ldapAttrName, value };
            String searchCondtion = ldapConfigMgr.CONDITION_FORMATS[operator].format(arguments);
            searchExpBuffer.append(searchCondtion);

        } else if (attrs.size() > 1) {
            searchExpBuffer.append("|");
            for (String entityType : entityTypes) {
                LdapEntity ldapEntity = ldapConfigMgr.getLdapEntity(entityType);
                ldapAttrName = ldapConfigMgr.getAttributeName(ldapEntity, propName);
                /*
                 * if (ldapAttrName == null) {
                 * //search property is not defined
                 * throw new PropertyNotDefinedException(WIMMessageKey.PROPERTY_NOT_DEFINED, Tr.formatMessage(
                 * tc,
                 * WIMMessageKey.PROPERTY_NOT_DEFINED,
                 * WIMMessageHelper.generateMsgParms(propName)));
                 * }
                 */
                Object value = null;

                Entity entity = null;
                if (entityType != null) {
                    if (entityType.equalsIgnoreCase("PersonAccount"))
                        entity = new PersonAccount();
                    else if (entityType.equalsIgnoreCase("Person"))
                        entity = new Person();
                    else if (entityType.equalsIgnoreCase("Group"))
                        entity = new Group();
                    else
                        entity = new Entity();

                    dataType = entity.getDataType(propName);
                }

                value = ldapConfigMgr.getLdapValue(propNode.getValue(), dataType, ldapConfigMgr.getSyntax(ldapAttrName));
                short operator = ldapConfigMgr.getOperator(propNode.getOperator());
                value = ldapConfigMgr.escapeSpecialCharacters((String) value);
                Object[] arguments = { ldapAttrName, value };
                String searchCondtion = ldapConfigMgr.CONDITION_FORMATS[operator].format(arguments);
                searchExpBuffer.append("(");
                searchExpBuffer.append(searchCondtion);
                searchExpBuffer.append(")");
            }
        }
    }
858314
private void genNode(final Element ent, final ResourceXMLParser.Entity entity) {
        for (final String nodeProp : nodeProps) {
            ent.addAttribute(nodeProp, notNull(entity.getProperty(nodeProp)));
        }
        genAttributes(ent, entity);
    }
1230102
public static void genId(Object target, String property, Class<? extends GenId> genClass, String table, String column) throws MapperException {
        try {
            GenId genId;
            if (CACHE.containsKey(genClass)) {
                genId = CACHE.get(genClass);
            } else {
                LOCK.lock();
                try {
                    if (!CACHE.containsKey(genClass)) {
                        CACHE.put(genClass, genClass.newInstance());
                    }
                    genId = CACHE.get(genClass);
                } finally {
                    LOCK.unlock();
                }
            }
            MetaObject metaObject = MetaObjectUtil.forObject(target);
            if (metaObject.getValue(property) == null) {
                Object id = genId.genId(table, column);
                metaObject.setValue(property, id);
            }
        } catch (Exception e) {
            throw new MapperException("生成 ID 失败!", e);
        }
    }