This method deals with the starting tags.

@param name
the name of the tag
972168
public void handleEndingTags(String name) {

        // System.err.println("Stop: " + name);

        if (ElementTags.IGNORE.equals(name)) {
            ignore = false;
            return;
        }
        if (ignore)
            return;
        // tags that don't have any content
        if (isNewpage(name) || ElementTags.ANNOTATION.equals(name) || ElementTags.IMAGE.equals(name)
                || isNewline(name)) {
            return;
        }

        try {
            // titles of sections and chapters
            if (ElementTags.TITLE.equals(name)) {
                Paragraph current = (Paragraph) stack.pop();
                if (currentChunk != null) {
                    current.add(currentChunk);
                    currentChunk = null;
                }
                Section previous = (Section) stack.pop();
                previous.setTitle(current);
                stack.push(previous);
                return;
            }

            // all other endtags
            if (currentChunk != null) {
                TextElementArray current;
                try {
                    current = (TextElementArray) stack.pop();
                } catch (EmptyStackException ese) {
                    current = new Paragraph();
                }
                current.add(currentChunk);
                stack.push(current);
                currentChunk = null;
            }

            // chunks
            if (ElementTags.CHUNK.equals(name)) {
                return;
            }

            // phrases, anchors, lists, tables
            if (ElementTags.PHRASE.equals(name) || ElementTags.ANCHOR.equals(name) || ElementTags.LIST.equals(name)
                    || ElementTags.PARAGRAPH.equals(name)) {
                Element current = (Element) stack.pop();
                try {
                    TextElementArray previous = (TextElementArray) stack.pop();
                    previous.add(current);
                    stack.push(previous);
                } catch (EmptyStackException ese) {
                    document.add(current);
                }
                return;
            }

            // listitems
            if (ElementTags.LISTITEM.equals(name)) {
                ListItem listItem = (ListItem) stack.pop();
                List list = (List) stack.pop();
                list.add(listItem);
                stack.push(list);
            }

            // tables
            if (ElementTags.TABLE.equals(name)) {
                Table table = (Table) stack.pop();
                try {
                    TextElementArray previous = (TextElementArray) stack.pop();
                    previous.add(table);
                    stack.push(previous);
                } catch (EmptyStackException ese) {
                    document.add(table);
                }
                return;
            }

            // rows
            if (ElementTags.ROW.equals(name)) {
                ArrayList cells = new ArrayList();
                int columns = 0;
                Table table;
                Cell cell;
                while (true) {
                    Element element = (Element) stack.pop();
                    if (element.type() == Element.CELL) {
                        cell = (Cell) element;
                        columns += cell.getColspan();
                        cells.add(cell);
                    } else {
                        table = (Table) element;
                        break;
                    }
                }
                if (table.getColumns() < columns) {
                    table.addColumns(columns - table.getColumns());
                }
                Collections.reverse(cells);
                String width;
                float[] cellWidths = new float[columns];
                boolean[] cellNulls = new boolean[columns];
                for (int i = 0; i < columns; i++) {
                    cellWidths[i] = 0;
                    cellNulls[i] = true;
                }
                float total = 0;
                int j = 0;
                for (Iterator i = cells.iterator(); i.hasNext();) {
                    cell = (Cell) i.next();
                    width = cell.getWidthAsString();
                    if (cell.getWidth() == 0) {
                        if (cell.getColspan() == 1 && cellWidths[j] == 0) {
                            try {
                                cellWidths[j] = 100f / columns;
                                total += cellWidths[j];
                            } catch (Exception e) {
                                // empty on purpose
                            }
                        } else if (cell.getColspan() == 1) {
                            cellNulls[j] = false;
                        }
                    } else if (cell.getColspan() == 1 && width.endsWith("%")) {
                        try {
                            cellWidths[j] = Float.parseFloat(
                                    width.substring(0, width.length() - 1)
                                            + "f");
                            total += cellWidths[j];
                        } catch (Exception e) {
                            // empty on purpose
                        }
                    }
                    j += cell.getColspan();
                    table.addCell(cell);
                }
                float widths[] = table.getProportionalWidths();
                if (widths.length == columns) {
                    float left = 0.0f;
                    for (int i = 0; i < columns; i++) {
                        if (cellNulls[i] && widths[i] != 0) {
                            left += widths[i];
                            cellWidths[i] = widths[i];
                        }
                    }
                    if (100.0 >= total) {
                        for (int i = 0; i < widths.length; i++) {
                            if (cellWidths[i] == 0 && widths[i] != 0) {
                                cellWidths[i] = (widths[i] / left)
                                        * (100.0f - total);
                            }
                        }
                    }
                    table.setWidths(cellWidths);
                }
                stack.push(table);
            }

            // cells
            if (ElementTags.CELL.equals(name)) {
                return;
            }

            // sections
            if (ElementTags.SECTION.equals(name)) {
                stack.pop();
                return;
            }

            // chapters
            if (ElementTags.CHAPTER.equals(name)) {
                document.add((Element) stack.pop());
                return;
            }

            // the documentroot
            if (isDocumentRoot(name)) {
                try {
                    while (true) {
                        Element element = (Element) stack.pop();
                        try {
                            TextElementArray previous = (TextElementArray) stack
                                    .pop();
                            previous.add(element);
                            stack.push(previous);
                        } catch (EmptyStackException es) {
                            document.add(element);
                        }
                    }
                } catch (EmptyStackException ese) {
                    // empty on purpose
                }
                if (controlOpenClose)
                    document.close();
                return;
            }
        } catch (DocumentException de) {
            throw new ExceptionConverter(de);
        }
    }
