读取xml文件为dom4j的Docment文档.
@param xmlPath 定位xml文件的路径，如：com/blinkfox/test.xml
@return 返回dom4j文档
19950
public static Document getDocument(String xmlPath) {
        try {
            InputStream is = Thread.currentThread().getContextClassLoader().getResourceAsStream(xmlPath);
            return new SAXReader().read(is);
        } catch (Exception e) {
            throw new XmlParseException("读取或解析xml文件失败，xmlPath是:" + xmlPath, e);
        }
    }
778934
public static boolean list2Xls(List<?> list, String xmlPath, String filePath, String fileName) throws Exception {
        //创建目录
        File file = new File(filePath);
        if (!(file.exists())) {
            if (!file.mkdirs()) {
                throw new RuntimeException("创建导出目录失败!");
            }
        }
        try {
            ExcelConfig config = getEasyExcel(xmlPath);
            return list2Xls(config, list, filePath, fileName);
        } catch (Exception e1) {
            return false;
        }
    }
1112121
public static String evaluate(XmlObject xmlbean, String path) {
        XmlCursor cursor = xmlbean.newCursor();
        String value;
        
// 1.2.3. use XQuery or selectPath
//
//        cursor.toFirstChild();
//        String defaultNamespace = cursor.namespaceForPrefix("");
//        String namespaceDecl = "declare default element namespace '" + defaultNamespace + "';";
//        Map<String,String> namespaces = new HashMap<String,String>();
//        cursor.getAllNamespaces(namespaces);
//        for (String prefix : namespaces.keySet())
//        {
//            namespaceDecl += "declare namespace " + prefix + "='" + namespaces.get(prefix) + "';";
//        }
//  1. use XQuery
//        XmlCursor results = cursor.execQuery(namespaceDecl + path);
//        value = (results==null)?null:results.getTextValue();
        
//  2. use selectPath on XmlObject
//        XmlObject[] result = xmlbean.selectPath(namespaceDecl + path);
        
//  3. use selectPath on XmlCursor   
//        cursor.toParent();
//        XmlOptions options = new XmlOptions();
//        options.put(Path.PATH_DELEGATE_INTERFACE,"org.apache.xmlbeans.impl.xpath.saxon.XBeansXPath");
//        cursor.selectPath(namespaceDecl + path, options);
//        if (cursor.getSelectionCount()>0) {
//            cursor.toNextSelection();
//            value = cursor.getTextValue();
//        } else value = null;

// 4. use our own implementation
        try {
            XmlPath matcher = new XmlPath(path);
            value = matcher.evaluate_segment(cursor, matcher.path_seg);
        } catch (XmlException e) {
            value = null; // xpath syntax error - treated as no match
        }
        
        cursor.dispose();
        return value;
    }
748498
public InputStream getConfPathXmlStream(String filePathName){
     int i = filePathName.lastIndexOf(".xml");
     String name = filePathName.substring(0, i);
     name = name.replace('.', '/');
     name += ".xml";
     return getConfStream(name);
  }
1351492
public static JsonPathCursor createCursor(String attributePath) {
        ArrayList<Triple> triples = new ArrayList<Triple>(DEFAULT_PATH_ELEMENT_COUNT);
        int start = 0;
        int end;
        while (start < attributePath.length()) {
            boolean isArray = false;
            try {
                while (attributePath.charAt(start) == '[' || attributePath.charAt(start) == '.') {
                    start++;
                }
            } catch (IndexOutOfBoundsException e) {
                throw createIllegalArgumentException(attributePath);
            }
            end = start + 1;
            while (end < attributePath.length()) {
                char c = attributePath.charAt(end);
                if ('.' == c || '[' == c) {
                    break;
                } else if (']' == c) {
                    isArray = true;
                    break;
                }
                end++;
            }
            String part = attributePath.substring(start, end);

            Triple triple = new Triple(part, part.getBytes(UTF8_CHARSET), isArray);
            triples.add(triple);
            start = end + 1;
        }
        return new JsonPathCursor(attributePath, triples);
    }
154839
public static Object executeXPath(Node document, String xpathExpression, Map<String, String> namespaceMapping, QName result)
                throws XPathException, MarshallingException
    {
        NamespaceMapContext mapContext = new NamespaceMapContext(namespaceMapping);
        try
        {
            XPathFactory xPathfactory = XPathFactory.newInstance();
            XPath xpath = xPathfactory.newXPath();
            xpath.setNamespaceContext(mapContext);
            XPathExpression expr = xpath.compile(xpathExpression);

            return executeXPath(document, expr, result);
        }
        catch (XPathExpressionException e)
        {
            throw new XPathException("Xpath(" + xpathExpression + ") cannot be compiled", e);
        }
        catch (Exception e)
        {
            throw new MarshallingException("Exception unmarshalling XML.", e);
        }
    }
