+++ /dev/null
-/*
- * UI Builder
- *
- * Copyright (c) 2000 - 2014 Samsung Electronics Co., Ltd. All rights reserved.
- *
- * 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.
- *
- * Contributors:
- * - S-Core Co., Ltd
- *
- */
-
-
-package org.tizen.webuibuilder.model.html;
-
-import java.util.List;
-
-import net.htmlparser.jericho.Attribute;
-import net.htmlparser.jericho.Attributes;
-import net.htmlparser.jericho.Element;
-import net.htmlparser.jericho.EndTag;
-import net.htmlparser.jericho.OutputDocument;
-import net.htmlparser.jericho.StartTag;
-
-import org.tizen.webuibuilder.BuilderConstants;
-
-
-public class JerichoUtil {
-
- public static final String QUOTATION_MARK = BuilderConstants.QUOTATION_MARK;
-
- public JerichoUtil() {
- }
-
- public static void addElement(OutputDocument output, Element element, Element refElement,
- String childElement) {
- if (output == null || element == null) {
- return;
- }
-
- List<Element> children = element.getChildElements();
- int size = children.size();
- if (size > 0) {
- Element lastElement = children.get(size - 1);
- for (int i = 0; i < size; i++) {
- Element child = children.get(i);
- if (child.equals(refElement)) {
- lastElement = children.get(i - 1);
- break;
- }
- }
- StringBuilder newTag = new StringBuilder();
- if (lastElement.isEmptyElementTag()) {
- StartTag startTag = lastElement.getStartTag();
- newTag.append(startTag.toString());
- newTag.append(childElement);
- output.replace(startTag, newTag);
- } else {
- EndTag endTag = lastElement.getEndTag();
- newTag.append(endTag.toString());
- newTag.append(childElement);
- output.replace(endTag, newTag);
- }
- } else {
- StringBuilder newTag = new StringBuilder();
- StartTag startTag = element.getStartTag();
- newTag.append(startTag.toString());
- newTag.append(childElement);
- output.replace(startTag, newTag);
- }
-
- // System.out.println("~~~addElement() outputDocument=" + output);
- }
-
- public static void setAttribute(OutputDocument output, Element element, String name,
- String value) {
- if (output == null || element == null) {
- return;
- }
-
- StartTag startTag = element.getStartTag();
- Attributes attributes = startTag.parseAttributes();
- Attribute attribute = attributes.get(name);
- String startTagStr = startTag.toString();
- StringBuilder newStartTag = new StringBuilder();
- if (attribute == null) {
- String tag = startTagStr.substring(0, startTag.toString().length() - 1);
- newStartTag.append(tag);
- newStartTag.append(BuilderConstants.SPACE);
- newStartTag.append(name);
- newStartTag.append(BuilderConstants.EQUAL + QUOTATION_MARK);
- newStartTag.append(value);
- newStartTag.append(QUOTATION_MARK);
- newStartTag.append(BuilderConstants.CLOSE_TRI_BRACKET);
- } else {
- int nameIndex = startTagStr.indexOf(name);
- int startValueIndex = startTagStr.indexOf(QUOTATION_MARK, nameIndex);
- int endValueIndex = startTagStr.indexOf(QUOTATION_MARK, startValueIndex + 1);
- newStartTag.append(startTagStr);
- newStartTag.replace(startValueIndex + 1, endValueIndex, value);
- }
- output.replace(startTag, newStartTag);
- // System.out.println("~~~setAttribute() outputDocument=" + output);
- }
-
-}