53570
def start_tag(self, alt=None, empty=False):
        """"""
        if alt:
            name = alt
        else:
            name = self.name
        result = "<" + name
        for it in self.attr:
            result += ' %s="%s"' % (it, escape(self.attr[it], {'"':"&quot;", '%': "%%"}))
        if empty:
            return result + "/>%s"
        else:
            return result + ">"
318929
public void addName(String name)
   {
      if (names.contains(name))
      {
         throw new IllegalArgumentException("already contains: " + name);
      }
      indexes.add(name);
      names.add(name);
      dirty = true;
   }
453897
def _handle_start_tag(self, attrs):
        
        try:
            tag_key = attrs['k']
        except KeyError:
            raise ValueError("Tag without name/key.")
        self._curr['tags'][tag_key] = attrs.get('v')
1136269
public void printXMLStartElement(String name, Map<String, String> attributes)
    {
        printXMLStartElement(name, createAttributes(attributes));
    }
131348
static final String createTag(final String name) {
		if (name.length() <= MAX_TAG_LEN) {
			return name;
		}

		final char[] tag = name.toCharArray();
		final int arrayLen = tag.length;
		int len = 0;
		int mark = 0;

		for (int i = 0; i < arrayLen; i++, len++) {
			if (tag[i] == '.') {
				len = mark;

				if (tag[len] != '.') {
					len++;
				}

				mark = len;

				if (i + 1 < arrayLen && tag[i + 1] != '.') {
					mark++;
				}
			}

			tag[len] = tag[i];
		}

		if (len > MAX_TAG_LEN) {
			int i = 0;

			mark--;

			for (int j = 0; j < len; j++) {
				if (tag[j] == '.' && ((j != mark) || (i >= MAX_TAG_LEN - 1))) {
					continue;
				}

				tag[i++] = tag[j];
			}

			len = i;

			if (len > MAX_TAG_LEN) {
				len = MAX_TAG_LEN;
			}
		}

		return new String(tag, 0, len);
	}
780097
public function startAttribute($name, $value)
    {
        $this->checkStartAttribute($name);

        $this->xmlWriter->startAttribute($name);
        $this->xmlWriter->text($value);
    }
238066
private function checkName(&$name)
    {
        if (! is_string($name)) {
            throw new InvalidTypeException(
                'The tag type must be a string, ' . gettype($name) . ' is given.'
            );
        }

        $name = strtolower(trim($name));
    }
