Package de.danet.an.util.web

Source Code of de.danet.an.util.web.W3CDomUtil

/*
* This file is part of the WfMOpen project.
* Copyright (C) 2001-2003 Danet GmbH (www.danet.de), GS-AN.
* All rights reserved.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
*
* $Id: W3CDomUtil.java 1607 2006-09-29 12:32:13Z drmlipp $
*
* $Log$
* Revision 1.1.1.1  2003/06/30 20:05:12  drmlipp
* Initial import
*
* Revision 1.7  2003/06/27 08:51:46  lipp
* Fixed copyright/license information.
*
* Revision 1.6  2003/04/25 14:50:59  lipp
* Fixed javadoc errors and warnings.
*
* Revision 1.5  2003/04/24 20:50:13  lipp
* Fixed some warnings.
*
* Revision 1.4  2003/02/24 10:46:41  lipp
* Removed usage of System.out and .err.
*
* Revision 1.3  2001/12/19 11:48:42  lipp
* XSP debug feature.
*
* Revision 1.2  2001/12/11 14:29:10  schlue
* Basic implementation of staff group types.
* ToDo: persistence, group type id, sub group types and group type template for new entries
*
* Revision 1.1  2001/10/25 07:49:33  lipp
* Moved W3CDomUtil to de.danet.an.util.web
*
* Revision 1.6  2001/10/17 12:16:12  montag
* importProcessDefinitions working
*
* Revision 1.5  2001/10/17 12:12:38  montag
* importProcessDefinitions working
*
* Revision 1.4  2001/10/15 12:21:35  lipp
* New methods for dialg hints.
*
* Revision 1.3  2001/10/12 13:25:23  lipp
* Making progress with new process list.
*
* Revision 1.2  2001/08/17 10:00:24  montag
* clean up classes and javadoc
*
* Revision 1.1  2001/08/12 16:48:50  montag
* Read in process definition for process types;
* dtd and encoding problem not solved yet !
*
*
*/

package de.danet.an.util.web;

import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;
import javax.xml.parsers.ParserConfigurationException;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
import org.w3c.dom.ProcessingInstruction;

/**
* Utilities for easy use of org.w3c.dom things.
*/
public class W3CDomUtil {

    /**
     * Just get a new, never used and fresh <code>Document</code>.
     * @return a new, never used and fresh <code>Document</code>
     */
    public static Document createNewDocument() {
  DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance ();
  DocumentBuilder db = null;
  try {
      db = dbf.newDocumentBuilder ();
  } catch (ParserConfigurationException e) {
      throw new IllegalStateException ();
  }
  Document doc = db.newDocument ();
  return doc;
    }

    /**
     * Returns a "link" element with the given attributes. Valid values
     * for <code>name</code>, <code>hint</code> and <code>type</code>
     * are documentated in the DV-Konzept.
     * @param doc The W3C DOM document in which the link will be inserted.
     * @param name The name atribute of the link.
     * @param hint The hint attribute of the link.
     * @param href The href attribute of the link. Strings starting with
     * "http://" are not modified.
     * @param display The display string used to show the link. (Use
     * <code>mappingSetup.mapText()</code> or similar before calling this
     * method.)
     * @return An W3C DOM element of type "link".
     * @deprecated
     */
    public static Element createLink
  (Document doc,
   String name, String hint, String href, String display) {
  Element link = doc.createElement ("link");
  link.setAttribute("name", name);
  link.setAttribute("hint", hint);
  // modify href to get a correct URI
  link.setAttribute("href", href);
  link.appendChild(doc.createTextNode(display));
  return link;
    }

    /**
     * Appends to a given node a "dialog hint node", i.e. a hint how a
     * node's attribute or a node's value is to be represented in a
     * dialog.
     * @param node the node to which the dialog hint node is to be
     * appended.
     * @param attribute the name of the node's attribute which is
     * attributed by the dialog hint. This parameter may be
     * <code>null</code> if the dialog hint applies to the value of the node.
     * @param type the type attribute of the dialog hint node.
     * @return the appended dialog hint element.
     */
    public static Element appendDialogHint (Node node, String attribute,
              String type) {
  Document doc = node.getOwnerDocument();
  Element diaAttr = doc.createElement ("dialog-hint");
  if (attribute != null) {
      diaAttr.setAttribute("attribute", attribute);
  }
  diaAttr.setAttribute("type", type);
  node.appendChild (diaAttr);
  return diaAttr;
    }

    /**
     * Appends to a given node a "dialog hint node", i.e. a hint how a
     * node's attribute or a node's value is to be represented in a
     * dialog.
     * @param node the node to which the dialog hint node is to be
     * appended.
     * @param attribute the name of the node's attribute which is
     * attributed by the dialog hint. This parameter may be
     * <code>null</code> if the dialog hint applies to the value of the node.
     * @param type the type attribute of the dialog hint node.
     * @param maxlength the maxlength attribute of the dialog hint node.
     * @return the appended dialog hint element.
     */
    public static Element appendDialogHint (Node node, String attribute,
              String type, long maxlength) {
  Document doc = node.getOwnerDocument();
  Element diaAttr = doc.createElement ("dialog-hint");
  if (attribute != null) {
      diaAttr.setAttribute("attribute", attribute);
  }
  diaAttr.setAttribute("type", type);
  diaAttr.setAttribute("maxlength", Long.toString(maxlength));
  node.appendChild (diaAttr);
  return diaAttr;
    }

    /**
     * Find the first PI node with the given PI target name.
     * @param doc the document to search.
     * @param name the PI target name.
     * @return the node found or <code>null</code>.
     */
    public static ProcessingInstruction findFirstPI
  (Document doc, String name) {
        NodeList nodelist = doc.getChildNodes();
        int i = nodelist.getLength();
        for (int j = 0; j < i; j++) {
            Node node = nodelist.item(j);
            if (node.getNodeType() == Node.PROCESSING_INSTRUCTION_NODE) {
    ProcessingInstruction pi = (ProcessingInstruction) node;
                if (pi.getTarget().equals(name)) {
                    return pi;
                }
            }
        }
  return null;
    }
}
TOP

Related Classes of de.danet.an.util.web.W3CDomUtil

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.