1116444
public static String getManifestXml(String apkFilePath) throws IOException {
        try (ApkFile apkFile = new ApkFile(apkFilePath)) {
            return apkFile.getManifestXml();
        }
    }
1372515
public static List<?> xls2List(String xmlPath, InputStream inputStream) throws Exception {
        Workbook wb = null;
        List<?> list = null;
        try {
            wb = Workbook.getWorkbook(inputStream);
            list = workbook2List(xmlPath, wb);
        } catch (Exception e) {
            throw new Exception("转换xls出错:" + e.getMessage());
        } finally {
            if (wb != null) {
                wb.close();
            }
        }
        return list;
    }
207246
public static umich.ms.fileio.filetypes.mzidentml.jaxb.standard.MzIdentMLType parse(Path path)
      throws FileParsingException {
    try {
      XMLStreamReader xsr = JaxbUtils.createXmlStreamReader(path, false);
      umich.ms.fileio.filetypes.mzidentml.jaxb.standard.MzIdentMLType mzIdentMLType = JaxbUtils
          .unmarshal(umich.ms.fileio.filetypes.mzidentml.jaxb.standard.MzIdentMLType.class, xsr);
      return mzIdentMLType;
    } catch (JAXBException e) {
      throw new FileParsingException(
          String.format("JAXB parsing of MzIdentML file failed (%s)",
              path.toAbsolutePath().toString()), e);
    }
  }
930134
public static InputStream loadFile(String filePath) {

        InputStream in = null;

        try {

            // 先用TOMCAT模式进行导入
            in = ClassLoaderUtil.getLoader().getResourceAsStream(filePath);
            if (in == null) {

                // 使用普通模式导入
                try {

                    return new FileInputStream(filePath);

                } catch (FileNotFoundException e) {
                    return null;
                }
            } else {

                return in;
            }

        } finally {

            if (in != null) {
                try {
                    in.close();
                } catch (IOException e) {
                    LOGGER.error("WHY HERE!", e);
                }
            }
        }
    }
259121
public String exportToHtml(String filePath, String fileName) {
        return OptionUtil.exportToHtml(this, filePath, fileName);
    }
1170133
private static String getValueOfTagInXMLFile( String filePath, String tagName )
	throws ParserConfigurationException, SAXException, IOException {

		File fXmlFile = new File(filePath);
		DocumentBuilderFactory dbFactory = DocumentBuilderFactory.newInstance();
		DocumentBuilder dBuilder = dbFactory.newDocumentBuilder();
		Document doc = dBuilder.parse(fXmlFile);

		// Optional, but recommended
		// Read this: http://stackoverflow.com/questions/13786607/normalization-in-dom-parsing-with-java-how-does-it-work
		doc.getDocumentElement().normalize();

		NodeList nList = doc.getElementsByTagName(tagName);
		String valueOfTagName = "";

		for (int temp = 0; temp < nList.getLength(); temp++) {
			Node nNode = nList.item(temp);
			valueOfTagName = nNode.getTextContent();
		}

		return valueOfTagName;
	}
699247
public static NodeList evaluateXpathExpression(String domStr, String xpathExpr)
			throws XPathExpressionException, IOException {
		Document dom = DomUtils.asDocument(domStr);
		return evaluateXpathExpression(dom, xpathExpr);
	}