1350234
public boolean startsWith(Name name) {
		if (name.size() == 0) {
			return false;
		}

		DistinguishedName start = null;
		if (name instanceof DistinguishedName) {
			start = (DistinguishedName) name;
		}
		else {
			return false;
		}

		if (start.size() > this.size()) {
			return false;
		}

		Iterator longiter = names.iterator();
		Iterator shortiter = start.getNames().iterator();

		while (shortiter.hasNext()) {
			Object longname = longiter.next();
			Object shortname = shortiter.next();

			if (!longname.equals(shortname)) {
				return false;
			}
		}

		// All names in shortiter matched.
		return true;
	}
836718
public static void addNames(final String tag, final Span[] names,
      final Parse[] tokens) {
    for (final Span nameTokenSpan : names) {
      final Parse startToken = tokens[nameTokenSpan.getStart()];
      final Parse endToken = tokens[nameTokenSpan.getEnd() - 1];
      final Parse commonParent = startToken.getCommonParent(endToken);
      // System.err.println("addNames: "+startToken+" .. "+endToken+"
      // commonParent = "+commonParent);
      if (commonParent != null) {
        final Span nameSpan = new Span(startToken.getSpan().getStart(),
            endToken.getSpan().getEnd());
        if (nameSpan.equals(commonParent.getSpan())) {
          commonParent.insert(new Parse(commonParent.getText(), nameSpan, tag,
              1.0, endToken.getHeadIndex()));
        } else {
          final Parse[] kids = commonParent.getChildren();
          boolean crossingKids = false;
          for (final Parse kid : kids) {
            if (nameSpan.crosses(kid.getSpan())) {
              crossingKids = true;
            }
          }
          if (!crossingKids) {
            commonParent.insert(new Parse(commonParent.getText(), nameSpan, tag,
                1.0, endToken.getHeadIndex()));
          } else {
            if (commonParent.getType().equals("NP")) {
              final Parse[] grandKids = kids[0].getChildren();
              if (grandKids.length > 1 && nameSpan
                  .contains(grandKids[grandKids.length - 1].getSpan())) {
                commonParent.insert(
                    new Parse(commonParent.getText(), commonParent.getSpan(),
                        tag, 1.0, commonParent.getHeadIndex()));
              }
            }
          }
        }
      }
    }
  }
147422
public void writeLineElement(String name, Object text)
  {
    startLineElement(name);
    writeText(text);
    endLineElement(name);
  }
