/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ /* * This file is part of the LibreOffice project. * * This Source Code Form is subject to the terms of the Mozilla Public * License, v. 2.0. If a copy of the MPL was not distributed with this * file, You can obtain one at http://mozilla.org/MPL/2.0/. * * This file incorporates work covered by the following license notice: * * Licensed to the Apache Software Foundation (ASF) under one or more * contributor license agreements. See the NOTICE file distributed * with this work for additional information regarding copyright * ownership. The ASF licenses this file to you 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 .
*/
// For backwards compatibility, the nRequirements flag word is // read/written as potentially signed hexadecimal number (though that has no // practical relevance given that it has only one flag with value 0x01 // defined).
usingnamespace osl; namespace jfw
{
static OString getElement(OString const & docPath,
xmlChar const * pathExpression)
{ //Prepare the xml document and context
OSL_ASSERT(!docPath.isEmpty());
jfw::CXmlDocPtr doc(xmlParseFile(docPath.getStr())); if (doc == nullptr) throw FrameworkException(
JFW_E_ERROR, "[Java framework] Error in function getElement (elements.cxx)"_ostr);
jfw::CXPathContextPtr context(xmlXPathNewContext(doc)); if (xmlXPathRegisterNs(context, reinterpret_cast<xmlChar const *>("jf"), reinterpret_cast<xmlChar const *>(NS_JAVA_FRAMEWORK)) == -1) throw FrameworkException(
JFW_E_ERROR, "[Java framework] Error in function getElement (elements.cxx)"_ostr);
CXPathObjectPtr pathObj = xmlXPathEvalExpression(pathExpression, context);
OString sValue; if (xmlXPathNodeSetIsEmpty(pathObj->nodesetval))
{ throw FrameworkException(
JFW_E_ERROR, "[Java framework] Error in function getElement (elements.cxx)"_ostr);
}
sValue = reinterpret_cast<char*>(pathObj->nodesetval->nodeTab[0]->content); return sValue;
}
NodeJava::NodeJava(Layer layer):
m_layer(layer)
{ //This class reads and write to files which should only be done in //application mode if (getMode() == JFW_MODE_DIRECT) throw FrameworkException(
JFW_E_DIRECT_MODE, "[Java framework] Trying to access settings files in direct mode."_ostr);
}
void NodeJava::load()
{ static constexpr OString sExcMsg("[Java framework] Error in function NodeJava::load" "(elements.cxx)."_ostr); if (SHARED == m_layer)
{ //we do not support yet to write into the shared installation
//check if shared settings exist at all.
OUString sURL(BootParams::getSharedData());
jfw::FileStatus s = sURL.isEmpty()
? FILE_DOES_NOT_EXIST : checkFileURL(sURL); if (s == FILE_INVALID) throw FrameworkException(
JFW_E_ERROR, "[Java framework] Invalid file for shared Java settings."_ostr); elseif (s == FILE_DOES_NOT_EXIST) //Writing shared data is not supported yet. return;
} elseif (USER == m_layer)
{ if (!prepareSettingsDocument())
{
SAL_INFO("jfw.level1", "no path to load user settings document from"); return;
}
} else
{
OSL_FAIL("[Java framework] Unknown enum used.");
}
//Read the user elements
OString sSettingsPath = getSettingsPath(); //There must not be a share settings file
CXmlDocPtr docUser(xmlParseFile(sSettingsPath.getStr())); if (docUser == nullptr) throw FrameworkException(JFW_E_ERROR, sExcMsg);
xmlNode * cur = xmlDocGetRootElement(docUser); if (cur == nullptr || cur->children == nullptr) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//set the <enabled> element //The element must exist if (m_enabled)
{
pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>("/jf:java/jf:enabled"),
contextUser); if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval)) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//set the <userClassPath> element //The element must exist if (m_userClassPath)
{
pathObj = xmlXPathEvalExpression(reinterpret_cast<xmlChar const *>("/jf:java/jf:userClassPath"),
contextUser); if ( ! pathObj || xmlXPathNodeSetIsEmpty(pathObj->nodesetval)) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//remove option elements
xmlNode* cur = vmParameters->children; while (cur != nullptr)
{
xmlNode* lastNode = cur;
cur = cur->next;
xmlUnlinkNode(lastNode);
xmlFreeNode(lastNode);
} //add a new line after <vmParameters> if (!m_vmParameters->empty())
{
xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(vmParameters, nodeCrLf);
}
for (autoconst & vmParameter : *m_vmParameters)
{
xmlNewTextChild(vmParameters, nullptr, reinterpret_cast<xmlChar const *>("param"),
CXmlCharPtr(vmParameter)); //add a new line
xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(vmParameters, nodeCrLf);
}
}
//remove option elements
xmlNode* cur = jreLocationsNode->children; while (cur != nullptr)
{
xmlNode* lastNode = cur;
cur = cur->next;
xmlUnlinkNode(lastNode);
xmlFreeNode(lastNode);
} //add a new line after <vmParameters> if (!m_JRELocations->empty())
{
xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(jreLocationsNode, nodeCrLf);
}
for (autoconst & JRELocation : *m_JRELocations)
{
xmlNewTextChild(jreLocationsNode, nullptr, reinterpret_cast<xmlChar const *>("location"),
CXmlCharPtr(JRELocation)); //add a new line
xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(jreLocationsNode, nodeCrLf);
}
}
if (xmlSaveFormatFile(sSettingsPath.getStr(), docUser, 1) == -1) throw FrameworkException(JFW_E_ERROR, sExcMsg);
}
void NodeJava::addJRELocation(OUString const & sLocation)
{ if (!m_JRELocations)
m_JRELocations = std::optional<std::vector<OUString> >(
std::vector<OUString> ()); //only add the path if not already present
std::vector<OUString>::const_iterator it =
std::find(m_JRELocations->begin(), m_JRELocations->end(), sLocation); if (it == m_JRELocations->end())
m_JRELocations->push_back(sLocation);
}
jfw::FileStatus NodeJava::checkSettingsFileStatus(OUString const & sURL)
{
jfw::FileStatus ret = FILE_DOES_NOT_EXIST;
//check the file time
::osl::DirectoryItem item;
File::RC rc = ::osl::DirectoryItem::get(sURL, item); if (File::E_None == rc)
{
::osl::FileStatus stat(osl_FileStatus_Mask_Validate);
File::RC rc_stat = item.getFileStatus(stat); if (File::E_None == rc_stat)
{
ret = FILE_OK;
} elseif (File::E_NOENT == rc_stat)
{
ret = FILE_DOES_NOT_EXIST;
} else
{
ret = FILE_INVALID;
}
} elseif(File::E_NOENT == rc)
{
ret = FILE_DOES_NOT_EXIST;
} else
{
ret = FILE_INVALID;
} return ret;
}
bool NodeJava::createSettingsDocument() const
{ const OUString sURL = getSettingsURL(); if (sURL.isEmpty())
{ returnfalse;
} //make sure there is a user directory
OString sExcMsg("[Java framework] Error in function createSettingsDocument " "(elements.cxx)."_ostr); // check if javasettings.xml already exist if (FILE_OK == checkSettingsFileStatus(sURL)) returntrue;
//make sure that the directories are created in case they do not exist
FileBase::RC rcFile = Directory::createPath(getDirFromFile(sURL)); if (rcFile != FileBase::E_EXIST && rcFile != FileBase::E_None) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//javasettings.xml does not exist yet
CXmlDocPtr doc(xmlNewDoc(reinterpret_cast<xmlChar const *>("1.0"))); if (! doc) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//Create the root element and name spaces
xmlNodePtr root = xmlNewDocNode(
doc, nullptr, reinterpret_cast<xmlChar const *>("java"), reinterpret_cast<xmlChar const *>("\n"));
if (root == nullptr) throw FrameworkException(JFW_E_ERROR, sExcMsg);
//Create a comment
xmlNodePtr com = xmlNewComment( reinterpret_cast<xmlChar const *>("This is a generated file. Do not alter this file!")); if (com == nullptr) throw FrameworkException(JFW_E_ERROR, sExcMsg);
if (xmlAddPrevSibling(root, com) == nullptr) throw FrameworkException(JFW_E_ERROR, sExcMsg);
while (cur != nullptr)
{ if (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("vendor")) == 0)
{
CXmlCharPtr xmlVendor = xmlNodeListGetString(
pDoc, cur->children, 1); if (! xmlVendor) return;
sVendor = xmlVendor;
} elseif (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("location")) == 0)
{
CXmlCharPtr xmlLocation = xmlNodeListGetString(
pDoc, cur->children, 1);
sLocation = xmlLocation;
} elseif (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("version")) == 0)
{
CXmlCharPtr xmlVersion = xmlNodeListGetString(
pDoc, cur->children, 1);
sVersion = xmlVersion;
} elseif (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("requirements")) == 0)
{
CXmlCharPtr xmlRequire = xmlNodeListGetString(
pDoc, cur->children, 1);
OUString sRequire = xmlRequire;
nRequirements = sRequire.toInt64(16); #ifdef MACOSX //javaldx is not used anymore in the mac build. In case the Java //corresponding to the saved settings does not exist anymore the //javavm services will look for an existing Java after creation of //the JVM failed. See stoc/source/javavm/javavm.cxx. Only if //nRequirements does not have the flag JFW_REQUIRE_NEEDRESTART the //jvm of the new selected JRE will be started. Old settings (before //OOo 3.3) still contain the flag which can be safely ignored.
nRequirements &= ~JFW_REQUIRE_NEEDRESTART; #endif
} elseif (xmlStrcmp(cur->name, reinterpret_cast<xmlChar const *>("vendorData")) == 0)
{
CXmlCharPtr xmlData = xmlNodeListGetString(
pDoc, cur->children, 1);
xmlChar* _data = static_cast<xmlChar*>(xmlData); if (_data)
{
rtl::ByteSequence seq(reinterpret_cast<sal_Int8*>(_data), strlen(reinterpret_cast<char*>(_data)));
arVendorData = decodeBase16(seq);
}
}
cur = cur->next;
}
if (sVendor.isEmpty())
m_bEmptyNode = true; //Get the javainfo attributes
CXmlCharPtr sVendorUpdate = xmlGetProp(pJavaInfo, reinterpret_cast<xmlChar const *>("vendorUpdate")); if ( ! sVendorUpdate) throw FrameworkException(JFW_E_ERROR, sExcMsg);
sAttrVendorUpdate = sVendorUpdate;
}
//Set xsi:nil in javaInfo element to false //the xmlNs pointer must not be destroyed
xmlNs* nsXsi = xmlSearchNsByHref(pDoc,
pJavaInfoNode, reinterpret_cast<xmlChar const *>(NS_SCHEMA_INSTANCE));
//Delete the children of JavaInfo
xmlNode* cur = pJavaInfoNode->children; while (cur != nullptr)
{
xmlNode* lastNode = cur;
cur = cur->next;
xmlUnlinkNode(lastNode);
xmlFreeNode(lastNode);
}
//If the JavaInfo was set with an empty value, //then we are done. if (m_bEmptyNode) return;
//add a new line after <javaInfo>
xmlNode * nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the vendor element
xmlNewTextChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("vendor"),
CXmlCharPtr(sVendor)); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the location element
xmlNewTextChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("location"),
CXmlCharPtr(sLocation)); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the version element
xmlNewTextChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("version"),
CXmlCharPtr(sVersion)); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the features element, for backwards compatibility (it used to support one flag // JFW_FEATURE_ACCESSBRIDGE = 0x01, but is ignored and always written as zero now)
xmlNewTextChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("features"), reinterpret_cast<xmlChar const *>("0")); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the requirements element
OUString sRequirements = OUString::number(
nRequirements, 16);
xmlNewTextChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("requirements"),
CXmlCharPtr(sRequirements)); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
//Create the vendorData element
rtl::ByteSequence data = encodeBase16(arVendorData);
xmlNode* dataNode = xmlNewChild(pJavaInfoNode, nullptr, reinterpret_cast<xmlChar const *>("vendorData"), reinterpret_cast<xmlChar const *>(""));
xmlNodeSetContentLen(dataNode, reinterpret_cast<xmlChar*>(data.getArray()), data.getLength()); //add a new line for better readability
nodeCrLf = xmlNewText(reinterpret_cast<xmlChar const *>("\n"));
xmlAddChild(pJavaInfoNode, nodeCrLf);
}
std::unique_ptr<JavaInfo> CNodeJavaInfo::makeJavaInfo() const
{ if (bNil || m_bEmptyNode) return std::unique_ptr<JavaInfo>(); return std::unique_ptr<JavaInfo>( new JavaInfo{
sVendor, sLocation, sVersion, nRequirements,
arVendorData});
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.