87945
public boolean parseXmlFlash(Path ttmlFilePath) {
        boolean ret;
        try {
            final DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance();
            dbf.setNamespaceAware(true);

            final DocumentBuilder db = dbf.newDocumentBuilder();
            doc = db.parse(ttmlFilePath.toFile());

            //Check that we have TTML v1.0 file as we have tested only them...
            final NodeList metaData = doc.getElementsByTagName("tt");
            final NodeList colorNote = doc.getElementsByTagName("style");
            if (metaData != null) {
                final Node node = metaData.item(0);

                if (node.hasAttributes()) {
                    // retrieve the begin and end attributes...
                    final NamedNodeMap attrMap = node.getAttributes();
                    final Node xmlns = attrMap.getNamedItem("xmlns");
                    if (xmlns != null) {
                        final String s = xmlns.getNodeValue();
                        if (!s.equals("http://www.w3.org/2006/04/ttaf1")
                                && !s.equals("http://www.w3.org/ns/ttml")) {
                            throw new Exception("Unknown TTML file version");
                        }
                    }
                } else {
                    throw new Exception("Unknown File Format");
                }
            } else {
                throw new Exception("Unknown File Format");
            }
            if (colorNote != null) {
                if (colorNote.getLength() == 0) {
                    this.color = "#FFFFFF";
                } else {
                    final Node node = colorNote.item(0);

                    if (node.hasAttributes()) {
                        // retrieve the begin and end attributes...
                        final NamedNodeMap attrMap = node.getAttributes();
                        final Node col = attrMap.getNamedItem("tts:color");
                        if (col != null) {
                            if (!col.getNodeValue().isEmpty()) {
                                this.color = col.getNodeValue();
                            }
                        }
                    } else {
                        throw new Exception("Unknown File Format");
                    }
                }
            } else {
                throw new Exception("Unknown File Format");
            }
            buildFilmListFlash();
            ret = true;
        } catch (Exception ex) {
            //Log.errorLog(46231470, ex, "File: " + ttmlFilePath);
            Log.errorLog(46231470, new String[]{ex.getLocalizedMessage(), "File: " + ttmlFilePath});
            ret = false;
        }
        return ret;
    }
300838
public XMLResource xml(JSONPathQuery path) throws Exception {
		Object jsonValue = path.eval(this);
		return xml(jsonValue.toString());
	}
486126
public static String getRdfaAttributes(I_CmsXmlDocument document, Locale contentLocale, String elementPath) {

        I_CmsXmlSchemaType schemaType = document.getContentDefinition().getSchemaType(elementPath);
        if (schemaType != null) {
            String path = "";
            if (elementPath.contains("/")) {
                path += "/" + removePathIndexes(elementPath.substring(0, elementPath.lastIndexOf("/")) + ":");
            }
            path += getTypeUri(schemaType.getContentDefinition()) + "/" + elementPath;
            return String.format(
                RDFA_ATTRIBUTES,
                CmsContentDefinition.uuidToEntityId(document.getFile().getStructureId(), contentLocale.toString()),
                path);
        } else {
            return "";
        }
    }