493852
public function startTag($name, $attributes = array(), $selfClosing = false) {
        // fprintf(STDOUT, $name);
        $lname = $this->normalizeTagName($name);

        // Make sure we have an html element.
        if (!$this->doc->documentElement && $name !== 'html' && !$this->frag) {
            $this->startTag('html');
        }

        // Set quirks mode if we're at IM_INITIAL with no doctype.
        if ($this->insertMode == static::IM_INITIAL) {
            $this->quirks = true;
            $this->parseError("No DOCTYPE specified.");
        }

        // SPECIAL TAG HANDLING:
        // Spec says do this, and "don't ask."
        if ($name == 'image') {
            $name = 'img';
        }

        // Autoclose p tags where appropriate.
        if ($this->insertMode >= static::IM_IN_BODY && HTML5_Elements::isA($name, HTML5_Elements::AUTOCLOSE_P)) {
            $this->autoclose('p');
        }

        // Set insert mode:
        switch ($name) {
            case 'html':
                $this->insertMode = static::IM_BEFORE_HEAD;
                break;
            case 'head':
                if ($this->insertMode > static::IM_BEFORE_HEAD) {
                    $this->parseError("Unexpected head tag outside of head context.");
                } else {
                    $this->insertMode = static::IM_IN_HEAD;
                }
                break;
            case 'body':
                $this->insertMode = static::IM_IN_BODY;
                break;
            case 'svg':
                $this->insertMode = static::IM_IN_SVG;
                break;
            case 'math':
                $this->insertMode = static::IM_IN_MATHML;
                break;
            case 'noscript':
                if ($this->insertMode == static::IM_IN_HEAD) {
                    $this->insertMode = static::IM_IN_HEAD_NOSCRIPT;
                }
                break;
        }

        // Special case handling for SVG.
        if ($this->insertMode == static::IM_IN_SVG) {
            $lname = HTML5_Elements::normalizeSvgElement($lname);
        }

        $pushes = 0;
        // when we found a tag thats appears inside $nsRoots, we have to switch the defalut namespace
        if (isset($this->nsRoots[$lname]) && $this->nsStack[0][''] !== $this->nsRoots[$lname]) {
            array_unshift($this->nsStack, array(
                '' => $this->nsRoots[$lname]
                    ) + $this->nsStack[0]);
            $pushes ++;
        }
        $needsWorkaround = false;
        if (isset($this->options["xmlNamespaces"]) && $this->options["xmlNamespaces"]) {
            // when xmlNamespaces is true a and we found a 'xmlns' or 'xmlns:*' attribute, we should add a new item to the $nsStack
            foreach ($attributes as $aName => $aVal) {
                if ($aName === 'xmlns') {
                    $needsWorkaround = $aVal;
                    array_unshift($this->nsStack, array(
                        '' => $aVal
                            ) + $this->nsStack[0]);
                    $pushes ++;
                } elseif ((($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : '') === 'xmlns') {
                    array_unshift($this->nsStack, array(
                        substr($aName, $pos + 1) => $aVal
                            ) + $this->nsStack[0]);
                    $pushes ++;
                }
            }
        }

        try {
            $prefix = ($pos = strpos($lname, ':')) ? substr($lname, 0, $pos) : '';


            if ($needsWorkaround !== false) {

                $xml = "<$lname xmlns=\"$needsWorkaround\" " . (strlen($prefix) && isset($this->nsStack[0][$prefix]) ? ("xmlns:$prefix=\"" . $this->nsStack[0][$prefix] . "\"") : "") . "/>";

                $frag = new \DOMDocument('1.0', 'UTF-8');
                $frag->loadXML($xml);

                $ele = $this->doc->importNode($frag->documentElement, true);
            } else {
                if (!isset($this->nsStack[0][$prefix]) || ($prefix === "" && isset($this->options['disableHtmlNsInDom']) && $this->options['disableHtmlNsInDom'])) {
                    $ele = $this->doc->createElement($lname);
                } else {
                    $ele = $this->doc->createElementNS($this->nsStack[0][$prefix], $lname);
                }
            }
        } catch (\DOMException $e) {
            $this->parseError("Illegal tag name: <$lname>. Replaced with <invalid>.");
            $ele = $this->doc->createElement('invalid');
        }

        // When we add some namespacess, we have to track them. Later, when "endElement" is invoked, we have to remove them.
        // When we are on a void tag, we do not need to care about namesapce nesting.
        if ($pushes > 0 && !HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
            // PHP tends to free the memory used by DOM,
            // to avoid spl_object_hash collisions whe have to avoid garbage collection of $ele storing it into $pushes
            // see https://bugs.php.net/bug.php?id=67459
            $this->pushes[spl_object_hash($ele)] = array($pushes, $ele);

            // SEE https://github.com/facebook/hhvm/issues/2962
            if (defined('HHVM_VERSION')) {
                $ele->setAttribute('html5-php-fake-id-attribute', spl_object_hash($ele));
            }
        }

        foreach ($attributes as $aName => $aVal) {
            // xmlns attributes can't be set
            if ($aName === 'xmlns') {
                continue;
            }

            if ($this->insertMode == static::IM_IN_SVG) {
                $aName = HTML5_Elements::normalizeSvgAttribute($aName);
            } elseif ($this->insertMode == static::IM_IN_MATHML) {
                $aName = HTML5_Elements::normalizeMathMlAttribute($aName);
            }

            try {
                $prefix = ($pos = strpos($aName, ':')) ? substr($aName, 0, $pos) : false;

                if ($prefix === 'xmlns') {
                    $ele->setAttributeNs(self::NAMESPACE_XMLNS, $aName, $aVal);
                } elseif ($prefix !== false && isset($this->nsStack[0][$prefix])) {
                    $ele->setAttributeNs($this->nsStack[0][$prefix], $aName, $aVal);
                } else {
                    $ele->setAttribute($aName, $aVal);
                }
            } catch (\DOMException $e) {
                $this->parseError("Illegal attribute name for tag $name. Ignoring: $aName");
                continue;
            }

            // This is necessary on a non-DTD schema, like HTML5.
            if ($aName == 'id') {
                $ele->setIdAttribute('id', true);
            }
        }

        // Some elements have special processing rules. Handle those separately.
        if ($this->rules->hasRules($name) && $this->frag !== $this->current) {
            $this->current = $this->rules->evaluate($ele, $this->current);
        }         // Otherwise, it's a standard element.
        else {
            $this->current->appendChild($ele);

            // XXX: Need to handle self-closing tags and unary tags.
            if (!HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
                $this->current = $ele;
            }
        }

        // This is sort of a last-ditch attempt to correct for cases where no head/body
        // elements are provided.
        if ($this->insertMode <= static::IM_BEFORE_HEAD && $name != 'head' && $name != 'html') {
            $this->insertMode = static::IM_IN_BODY;
        }

        // When we are on a void tag, we do not need to care about namesapce nesting,
        // but we have to remove the namespaces pushed to $nsStack.
        if ($pushes > 0 && HTML5_Elements::isA($name, HTML5_Elements::VOID_TAG)) {
            // remove the namespaced definded by current node
            for ($i = 0; $i < $pushes; $i ++) {
                array_shift($this->nsStack);
            }
        }
        // Return the element mask, which the tokenizer can then use to set
        // various processing rules.
        return HTML5_Elements::element($name);
    }
435413
public Tag create(String name) {
        String url = WxEndpoint.get("url.tag.create");
        TagWrapper tag = new TagWrapper(name);
        String json = JsonMapper.nonEmptyMapper().toJson(tag);
        logger.debug("create tag: {}", json);
        String response = wxClient.post(url, json);
        TagWrapper wrapper = JsonMapper.defaultMapper().fromJson(response, TagWrapper.class);
        return wrapper.getTag();
    }
141785
public void run(){
		System.out.println("Starting tagging service!");
		try {
			this.socket = new ServerSocket(this.port);
		}
		catch (IOException ioe){
			System.out.println(ioe);
			System.exit(1);
		}
		
		init();
		System.out.println("Tagging service is started successfully");
		while (true){
			Socket incoming = null;
			try{
				incoming = this.socket.accept();
				Session w = null;
				synchronized (pool) {
					if (pool.isEmpty()){
						w = new Session(vnTextPro);
						w.setSocket(incoming); //additional sessions
						w.start();						
					} else{
						w = pool.elementAt(0);
						pool.removeElementAt(0);						
						w.setSocket(incoming);
					}
				}
			}
			catch (IOException e){
				System.out.println(e);
				e.printStackTrace();
			}
		}
	}
179894
public void startElement(String elemName, Attributes attrs) {
        writeStartElement(elemName, attrs);
        m_tagStack.push(elemName);
    }
117737
private void maybeProcessDomTagName(Node n) {
    if (NodeUtil.isLValue(n)) {
      return;
    }
    String prefix = "goog$dom$TagName$";
    String tagName;
    if (n.isName() && n.getString().startsWith(prefix)) {
      tagName = n.getString().substring(prefix.length());
    } else if (n.isGetProp() && !n.getParent().isGetProp()
        && n.getFirstChild().matchesQualifiedName("goog.dom.TagName")) {
      tagName = n.getSecondChild().getString()
          .replaceFirst(".*\\$", ""); // Added by DisambiguateProperties.
    } else {
      return;
    }
    Node stringNode = IR.string(tagName).srcref(n);
    n.replaceWith(stringNode);
    compiler.reportChangeToEnclosingScope(stringNode);
  }
1209573
public static Tag getTag(String name) {

        Tag tag = TAGS.get(name);

        if (tag == null) {
            throw new RuntimeException("unknown tag: " + name);
        }

        return tag;
    }