<commit_before>/*
 * Copyright 2022 Allette Systems (Australia)
 * http://www.allette.com.au
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pageseeder.ox.pageseeder.xml;
import org.pageseeder.bridge.model.PSNotify;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

import net.pageseeder.app.simple.pageseeder.model.CommentParameter;
import net.pageseeder.app.simple.pageseeder.model.builder.CommentParameterBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <NAME>
 * @since 07 September 2022
 */

public class CommentParameterHandler extends DefaultHandler {

  private final CommentParameterBuilder cpBuilder;
  List<CommentParameter> cp;

  public CommentParameterHandler() {
    this.cp = new ArrayList<>();
    this.cpBuilder = new CommentParameterBuilder();
  }

  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (localName.equals("comment")) {
      cpBuilder.id(Long.valueOf(attributes.getValue("commentid")));
      cpBuilder.title(attributes.getValue("title"));
      cpBuilder.content(attributes.getValue("content"));
      cpBuilder.contentRole(attributes.getValue("contenttype"));
      cpBuilder.labels(attributes.getValue("labels"));
      cpBuilder.properties(attributes.getValue("properties"));
      cpBuilder.notify(PSNotify.valueOf(attributes.getValue("notify")));
      cpBuilder.type(attributes.getValue("type"));

      CommentParameter currCp = cpBuilder.buildComment();
      this.cp.add(currCp);<commit_msg>add null check for attributes<commit_after>/*
 * Copyright 2022 Allette Systems (Australia)
 * http://www.allette.com.au
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package org.pageseeder.ox.pageseeder.xml;
import net.pageseeder.app.simple.core.utils.SimpleStringUtils;
import org.pageseeder.bridge.model.PSNotify;
import org.xml.sax.Attributes;
import org.xml.sax.helpers.DefaultHandler;

import net.pageseeder.app.simple.pageseeder.model.CommentParameter;
import net.pageseeder.app.simple.pageseeder.model.builder.CommentParameterBuilder;

import java.util.ArrayList;
import java.util.List;

/**
 * @author <NAME>
 * @since 07 September 2022
 */

public class CommentParameterHandler extends DefaultHandler {

  private final CommentParameterBuilder cpBuilder;
  List<CommentParameter> cp;

  public CommentParameterHandler() {
    this.cp = new ArrayList<>();
    this.cpBuilder = new CommentParameterBuilder();
  }

  @Override
  public void startElement(String uri, String localName, String qName, Attributes attributes) {
    if (localName.equals("comment")) {
      cpBuilder.id(Long.valueOf(attributes.getValue("commentid")));
      cpBuilder.title(attributes.getValue("title"));

      if (!SimpleStringUtils.isBlank(attributes.getValue("content"))) {
        cpBuilder.content(attributes.getValue("content"));
      }
      if (!SimpleStringUtils.isBlank(attributes.getValue("contenttype"))) {
        cpBuilder.contentRole(attributes.getValue("contenttype"));
      }
      if (!SimpleStringUtils.isBlank(attributes.getValue("labels"))) {
        cpBuilder.labels(attributes.getValue("labels"));
      }
      if (!SimpleStringUtils.isBlank(attributes.getValue("properties"))) {
        cpBuilder.properties(attributes.getValue("properties"));
      }
      if (!SimpleStringUtils.isBlank(attributes.getValue("notify"))) {
        cpBuilder.notify(PSNotify.valueOf(attributes.getValue("notify")));
      } else {
        cpBuilder.notify(PSNotify.silent);
      }
      if (!SimpleStringUtils.isBlank(attributes.getValue("type"))) {
        cpBuilder.type(attributes.getValue("type"));
      }

      CommentParameter currCp = cpBuilder.buildComment();
      this.cp.add(currCp);
{'fraction_non_alphanumeric': 0.1142737547090833, 'fraction_numerical': 0.0058601925491837585, 'mean_word_length': 4.393905191873589, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 4, 'xml': 6}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6546017', 'n_tokens_mistral': 1303, 'n_tokens_neox': 1281, 'n_words': 321}