1370282
private Response browseRepository(final Node node, final String mavenPath, final String gadget) throws IOException
   {

      final PipedOutputStream po = new PipedOutputStream();
      final PipedInputStream pi = new PipedInputStream(po);
      new Thread()
      {
         @Override
         @SuppressWarnings("unchecked")
         public void run()
         {
            try
            {
               XMLOutputFactory factory = XMLOutputFactory.newInstance();
               // name spaces
               factory.setProperty(XMLOutputFactory.IS_REPAIRING_NAMESPACES, Boolean.TRUE);
               XMLStreamWriter xsw = factory.createXMLStreamWriter(po, Constants.DEFAULT_ENCODING);
               xsw.writeStartDocument(Constants.DEFAULT_ENCODING, "1.0");
               xsw.writeDTD("<!DOCTYPE html PUBLIC \"-//W3C//DTD XHTML 1.0 Strict//EN\" "
                  + "\"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd\">");
               xsw.writeCharacters("\n");
               if (gadget == null || !gadget.equalsIgnoreCase("true"))
               {
                  xsw.writeStartElement("html");
                  xsw.writeDefaultNamespace(XHTML_NS);
                  xsw.writeStartElement("head");
                  xsw.writeStartElement("style");
                  xsw.writeAttribute("type", "text/css");
                  xsw.writeCharacters("a {text-decoration: none; color: #10409C; }"
                     + "a:hover {text-decoration: underline;}" + ".centered { text-align: center; }"
                     + ".underlined { border-bottom : 1px solid #cccccc;  font-weight: bold;  text-align: center; }\n");
                  xsw.writeEndElement(); // style
                  xsw.writeStartElement("title");
                  xsw.writeCharacters("Maven2 Repository Browser");
                  xsw.writeEndElement(); // title
                  xsw.writeEndElement(); // head
               }
               xsw.writeStartElement("body");
               //
               xsw.writeStartElement("h2");
               xsw.writeAttribute("class", "centered");
               xsw.writeCharacters("Maven2 Repository");
               xsw.writeEndElement();
               //
               xsw.writeStartElement("table");
               xsw.writeAttribute("width", "90%");
               xsw.writeAttribute("style", "table-layout:fixed;");
               // table header
               xsw.writeStartElement("tr");
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "underlined");
               xsw.writeAttribute("width", "7%");
               xsw.writeEndElement(); // th
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "underlined");
               xsw.writeCharacters("name");
               xsw.writeEndElement(); // th
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "underlined");
               xsw.writeAttribute("width", "18%");
               xsw.writeCharacters("media-type");
               xsw.writeEndElement(); // th
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "underlined");
               xsw.writeAttribute("width", "15%");
               xsw.writeCharacters("size");
               xsw.writeEndElement(); // th
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "underlined");
               xsw.writeAttribute("width", "18%");
               xsw.writeCharacters("last modified");
               xsw.writeEndElement(); // th
               xsw.writeEndElement(); // tr
               // end table header

               // parent href
               String parent = mavenPath.substring(0, mavenPath.lastIndexOf('/'));
               xsw.writeStartElement("td");
               xsw.writeAttribute("class", "parenticon");
               xsw.writeEndElement();// td

               xsw.writeStartElement("td");
               xsw.writeStartElement("a");
               xsw.writeAttribute("href", parent + "?view=true&gadget=" + gadget);
               xsw.writeCharacters("..");
               xsw.writeEndElement(); // a
               xsw.writeEndElement(); // td
               xsw.writeEmptyElement("td");
               xsw.writeEmptyElement("td");
               xsw.writeEmptyElement("td");

               // NodeIterator nodes = node.getNodes();
               EntityCollection nodes = (EntityCollection)node.getNodes();
               Collections.sort(nodes.getList(), NODE_COMPARATOR);
               while (nodes.hasNext())
               {
                  Node node = nodes.nextNode();
                  xsw.writeStartElement("tr");
                  if (RESTArtifactLoaderService.isFile(node))
                  {
                     if (node.getName().endsWith("sha1"))
                        continue;
                     NodeRepresentation nodeRepresentation =
                        nodeRepresentationService.getNodeRepresentation(node, null);
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "fileicon");
                     xsw.writeEndElement();// td

                     xsw.writeStartElement("td");
                     xsw.writeAttribute("style", "font-style: italic;");
                     xsw.writeStartElement("a");
                     xsw.writeAttribute("href", (mavenPath.endsWith("/") ? mavenPath + node.getName() : mavenPath + "/"
                        + node.getName())
                        + "?view=true&gadget=" + gadget);
                     xsw.writeCharacters(node.getName());
                     xsw.writeEndElement(); // a
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters(nodeRepresentation.getMediaType());
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters("" + nodeRepresentation.getContentLenght());
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters(new Date(nodeRepresentation.getLastModified()).toString());
                     xsw.writeEndElement(); // td
                  }
                  else
                  {
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "foldericon");
                     xsw.writeEndElement();// td
                     xsw.writeStartElement("td");
                     xsw.writeStartElement("a");
                     xsw.writeAttribute("href", (mavenPath.endsWith("/") ? mavenPath + node.getName() : mavenPath + "/"
                        + node.getName())
                        + "?view=true&gadget=" + gadget);
                     xsw.writeCharacters(node.getName());
                     xsw.writeEndElement(); // a
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters("-");
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters("-");
                     xsw.writeEndElement(); // td
                     xsw.writeStartElement("td");
                     xsw.writeAttribute("class", "centered");
                     xsw.writeCharacters("-");
                     xsw.writeEndElement(); // td
                  }
                  xsw.writeEndElement(); // tr
               }

               xsw.writeStartElement("tr");
               xsw.writeEndElement();

               xsw.writeEndElement(); // table
               xsw.writeEndElement(); // body
               if (gadget == null || !gadget.equalsIgnoreCase("true"))
               {
                  xsw.writeEndElement(); // html
               }

               xsw.writeEndDocument();
            }
            catch (XMLStreamException xmle)
            {
               LOG.error(xmle.getLocalizedMessage(), xmle);
            }
            catch (RepositoryException re)
            {
               LOG.error(re.getLocalizedMessage(), re);
            }
            finally
            {
               try
               {
                  po.flush();
                  po.close();
               }
               catch (IOException e)
               {
                  LOG.error(e.getLocalizedMessage(), e);
               }
            }
         }
      }.start();

      // application/xhtml+xml content type is recommended for XHTML, but IE6
      // does't support this.
      return Response.ok(pi, "text/html").build();

   }